Closest one! - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Closest one! (
/showthread.php?tid=243108)
Closest one! -
GNGification - 21.03.2011
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!
Re: Closest one! -
Stigg - 21.03.2011
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.
Re: Closest one! -
GNGification - 21.03.2011
Thank you! This was just the thing I searched for, now I can just mod this for the things I want
Re: Closest one! -
Stigg - 21.03.2011
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
Re: Closest one! -
Roomeo - 21.03.2011
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
Re: Closest one! - XFlawless - 21.03.2011
You can use IsPlayerInRangeOfPoint it's faster.
Re: Closest one! -
Roomeo - 21.03.2011
Explain?
AW: Closest one! -
Pablo Borsellino - 21.03.2011
@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..
Re: Closest one! -
Roomeo - 21.03.2011
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
Re: Closest one! -
Stigg - 21.03.2011
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