If I don't type ID does it to myself -
RandomDude - 01.08.2013
pawn Код:
dcmd_rape(playerid, params[])
{
new ID = strval(params);
if(GetClosestPlayerToPlayer(playerid,ID) > RAPE_DISTANCE) return SendClientMessage(playerid, RED, "No One Close Enough To Rape.");
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, RED, "That player is not connected!");
if(ID == playerid) return SendClientMessage(playerid, RED, "You cannot rape yourself!");
I want it to do it to the closest player but it does it do my self
Re: If I don't type ID does it to myself -
-Prodigy- - 01.08.2013
Post the GetClosestPlayerToPlayer function. Chances are you aren't excluding yourself from the loop.
Re: If I don't type ID does it to myself -
RandomDude - 01.08.2013
pawn Код:
forward GetClosestPlayerToPlayer(playerid,ID);
public GetClosestPlayerToPlayer(playerid)
{
new Float:dist = 1000.0;
new targetid = INVALID_PLAYER_ID;
new Float:x1,Float:y1,Float:z1;
new Float:x2,Float:y2,Float:z2;
new Float:tmpdis;
GetPlayerPos(playerid,x1,y1,z1);
for(new i=0;i<MAX_PLAYERS;i++)
{
if(i == playerid) continue;
GetPlayerPos(i,x2,y2,z2);
tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
if(tmpdis < dist)
{
dist = tmpdis;
targetid = i;
}
}
return targetid;
}
There it is
Re: If I don't type ID does it to myself -
JimmyCh - 01.08.2013
How about
Re: If I don't type ID does it to myself -
Pottus - 01.08.2013
forward GetClosestPlayerToPlayer(playerid,ID);
public GetClosestPlayerToPlayer(playerid)
forward GetClosestPlayerToPlayer(playerid);
public GetClosestPlayerToPlayer(playerid)
Try it like this
pawn Код:
dcmd_rape(playerid, params[])
{
new ID = GetClosestPlayerToPlayer(playerid, RAPE_DISTANCE);
if(ID == INVALID_PLAYER_ID) return SendClientMessage(playerid, RED, "No One Close Enough To Rape.");
forward GetClosestPlayerToPlayer(playerid,Float:range=1000.0);
public GetClosestPlayerToPlayer(playerid,Float:range=1000.0)
{
new Float:dist = 1000.0;
new targetid = INVALID_PLAYER_ID;
new Float:x1,Float:y1,Float:z1;
new Float:x2,Float:y2,Float:z2;
new Float:tmpdis;
GetPlayerPos(playerid,x1,y1,z1);
for(new i=0;i<MAX_PLAYERS;i++)
{
if(!IsPlayerConnected(i) || i == playerid) continue;
GetPlayerPos(i,x2,y2,z2);
if(IsPlayerInRangeOfPoint(playerid, range, x2, y2, z2))
{
tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
if(tmpdis < dist)
{
dist = tmpdis;
targetid = i;
}
}
}
return targetid;
}
Re: If I don't type ID does it to myself -
Vrag - 01.08.2013
Jimmy I don't think so....
playerid != targetid[playerid]