GetPlayerPing bug - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetPlayerPing bug (
/showthread.php?tid=206747)
GetPlayerPing bug -
armyoftwo - 04.01.2011
pawn Код:
if(GetPlayerPing(playerid) > 300) {
new PlayerName[24];
GetPlayerName(playerid, PlayerName, 24);
foreach(Player, i) {
format(String, sizeof(String), LoadText(i, "PING_KICK"), PlayerName, playerid);
SendClientMessage(i ,COLOR_LIGHTRED, String);
}
Kick(playerid);
}
It checks every one second.
The problem is that it kicks even if i have 40 ping
Re: GetPlayerPing bug -
jameskmonger - 04.01.2011
It's not a bug, it's your code.
pawn Код:
foreach(Player, i) {
if(GetPlayerPing(i) > 300) {
Kick(i);
}
}
Re: GetPlayerPing bug -
armyoftwo - 04.01.2011
Quote:
Originally Posted by jameskmonger
It's not a bug, it's your code.
pawn Код:
foreach(Player, i) { if(GetPlayerPing(i) > 300) { Kick(i); } }
|
Well, you're wrong.
foreach(Player, playerid) - it will be the same.
You can use other int than 'i' if you didnt know
Re: GetPlayerPing bug -
HyperZ - 04.01.2011
I'm using this code and it works perfect.
OnPlayerConnect:
pawn Код:
SetTimerEx("PingCheck", 1000, 1, "i", playerid);
Somewhere in your script.
pawn Код:
forward PingCheck(playerid);
public PingCheck(playerid)
{
new string[256];
new ping = GetPlayerPing(playerid);
new playrname[MAX_PLAYER_NAME];
GetPlayerName(playerid, playrname, sizeof(playrname));
if(ping > 300)
{
format(string, sizeof(string), "\"%s\" has been kicked by Server. Reason: (High Ping) (His Ping: %d | Maximum: 300)", playrname, ping);
SendClientMessageToAll(0xFFFF00FF, string);
Kick(playerid);
}
}
Re: GetPlayerPing bug -
_rAped - 04.01.2011
Also note that the players ping could be like 9999 several seconds after he/she connected.
Re: GetPlayerPing bug -
armyoftwo - 04.01.2011
Quote:
Originally Posted by Clive
I'm using this code and it works perfect.
OnPlayerConnect:
pawn Код:
SetTimerEx("PingCheck", 1000, 1, "i", playerid);
Somewhere in your script.
pawn Код:
forward PingCheck(playerid); public PingCheck(playerid) { new string[256]; new ping = GetPlayerPing(playerid); new playrname[MAX_PLAYER_NAME]; GetPlayerName(playerid, playrname, sizeof(playrname)); if(ping > 300) { format(string, sizeof(string), "\"%s\" has been kicked by Server. Reason: (High Ping) (His Ping: %d | Maximum: 300)", playrname, ping); SendClientMessageToAll(0xFFFF00FF, string); Kick(playerid); } }
|
I will try your code, but it's practically the same.
Re: GetPlayerPing bug -
Calgon - 04.01.2011
Quote:
Originally Posted by _rAped
Also note that the players ping could be like 9999 several seconds after he/she connected.
|
When a player connects their ping is 65535 and it takes about a second or two for it to resolve to their normal ping. Add an additional variable and add on to it every second, after two or three seconds then check their ping and allow your timer to keep checking whether the player has been connected for long enough to be ping kicked.
Re: GetPlayerPing bug -
_rAped - 04.01.2011
Quote:
Originally Posted by Calgon
When a player connects their ping is 65535 and it takes about a second or two for it to resolve to their normal ping. Add an additional variable and add on to it every second, after two or three seconds then check their ping and allow your timer to keep checking whether the player has been connected for long enough to be ping kicked.
|
That's what I ment just coulden't remember the exact number, thank you
Re: GetPlayerPing bug -
Mean - 04.01.2011
I've seen alot of people having 65535 ping, well just do a SetTimerEx under OnPlayerSpawn with repeating on.
Re: GetPlayerPing bug -
Calgon - 04.01.2011
Quote:
Originally Posted by Mean
I've seen alot of people having 65535 ping, well just do a SetTimerEx under OnPlayerSpawn with repeating on.
|
That's generally inefficient, you could quite possibly end up with 500 timers. You should create a variable and set its value once a player has spawned, and a timer (containing a loop) will check the value and kick the player if the value is set and their ping is excessive.
Unrelated to the topic, I think you should re-consider the ping limit, 300 isn't too bad for a ping anyway - 500+ is.