Difference between revisions of "Activation Functions"

1,261 bytes added ,  17:55, 11 September 2006
m
no edit summary
imported>Ra5946
imported>Elder
m
Line 1: Line 1:
IN-GAME FUNCTIONS by guidobot101
IN-GAME FUNCTIONS by Guidobot




Line 6: Line 6:


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.
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:
How to set up an in-game function:


1) Copy any object that takes a script (I use Gold001). Rename to, e.g., TargFunction.
1) Copy any object that takes a script (I use Gold001). Rename to, e.g., TargFunction.
Line 18: Line 20:


5) Call this function by simply doing TargFunc01.Activate player 1.
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:
Here is an example of a method that you can call to get the position of the target cross hairs:
CODE




  scn TargFunctionScript
  scn TargFunctionScript
 
  ; initial position vector
  ; initial position vector
  float xPos
  float xPos
Line 68: Line 69:
  set xPos to 5*dx*cos
  set xPos to 5*dx*cos
  set yPos to 5*dy*cos
  set yPos to 5*dy*cos
  set zPos to 118+5*dz
  set zPos to 118-25*(player.IsSneaking)+5*dz
   
   
  End
  End


 
To use this function:
 
To use this function
 
CODE
 


  ; some script
  ; some script
Line 89: Line 85:
  set dy to TargFunc01.dy
  set dy to TargFunc01.dy
  set dz to TargFunc01.dz
  set dz to TargFunc01.dz
IMPORTANT NOTES
It turns out there is a bug that can occur if an in-game function is actively processing when the player enters a new cell. The effect is that the item bearing the script suddenly appears in your inventory as if 'IGFRef.Activate player' was called rather than 'IGFRef.Activate player 1'.
One way to fix this is to pass another actor ref instead of player. However, it depends on what you wish to achieve.
If you really want a static function then your best option is to use a remote static persistent token object - i.e. a true world activator object (e.g. a switch). This has no such issues and has the advantage of being slightly neater call syntax:
IGFActRef.Activate player
(Additionally you do not have to mark the placed IGFRef as initially disabled unless you need it to activate as a sensor for when the player is nearby.)
The disadvantage of this is that the GameMode part of the script will never be that useful since the activator item is remote. If you use items, as described above, you can always teleport them to the player location so they trigger every frame. However, in this case you may be better off using an unplayable item (aka token) on the player and using the OnActivate method or switch it on using globals.




One extra note on Stage functions (as discussed on the CS Wiki).
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.
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
  set x to 10; any value between 0-255
  SetStage MyQuest x
  SetStage MyQuest x


This property can be used to create small linked-lists, stacks, arrays, etc.
This property can be used to create small linked-lists, stacks, arrays, etc.


[[Category: Useful Code]]
[[Category: Useful Code]]
Anonymous user