Jump to content
Sign in to follow this  
shadow

Script for chopper loosing fuel?

Recommended Posts

I'm trying to think out how a script would look like taking away fuel from a chopper, but I'm not sure where to begin confused.gif

What I want is when the chopper has sustained 25% damage (unitname getdammage >= .25) I want to simulate a leaking fuel-tank by taking away the fuel bit by bit (i.e. increments of .01 in value pr. second for the fuel).

Then when the chopper have sustained 50% damage the fuel-loss should increase to i.e. .05 in value.

Finally when the chopper has sustained 75% damage the fuel-loss should increase to i.e. .1 in value.

I'm not sure where to begin. Is there a "getfuel" or "somefuel"-command ?

My biggest problem is that I'm not sure how I'd put up the mathematics (get amount of fuel and subtract with a variable).

Anyone clearheaded enough to help me? tounge.gif

I would very much like this to work before the weekend kicks in (need it for a mp-mission). Oh! and if it makes a difference; the mission will be run from a dedi-server and the script will be used for one chopper only.

Thanks in advance xmas.gif

Share this post


Link to post
Share on other sites
Guest

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

_chop = _this select 0

_rate = 0.0

_dt = 0.1

#loop

?(_chop getDammage > 0.25):_rate=0.01

?(_chop getDammage > 0.5):_rate=0.05

?(_chop getDammage > 0.75):_rate=0.1

~_dt

_chop setFuel( fuel(_chop) - _dt*_rate)

?(fuel _chop > 0): goto "loop"

<span id='postcolor'>

Or something like that

Share this post


Link to post
Share on other sites

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

?!(local heli):exit

#loop

~1

_i=0

?getdammage heli >=0.25:_i=0.01

?getdammage heli >=0.5:_i=0.05

?getdammage heli >=0.75:_i=0.1

?!(alive heli):exit

heli setfuel ((fuel heli)-_i)

goto "loop"<span id='postcolor'>

I can see denior's script now but nevermind. Mine is slightly different.  xmas.gif

Repaired timing.

Share this post


Link to post
Share on other sites
Guest

Bart.Jan, there is a bit of an error in your script. You have a sleep 0.001s long and then you remove the fuel. But the fuel rate is per second.

That chopper will be running out of fuel very very quickly xmas.gif

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (denoir @ Dec. 20 2002,15:31)</td></tr><tr><td id="QUOTE">Bart.Jan, there is a bit of an error in your script. You have a sleep 0.001s long and then you remove the fuel. But the fuel rate is per second.

That chopper will be running out of fuel very very quickly  xmas.gif<span id='postcolor'>

You are right. I repaired it.

Share this post


Link to post
Share on other sites

What is "~_dt" ?

Should I insert a "1" there to make the cycles drain fuel once every second?

If I add this into the script: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">?(_chop getDammage <= 0.05):_rate=0<span id='postcolor'>

Will that stop draining fuel then? Like simulating that the leak have been repaired by a repair-truck...

Share this post


Link to post
Share on other sites
Guest

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Shadow @ Dec. 20 2002,15:36)</td></tr><tr><td id="QUOTE">What is "~_dt" ?<span id='postcolor'>

It should sleep for an interval _dt. If you wait for one whole second the fuel drain will be choppy. Setting a smaller interval will make it smooth smile.gif

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">If I add this into the script: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">?(_chop getDammage <= 0.05):_rate=0<span id='postcolor'>

Will that stop draining fuel then? Like simulating that the leak have been repaired by a repair-truck...<span id='postcolor'>

Yepp smile.gif

Share this post


Link to post
Share on other sites

Okies, thanks

I see this is where the magic is:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_chop setFuel( fuel(_chop) - _dt*_rate)

<span id='postcolor'>

I'm trying to understand this part: ( fuel(_chop) - _dt*_rate)

fuel?

is that OFP's parameter for fuel for a vehicle?

So that line would mean fuel from the chopper minus 0.1*the rate

This is just what I have been avoiding since the first day I started writing external scripts tounge.gif

sooo confusing for my little brain biggrin.gif

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Shadow @ Dec. 20 2002,09:54)</td></tr><tr><td id="QUOTE">I'm trying to understand this part: ( fuel(_chop) - _dt*_rate)

fuel?

is that OFP's parameter for fuel for a vehicle?

So that line would mean fuel from the chopper minus 0.1*the rate<span id='postcolor'>

Yep, you got that right, fuel is a function call on a Vehicle, so vehicles fuel...

Leaking fuel is great, also you could make it so that when the chopper is refueled and started when heavily damaged it will explode after a while. That's the kind of fun tricks I like to put in my missions. xmas.gif

Share this post


Link to post
Share on other sites

I could'nt get your script to work right away, Den.

It reported som error with "_chop=_this select 0" something about expecting array etc

so I modified it to this and :

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

_dt = 0.1

#loop

?(getDammage heli1 > 0.25):_rate=0.01

?(getDammage heli1 > 0.5):_rate=0.05

?(getDammage heli1 > 0.75):_rate=0.1

~_dt

heli1 setFuel( fuel(heli1) - _dt*_rate)

?(fuel heli1 > 0): goto "loop"

<span id='postcolor'>

And now it works fine, except I need to tweak those rates a little bit (loosing too much fuel with 0.1

The bad thing with this version of the script is that it will only work with the united named "heli1". That is fine in this case, but it is not as dynamic as I was hoping for (possible future usage with all choppers in a mission etc)

BN880: I don't think I want to implement the explosion-thingy. I'm not sure how reallistic that is. I think I'll stick with the leaking_fuel-tank_untill_chopper_is_repaired for now wink.gif

Thanks for all the input fellas. I'll write you all into my will now biggrin.gif

Share this post


Link to post
Share on other sites
Guest

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Shadow @ Dec. 20 2002,17:46)</td></tr><tr><td id="QUOTE">I could'nt get your script to work right away, Den.

It reported som error with "_chop=_this select 0" something about expecting array etc<span id='postcolor'>

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

The bad thing with this version of the script is that it will only work with the united named "heli1". That is fine in this case, but it is not as dynamic as I was hoping for (possible future usage with all choppers in a mission etc)

<span id='postcolor'>

The point of that line was exactly to avoid that.

Save the code to a file, say "heliLeak.sqs" and then call it with

[ unitname ] exec "heliLeak.sqs"

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (denoir @ Dec. 20 2002,17:54)</td></tr><tr><td id="QUOTE">The point of that line was exactly to avoid that.

Save the code to a file, say "heliLeak.sqs" and then call it with

[ unitname ] exec "heliLeak.sqs"<span id='postcolor'>

I know and I tried.

Gives an error, something like this: "type object, expected array"

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

_dt = 0.01

#loop

?(getdammage heli1 < 0.85):_rate=0

?(getDammage heli1 > 0.25):_rate=0.01

?(getDammage heli1 > 0.5):_rate=0.025

?(getDammage heli1 > 0.75):_rate=0.05

~_dt

heli1 setFuel( fuel(heli1) - _dt*_rate)

?(fuel heli1 > 0): goto "loop"

<span id='postcolor'>

These values seems fine. Giving you approx 5, 2.5 and 1 minute of flight-time smile.gif

Share this post


Link to post
Share on other sites
Guest

Strange, I tried it here and it works fine confused.gif Are you sure that you remembered to put the unitname within brackets?

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

[ unitname ] exec ...

<span id='postcolor'>

Share this post


Link to post
Share on other sites

oh! wow.gif

I was'nt aware of that.

Works fine with brackets.

Don't mean to be annoying, but care to explain why I need the put brackets around the unitname?

Is it to tell OFP that the name inside the brackets is the variable to inherit from the "_this"-part in the script and into the script's parameter : "_chop" ?

Share this post


Link to post
Share on other sites
Guest

You use brackets to make an array. Since the line was

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

_chop = _this select 0

<span id='postcolor'>

We are telling it that _chop equals the first element of the array _this.

It is fully possible to define it like

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

_chop = _this

<span id='postcolor'>

and then call it with

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

unitname exec ...

<span id='postcolor'>

However usually you want to send multiple parameters to your script and then an array is needed.

Share this post


Link to post
Share on other sites

aaah okies smile.gif

Now I understand

thanks, bud

I'm kinda like the Norwegian railway:

I might be slow, but I'll get there.....eventually wink.gif

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  

×