How do I respawn near players? -
ivndosos - 02.02.2018
So I have a random spawning system,
How do I make them respawn to nearby players (not too nearby, Let's say a distance such as from grove street to binco shop).
Re: How do I respawn near players? -
Mugala - 02.02.2018
PHP код:
for (new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i,range,X,Y,Z)) SpawnPlayer(i);
}
Re: How do I respawn near players? -
jasperschellekens - 02.02.2018
Quote:
Originally Posted by Mugalito
PHP код:
for (new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i,range,X,Y,Z)) SpawnPlayer(playerid);
}
|
That wouldnt work obviously, stop posting random code that doesn't work man.
You can try something like this but it won't work i guess. What you want to do sound complicated but it might be possible.
You can also try to do something with
https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint
PHP код:
//onplayerdeath
new Float:px, Float:py, Float:pz;
for (new i = 0; i < MAX_PLAYERS; i++)
{
GetPlayerPos(i, px, py, pz);
SetPlayerPos(playerid,px+50, py+50, pz);
}
Why don't spawn them at the nearest hospital?
Re: How do I respawn near players? -
Mugala - 02.02.2018
jasperschellekens, it's not a random code, he wants to respawn a player which is near to a location (as I guessed, If I'm wrong than sry
try to provide more information what do u want to make)
Re: How do I respawn near players? -
ivndosos - 02.02.2018
I mean when a player does /respawn, or dies (I have the respawn command already, If you need it I'll post it)
It will spawn him to the nearby players, not too close of course, I'm making a sortof DM/TDM server so I don't want players to spam /respawn just to get to someone close to duel.
Re: How do I respawn near players? -
Mugala - 02.02.2018
okay for first you need to get position of nearby player, than u must increase or decrease this nearby player's X/Y position randomly, find out a Z cord and than set a player that coordinates.
u can use this function for get closest player
PHP код:
stock GetClosestPlayer(playerid,Float:limit)
{
new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2;
GetPlayerPos(playerid,x1,y1,z1);
new Float:Range = 999.9;
new id = -1;
foreach(Player,i)
{
if(playerid != i)
{
GetPlayerPos(i,x2,y2,z2);
new Float:Dist = GetDistanceBetweenPoints(x1,y1,z1,x2,y2,z2);
if(floatcmp(Range,Dist) == 1 && floatcmp(limit,Range) == 1)
{
Range = Dist;
id = i;
}
}
}
return id;
}
code credits:
cessil