[TOOLS] ID Tools (some functions) -
Kwarde - 10.01.2011
Hey I made some handy tools. This are the functions:
GetPlayerWithHighestScore(); - Returns player ID with highest score
GetIDFromIP(ip[]); - Returns the player with "ip" (lowest ID. If there are more players, the one with the highest IP won't be returned)
GetIDFromName(name[]); - Same as GetIDFromIP, but now with the name
GetLowestFreeID(); - Returns lowest free slot on the server (handy for the NCPC plugin)
Here they are. (I know that the most exists, but I couldn't really find an topic where they where really posted)
pawn Код:
stock GetLowestID()
{
for(new i = 0; i < MAX_PLAYERS; i++){
if(!IsPlayerConnected(i) && i > -1 && i < 501)
return i;
else continue;
}
return -1;
}
stock GetIDFromName(name[])
{
new iName[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++){
GetPlayerName(i, iName, MAX_PLAYER_NAME);
if(!strcmp(name, iName, false))
return i;
else continue;
}
return -1;
}
stock GetIDFromIP(ip[])
{
new IP[16];
for(new i = 0; i < MAX_PLAYERS; i++){
GetPlayerIp(i, IP, 16);
if(!strcmp(ip, IP, true))
return i;
else continue;
}
return -1;
}
stock GetPlayerWithHighestScore()
{
new HighestScore = cellmin, ID = INVALID_PLAYER_ID;
for(new i = 0; i < 500; i++){
if(!IsPlayerConnected(i)) continue;
if(GetPlayerScore(i) > HighestScore){
HighestScore = GetPlayerScore(i);
ID = i;
}
continue;
}
return ID != INVALID_PLAYER_ID ? ID : -1;
}
Regards,
Kevin
EDIT:
GetPlayerWithHighestScore is working
Re: [TOOLS] ID Tools (some functions) -
Flyfishes - 10.01.2011
Hah, usefull, amazing, short buy effective. Good work!
Re: [TOOLS] ID Tools (some functions) -
Kwarde - 10.01.2011
Thanks.
And I've added an test gamemode/filterscript. It's standard an gamemode, but if you want it as an FS (not tested, not recommended), change "#define FS false" to "#define FS true"
Re: [TOOLS] ID Tools (some functions) -
Gus_Stone - 10.01.2011
Nice script, keep up good work.
Re: [TOOLS] ID Tools (some functions) -
Kwarde - 10.01.2011
Ah bug detected. I'll try to fix it as soon as possible.
Quote:
Originally Posted by Kwarde
EDIT 2: GetPlayerWithHighestScore is always returning 1... editting ...
|
Re: [TOOLS] ID Tools (some functions) -
sleepysnowflake - 11.01.2011
AMAZING !!!
Re: [TOOLS] ID Tools (some functions) -
[MNC]Azz - 11.01.2011
hehe I remember that GetPlayerWithHighestScore xD
Re: [TOOLS] ID Tools (some functions) -
Blantas - 11.01.2011
Nice, but... Why do you need an array to store each player's score? Try this one, it should be better:
pawn Код:
stock GetPlayerWithHighestScore()
{
new MaxHighestScore, Player, TempScore;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(IsPlayerNPC(i)) continue;
TempScore = GetPlayerScore(i);
if(TempScore > MaxHighestScore)
{
MaxHighestScore = TempScore;
Player = i;
}
}
return Player;
}
Re: [TOOLS] ID Tools (some functions) -
Kwarde - 11.01.2011
I already tried something like that, but it returned "1". Maybe 'cuz it was an NPC.
I'll try it in one of the servers where I script. Thanks for making a response, 'cuz I forgot this
p.s.
Yes I already commented 'if(IsPlayerNPC' stuff
Re: [TOOLS] ID Tools (some functions) -
Kwarde - 19.01.2011
UPDATE:
GetPlayerWithHighestScore(); is working now. Here it is:
pawn Код:
GetPlayerWithHighestScore()
{
new HighestScore = -999999999, ID = INVALID_PLAYER_ID;
for(new i = 0; i < 500; i++){
if(!IsPlayerConnected(i)) continue;
if(GetPlayerScore(i) > HighestScore){
HighestScore = GetPlayerScore(i);
ID = i;
}
continue;
}
return ID != INVALID_PLAYER_ID ? ID : -1;
}