Raised This Month: $51 Target: $400
 12% 

Scripting Question(MySql)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 05-18-2014 , 10:30   Scripting Question(MySql)
Reply With Quote #1

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
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 05-18-2014 , 10:32   Re: Scripting Question(MySql)
Reply With Quote #2

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.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-18-2014 , 10:38   Re: Scripting Question(MySql)
Reply With Quote #3

So you need to save at a different time/trigger, or fix the crash issue.
__________________
Bugsy is offline
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 05-18-2014 , 10:39   Re: Scripting Question(MySql)
Reply With Quote #4

So, making a task every minute to save stats would be a good idea?
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-18-2014 , 12:08   Re: Scripting Question(MySql)
Reply With Quote #5

Quote:
Originally Posted by oxygen935 View Post
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") }
aron9forever is offline
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 05-18-2014 , 14:01   Re: Scripting Question(MySql)
Reply With Quote #6

What about constant "TASK_SAVE_INFO" ?
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-18-2014 , 14:32   Re: Scripting Question(MySql)
Reply With Quote #7

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.
__________________
Bugsy is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-19-2014 , 03:01   Re: Scripting Question(MySql)
Reply With Quote #8

Quote:
Originally Posted by oxygen935 View Post
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.
aron9forever is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 05-19-2014 , 12:25   Re: Scripting Question(MySql)
Reply With Quote #9

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

Accepting all kinds of requests via private message.
matsi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-19-2014 , 13:54   Re: Scripting Question(MySql)
Reply With Quote #10

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
    
    */



Last edited by HamletEagle; 05-20-2014 at 08:43.
HamletEagle is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 08:57.


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