Vehicle Data Timer Malfunction - 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: Vehicle Data Timer Malfunction (
/showthread.php?tid=512459)
Vehicle Data Timer Malfunction -
Aerotactics - 10.05.2014
So, I'm building a vehicle script for my server, and it's nearly done, besides some bug fixes. This bug I'm not sure how to fix, and I didn't want to go trying something just to have it not work. Thanks for your help.
Quote:
ISSUE: When I go to refill the vehicle's gas, instead of adding to the vehicle's existing data, it creates new data, and shows a second flickering 3d text label.
|
New Issue:Fixed the flickering, but the gas just doesn't work. After doing "/fix gas" the gas doesn't change.
pawn Code:
CMD:fix(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid)) return SCM(playerid,COLOR_GREY, "You are not in a vehicle.");
new str[16];
if(sscanf(params,"s[16]",str)) return SCM(playerid,COLOR_WHITE, "Usage: /fix [engine/tire/gas]");
new vehicleid = GetPlayerVehicleID(playerid);
for(new i=0;i<MAX_VEHICLES;i++)
{
if(vehicleid == DynVehicle[i])
{
...
if(!strcmp(str,"gas",true,3))
{
ToggleEngine(playerid,vehicleid,false);
TIMER_GASFILL[playerid] = SetTimer("GasTimer",GAS_FILL,true);
SCM(playerid,COLOR_WHITE, "You start pouring gas into the tank. Exit the vehicle to stop pouring gas.");
}
}
}
return 1;
}
public GasTimer(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
if (partInfo[playerid][gas] == 0)
{
KillTimer(TIMER_GASFILL[playerid]);
SCM(playerid,COLOR_WHITE, "You are out of stored fuel.");
return 1;
}
else if(vInfo[vehicleid][gas] == 100)
{
KillTimer(TIMER_GASFILL[playerid]);
SCM(playerid,COLOR_WHITE, "Gas tank is full.");
return 1;
}
else
{
partInfo[playerid][gas] -= 1;
vInfo[vehicleid][gas] += 1;
UpdateText(playerid,vehicleid);
}
return 1;
}
stock UpdateText(playerid,vehicleid)
{
new str[128];
format(str,sizeof(str),"Engine: %.0f\nTires: %i\nGas: %i", vInfo[vehicleid][engine],vInfo[vehicleid][tires],vInfo[vehicleid][gas]);
for(spawncar=0;spawncar<sizeof(vSpawns);spawncar++)
{
if(IsPlayerInVehicle(playerid,DynVehicle[spawncar])){Update3DTextLabelText(CarInfo[spawncar],COLOR_WHITE,str);}
}
return 1;
}
Re: Vehicle Data Timer Malfunction -
Konstantinos - 10.05.2014
Store the ID of the 3D label and before creating it again, remove the old one.
Re: Vehicle Data Timer Malfunction -
Aerotactics - 11.05.2014
Quote:
Originally Posted by Konstantinos
Store the ID of the 3D label and before creating it again, remove the old one.
|
It's not an issue with the text label because other functions work correctly, and they work almost exactly the same way. It's an issue with vehicle data, I just don't know how/why?
Re: Vehicle Data Timer Malfunction -
Aerotactics - 11.05.2014
Updated the thread. I managed to resolve the first issue partially.
Re: Vehicle Data Timer Malfunction -
RajatPawar - 11.05.2014
To start with -
pawn Code:
TIMER_GASFILL[playerid] = SetTimer("GasTimer",GAS_FILL,true);
You are setting a timer with no parameters, and using GasTimer(playerid)!
Use
SetTimerEx.