I found theese stocks quite useful at times, i hope you enjoy!
GetClosestPlayer(playerid,range);
Description: Gets the closest player to a range amount of your choise (50 is defult) requires PlayerToPoint!
stock GetClosestPlayer(playerid,range = 50)
{
new splayer,jon;
if(IsPlayerConnected(playerid))
{
jon = MAX_PLAYERS * 50;
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
for(new r = range; r > 0; r--) {
for(new i = 0; i < MAX_PLAYERS; i++) {
if(i==playerid) continue;
if(PlayerToPoint(r, i, x, y, z))
{
jon--;
splayer = i;
}
}
}
if(jon == MAX_PLAYERS * 50) splayer = INVALID_PLAYER_ID;
}
return splayer;
}
ReturnUser(name,playerid);
Description: My version of the ReturnUser function, it is easier to find the user using this since it checks if its ANYWHERE in the name, and not just from the beggining, for example:
players online:0.Edd
1.Johny
2.Gai
3.Homo
4.Vertical
if i type in "Omo" it will return 2, if i type in "Ical" it will return 4 etc.
ReturnUser(const playername[], user = INVALID_PLAYER_ID)
{
new i;
new hasmultiple=-1;
new ourplayer = -1;
new tmpuname[MAX_STRING];
for (i=0;i<MAX_PLAYERS;i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i,tmpuname,sizeof(tmpuname));
if (strfind(tmpuname,playername,true) != -1)
{
hasmultiple++;
ourplayer = i;
}
if (hasmultiple>0)
{
SendClientMessage(user,ARED,"More Then One Player Found, Please Be More Accurate!");
return INVALID_PLAYER_ID;
}
}
}
if(IsNumeric(playername) && IsPlayerConnected(strval(playername)))
{
hasmultiple++;
ourplayer = strval(playername);
if (hasmultiple>0)
{
SendClientMessage(user,0xA80000FF,"More Then One Player Found, Please Be More Accurate!");
return INVALID_PLAYER_ID;
}
}
return ourplayer;
}
i will release some more soon,
NOTE: b4 releasing them i changed a few things to make them more comfortable for the public, if you find any bugs (which i doubt you will) please contact me.
if you have any requests, dont hasitate to ask.
