Simple Animations
Ok in our first script we will make a simple animated sequence, first download the script example map here. Save it in your "sof\base\maps" folder. In this script we will make a bad guy kick open a door, kill a hostage and then come after you. So firstly open up the blank script, fire up SofRadiant and load the example map. (scriptex.map). For single player maps there are 2 ways to run a script, you can add the key "script" to the worldspawn entity with a value of the script path or you can target a "Script_Runner". For DM maps you can only target a "Script_Runner". The "Script_Runner" entity is very easy to use and there are only 2 main keys to worry about. The first is "targetname" and second is "script", the value for script is simply the path to the script we want to run, in our case "test/test". This path is taken from the "ds" folder being the root directory, so this part isn't needed. If you look at the map you will see several entities, for the moment look at the "m_nyc_mpunk" (punk1), notice in the entity properties that "Trigger_Spawn" is checked. This is just to demonstrate how it works, we would be better in this case if our enemy started off visible in our map. So "Trigger_Spawn" just means that the enemy wont appear until triggered or mentioned in a script. So first we need to declare our variables, add the following lines to the script under the declare section. local entity badguy local entity bumguy local entity door These are the names that we will refer to in our script, now we need to assign the entities to the variables. Add the following lines under assign. badguy = find entity with targetname "punk" bumguyguy = find entity with targetname "bum" door = find entity with targetname "stall_door" This is pretty self explanatory, we are simply setting our variables to point to the relevant entities. Now time for action, so under the action section add use entity badguy Compile the script, and the map and run it to test it out. When you step on the target and press the use key, the badguy should appear in the toilet. The hostage should appear right from the start, as he is not trigger spawned. Now we'll get him to kick open the door, so add the next 4 lines wait 1 seconds animate entity badguy performing action STD_XKICKDOOR_N_A_A use entity door play sound "impact/door/kickdoor.wav" for entity door at volume 0.9 The 1st line just makes the script wait for 1 second. The 2nd line plays the kickdoor animation for our badguy entity. There is a list of animations included in the docs folder of the sdk. Not sure if they all work, and which enemies they apply to. I haven't played with it too much, all I can suggest is that you experiment with them. The next line simply triggers our door, the same as if the player had used it or if we had used a trigger in our map. The 3rd line plays the appropriate sound for the door kicking animation. Compile the script and run the map again, (there is no need to compile the map again, only the script has changed). Now our badguy should appear and kick open the door. Now time for the kill, add the following animate entity badguy performing action RUN by moving [96, 0, 0] animate entity bumguy performing action STD_XAFRAIDSHAKE_N_N_N animate entity badguy performing action STD_F_FWD_S_2 targeting entity bumguy The 1st line moves the badguy by 96 units in the x plane (x,y,z), making him run. 2nd line makes the hostage shake, like a scared baby. 3rd line makes the badguy shoot the bum. STD_F_FWD_S_2= fire shot gun Compile and test it, notice that after the badguy shoots the hostage he just stands there like a lemon. This is because he is still tied to the script. To release him add the following line. animate entity badguy performing action SCRIPT_RELEASE Now if you compile and test it he should start shooting at you after he has killed the hostage Ok if it all works ok move on to tutorial 3. |