BASIC SCRIPTING
By RED
This tutorial is aimed at getting you started at basic scripting.
Ok where to begin !
Well first you need to know what u are aiming to do, in this tutorial we are
going to make a Artillery Script which will fire Artillery rounds at a Area of
the map (Targeted with a marker and activated with a trigger radio Alpha)
The first thing i am going to do is show you the script and how to use it, then give you the explination. this may sound irregualr but i find i learn better this way.
this is the script :
_Centre = _this select 0
_area = _this select 1
_shells _this select 2
_CentrePos = GetMarkerPos _Centre
_xco = _CentrePos select 0
_yco = _CentrePos select 1
_zco = _CentrePos select 2
_areaX2 = _area * 2
~2
titletext ["\n\n\n\n\n\n\nTake cover !","plain", 2]
~2
_a = _shells
#start
_bomb1 = "grenade" camCreate [_xco + Random(_areaX2) - _area,_yco +
Random(_areaX2) - _area,_zco + 150]
~1
_bomb2 = "grenade" camCreate [_xco + Random(_areaX2) - _area,_yco + Random(_areaX2) - _area,_zco + 150]
_a= _shells - 1
?(_a > 0) : goto "start"
Exit
You put this script into a .SQS file you make this kind of file in notepad.
When in notepad just copy and paste the script above in. Then click save as, name it "art.sqs" then change the box below from text file, to all files (*.*).
You now have the script in the sqs file but you need to make the game activate that script for it to work.
So first make a new mission in the editor (desert island). now save it as
"artytest", now go into the directory you saved the sqs file and copy
it into the missions folder, (default dir should be : C:\Program Files\Codemasters\OperationFlashpoint\
Users\username\missions\artytest.Intro) then just paste the sqs file into that
directory.
["art",20,10] exec "art.sqs"
now go into preview mode and it should activate the Artillery script and bombs should drop on the marker you placed when you press (0,0,1) to radio Alpha.
Explination of script.
"_Centre = _this select 0
_area = _this select 1
_shells = _this select 2"
these lines here state that, they create a block of data called "_Center" and so on, and it gets the info that goes in it by "= _this select 0" it gets the value of this from the trigger's onactivation feild because it has "_this select 0" which asks for the first value in ["art",20,10] exec "art.sqs" which is "art" and if it says _this select 1 its value would then be 20.
_CentrePos = GetMarkerPos _Centre this gets the posistion of the marker called art which is stored in _center (from last step).
note : there is also the getpos command but this is only used for units and not markers.
_xco = _CentrePos select 0
_yco = _CentrePos select 1
_zco = _CentrePos select 2
This gets the X,Y,Z co-ordinates of the marker.
_areaX2 = _area * 2
This just times the value area by 2 and stors the result in _areaX2.
~2
this just waits for 2 seconds, ie. ~1 is one second, ~3 is 3 seconds etc.
titletext ["\n\n\n\n\n\n\nTake cover !","plain", 2]
This will display the text "Take cover !" the \n just makes the text appear a line lower (new line).
#start
This is a Anchor that can be used to jump to later in the script, with the goto command.
_bomb1 = "grenade" camCreate [_xco + Random(_areaX2) - _area,_yco + Random(_areaX2) - _area,_zco + 150]
~1
_bomb2 = "grenade" camCreate [_xco + Random(_areaX2) - _area,_yco + Random(_areaX2) - _area,_zco + 150]
this creates a grenade called _bomb1 at the X,Y,Z co-ordinates of the marker, but uses the random command to simulate inacusary. it creates the grenade 150 meters above the marker, "_zco + 150"
Then 1 second later it makes another grenade called _bomb2 with the same properties as before, but woun't land in the same place of the first one because of the random command.
_a= _shells - 1
this simply takes 1 away from _a
?(_a > 0) : goto "start"
if the value of _a is bigger that 0 it will just go back to the anchor "start" is it is smaller it wil just move on past it.
Exit
This just states the end of the script.
Well i hope this has held you in some way :)
Tutorial by RED