If you haven't read part 1 of the scripting guide, then
please read it
For these tutorials to work, you should use either FPSC
v1.19 or
v1.20 (recommended)
Variables are basically strings (pieces of text) that hold values. For example, you could make a script that works together with another script by using variables. The first script would maybe set variable "playerstoodhere" to "1" and then the other script would check if it was 1, and if it was it would then do something. You can however make it so that a variable can only be read and edited by one entity by setting it as local.
NOTE: I will not be covering using variables without varnames.
eg setvar=HasKey,addvar=1
I will not be covering setup vars either
NOTE: You must have "Full Shader Effects" on in preferences and PostProcessing set to 1 in setup.ini for the script to look right.
First off, I'll tell you the conditions that you use for variables:
VarEqual=X Y -- Checks whether variable X is equal to Y
VarGreater=X Y -- Checks whether variable X's value is larger than Y
VarLess=X Y -- Checks whether variable X's value is less than Y
VarNotEqual=X Y -- Checks whether variable X is not equal to Y
And now the actions:
AddVar=X Y -- Adds Y to variable X's value
Cos=X Y -- Sets variable X to the cosine of Y degrees
DimLocalVar=X -- Sets variable X to local, this means that only the current entity can edit and read this variable
DimVar=X -- Sets variable X to global, this can be read and edited by any entity
DivVar=X Y -- Divides variable X by Y
ModVar=X Y -- Performs a modulus operation on variable X. This command is similar to the WrapVar action, but instead you can define the wrap around point with Y
MulVar=X Y -- Multiplies variable X by Y
SetVar=X Y -- Sets variable X's value to Y
SetVarRnd=X Y -- Sets variable X to a random number between 0 and Y
Sin=X Y -- This sets variable X to the sine of Y degrees
SubVar=X Y -- This subtracts Y from variable X's value
WrapVar=X -- This performs a modulus operation of variable X by 360
AddRawVar=X -- This adds variable X's value to the currently displayed on-screen text that is displayed by "FPGCRawText"
Next up are the internal variables, these are set by FPSC, and some can be modified. These hold things like the location of the current entity, or the player's health etc. For example, to set the camera angle on the X axis to 90, you would go SetVar=$CAX 90
$PH – Player’s health
$PL – Player’s lives
$RA – Player’s total ammo in right-hand
$A - Player’s total ammo
$RCA - Player’s ammo in right-hand gun
$CA - Player’s ammo in gun
$EH - Entity’s health
$EA - Entity’s ammo in gun (there is no total ammo for entities as they have unlimited ammo)
$EPX - Entity’s position in x-axis
$EPY - Entity’s position in y-axis
$EPZ - Entity’s position in z-axis
$EAX - Entity’s angle around x-axis
$EAY - Entity’s angle around y-axis
$EAZ - Entity’s angle around z-axis
$CPX - Camera’s position in x-axis
$CPY - Camera’s position in y-axis
$CPZ - Camera’s position in z-axis
$CAX - Camera’s angle around x-axis
$CAY - Camera’s angle around y-axis
$CAZ - Camera’s angle around z-axis
$MMX – Mouse movement in x direction
$MMY – Mouse movement in y direction
$AIR – Amount of air, or air level
$ARM – Amount of armour, or armour level
$DIF – Distance from player in feet (read-only)
$DIM – Distance from player in meters (read-only)
$DIS – The distance between the entity and the player (read only)
$FPS – Frame rate (read-only)
$MAX – Number of weapon slots
$WAT – Water height
NOTE: If a variable is "read-only", you cannot modify it.
For this tutorial, we will make a script for a "key". This key will be a poisonous object, that will poison the player, make them drop all of their weapons, lower their health to 10 and make the view all weird. Plus an optional motionsickness effect.
To start off, we'll begin with the default script:
;Artificial Intelligence Script
;Header
desc = Description of your script
;Triggers
;End of Script
First off, we want to set all of our required variables:
:state=0:state=1,DimVar=Active,SetVar=Active 0
Now we want to set it so that if the player touches the object (basically if you're within 40% of a segment of the object), it will be picked up, and Active will be set to 1
:VarEqual=Active 0,PlrDistWithin=40:PlayerTake,ColOff,SetVar=Active 1
Once this is done, we want to make all that cool stuff happen when Active is 1
:VarEqual=Active 1,State=1:State=2,SetVar=$PH 10
:VarEqual=Active 1:RemoveCurrentWeapon,CamFov=50,CamShake=50
Now for the optional "motion sickness" effect:
:VarEqual=Active 1,State=2:State=3,SetPostEffect=motionsickness
So your script should look something like this:
;Artificial Intelligence Script
;Header
desc = Poisonous Object
;Triggers
;Set Variables
:state=0:state=1,DimVar=Active,SetVar=Active 0
;Player Picks Up Object
:VarEqual=Active 0,PlrDistWithin=40:PlayerTake,ColOff,SetVar=Active 1
;Poisonous Effects
:VarEqual=Active 1,State=1:State=2,SetVar=$PH 10
:VarEqual=Active 1:RemoveCurrentWeapon,CamFov=50,CamShake=50
;MotionSickness
:VarEqual=Active 1,State=2:State=3,SetPostEffect=motionsickness
;End of Script
Now let me explain a few of the commands:
CamFov=X -- Sets the field-of-vision of the player to X
RemoveCurrentWeapon -- Removes the current weapon the player is using
CamShake=X -- Shakes the camera with a strength of X
PlayerTake -- Makes the player take the object
And you're done! Assign this script to an object and watch how your player becomes poisoned!
-TZK