Player spawn
#1

Hey,
How can i make when player died will respawn to the nearest Hospital, and when someone leave the server and back he will spawn on the last place he where before he left the server
and spawn place when player register ...
Thanks.
Reply
#2

this may be the code

PHP код:
#include <YSI\y_ini>

#define USER_FILE "SCNR/Users/%s.ini"


enum User
{
pQuit[]
}
new 
PlayerInfo[playerid][User];

public 
OnPlayerDisconnect(playeridreason)
{
new 
Float:xFloat:yFloat:z;
new 
quitpos GetPlayerPos(playeridxyz);
PlayerInfo[playerid][pQuit] = quitpos;
return 
1;
}


public 
OnPlayerSpawn(playerid)
{
SetPlayerPos(playeridpQuit[0], pQuit[1], pQuit[2]);
SetPlayerFacingAngle(playeridpQuit[3]);
return 
1;
}
stock SaveUserStats(playerid)
{
        if(
IsPlayerConnected(playerid) && IsLoggedIn{playerid} == 1)
    {
    
format(filesizeof(file), USER_FILEGetName(playerid));
        new 
INI:ufile INI_Open(file);
        
INI_WriteInt(ufile"pQuit"PlayerInfo[playerid][pQuit]);
        
INI_Close(ufile);
}
return 
1;

Reply
#3

Quote:
Originally Posted by Arshman
Посмотреть сообщение
this may be the code
PHP код:
new quitpos GetPlayerPos(playeridxyz);
PlayerInfo[playerid][pQuit] = quitpos
If I could give negative rep for that, I certainly would.

To determine the closest hospital you will have to maintain a list (array) of their locations.
PHP код:
new Float:gHospitalLocations[][4] = {
    {
xyza},
    {
xyza},
    {
xyza}
}; 
Obviously replace 'x', 'y' and 'z' with the actual coordinates and replace 'a' with the facing angle you want the player to have when they spawn there.

Next create a function that determines the closest hospital to the player;
PHP код:
GetClosestHospital(playerid)
{
    new 
closest = -1;
    
    for(new 
iFloat:minDist Float:0x7F800000sizeof(gHospitalLocations); i++)
    {
        new 
Float:currentDist GetPlayerDistanceFromPoint(playeridgHospitalLocations[i][0], gHospitalLocations[i][1], gHospitalLocations[i][2]);
        
        if(
currentDist minDist)
        {
            
minDist currentDist;
            
closest i;
        }
    }
    
    return 
closest;

When they die, get the closest hospital and then set the spawn info:
PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    new 
        
h_id GetClosestHospital(playerid);
    new
        
Float:gHospitalLocations[h_id][0],
        
Float:gHospitalLocations[h_id][1],
        
Float:gHospitalLocations[h_id][2],
        
Float:gHospitalLocations[h_id][3];
    
    
SetSpawnInfo(playerid, ..., xyza, ...);
    return 
1;

Reply
#4

actually i wasnt giving him the code for the Game Quit and relog position i didnt gave him the code of getting killed to nearest Hospital.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
If I could give negative rep for that, I certainly would.

To determine the closest hospital you will have to maintain a list (array) of their locations.
PHP код:
new Float:gHospitalLocations[][4] = {
    {
xyza},
    {
xyza},
    {
xyza}
}; 
Obviously replace 'x', 'y' and 'z' with the actual coordinates and replace 'a' with the facing angle you want the player to have when they spawn there.

Next create a function that determines the closest hospital to the player;
PHP код:
GetClosestHospital(playerid)
{
    new 
closest = -1;
    
    for(new 
iFloat:minDist Float:0x7F800000sizeof(gHospitalLocations); i++)
    {
        new 
Float:currentDist GetPlayerDistanceFromPoint(playeridgHospitalLocations[i][0], gHospitalLocations[i][1], gHospitalLocations[i][2]);
        
        if(
currentDist minDist)
        {
            
minDist currentDist;
            
closest i;
        }
    }
    
    return 
closest;

When they die, get the closest hospital and then set the spawn info:
PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    new 
        
h_id GetClosestHospital(playerid);
    new
        
Float:gHospitalLocations[h_id][0],
        
Float:gHospitalLocations[h_id][1],
        
Float:gHospitalLocations[h_id][2],
        
Float:gHospitalLocations[h_id][3];
    
    
SetSpawnInfo(playerid, ..., xyza, ...);
    return 
1;

Alright, i put it like that

PHP код:
new Float:gHospitalLocations[][4] = {
    {
xyza},
    {
xyza},
    {
xyza}
}
GetClosestHospital(playerid)
{
    new 
closest = -1;
    for(new 
iFloat:minDist Float:0x7F800000sizeof(gHospitalLocations); i++)
    {
        new 
Float:currentDist GetPlayerDistanceFromPoint(playeridgHospitalLocations[i][0], gHospitalLocations[i][1], gHospitalLocations[i][2]);
        if(
currentDist minDist)
        {
            
minDist currentDist;
            
closest i;
        }
    }
    return 
closest;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    new
        
h_id GetClosestHospital(playerid);
    new
        
Float:gHospitalLocations[h_id][0],
        
Float:gHospitalLocations[h_id][1],
        
Float:gHospitalLocations[h_id][2],
        
Float:gHospitalLocations[h_id][3];
    
SetSpawnInfo(playerid, ..., xyza, ...);
    return 
1;

But it show this errors ..

Код:
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(1231) : error 017: undefined symbol "x"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(1263) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(2262) : error 021: symbol already defined: "OnPlayerDeath"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(8752) : warning 203: symbol is never used: ""
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Reply
#6

Quote:
Originally Posted by Arshman
Посмотреть сообщение
this may be the code

PHP код:
#include <YSI\y_ini>
#define USER_FILE "SCNR/Users/%s.ini"
enum User
{
pQuit[]
}
new 
PlayerInfo[playerid][User];
public 
OnPlayerDisconnect(playeridreason)
{
new 
Float:xFloat:yFloat:z;
new 
quitpos GetPlayerPos(playeridxyz);
PlayerInfo[playerid][pQuit] = quitpos;
return 
1;
}
public 
OnPlayerSpawn(playerid)
{
SetPlayerPos(playeridpQuit[0], pQuit[1], pQuit[2]);
SetPlayerFacingAngle(playeridpQuit[3]);
return 
1;
}
stock SaveUserStats(playerid)
{
        if(
IsPlayerConnected(playerid) && IsLoggedIn{playerid} == 1)
    {
    
format(filesizeof(file), USER_FILEGetName(playerid));
        new 
INI:ufile INI_Open(file);
        
INI_WriteInt(ufile"pQuit"PlayerInfo[playerid][pQuit]);
        
INI_Close(ufile);
}
return 
1;

This code keep crashing my Pawno ...
Reply
#7

Quote:
Originally Posted by TwiiKzz
Посмотреть сообщение
Alright, i put it like that

[ .. ]

But it show this errors ..

Код:
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(1231) : error 017: undefined symbol "x"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(1263) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(2262) : error 021: symbol already defined: "OnPlayerDeath"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(8752) : warning 203: symbol is never used: ""
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
You weren't meant to copy and paste that code into your script directly. You got an example, now you have to try and figure where and how you should implement it by using his example of how to do it. You should try and adjust the code you were provided to fit into your script.

Код:
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(2262) : error 021: symbol already defined: "OnPlayerDeath"
This is an obvious error, try to learn from this as this is telling you that another OnPlayerDeath function is already in the script, and there can not be more than one, so what do you do? You merge the code into the other.

You're meant to learn from this example, not take it and just put it into your code, else you didn't learn anything.
Reply
#8

"Obviously replace 'x', 'y' and 'z' with the actual coordinates and replace 'a' with the facing angle you want the player to have when they spawn there."

Damn you can't read dude
Reply
#9

My code

PHP код:
new Float:gHospitalLocations[][4] = {
    {-
2660.9519,630.8198,14.4531,179.2536},
    {-
2207.3352,-2285.7437,30.6250,328.3635},
    {
2027.5869,-1421.5159,16.9922,134.5767},
    {
1183.1479,-1323.4757,13.5776,270.0348},
    {-
319.3146,1059.4440,19.7422,322.3916},
    {-
1514.5492,2527.2280,55.7423,348.1437},
    {
1576.8633,1768.6094,10.6719,87.9024},
};

GetClosestHospital(playerid)
{
    new 
closest = -1;

    for(new 
iFloat:minDist Float:0x7F800000sizeof(gHospitalLocations); i++)
    {
        new 
Float:currentDist GetPlayerDistanceFromPoint(playeridgHospitalLocations[i][0], gHospitalLocations[i][1], gHospitalLocations[i][2]);

        if(
currentDist minDist)
        {
            
minDist currentDist;
            
closest i;
        }
    }

    return 
closest;
}

public 
OnPlayerDeath(playeridkilleridreason)
{
    new
        
h_id GetClosestHospital(playerid);

    new
        
Float:gHospitalLocations[h_id][0],
        
Float:gHospitalLocations[h_id][1],
        
Float:gHospitalLocations[h_id][2],
        
Float:gHospitalLocations[h_id][3];

    
SetSpawnInfo(playerid, ..., -2660.9519,630.8198,14.4531,179.2536, ...);
    
SetSpawnInfo(playerid, ..., -2207.3352,-2285.7437,30.6250,328.3635, ...);
    
SetSpawnInfo(playerid, ..., 2027.5869,-1421.5159,16.9922,134.5767, ...);
    
SetSpawnInfo(playerid, ..., 1183.1479,-1323.4757,13.5776,270.0348, ...);
    
SetSpawnInfo(playerid, ..., -319.3146,1059.4440,19.7422,322.3916, ...);
    
SetSpawnInfo(playerid, ..., -1514.5492,2527.2280,55.7423,348.1437, ...);
    
SetSpawnInfo(playerid, ..., 1576.8633,1768.6094,10.6719,87.9024, ...);
    return 
1;

Errors ..

Код:
 C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(224) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(224) : error 008: must be a constant expression; assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(255) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(256) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(257) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(258) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(259) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(260) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(261) : error 029: invalid expression, assumed zero
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(253) : warning 204: symbol is assigned a value that is never used: "a"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(252) : warning 204: symbol is assigned a value that is never used: "z"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(251) : warning 204: symbol is assigned a value that is never used: "y"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(250) : warning 204: symbol is assigned a value that is never used: "x"
C:\Users\Omar Masri\Desktop\xTorMz Freeroam\gamemodes\xTorMzFreeroam.pwn(2275) : error 021: symbol already defined: "OnPlayerDeath"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


10 Errors.
Reply
#10

Help guys..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)