Altsor 2 Posted November 8, 2015 I'm quite new to functions with variables and scripting in general and I would really appreciate some help! The code will not even execute and I've been banging my head for hours now. Can someone please take a look? The function I'm trying to run is called spawnHeli (see code below) and its written in a file called functions.sqf. functions.sqf is called in init.sqf by execVM "functions.sqf"; and the spawnHeli function is called in a trigger in the editor by _nul = [getMarkerPos "heliSpawnPoint", "ocra"] spawn spawnHeli; The spawnHeli function I want to run as it is written in functions.sqf: It seams like already in the init phase the end of the functions.sqf file is not reached so can it be some error in the spawnHeli function preventing it from compiling? spawnHeli = { private["_xPos","_yPos","_zPos","_type"]; _xPos = this select 0; _yPos = this select 1; _zPos = this select 2; _type = _this select 3; _spawnMarkerPos = [_xPos,_yPos,_zPos]; if (isServer) then { _heli = []; _crew = []; _crew = creategroup EAST; if(_type == "ocra") then { _heli = [_spawnMarkerPos, 180, "O_Heli_Light_02_F", _crew] call bis_fnc_spawnvehicle; } else { if(_type == "kajman") then { _heli = [_spawnMarkerPos, 180, "O_Heli_Attack_02_F", _crew] call bis_fnc_spawnvehicle; } else { exitWith {}; }; }; _wp = _crew addWaypoint [getPos player, 0]; _wp setWaypointType "SAD"; _wp setWaypointCombatMode "RED"; _wp2 = _crew addWaypoint [getPos player, 1]; _wp2 setWaypointType "LOITER"; _wp2 setWaypointCombatMode "RED"; uiSleep 300; _wp3 = _crew addWaypoint [getMarkerPos "wpCas", 2]; _wp3 setWaypointType "Move"; _wp3 setWaypointCombatMode "green"; _Ocra = _heli select 0; waitUntil{ (getPos _Ocra) distance (getmarkerpos "wpCas") < 2000}; {deleteVehicle _x} forEach (crew _Ocra); deleteVehicle _Ocra; } else {}; }; Share this post Link to post Share on other sites
KevsNoTrev 44 Posted November 8, 2015 the function call in the editor is called before the init.sqf even gets read by the game. refer to Order of Initialisation: You will see the object initialisation fields are run way before the init.sqf If you really want to use the trigger then try changing the condition to this this && !(isnull spawnHeli) Untested but should work Share this post Link to post Share on other sites
Altsor 2 Posted November 8, 2015 the function call in the editor is called before the init.sqf even gets read by the game. refer to Order of Initialisation: You will see the object initialisation fields are run way before the init.sqf If you really want to use the trigger then try changing the condition to this this && !(isnull spawnHeli)Untested but should work Thanks, I added it but the function call is on.act on a trigger so it shouldnt be called until I step into the trigger which would be after init.sqf has run. I tried adding some variable inside the code to see how far I get. I managed to get through the whole code now on the init and I think also on the call but still no choppers will spawn. Share this post Link to post Share on other sites
Larrow 2799 Posted November 8, 2015 You presume the position is sent through in x,y and z as seperate variables which you then place in an array as _spawnMarkerPos. GetMarkerPos will already send your position as an array. spawnHeli = { if !(isServer) exitWith {}; private[ "_spawnedHeli", "_wp", "_dir" ]; params [ "_spawnMarkerPos", "_type" ]; _dir = [ _spawnMarkerPos, player ] call BIS_fnc_dirTo; switch ( toLower _type ) do { case ( "orca" ) : { _spawnedHeli = [_spawnMarkerPos, _dir, "O_Heli_Light_02_F", east] call BIS_fnc_spawnVehicle; }; case ( "kajman" ) : { _spawnedHeli = [_spawnMarkerPos, _dir, "O_Heli_Attack_02_F", east] call BIS_fnc_spawnVehicle; }; }; if ( isNil "_spawnedHeli" ) exitWith {}; _spawnedHeli params [ "_heli", "_crew", "_heliGroup" ]; _wp = _heliGroup addWaypoint [getPos player, 0]; _wp setWaypointType "SAD"; _wp setWaypointCombatMode "RED"; _wp = _heliGroup addWaypoint [getPos player, 0]; _wp setWaypointType "LOITER"; _wp setWaypointCombatMode "RED"; uiSleep 300; _wp = _heliGroup addWaypoint [getMarkerPos "wpCas", 0]; _wp setWaypointType "Move"; _wp setWaypointCombatMode "green"; _wp setWaypointStatements [ " this distance getMarkerPos 'wpCas' < 2000 "," { deleteVehicle _x; }foreach [ vehicle this ] + thisList; "]; }; Thanks, I added it but the function call is on.act on a trigger so it shouldnt be called until I step into the trigger which would be after init.sqf has run.This is correct, as long as you trigger is not immediately activated there should be no problems with initialisation order. 2 Share this post Link to post Share on other sites
Altsor 2 Posted November 8, 2015 Huge thanks for the help! You were right about the the parameters being wrong and I ended up pretty much copying your code cuz it looks much nicer and works better!Only thing that doesn't work in your code is the end-part where the heli and crew should be deleted. The way I wrote it works though: waitUntil{ (getPos _heli) distance (getmarkerpos "wpCas") < 2000}; {deleteVehicle _x} forEach (crew _heli); deleteVehicle _heli; Now the only problem I have is with helicopter behavior. When I use the "Search and Destroy" waypoint type the helli will not move on to the next waypoint until everyone around is dead. I don't want the chopper to be quite that ambitious so I set the waypoint to MOVE, but then he doesn't seem to find anyone and just hovers at the wp untill its time to go to the end-point. Any ideas how to use the SAD and then have him disengage`? I tried _heli disableAI "TARGET"; but no luck. Share this post Link to post Share on other sites
Larrow 2799 Posted November 8, 2015 spawnHeli = { if !(isServer) exitWith {}; private[ "_spawnedHeli", "_wp", "_dir" ]; params [ "_spawnMarkerPos", "_type" ]; _dir = [ _spawnMarkerPos, player ] call BIS_fnc_dirTo; switch ( toLower _type ) do { case ( "orca" ) : { _spawnedHeli = [_spawnMarkerPos, _dir, "O_Heli_Light_02_F", east] call BIS_fnc_spawnVehicle; }; case ( "kajman" ) : { _spawnedHeli = [_spawnMarkerPos, _dir, "O_Heli_Attack_02_F", east] call BIS_fnc_spawnVehicle; }; }; if ( isNil "_spawnedHeli" ) exitWith {}; _spawnedHeli params [ "_heli", "_crew", "_heliGroup" ]; //Initial move to AO _wp = _heliGroup addWaypoint [getPos player, 0]; _wp setWaypointType "MOVE"; _wp setWaypointCombatMode "RED"; _wp setWaypointBehaviour "COMBAT"; switch ( toLower _type ) do { case ( "orca" ) : { //SAD _wp = _heliGroup addWaypoint [getPos player, 0]; _wp setWaypointType "SAD"; //Cycle back to Move which is at the same position //so potentially cycles straight back into SAD _wp = _heliGroup addWaypoint [getPos player, 0]; _wp setWaypointType "CYCLE"; //5 mins orca only has fixed front facing weapons so joust attacks uiSleep 300; }; case ( "kajman" ) : { //Loiter at 400m _wp = _heliGroup addWaypoint [getPos player, 0]; _wp setWaypointType "LOITER"; _wp setWaypointLoiterType "CIRCLE"; _wp setWaypointLoiterRadius 400; //3 mins, a Kajman loitering 400m out is far more devastating //As it can bring its weapons to bare uiSleep 180; }; }; //Dissengage _heliGroup setCombatMode "GREEN"; _heliGroup setBehaviour "CARELESS"; //RTB _wp = _heliGroup addWaypoint [getMarkerPos "wpCas", 0]; _wp setWaypointType "Move"; _wp setWaypointCombatMode "GREEN"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointStatements [ " this distance getMarkerPos 'wpCas' < 2000 "," { deleteVehicle _x; }foreach ( [ vehicle this ] + thisList ); "]; //Force new waypoint as current _heliGroup setCurrentWaypoint _wp; };Comments in the code should be pretty explanatory put it through some quick testing at Marina on Stratis filled with random infantry.Set both helis up differently due to their weapons ability and each a different time as an Orca takes alot longer to bring its weapons on target. Also fixed RTB waypoint statement (oops my bad :/ ), could most likely do without the distance check and just delete it once it get there "true" but left it as per your original script. 3 Share this post Link to post Share on other sites
Altsor 2 Posted November 9, 2015 This is shaping up to pretty much the ultimate heli attack script! I am at work now but i'll try the script when I get home. Helicopter behavior seems a bit arbitrary at times but I look forward to see how well this works! Thanks alot for your help! Share this post Link to post Share on other sites
Altsor 2 Posted November 10, 2015 Been trying the code a bit and it works great! Very reasonable to have shorter time for the Kajman as it is pretty overpowered. Actually they Kajman almost surely means your are dead unless you have AA (and even then) so I will only use it once when I know the players have access to AA ;) Sometimes the Orca seems to have some problems finding a target and ends up just circling the players position until it leaves. Not sure why this is. Maybe its to some degree realistic that they don't always spot a target but then I try getting their attention by shooting at them and still the circling just continues. I only tried a couple of times so I'll give it some more tries tonight. Share this post Link to post Share on other sites