SA-MP Forums Archive
Help with my ping command - 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 my ping command (/showthread.php?tid=563322)



Help with my ping command - Nabster - 15.02.2015

It shows 0 ping all time

Код:
CMD:ping(playerid,params[])
{
	if(PInfo[playerid][Level] < 1)
    return SendClientMessage(playerid,STEALTH_BLUE,"You need to be level 1 to get ping of players.");
    new id, string[128];
    if(sscanf(params,"us",id))
	return SendClientMessage(playerid,STEALTH_BLUE,"USAGE: /ping [id]");
	if(!IsPlayerConnected(id))
	return SendClientMessage(playerid,STEALTH_BLUE,"That player is not connected!");
	new pPing[10],pName[25];
	GetPlayerPing(id,pPing,sizeof(pPing));
	GetPlayerName(id, pName, sizeof(pName));
	format(string, sizeof(string), "%s:[%d]", pName, pPing);
	SendClientMessage(playerid,COLOR_SIENNA,string);
	return 1;
}



Re: Help with my ping command - AndySedeyn - 15.02.2015

Variable 'pPing' doesn't need a size since it's an integer and not a string.

pawn Код:
new pPing, pName[24];
EDIT: That's not how you use GetPlayerPing!
Reread the following article please: https://sampwiki.blast.hk/wiki/GetPlayerPing

EDIT2: In your case it would look something like this:
pawn Код:
pPing = GetPlayerPing(id);



Re: Help with my ping command - HazardouS - 15.02.2015

Read the wiki page of GetPlayerPing (and sscanf2 maybe).
pawn Код:
CMD:ping(playerid,params[])
{
    if(PInfo[playerid][Level] < 1)
    return SendClientMessage(playerid,STEALTH_BLUE,"You need to be level 1 to get ping of players.");
    new id, string[128];
    if(sscanf(params,"u",id))
    return SendClientMessage(playerid,STEALTH_BLUE,"USAGE: /ping [id]");
    if(!IsPlayerConnected(id))
    return SendClientMessage(playerid,STEALTH_BLUE,"That player is not connected!");
    new pPing,pName[25];
    pPing = GetPlayerPing(id);
    GetPlayerName(id, pName, sizeof(pName));
    format(string, sizeof(string), "%s:[%d]", pName, pPing);
    SendClientMessage(playerid,COLOR_SIENNA,string);
    return 1;
}



Re: Help with my ping command - Nabster - 15.02.2015

Alright thanks for your help guys