OnPlayerDeath function not being called
#1

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
Reply
#2

check if killerid != INVALID_PLAYER_ID
Reply
#3

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;

Reply
#4

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

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

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

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 :/
Reply
#8

Which one is first?
Reply
#9

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;

Reply
#10

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))
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)