Help with GetPlayerPing
#1

What I wanted to do is I wanted a command /ping, with that player could enable a textdraw on the botton of the screen showing his ping "Ping: 234". The /ping command first checks if the player's ping text draw is on or not, if on then hide if not on then bring it on. Below is my attempt, but it doesn't do anything when I type /ping except for the SERVER: Unknown command notice.

pawn Код:
// On top of the script

new bool:ping[MAX_PLAYERS];
new Text:PingText[MAX_PLAYERS];


// OnPlayerConnect

    ping[playerid] = false;
    TextDrawFont(PingText[playerid], 2);
    TextDrawColor(PingText[playerid], 0xB0A32DFF);
    TextDrawSetProportional(PingText[playerid], true);
    TextDrawSetShadow(PingText[playerid], 1);

// OnGameModeInit

   for(new i=0; i<MAX_PLAYERS; i++)
    {
        PingText[i] = TextDrawCreate(222.5, 386, " ");
        }

// Command /ping

    CMD:ping(playerid,params[])
    {
        if(ping[playerid] == false)
        {
            new string[128];
            format(string,sizeof(string),"Ping: ~w~%s",GetPlayerPing(playerid));
            TextDrawSetString(PingText[playerid],string);
            ping[playerid] = true;
            return 1;
        }
        else
        {
            TextDrawHideForPlayer(playerid,PingText[playerid]);
            ping[playerid] = false;
            return 1;

        }
    }
Could someone help me out there please?
Reply
#2

first off, it says "SERVER: Unknown Command" because you don't have a return 1; on it. Second, GetPlayerPing returns a number, the "Ping: ~w~%s" should be "Ping: ~w~%d"
pawn Код:
// command
    CMD:ping(playerid,params[])
    {
        if(ping[playerid] == false)
        {
            new string[128];
            format(string,sizeof(string),"Ping: ~w~%d",GetPlayerPing(playerid));
            TextDrawSetString(PingText[playerid],string);
            ping[playerid] = true;
        }
        else
        {
            TextDrawHideForPlayer(playerid,PingText[playerid]);
            ping[playerid] = false;

        }
        return 1;
    }
Reply
#3

I fixed that. But still I don't see anything.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)