Jump to content
Sign in to follow this  
FederalRazer89

Cant delete campfire

Recommended Posts

I am trying to add some ambient items to a banditcamp, but my buring campfire wont get deleted when the script executes. The units that spawn with the camp gets deleted so i thought the same logic would apply to objects placed with the script. The game say something about a arma 3 undefined variable in expression and refers to the line "deletevehicle _campfire;"
 
 
The script:
MinimumAIamount = 6;
FR_fnc_MonitorAI = 
{
    private ["_grp","_randombanditcar","_randombanditcar","_campfire"];
    _grp = _this select 0;
    while {true} do
    {
        if ((player distance (leader _grp)) >= 2000) exitWith
        {
            {deleteVehicle _x} forEach units _grp;
            deleteVehicle _campfire;
            deleteVehicle _randombanditcar;
        };
        _time = time;
        waitUntil {time > (_time + 60)};
    };
};
 
0 = [] spawn {
    
    while {true} do 
    {
        _radius   = random [1200,1500,1800];
        _spawnPos = [player, _radius, (RANDOM 360)] call BIS_fnc_relPos;
        _spawnPos = [_spawnPos, 0.01, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;
        _grp      = [_spawnPos, INDEPENDENT,["I_C_Soldier_Para_2_F","I_Soldier_LAT_F","B_sniper_F","I_G_Soldier_A_F","O_Soldier_A_F","B_Soldier_A_F"]] call BIS_fnc_spawnGroup;
        _grp setBehaviour "STEALTH";
        _grp setFormation "WEDGE";
        _campfire        = "Campfire_burning_F" createVehicle _spawnPos;
        _randombanditcar = "I_G_Offroad_01_armed_F" createVehicle ([(_spawnPos select 0)+(random [3,5,10]),(_spawnPos select 1)+(random [3,5,10])]);
        createVehicleCrew _randombanditcar;
        _randombanditcar setFuel 0,1 
        _randombanditcar setDamage 0,2
       
        _randombanditcar addWeaponCargo ["srifle_DMR_02_DMS_F",1];         //weapons and ammo
        _randombanditcar addWeaponCargo ["srifle_DMR_03_MRCO_F",1];
        _randombanditcar addWeaponCargo ["srifle_DMR_05_SOS_F",1];      
        _randombanditcar addWeaponCargo ["MMG_02_black_RCO_BI_F",1];             
        _randombanditcar addWeaponCargo ["MMG_01_hex_ARCO_LP_F",1];      
 
        _randombanditcar addMagazineCargo ["10Rnd_338_Mag",2];
        _randombanditcar addMagazineCargo ["20Rnd_762x51_Mag",2];
        _randombanditcar addMagazineCargo ["150Rnd_93x64_Mag",2];
        _randombanditcar addMagazineCargo ["130Rnd_338_Mag",2];        
        
        _randombanditcar addItemCargo ["muzzle_snds_H",1];
        _randombanditcar addItemCargo ["muzzle_snds_L",1];
        _randombanditcar addItemCargo ["muzzle_snds_M",1];
        _randombanditcar addItemCargo ["muzzle_snds_B",1];
        _randombanditcar addItemCargo ["muzzle_snds_338_black",1];
        _randombanditcar addItemCargo ["muzzle_snds_93mmg",1];
        _randombanditcar addItemCargo ["bipod_01_F_blk",1];
        
        _campradius = random [2,5,20];
        _wp         = _grp addWaypoint [position _campfire, _campradius];
        _wp setWaypointType "GUARD";
        [_grp] spawn FR_fnc_MonitorAI;
        sleep 600;
        waitUntil {count units _grpcamp < MinimumAIamount};
 
    };
};
 
It feels like i am missing something simple. Tried to narrow down the problem to only the campfire with this little script:

        _radius   = random [1200,1500,1800];        _spawnPos = [player, _radius, (RANDOM 360)] call BIS_fnc_relPos;        _spawnPos = [_spawnPos, 0.01, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;        _campfire        = "Campfire_burning_F" createVehicle _spawnPos;        sleep 30;        deleteVehicle _campfire;

But it outputs error generic error in expression. I looked at the example that on the "deletevehicle" (https://community.bistudio.com/wiki/deleteVehicle)
If anyone can point out whats wrong or how to fix/workaround, that would be nice.

Share this post


Link to post
Share on other sites

_campfire is undefined in FR_fnc_MonitorAI, as well as _randombanditcar.

 

Also

        _time = time;

        waitUntil {time > (_time + 60)};
is the same as:
sleep 60;

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

The time things i didnt know, but when you say that both my varibles are undefined in the "FR_fnc_monitorAI" what do you specifically mean? Is it that i need both _campfire and _randombanditcar to spawn  FR_fnc_MonitorAI?

I am kind of new to scripting.

Share this post


Link to post
Share on other sites

FR_fnc_monitorAI is a separate function, within its scope nothing else exists that you didn't put in there as a variable.

Use params since it's making _this select n and private obsolete.

 

Also

        _randombanditcar setFuel 0,1 

        _randombanditcar setDamage 0,2
won't work.
 
Cheers

Share this post


Link to post
Share on other sites

What you need is to pass the objects into that function

FR_fnc_MonitorAI =
{
    params ["_grp", "_campfire", "_randombanditcar"];

    while {true} do
    {
        if ((player distance (leader _grp)) >= 2000) exitWith
        {
            {deleteVehicle _x} forEach units _grp;
            deleteVehicle _campfire;
            deleteVehicle _randombanditcar;
            deleteGroup _grp;
        };
    sleep 60;
    };
};

[_grp,_campfire,_randombanditcar] spawn FR_fnc_MonitorAI;

Looping for true in that case is bad idea i think

Share this post


Link to post
Share on other sites
Guest

_campfire is undefined in FR_fnc_MonitorAI, as well as _randombanditcar.

 

Also

        _time = time;

        waitUntil {time > (_time + 60)};
is the same as:

sleep 60;
Cheers

It's not the same.

According to the wiki this method is more precise than sleep.

Anyway in this exemple it's better to use a sleep

Share this post


Link to post
Share on other sites

It's not the same.

According to the wiki this method is more precise than sleep.

Anyway in this exemple it's better to use a sleep

Can you point me at the correct wiki entry where it says waituntil is more precise than sleep? Seem unable to find it.

 

Cheers

Share this post


Link to post
Share on other sites

After a lot of thinking about what you said Grumpy Old Man i tested some stuff and after i allmost gave up i tried to somehow link the FR_fnc_monitorAI and got the following code. This is the result after trying about 30 times with corrections, and it works
 

 
MinimumAIamount = 6;
FR_fnc_MonitorAI = 
{
    private ["_grp"];
    _grp             = _this select 0;
    _randombanditcar = _this select 1;
    _campfire        = _this select 2;
    while {true} do
    {
        if ((player distance (leader _grp)) >= 2000) exitWith
        {
            {deleteVehicle _x} forEach units _grp;
            {_randombanditcar deleteVehicleCrew _x} forEach crew _randombanditcar;
            deleteVehicle _randombanditcar;
            deleteVehicle _campfire;
            
        };
        _time = time;
        waitUntil {time > (_time + 60)};
    };
};
 
0 = [] spawn {
    
    while {true} do 
    {
        _radius   = random [1200,1500,1800];
        _spawnPos = [player, _radius, (RANDOM 360)] call BIS_fnc_relPos;
        _spawnPos = [_spawnPos, 0.01, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;
        _grp      = [_spawnPos, INDEPENDENT,["I_C_Soldier_Para_2_F","I_Soldier_LAT_F","B_sniper_F","I_G_Soldier_A_F","O_Soldier_A_F","B_Soldier_A_F"]] call BIS_fnc_spawnGroup;
        _grp setBehaviour "STEALTH";
        _grp setFormation "WEDGE";
        _campfire        = "Campfire_burning_F" createVehicle _spawnPos;
        _randombanditcar = "I_G_Offroad_01_armed_F" createVehicle ([(_spawnPos select 0)+(random [3,5,10]),(_spawnPos select 1)+(random [3,5,10])]);
        createVehicleCrew _randombanditcar;
        _randombanditcar setFuel 0,1;
        _randombanditcar setDir (RANDOM 360);
        _randombanditcar addWeaponCargo ["srifle_DMR_02_DMS_F",1];
        _randombanditcar addWeaponCargo ["srifle_DMR_03_MRCO_F",1];
        _randombanditcar addWeaponCargo ["srifle_DMR_05_SOS_F",1];      
        _randombanditcar addWeaponCargo ["MMG_02_black_RCO_BI_F",1];             
        _randombanditcar addWeaponCargo ["MMG_01_hex_ARCO_LP_F",1];      
 
        _randombanditcar addMagazineCargo ["10Rnd_338_Mag",2];
        _randombanditcar addMagazineCargo ["20Rnd_762x51_Mag",2];
        _randombanditcar addMagazineCargo ["150Rnd_93x64_Mag",2];
        _randombanditcar addMagazineCargo ["130Rnd_338_Mag",2];        
        
        _randombanditcar addItemCargo ["muzzle_snds_H",1];
        _randombanditcar addItemCargo ["muzzle_snds_L",1];
        _randombanditcar addItemCargo ["muzzle_snds_M",1];
        _randombanditcar addItemCargo ["muzzle_snds_B",1];
        _randombanditcar addItemCargo ["muzzle_snds_338_black",1];
        _randombanditcar addItemCargo ["muzzle_snds_93mmg",1];
        _randombanditcar addItemCargo ["bipod_01_F_blk",1];
        
        _campradius = random [2,5,20];
        _wp         = _grp addWaypoint [position _campfire, _campradius];
        _wp setWaypointType "GUARD";
        [_grp,_randombanditcar,_campfire] spawn FR_fnc_MonitorAI;
        sleep 600;
        waitUntil {count units _grp < MinimumAIamount};
 
    };
};
 
Thanks Grumpy Old Man

I forgot to update the website page so i didnt see the respons from davidoss and harmdhast, so i could have saved some time.

Share this post


Link to post
Share on other sites

 

FR_fnc_monitorAI is a separate function, within its scope nothing else exists that you didn't put in there as a variable.

Use params since it's making _this select n and private obsolete.

 

Also

        _randombanditcar setFuel 0,1 

        _randombanditcar setDamage 0,2
won't work.
 
Cheers

 

Why wont they work?

Share this post


Link to post
Share on other sites

0.2 not 0,2 , and maybe its need to be remotely executed, depends how you call it.

Share this post


Link to post
Share on other sites

What you need is to pass the objects into that function

FR_fnc_MonitorAI =
{
    params ["_grp", "_campfire", "_randombanditcar"];

    while {true} do
    {
        if ((player distance (leader _grp)) >= 2000) exitWith
        {
            {deleteVehicle _x} forEach units _grp;
            deleteVehicle _campfire;
            deleteVehicle _randombanditcar;
            deleteGroup _grp;
        };
    sleep 60;
    };
};

[_grp,_campfire,_randombanditcar] spawn FR_fnc_MonitorAI;

Looping for true in that case is bad idea i think

Do you mean the "while {true}" line? At moment i dont know any better ways to spawn AI without using this loop, if you know a better way please share.

Share this post


Link to post
Share on other sites


FR_fnc_MonitorAI =

{

    params ["_grp", "_campfire", "_randombanditcar"];

    waitUntil {sleep 60; (player distance (leader _grp)) >= 2000};

    

        {deleteVehicle _x} forEach units _grp;

        deleteVehicle _campfire;

        deleteVehicle _randombanditcar;

        deleteGroup _grp;

};

  • Like 1

Share this post


Link to post
Share on other sites
Guest

Can you point me at the correct wiki entry where it says waituntil is more precise than sleep? Seem unable to find it.

 

Cheers

 

I am sure I read it somewhere. But the only thing I could find was https://community.bistudio.com/wiki/Talk:sleep

I will continue to search but if I recall correctly sleep is not really precise (we are talking in milliseconds). That why all time based and critical execution timed functions uses time function.

Maybe KK can clarify that.

Share this post


Link to post
Share on other sites

Curious about that, never came across a situation where sleep wasn't accurate enough.

Time critical stuff should be called anyway, using eventhandlers in a best case scenario.

 

Cheers

Share this post


Link to post
Share on other sites
FR_fnc_MonitorAI =
{
    params ["_grp", "_campfire", "_randombanditcar"];

    waitUntil {sleep 60; (player distance (leader _grp)) >= 2000};
    
        {deleteVehicle _x} forEach units _grp;
        deleteVehicle _campfire;
        deleteVehicle _randombanditcar;
        deleteGroup _grp;
};

A "waituntil" command dosent it check each frame? Or do the "sleep 60" line controll it to every 60 second? Dont need high precision timing with the current scripts.

while i am still asking about optimizing stuff which is the best way to call scripts like the one discussed above? Using execVM at the moment.

Share this post


Link to post
Share on other sites
Guest

Arg. Do not use ExecVm. Use functions.

Just search Functions on the wiki you'll find it easily.

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  

×