SA-MP Forums Archive
Help with GetPlayerPing - 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 with GetPlayerPing (/showthread.php?tid=443627)



Help with GetPlayerPing - Goldilox - 13.06.2013

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?


Re: Help with GetPlayerPing - dubyabeast - 13.06.2013

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



Re: Help with GetPlayerPing - Goldilox - 13.06.2013

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