I've made an event system for one of my gamemdes and somehow everything got fucked up, callback OnPlayerDeath seems like to get called twice for unknown reason which I couldn't know for now.
OnPlayerDeath:
OnPlayerSpawn:
This is the debug output when the player dies in event:
Also at the first death the OnPlayerRequestClass gets called but in the second death it doesn't.
Any help would be appreciated.
Thanks in advance.
OnPlayerDeath:
PHP Code:
public OnPlayerDeath(playerid, killerid, reason) {
if(SpawnEx[playerid] == false) {
SendClientMessageToAll(-1, "Called - OnPlayerDeath #1");
mysql_format(mysql, string, sizeof(string), "DELETE FROM `Weapons` WHERE `ID` = %d", Info[playerid][ID]);
mysql_tquery(mysql, string);
if(killerid != INVALID_PLAYER_ID) {
SetPlayerWantedLevel(killerid, GetPlayerWantedLevel(killerid) + 1);
}
GivePlayerCash(playerid, -1000);
new weapon, ammo;
for (new i; i <= 12; i++) {
GetPlayerWeaponData(playerid, i, weapon, ammo);
switch (weapon) {
case 22 .. 32: ammo = 150;
}
switch (weapon) {
case 1 .. 43: {
if (weapon != 0) CreateStaticPickup(GetWeaponModelID(weapon), ammo, 19, X + random(4), Y + random(4), Z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
}
}
}
for (new i, j = sizeof(Hospitalcoor); i < j; i++) {
tmp_distance = GetPlayerDistanceFromPoint(playerid, Hospitalcoor[i][0], Hospitalcoor[i][1], Hospitalcoor[i][2]);
if (tmp_distance < distance) {
distance = tmp_distance;
closest = i;
}
}
SetSpawnInfo(playerid, NO_TEAM, GetPlayerSkin(playerid), Hospitalcoor[closest][0], Hospitalcoor[closest][1], Hospitalcoor[closest][2], Hospitalcoor[closest][3], 0, 0, 0, 0, 0, 0);
}
else {
SendClientMessageToAll(-1, "Called - OnPlayerDeath #2");
SetSpawnInfo(playerid, NO_TEAM, OldSkin[playerid], LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid], 0.0, 0, 0, 0, 0, 0, 0);
}
return 1;
}
PHP Code:
public OnPlayerSpawn(playerid) {
SendClientMessageToAll(-1, "Called - OnPlayerSpawn");
if(SpawnEx[playerid] == true) {
SpawnEx[playerid] = false;
SendClientMessageToAll(-1, "Called - OnPlayerSpawn #2");
SetPlayerInterior(playerid, LastInterior[playerid]);
SetPlayerHealth(playerid, LastHealth[playerid]);
SetPlayerArmour(playerid, LastArmour[playerid]);
InEvent[playerid] = 0;
}
return 1;
}
PHP Code:
public OnPlayerRequestClass(playerid, classid) {
if(ClassDisabled[playerid]) {
SendClientMessageToAll(-1, "Called - OnPlayerRequestClass #1");
new Float:distance = 99999.0, Float:tmp_distance, closest = -1;
if(SpawnEx[playerid] == false) {
SendClientMessageToAll(-1, "Called - OnPlayerRequestClass #2");
for (new i, j = sizeof(Hospitalcoor); i < j; i++) {
tmp_distance = GetPlayerDistanceFromPoint(playerid, Hospitalcoor[i][0], Hospitalcoor[i][1], Hospitalcoor[i][2]);
if (tmp_distance < distance) {
distance = tmp_distance;
closest = i;
}
}
SetSpawnInfo(playerid, NO_TEAM, GetPlayerSkin(playerid), Hospitalcoor[closest][0], Hospitalcoor[closest][1], Hospitalcoor[closest][2], Hospitalcoor[closest][3], 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
else {
SendClientMessageToAll(-1, "Called - OnPlayerRequestClass #3");
SetSpawnInfo(playerid, NO_TEAM, OldSkin[playerid], LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid], 0.0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
return 1;
}
else if(Info[playerid][Registered] == 1) {
TogglePlayerSpectating(playerid, false);
SetPlayerVirtualWorld(playerid, 99);
PutPlayerInVehicle(playerid, ClassVehicles[0], 1);
PutPlayerInVehicle(playerid, ClassVehicles[1], 1);
PutPlayerInVehicle(playerid, ClassVehicles[2], 1);
RemovePlayerFromVehicle(playerid);
SetPlayerPos(playerid, 1095.6807, 1079.3359, 10.8359);
SetPlayerFacingAngle(playerid, 311.4607);
SetPlayerCameraPos(playerid, 1102.4128, 1084.3353, 13.2434);
SetPlayerCameraLookAt(playerid, 1095.6807, 1079.3359, 10.8359);
switch(random(5)) {
case 0: ApplyAnimation(playerid, "DANCING", "dnce_M_a", 4.1, 1, 0, 0, 0, 0);
case 1: ApplyAnimation(playerid, "DANCING", "dnce_M_b", 4.1, 1, 0, 0, 0, 0);
case 2: ApplyAnimation(playerid, "DANCING", "dnce_M_c", 4.1, 1, 0, 0, 0, 0);
case 3: ApplyAnimation(playerid, "DANCING", "dnce_M_d", 4.1, 1, 0, 0, 0, 0);
case 4: ApplyAnimation(playerid, "DANCING", "dnce_M_e", 4.1, 1, 0, 0, 0, 0);
}
OldSkin[playerid] = GetPlayerSkin(playerid);
}
return 1;
}
PHP Code:
[18:33:43] Called - OnPlayerDeath #2
[18:33:43] Called - OnPlayerSpawn
[18:33:43] Called - OnPlayerSpawn #2
[18:33:43] Called - OnPlayerDeath #1
[18:33:43] Called - OnPlayerRequestClass #1
[18:33:43] Called - OnPlayerRequestClass #2
[18:33:43] Called - OnPlayerSpawn
Any help would be appreciated.
Thanks in advance.