• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Server] Duplicate CallBack call
#1
In my gamemode I use mysql as a data saving system. Most of the player data I will save the moment it is changed to avoid problems in case of server crash or crash, and I also save the player data when restarting the server (/ gmx).

PHP Code:
public OnPlayerDisconnect()
{
Player_DestroyAllVehicles(playerid);
Player_SaveRanking(playerid);
Player_SaveConfig(playerid);
Player_SaveMoney(playerid);
? ? 
Player_SaveData(playerid);
? ? 
Player_ClearVars(playerid);
Player_ClearAcessories(playerid);
Player_ClearInfo(playerid);
Inventory_Reset(playerid);


PHP Code:
public OnGameModeExit()
{
    foreach(new 
Player)
    {
        
Player_DestroyAllVehicles(i);
        
Player_SaveRanking(i);
        
Player_SaveConfig(i);
        
Player_SaveMoney(i);
        
Player_SaveData(i);
        
Player_ClearVars(i);
        
Player_ClearAcessories(i);
        
Player_ClearInfo(i);
        
Inventory_Reset(i);
    }
    
DestroyAllDynamicMapIcons();
    
DestroyAllDynamic3DTextLabels();
    
DestroyAllDynamicPickups();
    
mysql_close(ConexaoSQL);
    return 
1;




What I noticed is that when I restart the server, OnGameModeExit is saved and OnPlayerDisconnect is saved, doubling each player's save. For example: when I restart the server (/ gmx) the player's money is saved in OnGameModeExit and OnPlayerDisconnect, being saved 2 times without need.
How do I avoid this duplication of calls? Do I need to save player data on OnGameModeExit or just OnPlayerDisconnect?
Is OnPlayerDisconnect called by default by OnGameModeExit?
  Reply
#2
Code:
public OnGameModeExit() {
    ON_GAMEMODE_EXIT_SAVE = true;

    // ..SAVE
    return true
}

public OnPlayerDisconnect(playerid, reason) {
    if(ON_GAMEMODE_EXIT_SAVE == true)
        return false;

    // ..SAVE
    return true;
}


I don't know if the values of the variables are kept after gmx, I never used that
If they are, you will have to modify the variable in OnGamemodeInit setting as 'false'.
  Reply
#3
(2021-03-19, 05:02 PM)Kodokushi Wrote:
Code:
public OnGameModeExit() {

? ? ON_GAMEMODE_EXIT_SAVE = true;



? ? // ..SAVE

? ? return true

}



public OnPlayerDisconnect(playerid, reason) {

? ? if(ON_GAMEMODE_EXIT_SAVE == true)

? ? ? ? return false;



? ? // ..SAVE

? ? return true;

}





I don't know if the values of the variables are kept after gmx, I never used that

If they are, you will have to modify the variable in OnGamemodeInit setting as 'false'.



When the player disconnects I save the data and reset the variables.
  Reply
#4
For starters, dont use /gmx as it's unstable af



Use /rcon exit than start the server again.



Also, try on blank gm if the OPDC is called when you do /rcon gmx or /rcon exit, ion remember
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#5
(2021-03-19, 05:47 PM)Pinch Wrote: For starters, dont use /gmx as it's unstable af

Use /rcon exit than start the server again.

Also, try on blank gm if the OPDC is called when you do /rcon gmx or /rcon exit, ion remember

Yes. I tested it on an empty gamemode and OnPlayerDisconnect is also being called when OnGameModeExit and / rcon gmx is called

[Image: hdDlyns.png]

[Image: bhBfw7k.png]

[Image: 1wNbZAh.png]

Would that make saving on OnGameModeExit useless?
  Reply
#6
(2021-03-19, 06:06 PM)RhaegarX Wrote:
(2021-03-19, 05:47 PM)Pinch Wrote: For starters, dont use /gmx as it's unstable af



Use /rcon exit than start the server again.



Also, try on blank gm if the OPDC is called when you do /rcon gmx or /rcon exit, ion remember



Yes. I tested it on an empty gamemode and OnPlayerDisconnect is also being called when OnGameModeExit and / rcon gmx is called



[Image: hdDlyns.png]



[Image: bhBfw7k.png]



[Image: 1wNbZAh.png]



Would that make saving on OnGameModeExit useless?

Yes, don't save anything player-related OnGameModeExit then.
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#7
(2021-03-19, 09:56 PM)Pinch Wrote:
(2021-03-19, 06:06 PM)RhaegarX Wrote:
(2021-03-19, 05:47 PM)Pinch Wrote: For starters, dont use /gmx as it's unstable af



Use /rcon exit than start the server again.



Also, try on blank gm if the OPDC is called when you do /rcon gmx or /rcon exit, ion remember



Yes. I tested it on an empty gamemode and OnPlayerDisconnect is also being called when OnGameModeExit and / rcon gmx is called



[Image: hdDlyns.png]



[Image: bhBfw7k.png]



[Image: 1wNbZAh.png]



Would that make saving on OnGameModeExit useless?

Yes, don't save anything player-related OnGameModeExit then.



Yes. I removed the save made on OnGameModeExit and everything works perfectly, OPDC is called when restarting the server and without duplicating the save
  Reply
#8
Still, I don't recommend usage of /rcon gmx, fresh start is always my go-to
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#9
There's nothing wrong with gmx. Someone was claiming that on discord the other day as well with no proof or explanation. I don't know where these rumors come from, nor why people are so quick to believe them. If you think you've found a bug, document it reproducibly, otherwise stop spreading misinformation.
  Reply
#10
(2021-03-21, 12:16 PM)Y_Less Wrote: There's nothing wrong with gmx. Someone was claiming that on discord the other day as well with no proof or explanation. I don't know where these rumors come from, nor why people are so quick to believe them. If you think you've found a bug, document it reproducibly, otherwise stop spreading misinformation.

Oh, sorry, someone very "knowledgeable" told me that actually so that's why I believed, like Illidan or someone like that idk
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply


Forum Jump: