Editors Depot - Mission Editing and Scripting > Arma2 - Editing/Scripting Multiplayer

[Solved] Spawn Script Assistance

(1/1)

Fumbles:
Edit: Finally got this solved, it was a problem with the counter(s).  Changed them from _i + 1 to _i = _i +1 and it made it all work! 

Hey guys,

Working on a script that will spawn a random amount and variety of enemies in a town when the player activates a trigger.

Basically I have been using the Squint debugger and I'm getting no errors using it. When using it in game, the infantry are spawning but after that the script is not continuing on to the vehicles and static objects etc. All I get in game is the hint - '3' accompanied by the variable value.

In game I get the script error on line 120 - _spawnedUnit = _grp createUnit [_FootType, getMarkerPos _location, [], 0, "NONE"];

The error gives a 'type - any, expected object'.

Hope someone can help as this has me pulling my hair out - any advice would be greatly appreciated!


--- Code: ---//Created by Mark Henderson (Pte. M. Henderson [6thAB]
//3 Oct 2012

//Script for use with Faysh Kabur only
//Spawns enemies from pool when blufor is a certain distance from marker using trigger.

//Armour chance low
//Veh + static chance medium
//Infantry chance high

//Call using nul = ["MarkerName"] execVM "Scripts\spawn.sqf";

//Version 1.01



//Declare Private variables
private ["_enemyFootPool","_enemyArmPool","_enemyVehPool","_enemyStatPool","_footNumberSpawn","_ArmNumberSpawn","_VehNumberSpawn","_enemyFootPoolCount","_enemyArmPoolCount","_enemyVehPoolCount","_enemyStatPoolCount","_spawnedUnit","_ArmType","_VehType","_spawnedVehUnit","_StatType","_spawnedStatUnit","_i","_y","_z","_StatNumberSpawn","_FootType","_spawnedArmUnit","_location","_b","_grp"];

//Set Variable of Marker triggered

_location = _this select 0;

//Enemy pools in form of array, then counted

_enemyFootPool = ["TK_Soldier_AA_EP1","TK_Soldier_AAT_EP1","TK_Soldier_AMG_EP1","TK_Soldier_HAT_EP1",
                        "TK_Soldier_AR_EP1","TK_Commander_EP1","TK_Soldier_Crew_EP1","TK_Soldier_Engineer_EP1",
                        "TK_Soldier_GL_EP1","TK_Soldier_MG_EP1","TK_Soldier_Medic_EP1","TK_Soldier_Officer_EP1",
                        "TK_Soldier_EP1","TK_Soldier_B_EP1","TK_Soldier_LAT_EP" ,"TK_Soldier_AT_EP1"    
                        ,"TK_Soldier_Sniper_EP1", "TK_Soldier_SniperH_EP1","TK_Soldier_Sniper_Night_EP1","
TK_Soldier_TWS_EP1","TK_Soldier_Spotter_EP1","TK_Soldier_SL_EP1", "TK_Special_Forces_MG_EP1", "TK_Special_Forces_EP1", "TK_Special_Forces_TL_EP1"];

_enemyFootPoolCount = count _enemyFootPool;


_enemyArmPool = ["BMP2_TK_EP1","  BMP2_HQ_TK_EP1","BRDM2_TK_EP1","BRDM2_ATGM_TK_EP1","BTR60_TK_EP1",
"M113_TK_EP1","T34_TK_EP1","T55_TK_EP1","T72_TK_EP1","ZSU_TK_EP1"];

_enemyArmPoolCount = count _enemyArmPool;


_enemyVehPool = ["GRAD_TK_EP1","LandRover_MG_TK_EP1","LandRover_SPG9_TK_EP1","UAZ_Unarmed_TK_EP1",
"UAZ_AGS30_TK_EP1","UAZ_MG_TK_EP1"];

_enemyVehPoolCount = count _enemyVehPool;

_enemyStatPool = ["Igla_AA_pod_TK_EP1", "AGS_TK_EP1", "D30_TK_EP1", "KORD_high_TK_EP1","KORD_TK_EP1",
"Metis_TK_EP1", "2b14_82mm_TK_EP1","ZU23_TK_EP1"];

_enemyStatPoolCount = count _enemyStatPool;

//pick random number of each pool to spawn

hint "1";

//First if is for larger cities and towns

if ((_location == "Tall") || (_location == "faysh") || (_location == "mish") || (_location == "gerb"))

then {
    _footNumberSpawn = round (random 30);
    _ArmNumberSpawn = round (random 1);
    _VehNumberSpawn = round (random 3);
    _StatNumberSpawn = round (random 3);
    
    if (_footNumberSpawn <= 15)
    then {
        _footNumberSpawn = _footNumberSpawn + 15;
            };
    
    if (_VehNumberSpawn < 1)
    then {
        _VehNumberSpawn = _VehNumberSpawn + round (random 1);
            };
    
    if (_StatNumberSpawn < 2)
    then {
        _StatNumberSpawn = _StatNumberSpawn + round (random 1);
             };
             hint "2";
         }

//Else sets numbers for smaller towns and villages.

else {
    _footNumberSpawn = round (random 10);
    _ArmNumberSpawn = round (random 1);
    _VehNumberSpawn = round (random 2);
    _StatNumberSpawn = round (random 2);
    
    if (_footNumberSpawn <= 5)
    
    then{
        _footNumberSpawn = _footNumberSpawn + 5;
           };
    
    if (_ArmNumberSpawn == 1)
    
    then {
        _ArmNumberSpawn - round (random 1);
             };
            
        };

        hint "3";

        sleep 2;
        
        

if (true) then {
            
//Set Counter

_i = 0;

//While loop, selects random unit from pool arrays and spawns with UPS in init
while {_i < _footNumberSpawn} do {
    _FootType = _enemyFootPool select (round (random _enemyFootPoolCount));
    _grp = createGroup east;
    
    _spawnedUnit = _grp createUnit [_FootType, getMarkerPos _location, [], 0, "NONE"];
    _spawnedUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
    processInitCommands;

    _i + 1;
};

hint "4";

sleep 2;

//Count for armour
_b = 0;

//While loop now for armour

while {_b < _ArmNumberSpawn} do {
    _ArmType = _enemyArmPool select (round (random _enemyArmPoolCount));
    
    _spawnedArmUnit = createVehicle [_ArmType, getMarkerPos _location, [], 0, "NONE"];
    _spawnedArmUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
    processInitCommands;
    
    _b + 1;
    
};

sleep 2;
hint "5";

//Count for vehicles
_y = 0;

//While loop for vehicles

while {_y < _VehNumberSpawn} do {
    _VehType = _enemyVehPool select (round (random _enemyVehPoolCount));
    
    _spawnedVehUnit = createVehicle [_VehType, getMarkerPos _location, [], 0, "NONE"];
    _spawnedVehUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
    processInitCommands;
    
    _y + 1;
    
};

sleep 2;
hint "6";

//Set counter for statics

_z = 0;

//While loop for statics

while {_z < _StatNumberSpawn} do {
    _StatType = _enemyStatPool select (round (random _enemyStatPoolCount));
    
    _spawnedStatUnit = createVehicle [_StatType, getMarkerPos _location, [], 0, "NONE"];
    _spawnedStatUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
    processInitCommands;
    
    _z + 1;
    
};    

sleep 2;
};
hint "Complete";
--- End code ---

Navigation

[0] Message Index

Go to full version