Miles Per Gallon - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Miles Per Gallon (
/showthread.php?tid=508547)
Miles Per Gallon -
Luis- - 22.04.2014
Right guys, i'm stumped. After nearly a day searching the internet on how MPG works, i'm resorted to asking here.
Basically i'm revamping my fuel system and am adding in mpg & fuel capacity for each vehicle, so far I've got the mileage system working, but how would I go about getting the MPG from the mileage?
What would the formula be?
Re: Miles Per Gallon -
Luis- - 23.04.2014
Going to have to bump this, need help on the matter.
Re: Miles Per Gallon -
BigBrainAFK - 23.04.2014
i think you would do something like:
pawn Код:
randomtimer()
{
for(new a = 0; a < sizeof(Yourfuelarray); a++)
{
Yourfuelarray[carid] = drivenmiles * milespergallon
}
}
and then just link the function with a timer
Re: Miles Per Gallon -
Luis- - 23.04.2014
Ah right. You'll have to excuse me cause i'm a newbie when it comes to complex maths.
So basically the above code will give me the miles per gallon of say a Sultan? I would just times the mileage of the car with the miles per gallon that's in my array?
Re: Miles Per Gallon -
BigBrainAFK - 23.04.2014
yah you first have to set like an array for the milespergalon if this should be something else for every car
like:
pawn Код:
new milespergalon[212][] = {
"4", "4.5" and so on }
and fetch the MPG with a stock like:
pawn Код:
public GetMPGFromID(vid)
{
return milespergalon[i + 400];
}
or you just fetch it in the calculation
pawn Код:
randomtimer()
{
for(new a = 0; a < sizeof(Yourfuelarray); a++)
{
new model = GetVehicleID(carid)
Yourfuelarray[carid] = yourcarenum[carid][drivenmiles] * milespergallon[model]
}
}
Re: Miles Per Gallon -
BigBrainAFK - 23.04.2014
i should notice that this is madeup as i'm writing the quick replys so it could be that it dosen't work
Re: Miles Per Gallon -
Konstantinos - 23.04.2014
Quote:
Originally Posted by BigBrainAFK
pawn Код:
return milespergalon[i + 400];
|
Yeah, that should be subtraction because it will exceed the bounds.
---
You basically want to get the distance, don't you? The distance is equal with mileage x fuel.
Re: Miles Per Gallon -
BigBrainAFK - 23.04.2014
Quote:
Originally Posted by Konstantinos
Yeah, that should be subtraction because it will exceed the bounds.
---
You basically want to get the distance, don't you? The distance is equal with mileage x fuel.
|
oh ya thanks for the tip and i just wrote the fuel that was used over a distance sorry for that but reading is not my best so: I'm sorry ;(
Re: Miles Per Gallon -
Luis- - 23.04.2014
Oh, right. Well just added a temp string to see what the MPG actually was, says it's 3529 but the set MPG for the vehicle I was in was 38.
Need to figure out to make it do the MPG that is in the array now.