Jump to content
Sign in to follow this  
moddero

Surrender script(Range 300 meters)

Recommended Posts

I wish to create a script wich makes an specific number of units(all from the same side) "surrender" to the enemy side(just for blufor and opfor)when they are outnumbered by 60%

those units should be inside 300 meters radius circle from the enemy(any unit).

This is what i have come up whit:

1 = allunits + vehicles;
{


	if (_x iskindof "AllVehicles" &&(alive _x)) then {
_s = side _x;

_group=nearestObjects [_x, ["Man","Man"], 300]select 1 ;



switch (true) do {
			case (blufisur): 
				{


while(true)do {
_puntirank = rating _x;
_rankm = rating _redinmax; 
if (_puntirank>_rankm) exitWith {_redimax=_x-_redinmax;};
};
blufi join (group _redinmax); 
};
};
			case (redisur): 
				{
while(true)do {
_puntiranki = rating _x;
_rankj = rating _blufinmax; 
if (_puntiranki>_rankj) exitWith {_blufinmax=_x-_blufinmax;};
};
redie join (group _blufinmax); 
};
};


            {
       //i have placed this hint to see if  this paragraph runs,here it's where i have problems, i have never seen one of this hints in game...
           hint"start";
             switch (_s) do {
			case west: 
				{ _blufi=_blufi+[_x];hint "blufor detected";hintSilent format ["%1",_blufi]; };
			case east: 
				{ _redie=_redie+[_x]; };
			case resistance: 
				{ _nocolour=_nocolour+[_x]; };
};
switch (true) do {
			case ((_blufi*1.6)>(_redie)): 
				{ blufisur=true;
                                    hint "SURRENDER!!!"; };
			case ((_redie*1.6)>(_blufi)): 
				{ redisur=true; };
		};
}forEach group;

   } forEach 1;          







};

As i mark in the code i have problems when using the 2º for each inside the first one( for each 1 ;for each group;)the hints i placed never show up and the units never surrender because no group side its ever detected... is it not posible to use the comand for each 2 times at the same script? or calling it inside another?or both?

i have checked the information regarding the comand and i found nothing useful for my problem...

P.S.:I noticed that local variables does not work outside the comand ;example:

1=allunits;
{
_me=player;
}foreach 1;
hintSilent format ["%1",_me]; };

does not show the player unit...

i dont know if it's also the same with all the variables...

i tried sometimes with globals and it works, but sometimes not.(blufisur,redisur):confused:

Edited by moddero
translation mistakes

Share this post


Link to post
Share on other sites

A few things that may be causing problems just looking at the last script.

First I don't think a variable can be a number or start with a number so 1 = allunits; is probably not a good idea, also avoid single letter variables, use something a little more descriptive.

When you have a variable defined within {_me=player; } and you want the rest of the script to be able to see that variable you need to use private ["_me"];

You don't need the square brackets for single definitions but always use them for multiple definitions ie. private ["_me","_whatever"];

Also you should see some errors being produced if not then you should be using this http://forums.bistudio.com/showthread.php?121163-Script-not-working-Use-the-showScriptErrors-parameter!

Edited by F2k Sel

Share this post


Link to post
Share on other sites

hello,thanks for answering.

The second script its just for pointing one fact (reduced version)that local variables cannot be called in the same script from outside the foreach comand...however this works:

1=allunits;
{
_me=player;
hintSilent format ["%1",_me]; };
}foreach 1;

and this one too

off topic

This one its for stuning when some sort ammo its fired at someone(aturdido=stuned,wraith_mag=ammo)

and detect if an animation its running(particullary the animation i use for simulating the stun)

     l = allunits + vehicles;
{

	if (_x iskindof "AllVehicles" &&(alive _x)) then {
_movimient = _x addeventhandler ["AnimChanged",{if (_this select 1=="AdthPercMstpSrasWpstDnon_A3") 
then {hint"ok correcto";}} ]; 




          aturdidor = _x addeventhandler ["HandleDamage",{aturdido=_this select 0;if (_this select 4=="wraith_energy") then {aturdido switchmove "AdthPercMstpSrasWpstDnon_A3";{}}else{ _this select 2;}} ]; 


       };
} forEach l;

my problem would be with this:


1=allunits;
{
_me=player;


{
//exactly here its my problem
hint"this message never shows up";
hintSilent format ["%1",_me]; };
}foreach _x;
}foreach 1;

I need to run a 2º search whitin all the members of the group for detecting the sides of each one and compare if the number of one side its 60% higher than the other

(switch with case west,case east,case resistance and switch case blufir*1.6<redie ,case redie*1.6<blufir)

ah i forgot this also works:

1 = allunits + vehicles;
{


	if (_x iskindof "AllVehicles" &&(alive _x)) then {


_group=nearestObjects [_x, ["Man","Man"], 300]select 1 ;
hintSilent format ["%1",_group]; };
//hitsilent because it will be keep apearing till you end the mission and would be anoying...and because it lags a lot playing so many"dings"
}foreach 1;


Anyway my question should be:

Can i use the "foreach" comand within itslef?

and if the answer its not...

how could i create a script wich do what i want it to do.

For example sending the message"we surrender" when a certain group of units are outnumbered by an enemy squad ,60%higher withing a range of 300 meters(i don want the whole side to surrender just the small group)

Regarding the variable name i am agree with changing it but since it works everytime i try it i really don't care too much...in fact i did not named that way..i picked it up from USPMON script same as the switch for detecting the side (and in the spoiler script, the handle damage from celery scripts).

USPMOM has a surrender script but it makes all the units from one surrender(they put their hands and you can force them to join your group...may take a while tought...since they sometimes send you...)

I JUST WANT A SMALL GROUP WITHIN 300 M RADIUS!

but the only way i have think of programing it, its by this way...

maybe using while... or something...i dont know...thats why i need help...i have no more ideas...:(

Edited by moddero

Share this post


Link to post
Share on other sites

My problem with this script is that it crashes due to several errors.

1. you have two {{ and three }}} fix by remove } after hintSilent format ["%1",_me];}

2. error foreach : type number expected array fix by using _d1= allunits;

3. error found object expected array }foreach _x; should be } foreach [_x];

1=allunits;
{
_me=player;

{
//exactly here its my problem
hint"this message never shows up";
hintSilent format ["%1",_me]; };
}foreach _x;
}foreach 1;

try

_1d = allunits;
{

_me=player;
{
//exactly here its my problem
hint"this message never shows up";
hintSilent format ["%1",_me];
}foreach [_x];

}foreach _1d;

or

{
_me=player;
{
//exactly here its my problem
hint"this message never shows up";
hintSilent format ["%1",_me];
}foreach [_x];

}foreach  allunits;

I know this is only an example and not part of the script but you need to understand the basics.

I take it you still haven't enabled -showscripterrors other wise it would have told you what was wrong.

Share this post


Link to post
Share on other sites

Uhmm seems it can be done...both messages were shown at the screen.

My name and the other hint.

however this does no work as i intended

_des1 = allunits + vehicles;
{


	if (_x iskindof "AllVehicles" &&(alive _x)) then {


_groupi=nearestObjects [_x, ["Man","Man"], 300]select 1 ;



};

 {





           _s=side _x;
hintSilent format ["%1",_s];
             switch (_s) do {
			case west: 
				{ _blufi=_blufi+[_x];hintsilent"blufor detected";};
			case east: 
				{ _redie=_redie+[_x]; };

};

         }forEach [_groupi];


   } forEach _des1;  

its shows me:

0xcb866c

when it should be one of the sides...(west,east...)

and if i place

hintSilent format ["%1",_groupi];

showns "ANY"(inside the 2º "foreach" ,if inside the 1º it shows all the groups...one each time)

P.S.:I am trying to use the "-showScriptErrors" comand but i had some problems activating it (I thought it was already activated,but not showing any errors),and now...trying to see the scripts errors throught te ones from the addons i have active...i should probably try it without the addons activated,but i want the script to be compatible with them...

Edited by moddero

Share this post


Link to post
Share on other sites

Your were missing quite a bit of stuff.

A foreach in the first part of the script, declaring variables and a little delay so that all the hints can be seen not just the last.

You can always look in the error log it should be in Applications the file is arma2oa.RPT yours may be named differently depending on what you have installed. You can delete it to get a clean report next time you run the mission.

You could also the Squint editor that has built in error checker.

Upateded version in spoiler

private ["_groupi","_blufi","_redie"];

_des1 = allunits + vehicles;
{
          if (_x iskindof "AllVehicles" &&(alive _x)) then {

     _groupi = nearestObjects [_x, ["Man","allvehicles"], 300] ;

};
     } foreach  _des1;

/////////////////////////////////////////////////

   {
    _s = side _x;

         hintSilent format ["Name %1  Side %2 ",_x,_s];
sleep 2; // allow hint to display
             switch (_s) do {
			case west: 
				{ _blufi=_blufi+[_x];hintsilent "blufor detected";};
			case east: 
				{ _redie=_redie+[_x];hintsilent "opfor detected"; };


};
sleep 2;// If there are multiple units it allows time for them to be seen in the hint
    } forEach _groupi;

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  

×