[HELP]TextDraw Problem[HELP]!!!
#1

So,I am making a speed system for vehicles,but the problem is that when I enter a car the speed bar doesn't shoow up,here's the code:

pawn Код:
forward UpdateSpeed(playerid);
new uSpeed;

new Text:vSpeed;

stock GetPlayerSpeed(playerid, bool:kmh = true)
{
    new
        Float:xx,
        Float:yy,
        Float:zz,
        Float:pSpeed;

    if(IsPlayerInAnyVehicle(playerid))
    {
        GetVehicleVelocity(GetPlayerVehicleID(playerid),xx,yy,zz);
    }
    else
    {
        GetPlayerVelocity(playerid,xx,yy,zz);
    }

    pSpeed  = floatsqroot((xx * xx) + (yy * yy) + (zz * zz));
    return kmh ? floatround((pSpeed * 195.12)) : floatround((pSpeed * 136.66667));
}//WARNING:This works for vehicle also,event if the name of the function is not relevant :P

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
      new vString[128];
      format(vString,sizeof(vString),"Speed:%d",GetPlayerSpeed(playerid));
      new Float:x,Float:y;
      vSpeed = TextDrawCreate(x,y,vString);
      TextDrawAlignment(vSpeed,3);
      TextDrawColor(vSpeed,COLOR_WHITE);
      TextDrawFont(vSpeed,0);
      TextDrawShowForPlayer(playerid,vSpeed);
      uSpeed = SetTimer("UpdateSpeed",1000,true);
          if(oldstate == PLAYER_STATE_DRIVER&&newstate==PLAYER_STATE_ONFOOT)
         {
        TextDrawDestroy(vSpeed);
        KillTimer(uSpeed);
     }
   }
   return 1;
}

public UpdateSpeed(playerid)
{
      new vString[128];
      format(vString,sizeof(vString),"Speed:%d",GetPlayerSpeed(playerid));
      new Float:x,Float:y;
      vSpeed = TextDrawCreate(x,y,vString);
      TextDrawAlignment(vSpeed,3);
      TextDrawColor(vSpeed,COLOR_WHITE);
      TextDrawFont(vSpeed,0);
      TextDrawShowForPlayer(playerid,vSpeed);
      return 1;
}
Sp,that's all?Can anyone tell me why isn't working?Please help me asap.Thanks in advance.
Reply
#2

You shouldn't destroy the textdraw, just hide it. and use TextdrawSetString.
Reply
#3

Well,I did everything you said,it still doesn't show,anyone else?
Reply
#4

SetTimerEx.
Reply
#5

OK,thanks for trying to help,I used SetTimerEx now,but..,the speed bar still doesn't show!
Reply
#6

Sorry to bump the topic so fast!!!.Anyone,help please,in my point of view the code is correct so I don't see what it won't work..?
Reply
#7

At top add
pawn Код:
new Text:vSpeed[MAX_PLAYERS];
new uSpeed[MAX_PLAYERS];
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
      new vString[128];
      format(vString,sizeof(vString),"Speed:%d",GetPlayerSpeed(playerid));
      TextDrawSetString(vSpeed[playerid],vString);
      TextDrawShowForPlayer(playerid,vSpeed[playerid]);
      uSpeed[playerid] = SetTimerEx("UpdateSpeed",1000,true,"i",playerid);
         if(oldstate == PLAYER_STATE_DRIVER&&newstate==PLAYER_STATE_ONFOOT)
         {
        TextDrawHideForPlayer(playerid,vSpeed[playerid]);
        KillTimer(uSpeed[playerid]);
     }
   }
}

pawn Код:
public OnGameModeInit()
{
    for(new i=0;i<MAX_PLAYERS;++i)
    {
      vSpeed[i] = TextDrawCreate(x,y,"_");//Replace X,Y with coordinates.
      TextDrawAlignment(vSpeed[i],3);
      TextDrawColor(vSpeed[i],COLOR_WHITE);
      TextDrawFont(vSpeed[i],0);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)