Home   Help Search Login Register  

Author Topic: Working fuel gauge  (Read 2691 times)

0 Members and 1 Guest are viewing this topic.

Offline Colonel_Klink

  • Members
  • *
  • Independent Addon Creator
    • DC3D Game Modelling Zone
Working fuel gauge
« on: 04 Aug 2003, 11:15:34 »
Ever wondered about how much fuel you vehicle is using (supposing the  on screen indicators are not present for the addon)?
Here's a way of getting a fuel gauge to work on your plane, car, or boat using the inbuilt fuel command:
This presumes you know how to make  gauges in Oxygen.

1.
Create the animated objects in O2 i.e. gas needle and axis points in the appropriate lods (driver view and memory)

2.
Code: [Select]

class aniDipGas
{
type = "rotation";
animperiod = 5;
selection ="diplomaticgas";
axis = "osa diplomaticgas";
angle0=0;
angle1=   -2.844876;
};

angle0 is the start angle of your gas needle ( or Empty mark)
angle1 is the end angle of your gas needle (or Full tank mark on the gauge) . Note angle1 is in Radians. If you need to convert degrees to radians get my Degree to Radian convertor here:
http://www.dc3d.co.nz/Downloads/OFP/Tools/Degree2Radians.exe


3. The script code in gasgauge.sqs (note this script runs as long as the car is not destroyed):
Code: [Select]
_lincoln = _this select 0

#Start
_lincoln animate ["aniDipGas", 0]

#Repeat
~0.001
?!(isengineon _lincoln): goto "Start"
_lincoln animate ["aniDipGas", (fuel vehicle _lincoln)]

?(not alive _lincoln): goto "Exit"
goto "Repeat"

#Exit
exit

4. call the above script from the init eventhandler:
Code: [Select]
init = [_this select 0] exec "\youraddonName\gasgauge.sqs"
That's about it.. I think :)   8)  Have fun.
« Last Edit: 04 Aug 2003, 11:29:37 by Colonel_Klink »
Rebel without a pause...D.I.L.L.I.G.A.F.

asmodeus

  • Guest
Re:Working fuel gauge
« Reply #1 on: 05 Aug 2003, 09:43:32 »
Great tip!  I'm making this a sticky as I've not seen it in a tutorial yet... (that I can remember)   ;)

Thanks Colonel_Klink!   8)

Asmo

DeLiltMon

  • Guest
Re:Working fuel gauge
« Reply #2 on: 06 Aug 2003, 22:03:41 »
Hi Klink great stuff, just been trying to implement it and I'm encountering errors with the init line, I'm getting a "Local Variable in Global Space" error on the "_this", then if I change it to "this" I get a "Type nothing, expected Any" error with the "#" at the end of the line.
Any ideas what I'm doing wrong?

Offline Colonel_Klink

  • Members
  • *
  • Independent Addon Creator
    • DC3D Game Modelling Zone
Re:Working fuel gauge
« Reply #3 on: 06 Aug 2003, 22:50:10 »
Hi DeLiltMon
This is the exact line I use in the addon.
init = [_this select 0] exec "\CWKLDIP\gasgauge.sqs";
and it works okay.
If you cant get it to work send it to me and I'll take a look.
Cheers
Bob
Rebel without a pause...D.I.L.L.I.G.A.F.

DeLiltMon

  • Guest
Re:Working fuel gauge
« Reply #4 on: 06 Aug 2003, 23:11:43 »
Thanks for the quick reply Klink, if it works for you then it must be something I've done (or not done), no big surprise there really, I'm getting the same error with the init for the wipers too  ::), I'll have a look over the code and selections again and if I have no joy I'll get back to you.
Maybe I should drink less beer while trying this stuff  :-\
Cheers
DLM

Rastavovich

  • Guest
Re:Working fuel gauge
« Reply #5 on: 14 Jan 2004, 13:36:30 »
there is a better solution for that:

Use "engine" eventhandler, off course you need to update the script then a bit.

Script would be:
Code: [Select]
#loop
?!isengineon _this : _this animate ["aniDipGas",0], exit
_this animate ["aniDipGas", fuel _this]
~1
goto "loop"

and you would call it (in config):
Code: [Select]
engine = "if (_this select 1) Then {(_this select 0) exec {\youraddonname\gasgauge.sqs}}"
Advantage of that code is, the script doesnt run when vehicle just stands around. There is no need to check every 0.001 second since you wont notice a big movement of the indicator at all.

Offline Colonel_Klink

  • Members
  • *
  • Independent Addon Creator
    • DC3D Game Modelling Zone
Re:Working fuel gauge
« Reply #6 on: 07 Feb 2004, 11:14:10 »
Nice improvement. thanks, Rastavovich.  ;D
Rebel without a pause...D.I.L.L.I.G.A.F.

Offline Delta Hawk

  • Members
  • *
  • I'm a llama!
Re:Working fuel gauge
« Reply #7 on: 14 Jun 2004, 17:35:22 »
Nice I'm going to put this in my 18-wheeler.  But i got a question.  I really suck at this script stuff, so where does

#loop
?!isengineon _this : _this animate ["aniDipGas",0], exit
_this animate ["aniDipGas", fuel _this]
~1
goto "loop"

go in the .sqs file.  I'm thinking it replaces the repeat section

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Working fuel gauge
« Reply #8 on: 25 May 2005, 19:24:07 »
This thread is now being unstuck, information from this thread has been submitted to the Editors Depot in the form of a document.

Link is Here

Planck
I know a little about a lot, and a lot about a little.