Jump to content
Sign in to follow this  
456820

Take away fuel

Recommended Posts

Just wondering how I can remove a certain amount of fuel from a large list of vehicles. Since there is no 'getFuel' command so I can't get the amount of fuel and then remove say 0.30 fuel so just wondering are there any other ways of doing this?

Or am I just missing something really obvious which is most likely since I have not done much scripting for ArmA in a long time so I'm a tad rusty.

Share this post


Link to post
Share on other sites

Well you might get the value from the 'dialog' that shows the

amount (top left). Not sure though.

Share this post


Link to post
Share on other sites

http://community.bistudio.com/wiki/fuel

that checks how much fuel a unit has.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

unitname setfuel ((fuel unitname) -0.3)

for a list I'd use the foreach command, but not sure if you can make it check each individual fuel level via a trigger, unless you did it via a script

trigger covering all units you want, activation anyone:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

{[_x] exec "fuelscript.sqs"} foreach units (list this)

and then the script could be:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unit = _this select 0

_currentfuel = fuel _ unit

_unit setfuel (_currentfuel -0.3)

exit

[edit]

Forgot to say this is untested and off the top of my head, and yes, sqf is better, but I haven't a clue how all that works, so sqs it is.

Share this post


Link to post
Share on other sites

Thanks a lot Messiah works perfectly.

Edit - Just wondering is it possible to do the same thing but with ammo? Like just set enemy in a trigger area to %50 ammo?

Share this post


Link to post
Share on other sites

Glad to hear it worked. It means the editing brain isn't totally rusty just yet. Just to mention that you can also add a side check into the script if you only wanted it to hapen to a certain side, for instance, or a class check if you only wanted it for cars, tanks, aircraft, etc. Also, if this is for MP, the script would be executed on all clients, which means that its likely the unit would end up with 0 fuel once all the clients had run the script. I'm at work at present, but I have a Client/Server check bit of code back home, that I can insert into the script.

Its certainly possible for ammo, but I have a feeling it wouldn't be quite as simple. You would have to check what weapon the unit was carrying, what ammo that weapon used and how much of that ammo he was carrying, and then remove that ammunition. Unless of course there's a command in ArmA that acts like the ammunition slider in the unit edit screen, and can set things to 0.5 etc - I'm not totally sure.

I'll have a think about it and come back later with something (hopefully) - In the mean time perhaps someone quicker/better may have a solution.

Share this post


Link to post
Share on other sites

Ahh yeah the script is for MP, so will I just need to add

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local server) : exit

To the front of the script to make it run just on the server?

Share this post


Link to post
Share on other sites

the ammo one is a little out of my experience, but I've been thinking it over a little:

I'd say you'd obviously want to use the magazines command to check the ammo the units are carrying. So, same as before, trigger, set to detect enemy, and then the same activation code but of course a new script name.

There probably a better was of doing this, but I'm not sure how to get the script to take 50% ammo, round it to the nearest whole number, and take away... so:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

? !(local server) : exit

_unit = _this select 0

_mags = (magazines _unit)

_count == 3

_loopcount == 0

_mag1 = (_mags select 0)

_mag2 = (_mags select 1)

_mag3 = (_mags select 2)

_mag4 = (_mags select 3)

_unit removemagazines _mag1

_unit removemagazines _mag2

_unit removemagazines _mag3

_unit removemagazines _mag4

#loop

?_loopcount = _count : exit

_unit addmagazine _mag1

_unit addmagazine _mag2

_unit addmagazine _mag3

_unit addmagazine _mag4

_loopcount == (_loopcount + 1)

goto "loop"

there's definitly a better way to do it, but my scripting is simple and direct, rather than clever and correct biggrin_o.gif . Essentially the script checks the mags the unit has, and this returns an array. I've assumed that any given unit is at max going to have 4 different magazines on him at any given time - if this is wrong, then you just need to add more mag selections in the script. The script then removes all these magazines and then adds a set number back again (as defined by _count). Not exactly 50%, but a similiar end result.

again, hopefully someone who knows what they're doing and provide a better example.

Share this post


Link to post
Share on other sites
Ahh yeah the script is for MP, so will I just need to add

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local server) : exit

To the front of the script to make it run just on the server?

If you using arma v1.08 + (may even be lower) you can use the IsServer command instead of the local command.

Cheers

GC

Share this post


Link to post
Share on other sites
http://community.bistudio.com/wiki/fuel

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

unitname setfuel ((fuel unitname) -0.3)

Thanks ,that works a treat for me in the 'On Act' a trigger to make a Landie run outta fuel when it hits the trigger!

Changing the -0.3 to -10.0 notworthy.gif

Share this post


Link to post
Share on other sites

eh... I never managed to get any of my scripts to work without help of others...

So, I ask for help again, I have repair script, but I will also like to add refueling to the script. So when vehicle gets to certain amount of fuel to be refueled. I have this so far and it's not working:

*bold is modified by me

if (!isServer) exitWith {};

_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {10};
_damage = if (count _this > 2) then {_this select 2} else {0};
[b]_fuel = if (count _this > 3) then {_this select 3} else {0};[/b]
_times = if (count _this > 4) then {_this select 3} else {0};

_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_damage < 0) then {_damage = 0};
[b]if (_fuel < 0) then {_fuel = 0};[/b]
if (_times == 0) then {_noend = true;} else {_noend = false;};
if (_times < 0) then {_times = 0; _noend = true;};


while {_run} do 
{
waitUntil {getDammage _unit > _damage};
       [b]waitUntil {?(fuel unit < _fuel)[/b]
sleep _delay;
_unit setDamage 0;
       [b]_unit setFuel 1;[/b]

if !(_noend) then {_rounds = _rounds + 1};
if ((_rounds == _times) and !(_noend)) then {_run = false;};
};

Repair script works but after modifiying it with my refueling part it stops working.

Share this post


Link to post
Share on other sites

Please? Anyone? I really need this working for a mission I'm creating...

Share this post


Link to post
Share on other sites

Mmmm three errors on the same line :

instead of

       waitUntil {?(fuel unit < _fuel)

Type

       waitUntil {fuel _unit < _fuel};

But what's strange with your script is that a dammaged unit will also be refueled, and that an "out of fuel" unit will also be repaired.

Share this post


Link to post
Share on other sites

thx... I've fixed my problem. But I can see your point.

So should I go with something like:

if (bla bla) then

if (..) then...

And make two situations to check wether it's out of fuel then refuel or if it is damaged then repair...

I'm using this to repair and refuel planes in the air which are flying in loop during the mission... (just as visual effect)

Basically now I'm aware it's weird how I've set it up but the funny thing is, script does it's job so far... XD

What do you suggest to make it work like that?

Atm it looks like this:

if (!isServer) exitWith {};

_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {0};
_damage = if (count _this > 2) then {_this select 2} else {0};
_fuel = if (count _this > 3) then {_this select 3} else {0};
_times = if (count _this > 4) then {_this select 4} else {0};

_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_damage < 0) then {_damage = 0};
if (_fuel < 0) then {_fuel = 0};
if (_times == 0) then {_noend = true;} else {_noend = false;};
if (_times < 0) then {_times = 0; _noend = true;};


while {_run} do 
{
waitUntil {getDammage _unit > _damage or fuel _unit < _fuel};
sleep _delay;
_unit setDamage 0;
   _unit setFuel 1;

if !(_noend) then {_rounds = _rounds + 1};
if ((_rounds == _times) and !(_noend)) then {_run = false;};
};

Edited by Minoza

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  

×