If I don't type ID does it to myself
#1

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
Reply
#2

Post the GetClosestPlayerToPlayer function. Chances are you aren't excluding yourself from the loop.
Reply
#3

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
Reply
#4

How about
pawn Код:
playerid != targetid
Reply
#5

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;
}
Reply
#6

Jimmy I don't think so....
playerid != targetid[playerid]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)