Closest one!
#1

I really dont have an idea right now about that how to define the closest player, like example your a zombie and with key E it kills the closest player if he's enought close...


I dont really have an idea how to do that so I'll be very thankfull for the player who helps me!
Reply
#2

Found this with a little search:

pawn Код:
forward GetClosestPlayerToPlayer(playerid);
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;
}
Hope it helps or set's you in the right direction.
Reply
#3

Thank you! This was just the thing I searched for, now I can just mod this for the things I want
Reply
#4

Quote:
Originally Posted by GNGification
Посмотреть сообщение
Thank you! This was just the thing I searched for, now I can just mod this for the things I want
Glad i could help
Reply
#5

Stigg Can You Make A Tutorial About This ? I don't UnderStand it And i Need This help Also Pleaze
I Also Don't Know like bite thing
e.g /Rob it robs Nearest Player Don't Make Rob Just Make A Tutorial i want to learn this thing pleaze
Reply
#6

You can use IsPlayerInRangeOfPoint it's faster.
Reply
#7

Explain?
Reply
#8

@XFlawless: Dont say something like that, you dont know what he want.

@Roomeo: You have to put this Code from Stigg in your Gamemode anywhere. In your robcommand you make your Robfunction like Rob(playerid); or what ever to: Rob(GetClosestPlayerToPlayer(playerid)); This is really simple..
Reply
#9

this is Ok but i don't understand it what
pawn Код:
new Float:x1,Float:y1,Float:z1;
Means etc! so i need A Tutorial on Scripting Tutorials Pleaze if Someone do it
Reply
#10

Quote:
Originally Posted by Roomeo
Посмотреть сообщение
this is Ok but i don't understand it what
pawn Код:
new Float:x1,Float:y1,Float:z1;
Means etc! so i need A Tutorial on Scripting Tutorials Pleaze if Someone do it
https://sampwiki.blast.hk/wiki/Float
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)