AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Scripting Question(MySql) (https://forums.alliedmods.net/showthread.php?t=240591)

oxygen935 05-18-2014 10:30

Scripting Question(MySql)
 
Hey everyone,

I wanna ask a simple question, which i cannot answer, so i need your help. In my server i save some stats via MySQL. When server crashes(CPU Overflow), the client_disconnect is called? What i mean? I mean that if the server crashes, the current player stats will be saved to MySQL? If no, how can prevent that?

Thanks in advance.

With Respect,
Oxygen

YamiKaitou 05-18-2014 10:32

Re: Scripting Question(MySql)
 
If the server crashes, there is nothing to call as the process has already been terminated. You cannot do anything to make it call something on a crash.

Bugsy 05-18-2014 10:38

Re: Scripting Question(MySql)
 
So you need to save at a different time/trigger, or fix the crash issue.

oxygen935 05-18-2014 10:39

Re: Scripting Question(MySql)
 
So, making a task every minute to save stats would be a good idea?

aron9forever 05-18-2014 12:08

Re: Scripting Question(MySql)
 
Quote:

Originally Posted by oxygen935 (Post 2139463)
So, making a task every minute to save stats would be a good idea?

yeah, I use the same method
keep both saving on disconnection and add a timer to save stats

Code:
public client_putinserver(id) {     Load_MySql(id)     set_task(60.0, "Save", id+TASK_SAVE_INFO, _, _, "b")     } //this is good if you want to save every minute for each player beginning from when they join //if you just want to save all the players on the server public plugin_init() { set_task(60.0, "Save", _, _, _, "b") }

oxygen935 05-18-2014 14:01

Re: Scripting Question(MySql)
 
What about constant "TASK_SAVE_INFO" ?

Bugsy 05-18-2014 14:32

Re: Scripting Question(MySql)
 
You have a lot of options. Either at a set interval via set_task or a thinking entity, or some game event such as round start or round end.

aron9forever 05-19-2014 03:01

Re: Scripting Question(MySql)
 
Quote:

Originally Posted by oxygen935 (Post 2139566)
What about constant "TASK_SAVE_INFO" ?

it's just a number, whatever you want it to be
it's used so that each task has a specific id that has something to do with the player's id
for example, task_save_info = 1000, on player 32 the taskid will be 1032, you're gonna need that number to stop the task when a player leaves(which is important)

but if all you want to do is save, you can do it for all players at once, I use this method because I'm not only saving a currency but I'm also giving players +1 for each minute played, so you get the point.

matsi 05-19-2014 12:25

Re: Scripting Question(MySql)
 
What i would do is save whenever the data is updated, unless its updated very frequently. Or events such as round end like bugsy suggested. :)

HamletEagle 05-19-2014 13:54

Re: Scripting Question(MySql)
 
In order to make an entity you have to do something like this.

PHP Code:

#include < amxmodx >
#include < fakemeta >
#include < engine >

new const ClassName[ ] = "SaveDataFix" /*this will be the entity class name*/

public plugin_init ( ) {

    new 
iEntity
    iEntity 
create_entity "info_target" )
    
set_peviEntitypev_classnameClassName );
    
set_peviEntitypev_nextthinkget_gametime(  ) + 0.3 );
    
register_forwardFM_Think"fm_Think" );
    
    
}

public 
fm_Think iEntity ) {

    if ( ! 
pev_valid iEntity ) ) // check if ent is invalid
        
return; //if so stop the function
        
    
set_peviEntpev_nextthinkget_gametime(  ) + 1.0 //set a new think    
    
    /*
    
    your block of code that the entity will do
    
    */





All times are GMT -4. The time now is 09:43.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.