Jump to content
Vandeanson

addaction with condition "!alive lootbox1"

Recommended Posts

Gents,

 

I am trying to have this addaction only available to my player when the object "lootbox1" is not alive.

 

in init.sqf:

player addAction ["Spawn Lootbox","lootboxspawn.sqf",[],0,false,false,"","!alive lootbox1"];

 

This addaction will spawn a lootbox with Variable Name "lootbox1". I want this addaction to disappear if "lootbox1" is created and "alive". but when i destroy it, the addaction should become available again.

The addaction works as long as i do not use the condition "!alive lootbox1". Hence I am assuming the code for this condition is wrong.

 

appreciate any help;)

 

cheers

Share this post


Link to post
Share on other sites

What did you write in your sqf?

You need to "pass" the variable to your new lootBox. If not lootBox1 will stay lootBox1, destroyed or not. And broadcast the variable.

So write :

lootBox1 = createVehicle [ bla bla box]; // global (but exists only on the player's PC calling addAction)

publicVariable "lootBox1";  // variable shared with the other clients so they can addAction also (MP only, useless for SP)

lootBox1 is updated as global (and public) variable referring to the new created object, because you public variable its name.

 

Other way, more oriented for any named object you want to respawn:

Use setVehicleVarName. But this command is local and your addAction scope also. You'll probably need to broadcast that on all PCs. Even if the box is globally spawned (visible by all), its name must be shared.

 

So, you should have something like:

_lb = createVehicle [ bla bla box];  // A variable named _lb is passed to an object but that doesn't mean the object is named lootbox1
[_lb,"lootBox1"] remoteExec ["setVehicleVarName"]; //  now you have a string representation of the object (several object can have the same!)
[_lb, compile Format ["%1=_This","LootBox1"]] remoteExec ["call"];  // you affect the name to the object. It's unique (the last called, the last named)

 

Now you can say lootBox1 is always the last created box and you can apply any condition you want.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Hey man, thanks for your relpy;)

 

this is the lootboxspawn.sqf:

 

_lootbox = "Box_FIA_Support_F" createVehicle getPos player;
_lootbox setVehicleVarName "lootbox1"; lootbox1 = _lootbox;
clearMagazineCargoGlobal _lootbox;
clearWeaponCargoGlobal _lootbox;
clearItemCargoGlobal _lootbox;
clearBackpackCargoGlobal _lootbox;
_lootbox allowDamage false;
_lootbox addaction ["Remove","collect.sqf"];

 

and this is the collect.sqf (to delete the placed box)

 

params ["_obj"];
sleep 1;
deleteVehicle _obj;

would that still match your solution proposal?

I do not grasp it yet but will investigate tomorrow=)

 

Cheers

Share this post


Link to post
Share on other sites

some background fyi: i want this to be the box where rewards from completing objectives in my ravage survival mission spawn (e.g. complete a kill quest and upon completion a randomly selected item spawns into the box). the box needs to be placed at a secure and accessible location and it should give an incemtive for the player to build his base there. the above requested is needed, si that i can despawn the box and respawn it at a new location (e.g. when moving to another part of the map)

Share this post


Link to post
Share on other sites

SP or MP?

If MP, that will not work for the reason already written.

For your aim, you need to think about what you want exactly. You can spawn all boxes you want, you can add some specific behavior on it or not.

You can have a toggling addAction for deleting/spawning a create with a toggling menu.

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

×