Need help with hospital spawn
#1

Hello,

My name is Colween and im new here.
i have a big problem with my script (Hospital Spawn)

my codes
// OnPlayerSpawn
{
SetPlayerPos( p id etc )
return 1;
}

// Onplayerdeath

setplayerpos(p id etc)

And it respawn my player at OnPlayerSpawn's pos any solution?
Reply
#2

Not sure exactly what your issue is... but...

OnPlayerSpawn is called when a player is set to spawn, before actually spawning. Honestly setting the player's position there isn't the best option, a more proper way to avoid very minor weird things would be getting used to using SetSpawnInfo BEFORE the player is sent to OnPlayerSpawn.

Using SetPlayerPos will indeed set the player's position, the player will be where you tell them to be.

Setting the position in OnPlayerDeath is probably not going to do much for you for what you are doing, it's called when the player is pronounced dead. Using SetPlayerPos here will not set the player's position because the player is going to respawn and be sent to their spawn position (assigned by AddPlayerClass or SetSpawnInfo).



Basically, when OnPlayerSpawn is called, internally your player is going to be sent to the position set by AddPlayerClass or SetSpawnInfo. You are setting the player's position in OnPlayerSpawn (as most people do unfortunately, including me even), which will be after they are sent to the other position. Setting the position in OnPlayerDeath isn't going to do much.
Reply
#3

then? what i have to do now?
Reply
#4

Try using this.

SetSpawnInfo();
Reply
#5

Quote:
Originally Posted by ColweeN
View Post
then? what i have to do now?
We don't know what you have to do. You didn't explain anything and you didn't even give us real code. WHAT are you trying to do? What is your goal and what the hell is the problem?
Reply
#6

Hello,

@Crayder here are my codes.

public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid, 2616.5447,2453.2605,14.8672);
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
SetPlayerPos(playerid, 10.2967,148.8675,999.0613);
SetPlayerHealth(playerid, 100);
GivePlayerMoney(playerid, -500);
SendClientMessage(playerid, -1,"DOCTOR: You have paid your medical bill.");
return 1;
}
Reply
#7

Quote:
Originally Posted by ColweeN
View Post
Hello,

@Crayder here are my codes.

public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid, 2616.5447,2453.2605,14.8672);
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
SetPlayerPos(playerid, 10.2967,148.8675,999.0613);
SetPlayerHealth(playerid, 100);
GivePlayerMoney(playerid, -500);
SendClientMessage(playerid, -1,"DOCTOR: You have paid your medical bill.");
return 1;
}
You are ultimately spawning the player on the spawn zone on this callback
PHP Code:
public OnPlayerSpawn(playerid)
{
    
SetPlayerPos(playerid2616.5447,2453.2605,14.8672);
    return 
1;

You can use a variable, when player death variable = 1, if variable = 1 spawn player to hospital


add this on the top of the script, under includes
PHP Code:
new Hospitalized[MAX_PLAYERS]; 
Then, OnPlayerDeath
PHP Code:
public OnPlayerDeath(playeridkilleridreason)
{
    
Hospitalized[playerid] = 1;
    
SetPlayerPos(playerid10.2967,148.8675,999.0613);
    
SetPlayerHealth(playerid100);
    
GivePlayerMoney(playerid, -500);
    
SendClientMessage(playerid, -1,"DOCTOR: You have paid your medical bill.");
    return 
1;

and OnPlayerSpawn will be like this
PHP Code:
public OnPlayerSpawn(playerid)
{
    if(
Hospitalized[playerid]){
        
SetPlayerPos(playerid10.2967,148.8675,999.0613);
    }else{
        
SetPlayerPos(playerid2616.5447,2453.2605,14.8672);
     }
    return 
1;

Hope it will work
Reply
#8

Ay Ay! Thanks Akib Khan!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)