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

Loading player's name on client_putinserver returns null (maybe?)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
mrshark45
Member
Join Date: Jan 2016
Old 09-18-2019 , 07:18   Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #1

Hey, I'm working on a plugin that records the time played by a player, I load his saved timeplayed from a database at client_putinserver , but sometimes it returns 0, and the timeplayed resets , I think the problem may be that get_user_name on putinserver return null and when I try to load his played time from the database , it returns 0.
On client_putinserver , it loads the timeplayed, saved in a database.
PHP Code:
public client_putinserver(id){
    
loadPlayerTimePlayed(id);
    
//Sets up a tag based on the played time, doesn't modify timeplayed.
    
SetUserTag(id);
    
//Load his inventory based on his name, doesn't modify timeplayed.
    
Load(id);
}
loadPlayerTimePlayed(id){
    new 
Name[32];
    
get_user_name(idName,31)

    new 
data[1];
    
data[0] = id;

    
formatex(gszQuerycharsmax(gszQuery), "SELECT * FROM `TimePlayed` WHERE Name='%s'"Name);
    
SQL_ThreadQuery(gTuple"handleLoadData"gszQuerydatasizeof(data));
}
public 
handleLoadData(failstateHandle:queryerror[], errnumdata[], size){
    if(
failstate != TQUERY_SUCCESS){
        
log_amx("SQL Insert error: %s",error);
        return;
    }
    
    new 
id data[0];
    if(!
is_user_connected(id)) return;
    
    new 
Name[32];
    
get_user_name(idName,31)

    if(
SQL_MoreResults(query)){
        
TimePlayed[id] = SQL_ReadResult(query1);
    }else{
        
TimePlayed[id] = 0;

        
formatex(gszQuerycharsmax(gszQuery), "INSERT INTO `TimePlayed` VALUES ('%s', 0)"Name);
        
SQL_ThreadQuery(gTuple"handleStandard"gszQuery);
    }

And it increments the timeplayed every minute for every player
PHP Code:
public plugin_init(){
    
set_task(60.0,"AddTimePlayed",0,"",0,"b",0)
}

public 
AddTimePlayed(id){
    for(new 
0<= 32i++){
        if(!
is_user_bot(i) && is_user_connected(i)){
            
TimePlayed[i]++;
        }
    }

And it saves the timeplayed of each player on round end
PHP Code:
public EventRoundEnd(){
     for(new 
0<= 32i++){
        if(!
is_user_bot(i) && is_user_connected(i)){
            
UpdatePlayerTimePlayed(i);
        }
    }

And on client_disconnected
PHP Code:
public client_disconnected(id){
    
UpdatePlayerTimePlayed(id);

And the code for saving the timeplayed
PHP Code:
UpdatePlayerTimePlayed(id){
    new 
Name[32];
    
get_user_name(idName,31)
    
    
formatex(gszQuerycharsmax(gszQuery), "UPDATE `TimePlayed` SET TimePlayed='%d' WHERE Name='%s'"TimePlayed[id], Name);
    
SQL_ThreadQuery(gTuple"handleStandard"gszQuery);

mrshark45 is offline
 



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 12:28.


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