How do I respawn near players?
#1

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

PHP код:
for (new 0MAX_PLAYERSi++)
{
    if(
IsPlayerInRangeOfPoint(i,range,X,Y,Z)) SpawnPlayer(i);

Reply
#3

Quote:
Originally Posted by Mugalito
Посмотреть сообщение
PHP код:
for (new 0MAX_PLAYERSi++)
{
    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:pxFloat:pyFloat:pz;
for (new 
0MAX_PLAYERSi++)
{
    
GetPlayerPos(ipxpypz);
        
SetPlayerPos(playerid,px+50py+50pz);

Why don't spawn them at the nearest hospital?
Reply
#4

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)
Reply
#5

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.
Reply
#6

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:x1Float:y1Float:z1Float:x2Float:y2Float: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) == && floatcmp(limit,Range) == 1)
            {
                
Range Dist;
                
id i;
            }
        }
    }
    return 
id;

code credits: cessil
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)