Activation Functions
IN-GAME FUNCTIONS by guidobot101
This is an alternative to using stage functions.
It relies on the fact that the Activator method can be called on a persistant object at any time and operates immediately.
In-game functions are easier to create. They also do not have the restrictions that Stage functions have and allow for looping code through clever use of the additional GameMode block (using flags, counters, etc.). Additionally, they are an alternative way to add global variables to the game.
How to set up an in-game function:
1) Copy any object that takes a script (I use Gold001). Rename to, e.g., TargFunction. 2) Place a copy somewhere suitable in the world - preferably where you already have something or in your own cell. 3) Mark the object persistant. Mark it Initially Disabled. Give it a suiable name, e.g. TargFunc01. 4) Place a script on the object to do what you want. (See below for a neat example.) 5) Call this function by simply doing TargFunc01.Activate player 1.
Here is an example of a method that you can call to get the position of the target cross hairs:
CODE
scn TargFunctionScript
; initial position vector float xPos float yPos float zPos ; fly vector float dx float dy float dz ; private float ang float x float x2 float sin float cos Begin OnActivate ; horizontal fly vector set ang to player.GetAngle z if ang > 180 set ang to (ang)-360 endif set x to ang*0.0174532925 set x2 to x*x set sin to x*(1-(x2/6)*(1-(x2/20)*(1-(x2/42)*(1-(x2/72)*(1-x2/110))))) set cos to 1-0.5*x2*(1-(x2/12)*(1-(x2/30)*(1-(x2/56)*(1-x2/90)))) set dx to 10*sin set dy to 10*cos ; vertical fly vector set ang to player.GetAngle x set x to -ang*0.0174532925 set x2 to x*x set sin to x*(1-(x2/6)*(1-(x2/20)*(1-(x2/42)*(1-(x2/72)*(1-x2/110))))) set cos to 1-0.5*x2*(1-(x2/12)*(1-(x2/30)*(1-(x2/56)*(1-x2/90)))) set dz to 10*sin ; initial position vector (to add to player coords) set xPos to 5*dx*cos set yPos to 5*dy*cos set zPos to 118+5*dz End
To use this function
CODE
; some script ;... TargFunc01.Activate player 1 set xPos to TargFunc01.xPos+player.GetPos x set yPos to TargFunc01.yPos+player.GetPos y set zPos to TargFunc01.zPos+player.GetPos z set dx to TargFunc01.dx set dy to TargFunc01.dy set dz to TargFunc01.dz
One extra note on Stage functions (as discussed on the CS Wiki).
Apart from being useful in their own right, they have a very nice goto # / call # functionality.
CODE
set x to 10; any value between 0-255 SetStage MyQuest x
This property can be used to create small linked-lists, stacks, arrays, etc.