SA-MP Forums Archive
[HELP]TextDraw Problem[HELP]!!! - 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: [HELP]TextDraw Problem[HELP]!!! (/showthread.php?tid=358338)



[HELP]TextDraw Problem[HELP]!!! - Cjgogo - 10.07.2012

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.


Re: [HELP]TextDraw Problem[HELP]!!! - SomebodyAndMe - 10.07.2012

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


Re: [HELP]TextDraw Problem[HELP]!!! - Cjgogo - 10.07.2012

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


Re: [HELP]TextDraw Problem[HELP]!!! - Vince - 10.07.2012

SetTimerEx.


Re: [HELP]TextDraw Problem[HELP]!!! - Cjgogo - 10.07.2012

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


Re: [HELP]TextDraw Problem[HELP]!!! - Cjgogo - 11.07.2012

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..?


Re: [HELP]TextDraw Problem[HELP]!!! - [MM]RoXoR[FS] - 11.07.2012

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