05.11.2016, 11:11
Why can't I check if a player suicided (fell of a building, burned in fire etc.) with killerid == INVALID_PLAYER_ID ?
I don't know what I'm doing wrong.
Here's my onplayerdeath callback:
I don't know what I'm doing wrong.
Here's my onplayerdeath callback:
PHP код:
public OnPlayerDeath(playerid, killerid, reason)
{
new msg[144];
if(PlayerInfo[playerid][pAdminDuty] == 1 && PlayerInfo[playerid][pDuel] == 0)
{
SetPlayerHealth(playerid, 100);
new Float:X, Float:Y, Float:Z, Float:angle;
new skin;
skin = GetPlayerSkin(playerid);
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, angle);
SetSpawnInfo(playerid, ADUTY, skin, X, Y, Z, angle, 0, 0, 0, 0, 0, 0);
ClearAnimations(playerid);
}
if(reason != 50)
{
if(PlayerInfo[killerid][pDuel] == 1 && PlayerInfo[playerid][pDuel] == 1)
{
SetPlayerHealth(killerid, 0.0);
SetTimerEx("duelend", 100, false, "ii", killerid, playerid);
SetPlayerTeam(playerid, PlayerInfo[playerid][pLastTeam]);
SetPlayerTeam(killerid, PlayerInfo[killerid][pLastTeam]);
gTeam[playerid] = PlayerInfo[playerid][pLastTeam];
gTeam[killerid] = PlayerInfo[killerid][pLastTeam];
format(msg,sizeof(msg), "%s has won the duel!", UnderscoreToSpaceName(killerid));
SendClientMessage(playerid, COLORNOTIF, msg);
SendClientMessage(killerid, COLORNOTIF, msg);
PlayerInfo[playerid][pJustDied] = 1;
duelcount--;
}
else if(PlayerInfo[playerid][pHunted] == 1)
{
if(killerid == INVALID_PLAYER_ID)
{
format(msg,sizeof(msg),"Rest in peace %s, as he died in a tragic accident.", UnderscoreToSpaceName(playerid));
SendClientMessageToAll(COLORNOTIF, msg);
ForceClassSelection(playerid);
PlayerInfo[playerid][pHunted] = 0;
huntcount--;
return 1;
}
new td[MAX_PLAYER_NAME + 16];
format(td,sizeof(td),"killed by: %s",UnderscoreToSpaceName(killerid));
PlayerTextDrawSetString(playerid, killedby1[playerid], td);
PlayerTextDrawShow(playerid, killedby1[playerid]);
PlayerTextDrawShow(playerid, killedby2[playerid]);
PlayerTextDrawShow(playerid, killedby3[playerid]);
TextDrawHideForPlayer(playerid,TeamFBI);
TextDrawHideForPlayer(playerid,TeamGROVE);
TextDrawHideForPlayer(playerid,TeamBALLAS);
TextDrawHideForPlayer(playerid,TeamAL);
TextDrawHideForPlayer(playerid,TeamVAGOS);
TextDrawHideForPlayer(playerid,TeamLSPD);
TextDrawHideForPlayer(playerid,FPS[playerid]);
TextDrawHideForPlayer(playerid,Ping[playerid]);
if(killerid != INVALID_PLAYER_ID) SetPlayerScore(killerid, GetPlayerScore(killerid) + 100);
GivePlayerMoney(killerid, 20000);
format(msg, sizeof(msg), "%s has killed hunted %s and gained +100 score and $20,000 cash!", UnderscoreToSpaceName(killerid), UnderscoreToSpaceName(playerid));
SendClientMessageToAll(COLORNOTIF, msg);
ForceClassSelection(playerid);
PlayerInfo[playerid][pHunted] = 0;
PlayerInfo[playerid][pJustDied] = 1;
huntcount--;
}
else
{
if(killerid == INVALID_PLAYER_ID) return 0;
if(PlayerInfo[killerid][pDuel] == 1) return 0;
if(PlayerInfo[playerid][pDuel] == 1) return 0;
if(PlayerInfo[playerid][pHunted] == 1) return 0;
if(PlayerInfo[killerid][pAdminDuty] == 1) return 0;
if(PlayerInfo[playerid][pAdminDuty] == 1) return SpawnPlayer(playerid);
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, killerid);
new td[MAX_PLAYER_NAME + 16];
format(td,sizeof(td),"killed by: %s",UnderscoreToSpaceName(killerid));
PlayerTextDrawSetString(playerid, killedby1[playerid], td);
PlayerTextDrawShow(playerid, killedby1[playerid]);
PlayerTextDrawShow(playerid, killedby2[playerid]);
PlayerTextDrawShow(playerid, killedby3[playerid]);
TextDrawHideForPlayer(playerid,TeamFBI);
TextDrawHideForPlayer(playerid,TeamGROVE);
TextDrawHideForPlayer(playerid,TeamBALLAS);
TextDrawHideForPlayer(playerid,TeamAL);
TextDrawHideForPlayer(playerid,TeamVAGOS);
TextDrawHideForPlayer(playerid,TeamLSPD);
TextDrawHideForPlayer(playerid,FPS[playerid]);
TextDrawHideForPlayer(playerid,Ping[playerid]);
GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~w~respawning in 5...", 1500, 3);
PlayerTextDrawShow(playerid, respawning[playerid]);
SetTimerEx("respawn1", 1000, 0, "i", playerid);
SetPlayerScore(killerid, GetPlayerScore(killerid) + 5);
GivePlayerMoney(killerid, 2500);
SendClientMessage(killerid, COLORNOTIF, "You have gained +5 score and $2500 for killing an opponent!");
SendDeathMessage(killerid,playerid,reason);
PlayerState[playerid][pTazer] = 0;
PlayerState[playerid][pCuffed] = 0;
PlayerState[playerid][pDetained] = 0;
PlayerState[playerid][pGettingDragged] = 0;
PlayerState[playerid][pDraggedBy] = INVALID_PLAYER_ID;
PlayerState[playerid][pTazed] = 0;
PlayerInfo[playerid][pJustDied] = 1;
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
ServerInfo[Kills]++;
ServerInfo[Deaths]++;
//ServerInfo[SScore]+=5;
if(gTeam[killerid] == FBI) ++Score[FBI];
if(gTeam[killerid] == LSPD) ++Score[LSPD];
if(gTeam[killerid] == AL) ++Score[AL];
if(gTeam[killerid] == GROVE) ++Score[GROVE];
if(gTeam[killerid] == VAGOS) ++Score[VAGOS];
if(gTeam[killerid] == BALLAS) ++Score[BALLAS];
UpdateScore();
}
}
if(reason == 50)
{
if(PlayerInfo[playerid][pAdminDuty] == 1 || PlayerInfo[killerid][pAdminDuty] == 1) return 0;
format(msg, sizeof(msg), "%s has been jailed for heliblading %s.", UnderscoreToSpaceName(killerid), UnderscoreToSpaceName(playerid));
SendClientMessageToAll(COLORLIGHTRED,msg);
SendClientMessage(killerid, COLORLIGHTRED, "You have been jailed for heliblading. Time: 1 hour.");
SetPlayerInterior(killerid, JAIL_INT);
SetPlayerVirtualWorld(killerid, JAIL_VW);
loadingobj(killerid);
new rand = random(sizeof(AdminPrisonFloat));
SetPlayerPos(killerid, AdminPrisonFloat[rand][0], AdminPrisonFloat[rand][1], AdminPrisonFloat[rand][2]);
ResetPlayerWeapons(killerid);
GameTextForPlayer(killerid, "~w~Welcome to ~n~~r~Admin Prison", 5000, 3);
PlayerState[killerid][pAdmJail] = 1;
PlayerState[killerid][pAdmJailTime] = 3600;
SetPlayerColor(killerid, COLORPRISON);
SetPlayerSkin(killerid, 8);
SetPlayerFacingAngle(killerid, 180);
SetCameraBehindPlayer(killerid);
}
if(GetPlayerWeapon(killerid) == reason)
{
new IP[16];
GetPlayerIp(playerid, IP, sizeof(IP));
SendClientMessage(playerid, COLORRED, "You have been automatically banned for fake killing.");
format(msg,sizeof(msg),"AdmBan: %s (IP - %s) has been automatically banned for fake killing.", UnderscoreToSpaceName(playerid), IP);
ABroadcast(COLORLIGHTRED, msg, 1);
SetTimerEx("FakeKillKick", 100, 0, "i", playerid);
PlayerInfo[playerid][pBanned] = 1;
AddBan(IP);
Log("logs/bans.txt", msg);
}
return 1;
}