Jump to content
Sign in to follow this  
UKSF

UKSF Development Team - Insurgent Spawn Script - Group Error (Variable Shinanigans)

Recommended Posts

Here is a live version of the code:

http://piratepad.net/ZJaYj1MqaO

I am making this script that when triggered spawns a group of AI in a given radius of a given location.

Then gets the AI to pickup a weapon at a weapon crate. Then sends the AI of to a zone to patrol using UPSMON. You can find the brief on our project here.

I have been doing JAVA, C++ and OOPPHP for just under a year but this arma projects is the first stab I have taken at ARMA scripting despite being an arma player for more than 5 years.

I have got the code working pretty much up to the edge, it isn't complete and I'm worried about a couple things popping up in the future but one thing in particular is giving me trouble. The _grpAll variable isn't working and it isn't spitting any error. I can see the AI join a new group but they are joining a new one each time. I had them all joining a group together previously but I have not changed anything.

Again specifically the _grpAll variable is not working when [_this] join _grpAll is called.

here is the code if the live version gets messed with:

//0 = [[crate_1, "Zone2"], [25, 500, 400], [1000, 1000, 0, "WEST", "PRESENT"], thistrigger] execVM "time_spawn_insurgents.sqf";
if !(IsServer) exitwith {};

uksf_spawn_process={
_pos = _this select 0;
_amount = _this select 1;
_spawnRadius = _this select 2;
_crate = _this select 3;
Zone = _this select 4;

_grpAll = creategroup east;
_houses = nearestobjects [_pos, ["House_F"], _spawnRadius];

_buipos = [];//empty array

_count = 0;//dummy counter
{
    _poses = [];
    while {format ["%1", _x buildingpos _count] != "[0,0,0]" } do
    {

        _bpos = _x buildingpos _count; //number of positions
        _poses = _poses + [_bpos]; // add them to array
        _count = _count + 1;         //increment
        sleep 0.01; //sleep

    };
    if (count _poses > 0) then
    {
       _buipos = _buipos + [[_x, _poses]];
    };
} foreach _houses;

_num = 0; //dummy number we raise each time the loop goes one round
while {_num < _amount} do
{
   _grp = creategroup east;
   _h = _buiPos select floor (random (count _buiPos));
   _ranPos = (_h select 1) select floor (random (count (_h select 1)));
   _unit = _grp createUnit ["CAF_AG_EEUR_R_AK47", _pos, [], 0, "None"];
   RemoveAllWeapons _unit;
   _unit setpos _ranPos;
   _unit setvariable ["crate", _crate];
   _unit setvariable ["grp", [_grpAll, _grp]];
   _crateCoords = getpos _crate;

   _wp = _grp addWaypoint [_crateCoords, 0.1];
   _grp setCombatMode "RED";

   _wp setWaypointStatements
        [
        "true", "0 = this spawn
        {
           _crate = _this getvariable 'crate';
           _grpAll = (_this getvariable 'grp') select 0;
           _grp = (_this getvariable 'grp') select 1;
           _Zone = (_this getvariable 'Zone') select 0;
           0 = [_this] execVM 'equip_insurgent.sqf';
           0 = [_this, Zone] execVM 'scripts\upsmon.sqf';
           [_this] join _grpAll;
           deleteGroup _grp;
        }"
        ];

   _num = _num + 1;
   sleep 0.5;
};
};

_LocationInfo = _this select 0;
_crate = _LocationInfo select 0;
_Zone = _LocationInfo select 1;

_MeasureInfo = _this select 1;
_amount = _MeasureInfo select 0;
_spawnRadius = _MeasureInfo select 1;
_Cooldown = _MeasureInfo select 2;

_Trigger = _this select 2;
_Areax = _Trigger select 0;
_Areay = _Trigger select 1;
_Arear = _Trigger select 2;
_who = _Trigger select 3;
_how = _Trigger select 4;

_TrigoB = _this select 3;

Trigger = _Trigger;
MeasureInfo = _MeasureInfo;
LocationInfo =  _LocationInfo;

_pos = position _TrigoB;
_dCr=damage _crate;
if (_dCr<1) then {
_myTempParams = [_pos, _amount, _spawnRadius, _crate, _Zone];
_myTempVariableTwo = _myTempParams call uksf_spawn_process;

deletevehicle _TrigoB;
sleep _Cooldown;

_trg = createTrigger["EmptyDetector", _pos];
_trg setTriggerArea[_Areax, _Areay, _Arear, false];
_trg setTriggerActivation[_who, _how, true];

_trg setTriggerStatements["this", "
0 = [LocationInfo, MeasureInfo, Trigger, thistrigger] execVM 'time_spawn_insurgents.sqf';", " "];
};

Really really hope someone can help, so thanks.

Also if you are trying to run this you may want to change the classname of the character getting spawned and you may want to remove the lines executing

0 = [_this] execVM 'equip_insurgent.sqf';

0 = [_this, Zone] execVM 'scripts\upsmon.sqf';

Thanks again for any help.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×