OnPlayerDeath getting called twice
#1

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:
PHP код:
public OnPlayerDeath(playeridkilleridreason) {
    if(
SpawnEx[playerid] == false) {
        
SendClientMessageToAll(-1"Called - OnPlayerDeath #1");
        
mysql_format(mysqlstringsizeof(string), "DELETE FROM `Weapons` WHERE `ID` = %d"Info[playerid][ID]);
        
mysql_tquery(mysqlstring);
        if(
killerid != INVALID_PLAYER_ID) {
            
SetPlayerWantedLevel(killeridGetPlayerWantedLevel(killerid) + 1);
        }
        
GivePlayerCash(playerid, -1000);
        new 
weaponammo;
        for (new 
i<= 12i++) {
            
GetPlayerWeaponData(playeridiweaponammo);
            switch (
weapon) {
                case 
22 .. 32ammo 150;
            }
            switch (
weapon) {
                case 
.. 43: {
                    if (
weapon != 0CreateStaticPickup(GetWeaponModelID(weapon), ammo19random(4), random(4), ZGetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
                }
            }
        }
        for (new 
isizeof(Hospitalcoor); ji++) {
            
tmp_distance GetPlayerDistanceFromPoint(playeridHospitalcoor[i][0], Hospitalcoor[i][1], Hospitalcoor[i][2]);
            if (
tmp_distance distance) {
                
distance tmp_distance;
                
closest i;
            }
        }
        
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid), Hospitalcoor[closest][0], Hospitalcoor[closest][1], Hospitalcoor[closest][2], Hospitalcoor[closest][3], 000000);
    }
    else {
        
SendClientMessageToAll(-1"Called - OnPlayerDeath #2");
        
SetSpawnInfo(playeridNO_TEAMOldSkin[playerid], LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid], 0.0000000);
    }
    return 
1;

OnPlayerSpawn:
PHP код:
public OnPlayerSpawn(playerid) {
        
SendClientMessageToAll(-1"Called - OnPlayerSpawn");
    if(
SpawnEx[playerid] == true) {
        
SpawnEx[playerid] = false;
        
SendClientMessageToAll(-1"Called - OnPlayerSpawn #2");
        
SetPlayerInterior(playeridLastInterior[playerid]);
        
SetPlayerHealth(playeridLastHealth[playerid]);
        
SetPlayerArmour(playeridLastArmour[playerid]);
        
InEvent[playerid] = 0;
    }
    return 
1;

PHP код:
public OnPlayerRequestClass(playeridclassid) {
    if(
ClassDisabled[playerid]) {
        
SendClientMessageToAll(-1"Called - OnPlayerRequestClass #1");
        new 
Float:distance 99999.0Float:tmp_distanceclosest = -1;
        if(
SpawnEx[playerid] == false) {
            
SendClientMessageToAll(-1"Called - OnPlayerRequestClass #2");
            for (new 
isizeof(Hospitalcoor); ji++) {
                
tmp_distance GetPlayerDistanceFromPoint(playeridHospitalcoor[i][0], Hospitalcoor[i][1], Hospitalcoor[i][2]);
                if (
tmp_distance distance) {
                    
distance tmp_distance;
                    
closest i;
                }
            }
            
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid), Hospitalcoor[closest][0], Hospitalcoor[closest][1], Hospitalcoor[closest][2], Hospitalcoor[closest][3], 000000);
            
SpawnPlayer(playerid);
        }
        else {
            
SendClientMessageToAll(-1"Called - OnPlayerRequestClass #3");
            
SetSpawnInfo(playeridNO_TEAMOldSkin[playerid], LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid], 0.0000000);
            
SpawnPlayer(playerid);
        }
        return 
1;
    }
    else if(
Info[playerid][Registered] == 1) {
        
TogglePlayerSpectating(playeridfalse);
        
SetPlayerVirtualWorld(playerid99);
        
PutPlayerInVehicle(playeridClassVehicles[0], 1);
        
PutPlayerInVehicle(playeridClassVehicles[1], 1);
        
PutPlayerInVehicle(playeridClassVehicles[2], 1);
        
RemovePlayerFromVehicle(playerid);
        
SetPlayerPos(playerid1095.68071079.335910.8359);
        
SetPlayerFacingAngle(playerid311.4607);
        
SetPlayerCameraPos(playerid1102.41281084.335313.2434);
        
SetPlayerCameraLookAt(playerid1095.68071079.335910.8359);
        switch(
random(5)) {
            case 
0ApplyAnimation(playerid"DANCING""dnce_M_a"4.110000); 
            case 
1ApplyAnimation(playerid"DANCING""dnce_M_b"4.110000); 
            case 
2ApplyAnimation(playerid"DANCING""dnce_M_c"4.110000); 
            case 
3ApplyAnimation(playerid"DANCING""dnce_M_d"4.110000); 
            case 
4ApplyAnimation(playerid"DANCING""dnce_M_e"4.110000); 
        }
        
OldSkin[playerid] = GetPlayerSkin(playerid);
    }
    return 
1;

This is the debug output when the player dies in event:
PHP код:
[18:33:43Called OnPlayerDeath #2
[18:33:43Called OnPlayerSpawn
[18:33:43Called OnPlayerSpawn #2
[18:33:43Called OnPlayerDeath #1
[18:33:43Called OnPlayerRequestClass #1
[18:33:43Called OnPlayerRequestClass #2
[18:33:43Called OnPlayerSpawn 
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.
Reply
#2

At OnPlayerSpawn you have
PHP код:
SetPlayerHealth(playeridLastHealth[playerid]); 
Maybe LastHealth is 0.0?
Reply
#3

No, It's 100.0.
Reply
#4

Sorry for bumping, but I really need a fix for this!
Reply
#5

OnPlayerDeath is called 2 times, but do you die 2 times?
Reply
#6

Of course .. lol
Reply
#7

I still think this is caused by the 'SetPlayerHealth' at OnPlayerSpawn

do this just to be sure

PHP код:
public OnPlayerSpawn(playerid) { 
        
SendClientMessageToAll(-1"Called - OnPlayerSpawn"); 
    if(
SpawnEx[playerid] == true) { 
        
SpawnEx[playerid] = false
        
SendClientMessageToAll(-1"Called - OnPlayerSpawn #2"); 
        
SetPlayerInterior(playeridLastInterior[playerid]); 
        
//SetPlayerHealth(playerid, LastHealth[playerid]); 
        
printf("%f",LastHealth[playerid]);
        
SetPlayerArmour(playeridLastArmour[playerid]); 
        
InEvent[playerid] = 0
    } 
    return 
1

Reply
#8

Simple:
The variable LastHealth don't are set to any value, because this, the value default are 0.
Reply
#9

LastHealth variable will never be 0.0, I debugged it, it works fine as I already said up there
The issue comes from OnPlayerDeath I'm pretty sure but there is nothing seems bad ...
Reply
#10

Look how I see your problem: The player dies and when he spawns SOMEONE or SOMETHING kills him [ SetPlayerHealth(playerid,0.0)? ], and because of this OnPlayerDeath gets called 1 more time.

Quote:
Originally Posted by oMa37
Посмотреть сообщение
LastHealth variable will never be 0.0, I debugged it, it works fine
You may say you debugged LastHealth, but go and put a // in front of SetPlayerHealth at OnPlayerSpawn.
Look at your debug:
PHP код:
[18:33:43Called OnPlayerDeath #2 
[18:33:43Called OnPlayerSpawn 
[18:33:43Called OnPlayerSpawn #2 
[18:33:43Called OnPlayerDeath #1 
[18:33:43Called OnPlayerRequestClass #1 
[18:33:43Called OnPlayerRequestClass #2 
[18:33:43Called OnPlayerSpawn 
The player dies (he's in event) - OnPlayerDeath #2; now the player spawns, and SpawnEx is still true so - OnPlayerSpawn #2; but it gets killed there so OnPlayerDeath is called again (this time with #1 because SpawnEx was set to false previously)

If this is not working go and find timers/anything else that can kill your player after spawning.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)