Posted: 7th Mar 2009 07:47
1. What are the affects of being activated?
2. And what is the relationship between activate and used?
3. How do you activate something?
4. How do you use something?
Just because something is activated doesn't mean something will happen. Its all in the coding. Something with an activation of 0 is still active.
3. How do you activate something?
You need to have an entity (a trigger zone or any dynamic entity (like a switch) that is running a script (a .fpi file). This file is listed in the entities AI scripts main property box.
The script needs to be written to check (listen) for a condition and the condition must be followed by one of the actions below:
:activate=
:activateallinzone=
:activateallinzone
:activateifused=
So, first you need to meet a condition before you can activate something. Common conditions are listed below:
:plrdistwithin=X
:plrdistwithin=X, plrusingaction=1
(any time the gamer presses the ENTER key, plrusingaction =1 when the key is not down, plrusingaction=0)
:plrwithinzone=1
(checks to see if the player is within the trigger zone)
:scancodekeypressed=X
(The "a" key is 30, Reference page 56 of the community guide for a complete list for your keyboard)
Once the condition is met (true) then you need an action. Common actions to activate something are listed below:
:activate=
This will set the activation value of the entity running the script. It can be 0,1,2,3,4,.....
:activateallinzone=X
Well, you need a zone, so probably the entity running this script is a trigger zone entity (TZE). A TZE can have its zone resized (shift+LMB drag). All entities within the zone will have their activation values set to X. It can be 0, 1, 2, 3....
activateallinzone Similr to the one above but there is no X. All activation values (for those in the zone) will be set to 1.
activateifused=X
First you need the name of a different entity. You place this in the IF USED property box of the entity running this script. This other entity will than have an activation value of X (0, 1, 2, 3, ....)
Note 1 The IF USED entity does NOT require the entity running this script to be used (ENTER key) nor does it require the entity mentioned in the IF USED property box to be used. NOTHING needs to be used. Maybe it would be less confusing if the action was re-written :activateLINKEDentity=X and then have the property box renamed to LINKEDentity
Note 2 This can also be used to "deactivate" an entity.
:plrwithinzone=1:activateifused=0
So a much more technical name for this action would be
:setActivationValueOfLinkedEntity=X
likewise
:activate=X would be :setActivationValue=X
So far you made a dynamic entity. You gave it a script. The script was written to check (listen for) a condition to be met. Once that condition was met, either its activation value or another entities activation value was set/changed. You've activated an entity.
But nothing happens! So what if you've changed someones activation value.
1. What are the affects of being activated?
Whatever you want them to be. It all depends on the script. And this script really depends on one condition:
:activated=X
Follow this condition with any action you want.
For example, you have a TZE with 3 lights, all within the zone of the TZE. The TZE is running a main AI script:
:plrwithinzone=1:activateallinzone=7
Now each of the 3 lights also need to be running a ,main AI script:
:activated=7:lightoff (or you could use the action :lighton)
(I believe lightoff is a function call coded in the source engine. I think only lights can call this function. If you put this script as the main AI for a dynamic crate I don't know what would happen.)
Example 2, you have a switch entity running a main AI script:
plrdistwithin=100,plrusingaction=1:activateifused=1
Then you need a door. Give the door a name (REDdoor). Place this name in the switches IF USED property box. And give the door a main ai script that contains:
:state=0,activated=1:state=1,setframe=0
:state=1:incframe=0
:state=1,frameatend=0:state=2,coloff
This plays through animation 0 (the door opens) and turns off the colission. All these actions followed from the :activated=X condition.
4. How do you "use" something?
You just need the entity to have a script that is listening for one condition:
plrusingaction=1
Any time the Enter key is pressed this condition will be true. So, usually you will give a second condition so the action isn't always being triggered everytime the gamer hits enter.
:plrdistwithin=X, plrusingaction=1
Now you can only "use" the entity when you are within X units of it.
5. What is the affect of using something?
Anything you want. Its all in the script, in the actions that follow the condition.
For example, place a dynamic entity that looks like a glass of red water on a desk. Give it a main AI script:
:plrdistwithin=100,plrusingaction=1:plraddhealth=-100
You just made a poison drink.
Usually, the script will also contain some code to let the player know they can "use" this entity.
:state=0:hudreset,hudx=50,hudy=90,hudimagefine=gamecore\text\DRINK_ME.tga,hudname=userprompt,hudhide=1,hudmake=display,state=10
:plrdistwithin=100:hudshow=userprompt,hudfadeout=userprompt
Example 2, place a dynamic entity that looks like a glass of blue water on a different desk (more than 100 units from the first glass). Give it a main AI script:
:plrdistwithin=100,plrusingaction=1:activateifused=1
If you placed the name REDdoor in the IF USED property box of the glass. Then "drinking" / "using" the glass would open the door. Welcome to the Matrix.
2. And what is the relationship between activate and used?
Well, there is no DIRECT connection. But as you see in the example above, you can connect them. Its all in the scripting.
So don't let the :activateifused fool you. Nothing is automatically doing to happen if you activate something or if you use something. Likewise, placing something in the IF USED property box will not automatically activate it when the first entity is "used". Its all in the how you script it.
Entites are not like robots that are either activated (on) or deactivated (off). An active state is no more active than a "deactive" state. You are not turning something on and off. You are setting an Activation Value and then later checking that value.
Additional Note:
the action :activateifusednear=X does not activate the entity (1) by hitting "ENTER" when you are near it. It activates the entity (2) listed in the IF USED property box and other entites (3,4,5) that are near that entity. But I'm really not sure what distance is no longer considered near.
and I believe this action will trigger the condition nearactivatable=1 if the "near entities", entities (3,4,5) have this condition in their main AI script.
Additional Note 2:
Changing the entity's Spawn at Start property box to No will make the entity wait until its activated to spawn. So do this (change it to no) then place a TZE and expand the zone. Place a couple of the late spawning entites within this zone. Then give the TZE a script of :
:state=0,plrwithinzone=1:activateallinzone=1
Whenever you step into this zone. The entities will appear in the zone with you.