SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/03/2019, 01:59 AM   #1
ColweeN
Little Clucker
 
ColweeN's Avatar
 
Join Date: Apr 2018
Location: United States
Posts: 20
Reputation: 0
Default Need help with hospital spawn

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?
ColweeN is offline   Reply With Quote
Old 29/03/2019, 02:24 AM   #2
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Need help with hospital spawn

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.
Crayder is offline   Reply With Quote
Old 29/03/2019, 02:28 AM   #3
ColweeN
Little Clucker
 
ColweeN's Avatar
 
Join Date: Apr 2018
Location: United States
Posts: 20
Reputation: 0
Default Re: Need help with hospital spawn

then? what i have to do now?
ColweeN is offline   Reply With Quote
Old 29/03/2019, 02:36 AM   #4
MSC
Little Clucker
 
MSC's Avatar
 
Join Date: Feb 2019
Location: Tunisia
Posts: 24
Reputation: 0
Default Re: Need help with hospital spawn

Try using this.

SetSpawnInfo();
__________________
- Closed all projects, will be back soon -
MSC is offline   Reply With Quote
Old 29/03/2019, 03:20 AM   #5
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Need help with hospital spawn

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?
Crayder is offline   Reply With Quote
Old 29/03/2019, 07:08 AM   #6
ColweeN
Little Clucker
 
ColweeN's Avatar
 
Join Date: Apr 2018
Location: United States
Posts: 20
Reputation: 0
Default Re: Need help with hospital spawn

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;
}
ColweeN is offline   Reply With Quote
Old 29/03/2019, 08:12 AM   #7
akib
Huge Clucker
 
akib's Avatar
 
Join Date: Jun 2016
Location: Bangladesh
Posts: 283
Reputation: 2
Default Re: Need help with hospital spawn

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
__________________
ImKhan#4244
akib is offline   Reply With Quote
Old 29/03/2019, 08:36 AM   #8
ColweeN
Little Clucker
 
ColweeN's Avatar
 
Join Date: Apr 2018
Location: United States
Posts: 20
Reputation: 0
Default Re: Need help with hospital spawn

Ay Ay! Thanks Akib Khan!
ColweeN is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ajuda] spawn hospital minimessi10 Português/Portuguese 1 28/10/2014 12:34 AM
spawn at hospital when die Gooday Scripting Help 33 13/03/2012 12:25 PM
Always spawn at hospital. Please help! :( sass839 Help Archive 12 24/02/2010 02:41 PM
Help|How to fix the hospital spawn (CRP) itayizra Help Archive 0 16/10/2009 05:32 PM
[bug] Hospital Spawn bug ((I will pay for it)) tony_fitto Help Archive 3 15/10/2009 03:26 PM


All times are GMT. The time now is 01:10 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.