SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/08/2017, 04:03 PM   #1
oMa37
Gangsta
 
oMa37's Avatar
 
Join Date: Feb 2016
Posts: 970
Reputation: 136
Default OnPlayerDeath getting called twice

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.
oMa37 is online now   Reply With Quote
Old 12/08/2017, 04:49 PM   #2
GaByM
Little Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Posts: 46
Reputation: 0
Default Re: OnPlayerDeath getting called twice

At OnPlayerSpawn you have
PHP Code:
SetPlayerHealth(playeridLastHealth[playerid]); 
Maybe LastHealth is 0.0?
__________________
Sorry for my bad English.
GaByM is offline   Reply With Quote
Old 12/08/2017, 04:55 PM   #3
oMa37
Gangsta
 
oMa37's Avatar
 
Join Date: Feb 2016
Posts: 970
Reputation: 136
Default Re: OnPlayerDeath getting called twice

No, It's 100.0.
oMa37 is online now   Reply With Quote
Old 12/08/2017, 05:21 PM   #4
oMa37
Gangsta
 
oMa37's Avatar
 
Join Date: Feb 2016
Posts: 970
Reputation: 136
Default Re: OnPlayerDeath getting called twice

Sorry for bumping, but I really need a fix for this!
oMa37 is online now   Reply With Quote
Old 12/08/2017, 07:18 PM   #5
GaByM
Little Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Posts: 46
Reputation: 0
Default Re: OnPlayerDeath getting called twice

OnPlayerDeath is called 2 times, but do you die 2 times?
__________________
Sorry for my bad English.
GaByM is offline   Reply With Quote
Old 12/08/2017, 10:04 PM   #6
oMa37
Gangsta
 
oMa37's Avatar
 
Join Date: Feb 2016
Posts: 970
Reputation: 136
Default Re: OnPlayerDeath getting called twice

Of course .. lol
oMa37 is online now   Reply With Quote
Old 12/08/2017, 10:13 PM   #7
GaByM
Little Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Posts: 46
Reputation: 0
Default Re: OnPlayerDeath getting called twice

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

do this just to be sure

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(playerid, LastHealth[playerid]); 
        
printf("%f",LastHealth[playerid]);
        
SetPlayerArmour(playeridLastArmour[playerid]); 

        
InEvent[playerid] = 0
    } 
    return 
1

__________________
Sorry for my bad English.
GaByM is offline   Reply With Quote
Old 12/08/2017, 10:46 PM   #8
pabloalber84ban
Little Clucker
 
Join Date: Jun 2016
Posts: 24
Reputation: 0
Default Re: OnPlayerDeath getting called twice

Simple:
The variable LastHealth don't are set to any value, because this, the value default are 0.
pabloalber84ban is offline   Reply With Quote
Old 13/08/2017, 12:02 AM   #9
oMa37
Gangsta
 
oMa37's Avatar
 
Join Date: Feb 2016
Posts: 970
Reputation: 136
Default Re: OnPlayerDeath getting called twice

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 ...
oMa37 is online now   Reply With Quote
Old 13/08/2017, 12:16 AM   #10
DaniceMcHarley
High-roller
 
DaniceMcHarley's Avatar
 
Join Date: Feb 2012
Posts: 1,684
Reputation: 83
Default Re: OnPlayerDeath getting called twice

Can you elaborate further on the issue? I don't understand what it is that is wrong yet.
DaniceMcHarley is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnPlayerDeath is not getting called MichiEXE Scripting Help 2 23/05/2016 06:55 PM
OnPlayerDeath not being called zaibaslr2 Scripting Help 0 05/06/2015 08:19 AM
OnPlayerDeath isn't getting called correctly Luis- Scripting Help 3 26/11/2014 02:15 PM
OnPlayerDeath Not getting called. Black Wolf Scripting Help 16 16/01/2013 08:39 AM
OnPlayerDeath is not being called bigcomfycouch Help Archive 2 29/08/2010 07:09 AM


All times are GMT. The time now is 04:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.