Timers with vehicle ID.
#1

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?
Reply
#2

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);
}
Reply
#3

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?
Reply
#4

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);
Reply
#5

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);
Reply
#6

Код:
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.
Reply
#7

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'
Reply
#8

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)
}
Reply
#9

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
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)