Young Eagle 0 Posted August 20, 2007 Hello! Can someone please tell me how to use scripts in ArmA step by step? I've got a "choppers.sqs" for better helo formation flying, I created a user mission in editor, then put this "choppers.sqs" into that mission folder, but after I typed command this exec "choppers.sqs" in unit's initialization field, I got an error message. Thanks in advance! Share this post Link to post Share on other sites
Kode 0 Posted August 20, 2007 I think you'll have more succes in the Arma editing section of the forums, troubleshooting is more like in having problems to run/launch/play the game Share this post Link to post Share on other sites
JdB 151 Posted August 20, 2007 I got an error message. It might help if you posted that error message here Share this post Link to post Share on other sites
jasono 0 Posted August 20, 2007 try [this] exec "chopper.sqs". And as Kode pointed out, this would be better in ArmA Editing. Share this post Link to post Share on other sites
Young Eagle 0 Posted August 21, 2007 I got an error message. It might help if you posted that error message here The error message says: 'var= _this |#| select 8' Error select: Type object, expected array, Config entry Quote[/b] ]try [this] exec "chopper.sqs". got similar error message. I tried some tips from the link below, but still no success http://www.flashpoint1985.com/cgi-bin....t=56560 where should I place these custom scripts and how to activate them? Share this post Link to post Share on other sites
tj72 0 Posted August 21, 2007 The problem is that your telling the script to assign var to _this select 8 but there is no array to select from only an object. Like the unit who is calling the script. you have to execute the script with the array like so: [1,2,player] exec chopper.sqs then in the script var = _this select 2 which in this case would be player. So if this script was from somewhere else you need to see how its called up in that mission and create the same conditions for your mission. However it is started in original form is how it has to be here. You cant just take a script that is starting with a specific array as Ive shown above and switch the array to this because the script is missing the variables it needs to work. Share this post Link to post Share on other sites
Young Eagle 0 Posted August 21, 2007 Thanks for the explaination, TJ72! So, as I understand, according to the error message, there should be 8 units including me in the mission? If I want desired number of units in my custom mission, I have to edit the scripts to fit my needs, is that correct? edit* I copied all contents from the "choppers.sqs" script here: Quote[/b] ];Handy tools for choppers by geloxo;Feel free to use the code here on your scripts or modify it but please share the resulting script ;[vehicle, ref path to follow, speed limit, [x,y,z], action waypoint, "action", [x´,y´,z`], "marker", variable] exec "scripts\choppers.sqs" _veh = _this select 0 _ref = _this select 1 _vspeed = _this select 2 ;Relative position correction (for formations) _xoff = (_this select 3) select 0 _yoff = (_this select 3) select 1 _zoff = (_this select 3) select 2 _roff = (_xoff^2 + _yoff^2)^0.5 _Ftheta = _xoff atan2 _yoff ;Relative position correction (for action only) _xact = (_this select 6) select 0 _yact = (_this select 6) select 1 _zact = (_this select 6) select 2 _ract = (_xact^2 + _yact^2)^0.5 _Atheta = _xact atan2 _yact ;Waypoint to start action (select 0 to execute at last waypoint, and 1,2,etc to start at ref unit waypoints) _wpact = _this select 4 _action = _this select 5 ;Action marker position _marker = _this select 7 _mxpos = getmarkerpos _marker select 0 _mypos = getmarkerpos _marker select 1 _msize = (((getmarkersize _marker) select 0)^2 + ((getmarkersize _marker) select 0)^2)^0.5 ;custom variable for action ;"land" = waiting time ;"load" = unit to load ;"unload" = unit to unload ;"supply" = # crates to drop ;"hotlz" = # arty rounds over LZ ;"bombs" = # bombs to drop ;"aagun" = # rounds to fire ;"fire" = weapon type ;"follow" = leader to follow _var = _this select 8 ;Move factor during flight to target ;(100 = aprox 30km/h, 200 = aprox 70km/h, 300 = aprox 100km/h, 400 = aprox 140km/h, 600 = aprox 200km/h, 800 = aprox 220km/h) _fact = 300 ;Initial values driver _veh setskill 1 _wp = 1 _land = false _fire = false _wait = false _cargo = false _hotlz = false _i = 0 ;**************************** LOOP **************************** #loop ;Vehicle data _vxpos = getPos _veh select 0 _vypos = getPos _veh select 1 _alt = getPos _veh select 2 _vup = vectorup _veh ;Reference waypoint position (0 if no such wp exists) _wxpos = getWPPos [_ref, _wp] select 0 _wypos = getWPPos [_ref, _wp] select 1 ;Choose option when path is completed (default = continue flight) if ((_wxpos == 0) and (_wypos == 0) and (_action == "stop")) then {dostop _veh; goto "exit"} if ((_wxpos == 0) and (_wypos == 0) and (_action == "repeat")) then {_wp = 1; goto "nextwp"} if ((_wxpos == 0) and (_wypos == 0) and (_action == "land")) then {_Ftheta = _Atheta; _roff = _ract; goto "land"} ;Choose option when action is scheduled at a given waypoint (default = next waypoint) if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "land") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "land"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "load") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "land"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "unload") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "land"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "supply") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "land"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "hotlz") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "land"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "explode") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "land"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "eject") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "eject"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "bombs") and (not(_wait))) then {_Ftheta = _Atheta; _roff = _ract; goto "bombs"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "fire") and (not(_fire))) then {_Ftheta = _Atheta; _roff = _ract; goto "fire"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "attack") and (not(_fire))) then {_Ftheta = _Atheta; _roff = _ract; goto "fire"} if ((_wpact != 0) and (_wp == _wpact + 1) and (_action == "formup")) then {_Ftheta = _Atheta; _roff = _ract} if (_action == "follow") then {_Ftheta = _Atheta; _roff = _ract; goto "follow"} ;************************ NEXT WP ****************************** ;New target position according to waypoint _theta = (_wxpos - _vxpos) atan2 (_wypos - _vypos) _ratio = ((_wxpos - _vxpos)^2 + (_wypos - _vypos)^2)^0.5 ;When waypoint is reached switch to next one (takes into account formattion correction) if (_ratio <= 50 + _roff) then {_wp = _wp + 1} ;Altitude to fly at (0 keeps current one) if (_zoff != 0) then {_veh flyinheight _zoff} ;Limit vehicle speed (0 keeps no limit) if (_vspeed != 0) then {_veh limitspeed _vspeed} goto "move" ;******************** FOLLOW PROCEDURE ************************** #follow ;New target position according to waypoint _theta = (_wxpos - _vxpos) atan2 (_wypos - _vypos) _ratio = ((_wxpos - _vxpos)^2 + (_wypos - _vypos)^2)^0.5 ;When waypoint is reached switch to next one (takes into account formattion correction) if (_ratio <= 50 + _roff) then {_wp = _wp + 1} ;Altitude to fly at (0 keeps current one) if (_zoff != 0) then {_veh flyinheight _zoff} ;Limit vehicle speed when approaching leader _correct = "none" _LWdist = _var distance [_wxpos,_wypos] if (_ratio > _LWdist + (1.25 * _roff)) then {_correct = "increase"; _veh limitspeed 1.05 * speed _var} if (_ratio <= _LWdist + _roff) then {_correct = "none"; _veh limitspeed speed _var} if (_ratio < _LWdist + (0.75 * _roff)) then {_correct = "decrease"; _veh limitspeed 0.95 * speed _var} goto "move" ;********************* LAND PROCEDUREs ************************** #land _land = true _theta = (_mxpos - _vxpos) atan2 (_mypos - _vypos) _ratio = ((_mxpos - _vxpos)^2 + (_mypos - _vypos)^2)^0.5 ;Altitude reduction when approaching LZ if ((_alt > _ratio / 4) and (_alt > 10)) then {_veh flyinheight _ratio / 4} ;Speed reduction when approaching LZ if ((speed _veh > _ratio / 2) and (speed _veh > 5)) then {_veh limitspeed _ratio / 2} ;Acurracy reduction when approaching LZ if (_fact > 300) then {_fact = 300} if (speed _veh <= 70) then {_fact = 200} if (speed _veh <= 30) then {_fact = 100} if (speed _veh <= 20) then {_fact = 50} ;touchdown on LZ if (_ratio <= 10 + _roff) then {dostop _veh; _veh flyinheight 0} if ((_action == "load") and (not(_wait))) then {goto "load"} if ((_action == "unload") and (not(_wait))) then {goto "unload"} if ((_action == "supply") and (not(_wait))) then {goto "supply"} if ((_action == "hotlz") and (_ratio <= 100) and (not(_hotlz))) then {_veh sidechat "Entering hot LZ"; _hotlz = true; [_veh,30,_var,1,["Sh_105_HE"]] exec "scripts\artillery.sqs"} if ((_action == "explode") and (_alt <= 2)) then {[_veh,0,1,0.1,["Bo_GBU12_LGB"]] exec "scripts\artillery.sqs"; goto "exit"} ;waiting time in LZ if ((_alt > 2) and (not(_wait))) then {goto "move"} ~_var _wait = true ;exit script when path is completed and action is "land" if ((_wait) and (_wxpos == 0) and (_wypos == 0)) then {_veh action ["ENGINEOFF", _veh]; goto "exit"} else {goto "move"} ;********************* LOAD PROCEDURE ************************ #load if ((_alt <= 2) and (not(_cargo))) then {_cargo = true; _veh action ["ENGINEOFF", _veh]; [_var, _veh] exec "scripts\enter.sqs"} ;switch engine (prevents chopper to take off when soldiers get in) if (_cargo) then {_veh action ["ENGINEOFF", _veh]} ;pickup units if ({_x in _veh} count units _var == {alive _x} count units _var) then {_veh sidechat "Load complete"; _wait = true} goto "move" ;********************* UNLOAD PROCEDURE ************************ #unload if ((_alt <= 2) and (not(_cargo))) then {_cargo = true; [_var, _veh] exec "scripts\exit.sqs"} ;unload units if ({_x in _veh} count units _var == 0) then {_veh sidechat "Unload complete"; _wait = true} goto "move" ;********************* SUPPLY PROCEDURE ************************ #supply if ((_alt <= 2) and (not(_wait)) and (side _veh == west)) then {_i = _i + 1; "WeaponBoxWest" createvehicle [_vxpos, _vypos]} if ((_alt <= 2) and (not(_wait)) and (side _veh == east)) then {_i = _i + 1; "WeaponBoxEast" createvehicle [_vxpos, _vypos]} ;unload supplies if (_i == _var) then {_veh sidechat "Resupply complete"; _wait = true} else {goto "move"} ~5 goto "move" ;********************* EJECT PROCEDURE ************************ #eject _theta = (_mxpos - _vxpos) atan2 (_mypos - _vypos) _ratio = ((_mxpos - _vxpos)^2 + (_mypos - _vypos)^2)^0.5 ;Altitude setting when approaching LZ if (_zact > 75) then {_veh flyinheight _zact} else {_veh flyinheight 75} ;arrival on LZ if ((_ratio <= 100 + _roff) and (not(_wait))) then {_wait = true; [_var, _veh] exec "scripts\eject.sqs"} ;unload units if ({_x in _veh} count units _var == 0) then {_veh sidechat "Eject complete"} goto "move" ;********************* BOMBS PROCEDURE ************************ #bombs ;New expected position for bombs _bxpos = _vxpos + (sin(_theta) * 30 * _i) + (sin(90 + _theta) * 50) _bypos = _vypos + (cos(_theta) * 30 * _i) + (cos(90 + _theta) * 50) ;create bombs if (_i < _var) then {_i = _i + 1; "Bo_GBU12_LGB" createvehicle [_bxpos, _bypos, 500]} ;bombardment complete if (_i == _var) then {_veh sidechat "Bombardment complete"; _wait = true} goto "move" ;********************* FIRE PROCEDURES ************************** #fire _theta = (_mxpos - _vxpos) atan2 (_mypos - _vypos) _ratio = ((_mxpos - _vxpos)^2 + (_mypos - _vypos)^2)^0.5 ;Altitude to fly at (0 keeps current one) if (_zact != 0) then {_veh flyinheight _zact} ;Find target within marker radius _target = _veh findnearestenemy (getmarkerpos _marker) _dist = _target distance (getmarkerpos _marker) if ((_ratio >= 200 + _roff) and (_dist <= _msize)) then {_veh setcombatmode "blue"; _veh dotarget _target} ;fire weapon if ((_ratio < 200 + _roff) and (_dist <= _msize) and (_action == "fire")) then {[_veh,_var,10,0.5] exec "scripts\fireweapon.sqs"} ;attack marker if ((_ratio < 200 + _roff) and (_dist <= _msize) and (_action == "attack")) then {_veh setbehaviour "combat"; _veh setcombatmode "red"} ;continue pattern if (_ratio <= 50 + _roff) then {_fire = true} goto "move" ;************************ MOVE ********************************* #move ;Formation correction _Stheta = _Ftheta + _theta ;New expected position _txpos = _vxpos + (sin(_theta) * _fact) + (sin(_Stheta) * _roff) _typos = _vypos + (cos(_theta) * _fact) + (cos(_Stheta) * _roff) ;Order to move to next expected position _veh domove [_txpos, _typos] ;Vectorup visual correction (not active on landings) _vupx = _vup select 0 _vupy = _vup select 1 _vupz = _vup select 2 if (abs(_vupx) < 0.01) then {_vupx = 0} if (abs(_vupy) < 0.01) then {_vupy = 0} ;if (not(_land)) then {_veh setvectorup [_vupx, _vupy, _vupz]} ;*************************************************************** ;Debug information (optional) ;hint format ["theta: %1 \nRatio: %2 \nSpeed: %3  \nFact: %4 \nAltitude: %5 \nWP Action: %6 \nAction: %7", _theta, _ratio, speed _veh, _fact, _alt, _wpact, _action] ;hint format ["Vupx: %1 \nVupy: %2 \nVupz: %3", _vupx, _vupy, _vupz] ;hint format ["Target: %1 \nDistance: %2 \nFire: %3 \nCurrent: %4 \nMsize: %5", _target, _dist, _fire, assignedtarget _veh, _msize] ;hint format ["Units: %1 \nCargo: %2 \nEngineOn: %3", count units _var, {_x in _veh} count units _var, isengineon _veh] ;hint format ["roff: %1 \nRatio-LWdist: %2 \nLspeed: %3 \nSpeed: %4 \nCorrect: %5", _roff, _ratio - _LWdist, speed _var, speed _veh, _correct] ~0.01 ?(not (alive _veh)) : goto "exit" goto "loop" #exit exit let's say I want another chopper to follow my lead start from engine off state, then fly in formation, which string should I change? Please give me an example. After changing that, what command should I use to activate the script? Should I put the command into both initilization field or just put it into AI's initilization field? Where should I store the script, like this: "C:\My documents\ArmA\missions\Chopper\scripts"? Sorry if this question annoys you guys, I really want to see the result using this script. Any help would be much appreciated! Share this post Link to post Share on other sites
tj72 0 Posted August 21, 2007 Almost, If you had less units than expected or less anything than expected then you get a "zero divisor" not an "expected" Below is the array that this script is expecting. The script author intends you to use this array to make the script work. Not a list of units but a mixture of variables, arrays and strings. This is a complicated setup but if you can understand this you will be well on your way to more advanced script concepts. ;[vehicle, ref path to follow, speed limit, [x,y,z], action waypoint, "action", [x´,y´,z`], "marker", variable] exec "scripts\choppers.sqs" So the next part is. find out where this array is used in the script creators example. Such as the first in the list (select 0) is vehicle, this is probably the assigned name of the vehicle (i.e. your chopper) but Im just guessing so see if in example mission there is a chopper and what its name is. then find this line of code (might be in a trigger in editor or in a script seperate from this one) and see if the vehicle name is there. NOW you know you can change this value and proceed. Share this post Link to post Share on other sites