[HELP] - OnPlayerDeath [+rep]
#1

Hi,

This script is complicated a bit [well for me], i had 2 bugs.
1. When you suicided, you would just freeze and not spawn to the hospital, however i fixed it.
2. When someone shoots you, you freeze and again, not spawning at the hospital.

Here is the code:

Код:
public OnPlayerDeath(playerid,killerid,reason)
{
	if(License[playerid][StepB] >=1||License[playerid][StepD] >=1||License[playerid][StepF] >=1)
	{
	    License[playerid][StepB]=0;
        License[playerid][StepF]=0;
        License[playerid][StepD]=0;
        DisablePlayerRaceCheckpoint(playerid);
        DestroyVehicle(License[playerid][Vehicle]);
	    SendClientMessage(playerid,LRED,"You have failed the test");
	}
	if(PB[playerid]==0)
    {
		Died[playerid]=1;
		SetPlayerPos(playerid, 2035.2500,-1411.8441,16.9922,142.2312);
        SendDeathMessage(killerid,playerid,reason);
	}
    if(killerid !=INVALID_PLAYER_ID)
	{
  		if(PB[playerid]==1)
 		{
			new str[128];
        	format(str,sizeof(str),"'%s' has been terminated by '%s'",PlayerName(playerid),PlayerName(killerid));
        	GivePlayerMoneyEx(killerid,200);
        	SendNearbyMessage(playerid,250,str,RED);
        	GameTextForPlayer(killerid,"~g~+$200",3000,1);
		}
		if(PB[playerid]==0)
 		{
        	if(PlayerOrgType(killerid)==LAW&&GetPlayerWantedLevel(playerid) >=1)
			{
 				new string[128];
				Died[playerid]=0;
				Jailed[playerid]=2;
				new rand=100 +random(1000);
				GivePlayerMoneyEx(killerid,rand);
 				format(string,sizeof(string),"~g~+$%i",rand);
 				GameTextForPlayer(killerid,string,3000,1);
 				format(string,sizeof(string),"%s has been arrested by Officer %s",PlayerName(playerid),PlayerName(killerid));
  				SendClientMessageToAll(RED,string);
                if(PlayerAwards[killerid][Jailer]==0)
				{
 					GivePlayerMoneyEx(killerid,800);
					PlayerAwards[killerid][Jailer]=1;
 					GamerScore[playerid]=GamerScore[playerid]+50;
  					SendClientMessage(killerid,YELLOW,"Achievement Unlocked: {FFFFFF}Cleaning The Streets!");
					SendClientMessage(killerid,LGREEN,"BONUS: $800 || +50 Gamer Score");
				}
			}
			if(PlayerOrgType(killerid)!=LAW)
			{
			    format(Reason[killerid],25,"Murder");
				SetPlayerWantedLevel(killerid,GetPlayerWantedLevel(killerid)+2);
				for(new a=0;a<MAX_PLAYERS;a++)
				{
        			if(IsPlayerConnectedEx(a))
       				{
   				    	new str[128];
        				if(PlayerOrgType(a)==LAW)
        	 			{
							format(str,sizeof(str),"RADIO - %s has been reported for a murder",PlayerName(killerid));
        	   				SendClientMessage(a,BLUE,str);
        	    		}
						GetPlayerPos(playerid,pX[playerid],pY[playerid],pZ[playerid]);
						if(IsPlayerInRangeOfPoint(a,7,pX[playerid],pY[playerid],pZ[playerid]))
						{
						    if(a!=playerid&&a!=killerid)
						    {
								format(str,sizeof(str),"You saw how badly %s was murdered by %s",PlayerName(playerid),PlayerName(killerid));
        	   					SendClientMessage(a,BLUE,str);
							}
       	 	    		}
					}
				}
			}
		}
	}
	if(killerid==INVALID_PLAYER_ID)
	{
		if(PlayerAwards[playerid][Suicide]==0)
		{
   			GivePlayerMoneyEx(playerid,250);
		    PlayerAwards[playerid][Suicide]=1;
		    SetPlayerPos(playerid, 2035.2500,-1411.8441,16.9922,142.2312);
			GamerScore[playerid]=GamerScore[playerid]+60;
  			SendClientMessage(playerid,YELLOW,"Achievement Unlocked: {FFFFFF}Good Bye Cruel World!");
  			SendClientMessage(playerid,LGREEN,"BONUS: $250 || +60 Gamer Score");
		}
	}
	if(GetPlayerMoneyEx(playerid) > 4)
	{
		GivePlayerMoneyEx(playerid,-GetPlayerMoneyEx(playerid)/2);
	}
    if(IsRobbing[playerid]==1)
	{
		Died[playerid]=1;
        rcash[playerid]=0;
        IsRobbing[playerid]=0;
        SendDeathMessage(killerid,playerid,reason);
        SetPlayerPos(playerid, 2035.2500,-1411.8441,16.9922,142.2312);
        SendClientMessage(playerid,LRED,"Robbery failed,you lost all of your loot");
    }
    Suited[playerid]=0;
    IsBleeding[playerid]=0;
    SetPlayerInterior(playerid,0);
	ResetPlayerWeaponsEx(playerid);
    SetPlayerVirtualWorld(playerid,0);
	SetPlayerSkin(playerid,Skin[playerid]);
    TextDrawHideForPlayer(playerid,Textdraw1);
    TextDrawHideForPlayer(playerid,Textdraw2);
    TextDrawHideForPlayer(playerid,Textdraw3);
    TextDrawHideForPlayer(playerid,Textdraw4);
    TextDrawHideForPlayer(playerid,Textdraw5);
	TextDrawHideForPlayer(playerid,Zones[playerid]);
	SetPlayerFightingStyle(playerid,Fstyle[playerid]);
 	return 1;
}
Any of you got a clue, how to spawn at the Hospital after getting killed by another player?

Thanks.
Reply
#2

The SetPlayerPos must be put in OnPlayerSpawn
Reply
#3

This is how my OnPlayerSpawn looks

Код:
public OnPlayerSpawn(playerid)
{
	if(Died[playerid]==1)
	{
	    Died[playerid]=0;
		if(IsPlayerInRangeOfPoint(playerid,2500,2034.6943,-1406.8729,17.1975))
		{
		    SetPlayerPos(playerid,2034.6943,-1406.8729,17.1975);
		}
		if(IsPlayerInRangeOfPoint(playerid,2500,1578.3215,1768.5914,10.8203))
		{
		    SetPlayerPos(playerid,1578.3215,1768.5914,10.8203);
		}
		if(IsPlayerInRangeOfPoint(playerid,2500,-2648.6311,635.9958,14.4531))
		{
		    SetPlayerPos(playerid,-2648.6311,635.9958,14.4531);
		}
        if(!IsPlayerInRangeOfPoint(playerid,2500,-2648.6311,635.9958,14.4531)&&!IsPlayerInRangeOfPoint(playerid,2500,1578.3215,1768.5914,10.8203)&&!IsPlayerInRangeOfPoint(playerid,2500,2034.6943,-1406.8729,17.1975))
		{
		    SetPlayerPos(playerid,1177.9857,-1323.0596,14.0977);
		}
    }
But still, i freeze and im not spawning at the Hospital, any suggestions?
Reply
#4

Reply
#5

try this

PHP код:
public OnPlayerSpawn(playerid)
{
    if(
Died[playerid]==1)
    {
        
        if(
IsPlayerInRangeOfPoint(playerid,2500,2034.6943,-1406.8729,17.1975))
        {
            
SetPlayerPos(playerid,2034.6943,-1406.8729,17.1975);
        }
        else if(
IsPlayerInRangeOfPoint(playerid,2500,1578.3215,1768.5914,10.8203))
        {
            
SetPlayerPos(playerid,1578.3215,1768.5914,10.8203);
        }
        else if(
IsPlayerInRangeOfPoint(playerid,2500,-2648.6311,635.9958,14.4531))
        {
            
SetPlayerPos(playerid,-2648.6311,635.9958,14.4531);
        }
                else
        {
            
SetPlayerPos(playerid,1177.9857,-1323.0596,14.0977);
        }
                
Died[playerid]=0;
    }

Reply
#6

OnPlayerSpawn is called when a player respawns after OnPlayerDeath.

I recommend just setting their position in OnPlayerSpawn rather than death.
Reply
#7

The problem was fixed, i'll give you rep+ anyways.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)