Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

OnPlayerDeath getting called twice

$
0
0
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 Code:

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 Code:

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 Code:

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 Code:

[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.

Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>