SA-MP Forums Archive
OnPlayerDeath function not being called - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerDeath function not being called (/showthread.php?tid=664133)



OnPlayerDeath function not being called - akib - 20.02.2019

Hello, OnPlayerDeath function isn't calling in my gamemode

PHP Code:
public OnPlayerDeath(playeridkilleridreason)
{
    print(
"Player died");
    if (
PlayerInfo[playerid][pInjured] == 0)
    {
        
PlayerInfo[playerid][pInjured] = 1;
        
GetPlayerPos(playeridinj_x,inj_y,inj_z);
        
GetPlayerFacingAngle(playeridinjured_angle);
    }
    else if (
PlayerInfo[playerid][pInjured] == 1)
    {
        
KillTimer(AcceptDeathTimer[playerid]);
        
KillTimer(LoseHealthTimer[playerid]);
        
AcceptDeath[playerid] = 0;
        
PlayerInfo[playerid][pInjured] = 0;
        
Hospitalized[playerid] = 1;
    }
    return 
1;

I tried with only print but still, it doesn't work


Re: OnPlayerDeath function not being called - xSkin - 20.02.2019

check if killerid != INVALID_PLAYER_ID


Re: OnPlayerDeath function not being called - akib - 20.02.2019

Quote:
Originally Posted by xSkin
View Post
check if killerid != INVALID_PLAYER_ID
tried, killerid isn't invalid

PHP Code:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
killerid==INVALID_PLAYER_ID) return print("Error");
    print(
"Player died");
    if (
PlayerInfo[playerid][pInjured] == 0)
    {
        
PlayerInfo[playerid][pInjured] = 1;
        
GetPlayerPos(playeridinj_x,inj_y,inj_z);
        
GetPlayerFacingAngle(playeridinjured_angle);
    }
    else if (
PlayerInfo[playerid][pInjured] == 1)
    {
        
KillTimer(AcceptDeathTimer[playerid]);
        
KillTimer(LoseHealthTimer[playerid]);
        
AcceptDeath[playerid] = 0;
        
PlayerInfo[playerid][pInjured] = 0;
        
Hospitalized[playerid] = 1;
    }
    return 
1;




Re: OnPlayerDeath function not being called - TheToretto - 20.02.2019

Launch the server with the crashdetect plugin and kill yourself, then check the server's logs to see if something is wrong?


Re: OnPlayerDeath function not being called - akib - 20.02.2019

i am having problem with my crashdetect, is there any other way?


Re: OnPlayerDeath function not being called - TheToretto - 20.02.2019

Your code is correct, there's nothing wrong with it.


Re: OnPlayerDeath function not being called - akib - 20.02.2019

I have a part of my script as a include file, called groups.inc

In groups.inc, I used y_hooks, something like that Hook:gs_OnPlayerDeath(playerid,killerid,reason)

inside that i placed this code
PHP Code:
if(GroupInfo[PlayerInfo[killerid][pGroup]][gType]==GROUP_TYPE_HITMAN){
        new 
cid,m[512];
        if(
IsPlayerInContract(playerid)){
            
cid GetPlayerContractID(playerid);
            
ContractInfo[cid][c_killer] = PlayerInfo[killerid][pID];
            
GiveMoney(playerid,-ContractInfo[cid][c_amount]);
            
format(msizeof(m), "You were killed by hitman. You lost -$%i."ContractInfo[cid][c_amount]);
            
SendClientMessage(playeridCOLOR_YELLOWm);
            
format(msizeof(m), "You have finished a contract of $%i. You received $%d."ContractInfo[cid][c_amount],ContractInfo[cid][c_amount]/2);
            
SendClientMessage(killeridCOLOR_YELLOWm);
            
GiveMoney(killerid,ContractInfo[cid][c_amount]/2);
            
mysql_format(dbhandlemsizeof(m), "UPDATE contracts SET killer='%i' WHERE id='%i'"PlayerInfo[killerid][pID],ContractInfo[cid][c_SQLID]);
            
mysql_tquery(dbhandlem);
            
SendPlayerToHospital(playerid);
            return 
1;
        }
    } 
this code is blocking other codes that next to it :/


Re: OnPlayerDeath function not being called - TheToretto - 20.02.2019

Which one is first?


Re: OnPlayerDeath function not being called - akib - 20.02.2019

Quote:
Originally Posted by TheToretto
View Post
Which one is first?
OnPlayerDeath now looks like
PHP Code:
public OnPlayerDeath(playeridkilleridreason)
{
    print(
"Ok");
    if(
GroupInfo[PlayerInfo[killerid][pGroup]][gType]==GROUP_TYPE_HITMAN){
        new 
cid,m[512];
        if(
IsPlayerInContract(playerid)){
            
cid GetPlayerContractID(playerid);
            
ContractInfo[cid][c_killer] = PlayerInfo[killerid][pID];
            
GiveMoney(playerid,-ContractInfo[cid][c_amount]);
            
format(msizeof(m), "You were killed by hitman. You lost -$%i."ContractInfo[cid][c_amount]);
            
SendClientMessage(playeridCOLOR_YELLOWm);
            
format(msizeof(m), "You have finished a contract of $%i. You received $%d."ContractInfo[cid][c_amount],ContractInfo[cid][c_amount]/2);
            
SendClientMessage(killeridCOLOR_YELLOWm);
            
GiveMoney(killerid,ContractInfo[cid][c_amount]/2);
            
mysql_format(dbhandlemsizeof(m), "UPDATE contracts SET killer='%i' WHERE id='%i'"PlayerInfo[killerid][pID],ContractInfo[cid][c_SQLID]);
            
mysql_tquery(dbhandlem);
            
SendPlayerToHospital(playerid);
            return 
1;
        }
    }
    if (
PlayerInfo[playerid][pInjured] == 0){
        
SendClientMessage(playerid, -1"Reached");
        
PlayerInfo[playerid][pInjured] = 1;
        
GetPlayerPos(playeridinj_x,inj_y,inj_z);
        
GetPlayerFacingAngle(playeridinjured_angle);
    }
    else if (
PlayerInfo[playerid][pInjured] == 1)
    {
        
KillTimer(AcceptDeathTimer[playerid]);
        
KillTimer(LoseHealthTimer[playerid]);
        
AcceptDeath[playerid] = 0;
        
PlayerInfo[playerid][pInjured] = 0;
        
Hospitalized[playerid] = 1;
    }
    return 
1;




Re: OnPlayerDeath function not being called - Calisthenics - 20.02.2019

When a run time error occurs in `OnPlayerDeath` callback from groups.inc, it breaks the hook chain and makes the public function from the gamemode not to be called.

What is the problem with crashdetect plugin? Have you tried older versions? It will make it easier.

Code:
if(GroupInfo[PlayerInfo[killerid][pGroup]][gType]==GROUP_TYPE_HITMAN){
Check if `killerid` is not INVALID_PLAYER_ID.
Check if `PlayerInfo[killerid][pGroup]` is in range (0 <= PlayerInfo[killerid][pGroup] < sizeof (GroupInfo))

Code:
cid = GetPlayerContractID(playerid); 
ContractInfo[cid][c_killer] = PlayerInfo[killerid][pID];
Check if `cid` is in range (0 <= cid < sizeof (ContractInfo))