SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/06/2014, 11:03 PM   #1
jeffery30162
Huge Clucker
 
Join Date: Jun 2012
Posts: 312
Reputation: 10
Default vehicle issue

I am creating a fuel system for my vehicles and I have a 3d textdraw on the vehicle that acts like a progress bar.
When the player gets into the vehicle the comde sniplet is called.

Code:
public UpdateCarFuel(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
for(new idx=1; idx<MAX_CAR; idx++)
{
if(vehicleid == CarInfo[idx][cVID] && IsPlayerInVehicle(playerid, CarInfo[idx][cVID]))
{
    new FuelPercent0 = CarInfo[idx][Fuel]/CarInfo[idx][MaxFuel];
    new FuelPercent = FuelPercent0 * 100;
    new string1[32];
    format(string1, sizeof(string1), "Fuel: %d || Max Fuel %d", CarInfo[idx][Fuel], CarInfo[idx][MaxFuel]);
	SendClientMessage(playerid,COLOR_ORANGE,string1);
    new string[32];
    format(string, sizeof(string), "Percentage Full: %d", FuelPercent0);
	SendClientMessage(playerid,COLOR_BLUE,string);
	if(FuelPercent > -1 && FuelPercent < 11) // CarInfo[idx][Fuel]: 0 - 10
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "I{FF0000}IIIIIIIII");
	}
	else if(FuelPercent > 10 && FuelPercent < 21) // CarInfo[idx][Fuel]: 11 - 20
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "II{FF0000}IIIIIIII");
	}
	else if(FuelPercent > 20 && FuelPercent < 31) // CarInfo[idx][Fuel]: 21 - 30
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "III{FF0000}IIIIIII");
	}
	else if(FuelPercent > 30 && FuelPercent < 41) // CarInfo[idx][Fuel]: 31 - 40
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "IIII{FF0000}IIIIII");
	}
	else if(FuelPercent > 40 && FuelPercent < 51) // CarInfo[idx][Fuel]: 41 - 50
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "IIIII{FF0000}IIIII");
	}
	else if(FuelPercent > 50 && FuelPercent < 61) // CarInfo[idx][Fuel]: 51 - 60
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "IIIIII{FF0000}IIII");
	}
	else if(FuelPercent > 60 && FuelPercent < 71) // CarInfo[idx][Fuel]: 61 - 70
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "IIIIIII{FF0000}III");
	}
	else if(FuelPercent > 70 && FuelPercent < 81) // CarInfo[idx][Fuel]: 71 - 80
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "IIIIIIII{FF0000}II");
	}
	else if(FuelPercent > 80 && FuelPercent < 91) // CarInfo[idx][Fuel]: 81 - 90
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "IIIIIIIII{FF0000}I");
	}
	else if(FuelPercent > 90 && FuelPercent < 101) // CarInfo[idx][Fuel]: 91 - 100
	{
	    Update3DTextLabelText(CarInfo[idx][Text3D:cTextfuel], COLOR_GREEN, "IIIIIIIIII");
	}
}
}
return 1;
}
When the code sniplet is called it gets the correct fuel and max fuel ammount, but when i try to find the percentage(fuel/ maxfuel) it always reterns a 0.

please help me
jeffery30162 is offline   Reply With Quote
Old 15/06/2014, 11:17 PM   #2
Kimossab
Huge Clucker
 
Kimossab's Avatar
 
Join Date: Jul 2012
Location: Portugal
Posts: 484
Reputation: 108
Default Re: vehicle issue

instead of making FuelPercent = FuelPercent0 *100 makesomething like this:

FuelPercent = (CarInfo[idx][Fuel]*100)/CarInfo[idx][MaxFuel];

and forget the FuelPercent0 variable. Simply becasue you're using integer when making a division. The value of FuelPercent0 would always be under 1, something like 0.3431321 but since you're not using a float it will always be 0. So either make:
new Float:FuelPercent0
or do the thing I said above, that way you don't need a float because it will give an integer, because you multiply by 100 before dividing
__________________
Who even cares about signatures?

ALL HAIL THE ASTERISK!
My Pastebinas.
Kimossab is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vehicle Spawn Issue JamieVic Scripting Help 10 17/06/2013 08:28 PM
Unoccupied vehicle sync, boat surfing pausing issue, parachute with vehicle issue, surfing w/ skydiving issue Kar Bug Reports 2 10/06/2013 09:24 AM
AVS Vehicle issue. OpticKiller Scripting Help 8 16/05/2013 02:20 AM
Vehicle health issue HeLiOn_PrImE Scripting Help 4 25/09/2011 06:02 AM
Vehicle id issue BMan17 Scripting Help 2 24/08/2011 11:37 PM


All times are GMT. The time now is 09:04 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.