I think it's about time I popped in to see if there's anything I could help with. Sorry I didn't come sooner; I got a little carried away playing with DAI scripts and watching player-neutral teams kill each other like crazy
Since there seems to be confustion on the HL2 Medkits, let me post my own and explain what I did:
;Artificial Intelligence Script
;Header
;By Captain Coder
desc = Script request | Half-Life 2 Medkit - will give player upto 100 health
;Triggers
:state=0:dimlocalvar=healthgiven,setvar=healthgiven 0,state=1
:state=1,plrdistwithin=40,inview=1,varless=healthgiven 100,plrhealthless=500:state=2,etimerstart
:state=2,etimergreater=100:plraddhealth=1,addvar=healthgiven 1,state=1
;End of Script
So, in state 0, I declared a variable named "healthgiven" that can only be accessed by the script that declared the variable. This allows you to have lots of kits running the same script without sucking health out all of them at once
. I also set "healthgiven" to 0. This variable will count how many points of health the player takes. Then we move on to state 1.
In state 1, the script first checks to see if the player is within 40 FPSC units. 1 FPSC unit is about 1 inch in the real world, so I thought 3 and a half feet was a reasonably realistic distance. Then the script checks to see if the the medkit is in the players view. This makes sense, as it would seem rather odd if the player was able to soak up juice while his hands were busy in combat
. Then we check to see if our "healthgiven" variable is less than 101 points (if we say 100 then the player will only get 99 points, because the variable is only checking to see if the variable has less than 100 points, not less than
or equal to). If it is less than 101, then the script checks to see if the player even needs any health. Finally, if the script passes all of these tests, then we move onto state 2, and we start an entity timer.
In state 2, we check to see if the entity timer is greater than 100. Entity and normal timers measure in milliseconds, so 100 milliseconds = 1/10 of a second. Then we go straight to actions. We first give the player 1 point of sweet wonderful goodness. Then we add one point to our "healthgiven" variable. Then we go back to state 1, and it all repeats.
Here is a second script, in this one the player must press the "Use" key in order to get health:
;Artificial Intelligence Script
;Header
;By Captain Coder
desc = Script request | Half-Life 2 Medkit V2 - will give player upto 100 health
;Triggers
:state=0:dimvar=healthgiven,setvar=healthgiven 0,state=1
:state=1,plrdistwithin=40,inview=1,varless=healthgiven 101,plrhealthless=500,plrusingaction=1:state=2,etimerstart
:state=2,etimergreater=100:plraddhealth=1,addvar=healthgiven 1,state=1
;End of Script
I hope I didn't ruin it for you
Merry Christmas!
Captain Coder
EDIT:
Sorry,
Skeeter, just saw how you said you didn't understand what states were used for; let me try to quickly explain it.
States are basically used to control what happens and when. The state always equals 0 when an entity is spawned until it is told to go to another state.
Let's look at a simple script:
:state=0,plrdistwithin=40:state=1
:state=1:activateifused=1,state=2
In this script, as soon as the object is spawned, it will check to see if the player is within 40 units. As soon as the player is within 40 units, it will go to state 1. However, it will not go to state 1
until the player is within 40 units. When the script reaches state 1, it activates what ever entity is within the "If Used" space in the entity's properties. However, it will only activate the entity if it is at state 1. The script will not reach state 1 unless the player stands within 40 units. The last part, state=2, is just a little thing scripters like to add to save a teeny-tiny bit of FPS. However, I suspect that this might cause bugs in executable games, especially when loading a saved game. I have yet to prove this though. Did all that make sense?
As a believer in Jesus Christ, I am trying to use my passion for game creation for His glory.