[HOSPITAL SYSTEM] i need help with it please
#1

When i die i should be kept in the hospital for 60 seconds but when i die the piece of code isnt exicuted =l heres my codes
These are the forwards:
Код:
forward DEAD1(playerid);
forward RespawnHospital(playerid);
This is in OnPlayerDeath:
Код:
SetTimer("RespawnHospital", 3500, 0);
And here are my new publics:
Код:
public RespawnHospital(playerid)
{
    SendClientMessage(playerid, COLOUR_YELLOW, "You're being rushed to the hospital!");
    SetPlayerPos(playerid, 1221.7010,-1328.6449,13.4821);
    SetPlayerCameraPos(playerid, 1204.3781,-1313.3323,16.3984);
    SetPlayerCameraLookAt(playerid, 1174.7167,-1323.4485,14.5938);
  	TogglePlayerControllable(playerid,0);
    SetTimer("DEAD1", 50000, 0); 
    return 1;
}

public DEAD1(playerid)
{
    SetPlayerHealth(playerid,100);
    SetPlayerPos(playerid,1172.6569,-1323.2815,15.4025);
  	TogglePlayerControllable(playerid,1);
    return 1;
}
Any ideas? Thanks for the help
Reply
#2

Shouldn't
pawn Код:
public DEAD1(playerid)
Be

pawn Код:
public OnPlayerDeath
Reply
#3

I think the problem comes here. Everytime someone dies program goes trough OnPlayerDeath(), and when he finishes it he automaticly goes OnPlayerSpawn() and spawns player. I think you should make a global varialble which will tell callback OnPlayerSpawn not to spawn player. For example:
pawn Код:
new gPlayerDied[MAX_PLAYERS];
OnPlayerDeath(playerid,killerid,reason)
{
     gPlayerDied[playerid]=1;
     return 1;
}
OnPlayerSpawn(playerid)
{
     if(gPlayerDied[playerid]==1)
     return 0;
     else return 1;
}
And on DEAD1(playerid) i would add SetCameraBehindPlayer(playerid);
Hope this help
Reply
#4

i dont understand roko if i make the code miss out my new publics i cannot make a timer =S
Reply
#5

I just gave you an example how to prevent spawning( I think once you die, you spawn where you don't want to be spawned). Try to add these lines to your callbacks.
OnPlayerDeath:
pawn Код:
gPlayerDied[playerid]=1;
before
pawn Код:
SetTimer("RespawnHospital", 3500, 0);
and
pawn Код:
if(gPlayerDied[playerid]==1)
     return 0;
on top of OnPlayerSpawn.
Even, this might work when you test, you shloudn't use SetTimer, but SetTimerEx.
Reply
#6

im still not getting it how will that stop the players from spawning for the amount of time i want it =S

could you kinda give a better coding example please =) sorry for being a pain but im confused haha
Reply
#7

pawn Код:
forward DEAD1(playerid);
forward RespawnHospital(playerid);

new gPlayerDied[MAX_PLAYERS];

public OnPlayerDeath(playerid,killerid,reason)
{
        gPlayerDied[playerid]=1;// this flags that player has died, we will need it OnPlayerSpawn
        SetTimerEx("RespawnHospital", 3500, 0,"d",playerid);// this will happen after 3.5 sec, why SetTimerEx check https://sampwiki.blast.hk/wiki/SetTimerEx
        //... whatever is in your code.
        return 1;// once program comes to this code, he automaticly goes to OnPlayerSpawn. We don't want player to be spawned somewhere random, do we?
}
public OnPlayerSpawn(playerid)
{// once player attempts to spawn, we don't allow him with this code.
        if(gPlayerDied[playerid] == 1)// this checks if he died, if so it enters this if clause
        {
            gPlayerDied[playerid]=0;// we are setting this variable to default because we don't need it anymore.
            return 0;// this prevents player from spawning and exits the callback.
        }
        //... whatever is in your code
        return 1;
}

public RespawnHospital(playerid)
{
    SendClientMessage(playerid, COLOUR_YELLOW, "You're being rushed to the hospital!");
    SetPlayerPos(playerid, 1221.7010,-1328.6449,13.4821);
    SetPlayerCameraPos(playerid, 1204.3781,-1313.3323,16.3984);
    SetPlayerCameraLookAt(playerid, 1174.7167,-1323.4485,14.5938);
    TogglePlayerControllable(playerid,0);
    SetTimerEx("DEAD1", 50000, 0,"d",playerid);
    return 1;
}

public DEAD1(playerid)
{
    SetPlayerHealth(playerid,100);
    SetPlayerPos(playerid,1172.6569,-1323.2815,15.4025);
    TogglePlayerControllable(playerid,1);
    SetCameraBehindPlayer(playerid);
    return 1;
}
Now okay?
Reply
#8

yep i undestood that time but when i have copyed the code into my server i still just spawn.
Reply
#9

i think it does it because there is still nothing telling it to go to the forwards.... =l
Reply
#10

Really, don't know where is the problem. Are you sure your coordinates are correct?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)