get closest player +rep -
bboytimix - 26.10.2017
hello there i got a problem with this warp/teleport system
its work okay sometimes but if im too far from the traget nothing happens just nothing no effect
also when there only me in server i dont get the message "the server are empty
can someone fix it or explain the issue? idk whats wrong here
pawn Код:
if(PlayerTeam[playerid] == Matrix)
{
if(PlayerInfo[playerid][SkillLevel] == 2)
{
if(PInfo[playerid][CanWarp] == 0) return SendClientMessage(playerid,red,"You dont have enough energy to use your power");
new id = -1;
id = GetClosestPlayer(playerid,9000);//i tried to increase the range ........but the problem are same
if(id == -1) return SendClientMessage(playerid,red,"server is empty");
if(Team[id] == Matrix) return SendClientMessage(playerid,red,"You are to close to another matrix");
PInfo[playerid][CanWarp] = 0;
PInfo[playerid][WarpTimer] = SetTimerEx("ResetDigVar",DIGTIME,false,"i",playerid);
SetTimerEx("WarpToTarget",3000,false,"ii",playerid,id);
static Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
}
here is the GetClosestPlayer
pawn Код:
function Float:GetDistanceBetweenPoints(Float:rx1,Float:ry1,Float:rz1,Float:rx2,Float:ry2,Float:rz2)
{
return floatadd(floatadd(floatsqroot(floatpower(floatsub(rx1,rx2),2)),floatsqroot(floatpower(floatsub(ry1,ry2),2))),floatsqroot(floatpower(floatsub(rz1,rz2),2)));
}
stock GetClosestPlayer(playerid,Float:limit)
{
new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2;
GetPlayerPos(playerid,x1,y1,z1);
new Float:Range = 999.9;
new id = INVALID_PLAYER_ID;//-1
for(new i; i < MAX_PLAYERS;i++)
{
if(!IsPlayerConnected(i)) continue;
if(playerid != i)
{
GetPlayerPos(i,x2,y2,z2);
new Float:Dist = GetDistanceBetweenPoints(x1,y1,z1,x2,y2,z2);
if(floatcmp(Range,Dist) == 1 && floatcmp(limit,Range) == 1)
{
Range = Dist;
id = i;
}
}
}
return id;
}
Re: get closest player +rep -
Lokii - 26.10.2017
Here:
PHP код:
#include <a_samp>
#include <izcmd>
subcoords(Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2)
{
return floatround(floatabs(floatsub(x, x2) + floatsub(y, y2) + floatsub(z, z2)));
}
CMD:closestp(playerid, params[])
{
new closestplayer = -1, closest = 999999, str[63], name[24], Float:px, Float:py, Float:pz, Float:px2, Float:py2, Float:pz2;
GetPlayerPos(playerid, px, py, pz);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(!IsPlayerConnected(i) || i == playerid) continue;
GetPlayerPos(i, px2, py2, pz2);
if(subcoords(px, py, pz, px2, py2, pz2) < closest)
{
closestplayer = i;
GetPlayerName(i, name, sizeof(name));
closest = subcoords(px, py, pz, px2, py2, pz2);
}
}
if(closestplayer == -1) return SendClientMessage(playerid, -1, "You'r the only one in the server");
else
{
format(str, sizeof(str), "The closest player to you is: {00FF00}%s", name);
SendClientMessage(playerid, -1, str);
}
return 1;
}