Jump to content
Sign in to follow this  
groshnak

Random delete script

Recommended Posts

So i'm trying to make a script that will randomly remove a group of things. I use this to randomize some ambush points so that they have a 33% chance of being there. Heres what i could come up with, but its quite clumsy:

randomdelete=[ambushman1,ambushman2,ambushman4,ambushman5] exec "delete.sqf"

_delete1=_this select 0;
_delete2=_this select 1;
_delete3=_this select 2;
_delete4=_this select 3;

_deletearray1 = ["_delete0","_delete1"];
_deletearray2 = ["_delete2","_delete3","_delete4"];

_lottery = floor(random 3);

switch _lottery do {

case 0: {{deletevehicle _x} foreach _deletearray1};
case 1: {{deletevehicle _x} foreach _deletearray2};
case 2: {exit};
default {};
};   

So you see if i wanted to delete 20 units with this script i would have to keep going on and on adding things to the script. Is there a way to automatically choose all the units that are given in the script call without having to define all of them 1 By 1?

Share this post


Link to post
Share on other sites

I think if I understand correctly, all you would need to do is use "_this" by itself:

//call to delete.sqf
[unit,unit2,unit3] execVM "delete.sqf";

//delete.sqf

{deleteVehicle _x} forEach _this;

//_this = [unit,unit2,unit3]

But I may be misreading or misunderstanding what your going for.

Share this post


Link to post
Share on other sites
I think if I understand correctly, all you would need to do is use "_this" by itself:

//call to delete.sqf
[unit,unit2,unit3] execVM "delete.sqf";

//delete.sqf

{deleteVehicle _x} forEach _this;

//_this = [unit,unit2,unit3]

But I may be misreading or misunderstanding what your going for.

And this would delete all the units? Well this works. I was overcomplicating it apparently.

So here we have 50% chance to delete all the given units.

_lottery = floor(random 2); 

switch _lottery do { 

case 0: {{deleteVehicle _x} forEach _this}; 
case 1: {exit}; 
default {}; 
};  

Share this post


Link to post
Share on other sites
I was overcomplicating it apparently.

You were drastically overcomplicating it. Is the group thing necessary?

delete_some_units =
{
{
	if ((random 100) > 33) then //right now 67% chance to be deleted. change > to < for 33% chance to be deleted
	{
		deleteVehicle _x;
	};
}forEach _this;
};

[unit1,unit2,unit3,unit4,unit5, /* etc */] call delete_some_units;

Share this post


Link to post
Share on other sites
You were drastically overcomplicating it. Is the group thing necessary?

delete_some_units =
{
{
	if ((random 100) > 33) then //right now 67% chance to be deleted. change > to < for 33% chance to be deleted
	{
		deleteVehicle _x;
	};
}forEach _this;
};

[unit1,unit2,unit3,unit4,unit5, /* etc */] call delete_some_units;

Thanks! This seems like the "better way" i was looking for. Group thing is not needed, i can just run this same thing for all the different groups.

Dreaded's chance system is what I was going to recommened to you as a switch statement is way too much work...

And also FYI, .sqf ignores the command "exit": https://community.bistudio.com/wiki/exit

Good to know, sqs is hard to get rid of :)

Edited by Groshnak

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  

×