OnPlayerDeath function not being called -
akib - 20.02.2019
Hello, OnPlayerDeath function isn't calling in my gamemode
PHP Code:
public OnPlayerDeath(playerid, killerid, reason)
{
print("Player died");
if (PlayerInfo[playerid][pInjured] == 0)
{
PlayerInfo[playerid][pInjured] = 1;
GetPlayerPos(playerid, inj_x,inj_y,inj_z);
GetPlayerFacingAngle(playerid, injured_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
check if killerid != INVALID_PLAYER_ID
|
tried, killerid isn't invalid
PHP Code:
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid==INVALID_PLAYER_ID) return print("Error");
print("Player died");
if (PlayerInfo[playerid][pInjured] == 0)
{
PlayerInfo[playerid][pInjured] = 1;
GetPlayerPos(playerid, inj_x,inj_y,inj_z);
GetPlayerFacingAngle(playerid, injured_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(m, sizeof(m), "You were killed by hitman. You lost -$%i.", ContractInfo[cid][c_amount]);
SendClientMessage(playerid, COLOR_YELLOW, m);
format(m, sizeof(m), "You have finished a contract of $%i. You received $%d.", ContractInfo[cid][c_amount],ContractInfo[cid][c_amount]/2);
SendClientMessage(killerid, COLOR_YELLOW, m);
GiveMoney(killerid,ContractInfo[cid][c_amount]/2);
mysql_format(dbhandle, m, sizeof(m), "UPDATE contracts SET killer='%i' WHERE id='%i'", PlayerInfo[killerid][pID],ContractInfo[cid][c_SQLID]);
mysql_tquery(dbhandle, m);
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
Which one is first?
|
OnPlayerDeath now looks like
PHP Code:
public OnPlayerDeath(playerid, killerid, reason)
{
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(m, sizeof(m), "You were killed by hitman. You lost -$%i.", ContractInfo[cid][c_amount]);
SendClientMessage(playerid, COLOR_YELLOW, m);
format(m, sizeof(m), "You have finished a contract of $%i. You received $%d.", ContractInfo[cid][c_amount],ContractInfo[cid][c_amount]/2);
SendClientMessage(killerid, COLOR_YELLOW, m);
GiveMoney(killerid,ContractInfo[cid][c_amount]/2);
mysql_format(dbhandle, m, sizeof(m), "UPDATE contracts SET killer='%i' WHERE id='%i'", PlayerInfo[killerid][pID],ContractInfo[cid][c_SQLID]);
mysql_tquery(dbhandle, m);
SendPlayerToHospital(playerid);
return 1;
}
}
if (PlayerInfo[playerid][pInjured] == 0){
SendClientMessage(playerid, -1, "Reached");
PlayerInfo[playerid][pInjured] = 1;
GetPlayerPos(playerid, inj_x,inj_y,inj_z);
GetPlayerFacingAngle(playerid, injured_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))