Jump to content
Sign in to follow this  
nicolasroger

same script on mutiple unit problem

Recommended Posts

I have a problem with a script I've created.

I use the same script on 2 empty vehicle. When I use the first vehicle, everything is alright. But when I get out of the first vehicle and use the second one, some problems occur.

The second vehicle script still use variables from the first vehicle script.

I'm pretty sure I'm not the first one who has this problem but I couldn't find anything with the search function.

Most of my variables are local, but that doesn't help. Is there anyway I can make variables specific to the vehicle who call the script?

Share this post


Link to post
Share on other sites

Every vehicle in the game I believe you has a space for its own variables you can define. By "vehicle" i mean entity in general. Use setVariable and getVariable.

Share this post


Link to post
Share on other sites

I tried messing around with setVariable, but I couldn't get my script to work with it.

here is my script:

carpet.sqf:

//______________________________________________
// Author: Nicolas				 |
// version: 1.1					 |
// Do whatever you want with this script, 	 |
// just give proper credit if needed		 |
//______________________________________________|
//

//get variables from the initbox of the plane
_plane = _this select 0;
waitUntil {(driver _plane) == player};
_minAlt = if (count _this > 1) then {_this select 1} else {40};
_nbBombs = if (count _this > 2) then {_this select 2} else {12};
_nbSalve = if (count _this > 3) then {_this select 3} else {3};
_bombDelay = if (count _this > 4) then {_this select 4} else {0.15};
_bombType = if (count _this > 5) then {_this select 5} else {"Bo_GBU12_LGB"};

//compile functions
pause = compile loadFile "carpet\pauseBombing.sqf";
resume = compile loadFile "carpet\resumeBombing.sqf";

//temp variables
_i = 0;
_localNbBombs = _nbBombs;
_localNbSalve = _nbSalve -1;
_times = (_nbBombs / 2);

//spawning bombs
while {_nbSalve > 0} do
{
sleep 2;
_localNbBombs = _nbBombs;
  	hint format["Carpet Bombs\n%1 | %2", _nbBombs, _localNbSalve];
_id0 = call pause; //add the action "open bomb suit" and check for altitude
waitUntil {_id0}; 

for [{_i=0}, {_i<_times}, {_i=_i+1}] do
{
	_bomb = _bombtype createVehicle [1000, 1000, 1000];
	_bomb attachTo [_plane, [4, 0, -5]]; //spawn under left wing
	sleep 0.01;  //allow the bomb to be attached before detaching it
	detach _bomb;		
	sleep _bombDelay;
	_localNbBombs = _localNbBombs - 1;
   	hintSilent format["Carpet Bombs\n%1 | %2", _localNbBombs, _localNbSalve];

	_bomb2 = _bombType createVehicle [1000, 1000, 1000];
	_bomb2 attachTo [_plane, [-4, 0, -5]]; //spawn under right wing
	sleep 0.01;  //allow the bomb to be attached before detaching it
	detach _bomb2;
	sleep _bombDelay;
	_localNbBombs = _localNbBombs - 1;
   	hintSilent format["Carpet Bombs\n%1 | %2", _localNbBombs, _localNbSalve];
};
_nbSalve = _nbSalve - 1;
_localNbSalve = _localNbSalve - 1;
};

the function "pause":

_returnValue = false;
test = false;

_id3 =  _plane addAction ["Open bomb suit", "carpet\resumeBombing.sqf"];
waitUntil {test};
hint format["Carpet Bombs\n%1 | %2", _nbBombs, _localNbSalve];

if ((getPos _plane select 2) < _minAlt) then
{
_plane removeAction _id3;
player globalChat format["Minimum altitude of %1 required", _minAlt];
_id1 = call pause;
} 
else
{
_returnValue = true;
player globalChat format["%1","Bombs Away!"];
_plane removeAction _id3;
};
_returnValue

the function "resume":

test = true;

here is what i do to test my script:

-I put the same script on 2 different empty c-130j

-I set 2 different minimum altitude allowed

-I enter the first plane and use the action "open bomb suit" (it is inside function "pause")

-I receive the text "Minimum altitude of 66 required"

-I now enter the second plane and use the action "open bomb suit"

-I receive the text "Minimum altitude of 50 required"

everything is good so far, BUT:

-I now go back in the first plane and use the action "open bomb suit"

-I receive the text "Minimum altitude of 50 required" (there is my problem)

it should say 66, not 50 :confused:

tell me if anything isn't clear in my script or anywhere else. I tried to comment my script properly. I want to help you help me:D

Edited by nicolasroger

Share this post


Link to post
Share on other sites

I want to add that I'm pretty sure the problem isn't located in the lines below "_id0 = call pause;" and not in the "//temp variables" part. So don't bother to understand these part.

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  

×