Jump to content
Joe98

How to delete an object at random with a script?

Recommended Posts

I place myself on the map and arrange it so I start at one of 30 places at random.

I place 2 enemy soldiers on the map. They are named

red1 and red2

 

I want the 2 enemy soldiers to start the mission about 200 meters to my north. When the mission starts a script runs and places the 2 soldiers 200 meters to my north as planned.

 

However I want red2 to appear sometimes and not other times. I means I never know how many enemy there are.

So, in the init of red2 I set it so that he appears only 50% of the time

Now, from time to time red2 is deleted. It means the script above stops with an error message:

"object red2 does not exist" or words to that effect.

 

In the meantime if I wish to delete red2 in a script, I can use: deletevehicle red2

So, I am looking for a command along the lines of:

deletevehicle red 2 and do so at random.

 

What is the command for this?

.

 

Share this post


Link to post
Share on other sites

I'm not sure I understood the request exactly but you could try,
 

In the init file put,

red1=objNull;

Then something like,

random=[0,1] BIS_fnc_selectRandom;
If (red1 !=objNULL && random ==1) then {deletevehicle red1;};

Have fun!

  • Like 2

Share this post


Link to post
Share on other sites

Yep, wogz187's script seems about right, or you could actually do it the other way around (depending on the structure of your other scripts and calls)..., that is instead of deleting red2 at random, create red2 at random, with pretty much the same effect.

 

  • Like 2

Share this post


Link to post
Share on other sites
20 hours ago, wogz187 said:

Then something like,


random=[0,1] BIS_fnc_selectRandom

nothing will happen unless you call it first

  • Haha 2

Share this post


Link to post
Share on other sites


if (random 100 < 75) then {

    // With a chance of 75%

    deleteVehicle red2;

};

  • Like 1

Share this post


Link to post
Share on other sites

If using the Editor, just set the unit to 50% probably in the probability setting. Just double-click to open the settings. No need to script.

Share this post


Link to post
Share on other sites
3 minutes ago, Von Quest said:

If using the Editor, just set the unit to 50% probably in the probability setting. Just double-check to open the settings. No need to script.

 

It seems like he knows that, and actually is looking for a way to do it in a script also.

 

Reason unknown though.

 

I need to add that you can check the existance of a variable (or unit) with isNil:

 


if (!isNil ”red2”) then {

    // red2 exists and handling it here will not generate script errors.

};

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, wogz187 said:

I guess it doesn't have to be either or.

 

giphy.gif

  • Thanks 1

Share this post


Link to post
Share on other sites

@everybody,

Let's be honest though, if I forget to type "call", I probably should stick to the selectRandom method.

 

Thanks, Dedmen.

  • Like 1

Share this post


Link to post
Share on other sites
15 hours ago, engima said:

 


if (random 100 < 75) then {

    // With a chance of 75%

    deleteVehicle red2;

};

 

 

Thank you to enigma.  This is what I was looking for.  I wrote it like this:

 

if  (random  100  <  50)  then  {deleteVehicle red2 };   // Giving a chance of 50% of being deleted

 

 

  • Like 3

Share this post


Link to post
Share on other sites

deleteVehicle selectRandom [objNull, red2]

will also give you 50/50 chance. Or

call selectRandom [{}, {deleteVehicle red2}]

  • Like 4

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

×