SA-MP Forums Archive
Timers with vehicle ID. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Timers with vehicle ID. (/showthread.php?tid=152416)



Timers with vehicle ID. - IcyBlight - 04.06.2010

How do I carry the vehicle ID along in a SetTimerEx? Because some vehicles are not arrayed, in other words, their vehicle ID's are numbers. Some are named in arrays, like kacc_humvee etc., and that would be a string.

So how do I carry along the vehicle's ID?

This code below crashes my compiler.
pawn Код:
updatespeedtimer = SetTimerEx("UpdateSpeed", 500, true, "ds", playerid, vehid);

forward UpdateSpeed(playerid, vehid);
public UpdateSpeed(playerid, vehid);
{
    new speed = GetPlayerSpeed(playerid, false);
    new string[3];
    format(string, sizeof string, "%d", speed);
    TextDrawSetString(SpeedoSpeed, string)
}
Could someone tell me how to do this properly?

EDIT: Oh wait, I think I solved it.

Just carry along the playerid and then get the vehicle ID in the timer?


Re: Timers with vehicle ID. - IcyBlight - 04.06.2010

This piece of code(after fixed) crashes the compiler. Someone look at it?

pawn Код:
forward UpdateSpeed(playerid);
public UpdateSpeed(playerid);
{
    new speed = GetPlayerSpeed(playerid, false);
    new string[3];
    format(string, sizeof string, "%d", speed);
    TextDrawSetString(SpeedoSpeed, string)
}
I localized the problem to here:
pawn Код:
new speed = GetPlayerSpeed(playerid, false);
pawn Код:
stock GetPlayerSpeed(playerid,bool:kmh)
{
  new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}



Re: Timers with vehicle ID. - (SF)Noobanatior - 04.06.2010

pawn Код:
forward UpdateSpeed(playerid);
public UpdateSpeed(playerid);
{
    new Float:speed = GetPlayerSpeed(playerid, false);
    new string[16];
    format(string, sizeof string, "%0.f km/h", speed);
    TextDrawSetString(SpeedoSpeed, string);
}
this work?


Re: Timers with vehicle ID. - On_Top_Non_Stop - 04.06.2010

Well, for a start
updatespeedtimer = SetTimerEx("UpdateSpeed", 500, true, "ds", playerid, vehid);

Should be

updatespeedtimer = SetTimerEx("UpdateSpeed", 500, true, "dd", playerid, vehid);

And since your updating the speed with SetTimerEx, your variable should be
pawn Код:
new updatespeedtimer[MAX_PLAYERS];
pawn Код:
updatespeedtimer[playerid] = SetTimerEx(.....
Edit: Also, use (SF)Noobanatior's public and remove vehicleID from the timer.

pawn Код:
SetTimerEx("UpdateSpeed", 500, true, "d", playerid);



Re: Timers with vehicle ID. - IcyBlight - 04.06.2010

Noobinator's clearly isn't right.

Speed isn't a float, since it's rounded.

I'll test those you gave me, but it still doesn't explain why my compiler crashes when I use GetPlayerSpeed?

pawn Код:
forward UpdateSpeed(playerid);
public UpdateSpeed(playerid);
{
    new speed = GetPlayerSpeed(playerid, false);
    new speedstring[16];
    format(speedstring, sizeof speedstring, "%d MPH", speed);
    TextDrawSetString(SpeedoSpeed, speedstring)
}
When following line is removed, it doesn't crash.

pawn Код:
new speed = GetPlayerSpeed(playerid, false);



Re: Timers with vehicle ID. - DJDhan - 04.06.2010

Код:
updatespeedtimer = SetTimerEx("UpdateSpeed", 500, true, "ds", playerid, vehid);

forward UpdateSpeed(playerid, vehid);
public UpdateSpeed(playerid, vehid);
{
new speed = GetPlayerSpeed(playerid, false);
new string[3];
format(string, sizeof string, "%d", speed);
TextDrawSetString(SpeedoSpeed, string)
}
Above is your code....

Quote:

public UpdateSpeed(playerid, vehid); //<----

Pff there shouldn't be any semi-colon if you are defining a function.


Re: Timers with vehicle ID. - IcyBlight - 04.06.2010

Quote:
Originally Posted by DJDhan
Код:
updatespeedtimer = SetTimerEx("UpdateSpeed", 500, true, "ds", playerid, vehid);

forward UpdateSpeed(playerid, vehid);
public UpdateSpeed(playerid, vehid);
{
new speed = GetPlayerSpeed(playerid, false);
new string[3];
format(string, sizeof string, "%d", speed);
TextDrawSetString(SpeedoSpeed, string)
}
Above is your code....

Quote:

public UpdateSpeed(playerid, vehid); //<----

Pff there shouldn't be any semi-colon if you are defining a function.
Hah, thanks, it works now. Stupid mistake. Or, at least it doesn't crash, I'll have to see if it works tho'


Re: Timers with vehicle ID. - Think - 04.06.2010

Quote:
Originally Posted by IcyBlight
Noobinator's clearly isn't right.

Speed isn't a float, since it's rounded.

I'll test those you gave me, but it still doesn't explain why my compiler crashes when I use GetPlayerSpeed?

pawn Код:
forward UpdateSpeed(playerid);
public UpdateSpeed(playerid);
{
    new speed = GetPlayerSpeed(playerid, false);
    new speedstring[16];
    format(speedstring, sizeof speedstring, "%d MPH", speed);
    TextDrawSetString(SpeedoSpeed, speedstring)
}
When following line is removed, it doesn't crash.

pawn Код:
new speed = GetPlayerSpeed(playerid, false);
it should be

pawn Код:
forward UpdateSpeed(playerid);
public UpdateSpeed(playerid);
{
    new Float:speed = GetPlayerSpeed(playerid, false);
    new speedstring[16];
    format(speedstring, sizeof speedstring, "%f MPH", speed);
    TextDrawSetString(SpeedoSpeed, speedstring)
}



Re: Timers with vehicle ID. - IcyBlight - 04.06.2010

Oh god damn it no, it's not a float, look

pawn Код:
stock GetPlayerSpeed(playerid,bool:kmh)
{
  new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100); // <------------ FLOAT ROUND = INTEGER
}