Closest Player Help? - 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)
+--- Thread: Closest Player Help? (
/showthread.php?tid=454154)
Closest Player Help? -
RandomDude - 27.07.2013
pawn Код:
dcmd_rape(playerid, params[])
{
new ID = strval(params);
if(!strlen(params))
{
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /rape [ID]");
}
else
{
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_ERROR, "That player is not connected!");
if(ID == playerid) return SendClientMessage(playerid, COLOR_ERROR, "You cannot rape yourself!");
if(rapespam[playerid] == 0)
{
if(GetDistanceBetweenPlayers(playerid,ID) > RAPE_DISTANCE) return SendClientMessage(playerid, COLOR_ERROR, "You are not close enough to eachother!");
I just want it to rape the closest player near him
Not rape [ID]
Re: Closest Player Help? -
Donvalley - 27.07.2013
add this to your script:
pawn Код:
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;
}
search ****** and you will find the answers
http://lmgtfy.com/?q=rape+closeset+player+samp
just so you don't get heaps of reply's saying search before you post
Re: Closest Player Help? -
RandomDude - 27.07.2013
Ahh I already have that thanks :P