Speedometer textdraw issue
#1

Good evening!

Can't remember, is it from the time when server changed to 0.3.7 version or earlier , but main problem is that speedo textdraw doesn't show up like it should be: "KM/H: 50" (speed "50" is for example). Now, when I type command "/speedo" it shows me black line, almost at the top, screen below:



So, here's the lines:

At the top:
pawn Код:
new showspeedo[MAX_PLAYERS], Text:Speedometer[MAX_PLAYERS];
Under "OnGameModeInit":
pawn Код:
foreach(new i : Player)
    {
        if(IsPlayerConnected(i))
        {
            Speedometer[i] = TextDrawCreate(300.0, 437.0, "KM/H: 0");
            TextDrawFont(Speedometer[i], 1);
            TextDrawSetOutline(Speedometer[i], 1);
            TextDrawSetShadow(Speedometer[i], 0);
        }
    }
Under commands:
pawn Код:
CMD:speedo(playerid, params[])
{
    #pragma unused params
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must be in vehicle to use this command!");
    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_RED, "Only driver can use this command!");
    if(showspeedo[playerid] == 0)
    {
        TextDrawShowForPlayer(playerid, Speedometer[playerid]);
        showspeedo[playerid] = 1;
        SendClientMessage(playerid, COLOR_GREEN, "^ Speedometer ON!");
    }
    else if(showspeedo[playerid] == 1)
    {
        TextDrawHideForPlayer(playerid, Speedometer[playerid]);
        showspeedo[playerid] = 0;
        SendClientMessage(playerid, COLOR_RED, "^ Speedometer OFF!");
    }
    return 1;
}
Under "OnPlayerStateChange"
pawn Код:
if(showspeedo[playerid] == 1)
    {
        if(oldstate == PLAYER_STATE_DRIVER)
        {
            if(newstate == PLAYER_STATE_ONFOOT)
            {
                TextDrawHideForPlayer(playerid, Speedometer[playerid]);
                showspeedo[playerid] = 0;
            }
        }
    }
And under "OnPlayerUpdate":
pawn Код:
if(showspeedo[playerid] == 1 && IsPlayerInAnyVehicle(playerid))
    {
        new SpeedString[24];
        format(SpeedString, sizeof(SpeedString), "~g~KM/H: ~r~%d", GetVehicleSpeed(GetPlayerVehicleID(playerid)));
        TextDrawShowForPlayer(playerid, Speedometer[playerid]);
        TextDrawSetString(Speedometer[playerid], SpeedString);
    }
Reply
#2

See Textdraw wiki.
Quote:

The textdraw variable also needs to be prefixed with the Text: tag and should be initialized with the value Text:INVALID_TEXT_DRAW. If you omit the initialization, the textdraw may conflict with others as you add more textdraws.

So EVERY textdraw you have should be declared and initialized like this:
Код:
new Text:MyTextDraw = Text:INVALID_TEXT_DRAW; //Global textdraw
new PlayerText:MyTextDraw = PlayerText:INVALID_TEXT_DRAW; //Per player textdraw
Also, why do you use Text:Speedometer[MAX_PLAYERS] instead of PlayerText:Speedometer[MAX_PLAYERS]? You can only have 2048 global textdraws! With your method you can only create 2 textdraws, because MAX_PLAYERS = 1000. If you use PlayerText, you can create 256 textdraws FOR EACH PLAYER!
Reply
#3

Took few minutes to understand, where was the problem, because changed from "Text:" to "PlayerText:" didn't fixed problem, but there was a little thing -> added under OnPlayerConnect callback not OnGameModeInit callback. As a result - working as before.

Thank you Freaksken for help, I appreciate it..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)