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

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


Post New Thread Reply   
 
Thread Tools Display Modes
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
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 09-18-2019 , 07:37   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #2

I had this problem too when using client_putinserver.
Try using client_connect instead - I haven't experienced any issues ever since I switched to it.
__________________

Last edited by OciXCrom; 09-18-2019 at 07:37.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
mrshark45
Member
Join Date: Jan 2016
Old 09-18-2019 , 09:58   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
I had this problem too when using client_putinserver.
Try using client_connect instead - I haven't experienced any issues ever since I switched to it.
Ok, I'll try it
mrshark45 is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 09-18-2019 , 10:37   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #4

adding a delay of 0.2sec for example on putinserver can fix it, i think
also when doing Update time of the players in the round_end, isnt it better to have one Query for updating all players than 32 queries for each player?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
mrshark45
Member
Join Date: Jan 2016
Old 09-18-2019 , 11:17   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #5

Quote:
Originally Posted by JocAnis View Post
adding a delay of 0.2sec for example on putinserver can fix it, i think
also when doing Update time of the players in the round_end, isnt it better to have one Query for updating all players than 32 queries for each player?
I tried with delay , it didn't work, also I'm using one for loop at the round end to save the time played for all the players, not 32...
mrshark45 is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 09-18-2019 , 11:24   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #6

you are doing loop through all players...i tryed to tell you: do one query with the loop into that query, but whatever..

also about colum which is named Name, if i remember correctly some years ago Bugsy stated to better change its name
reason: mysql by default has something with column 'name' or something like
solution: change column name
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
mrshark45
Member
Join Date: Jan 2016
Old 09-18-2019 , 13:38   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #7

Quote:
Originally Posted by JocAnis View Post
you are doing loop through all players...i tryed to tell you: do one query with the loop into that query, but whatever..

also about colum which is named Name, if i remember correctly some years ago Bugsy stated to better change its name
reason: mysql by default has something with column 'name' or something like
solution: change column name
Ok, I'll try to change the column name, but I still don't get what you want to say about the query in round end
PHP Code:
public plugin_init(){
     
register_logevent"EventRoundEnd"2"1=Round_End" );
}


public 
EventRoundEnd(){
     for(new 
0<= 32i++){
        if(!
is_user_bot(i) && is_user_connected(i)){
            
UpdatePlayerTimePlayed(i);
        }
    }

mrshark45 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-18-2019 , 23:38   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #8

Any player-specific data should be based on SteamID and then you would use client_authorized().
__________________
fysiks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-19-2019 , 01:01   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #9

Loop through using get_players array with these flags ch

Also you should check if player is connected first before checking if he's Bot in standard player loop the thing is the native might result in an error not continuing the rest of the code.

Also instead of passing the id in the data of the thread query you should pass the name directly since if you have too many queries and it needs to take an amount of time to execute and in that time the player leaves (disconnect) the data is longer saved. Unless some1 else joined in his slot.

Also seems like you are getting the value of the wrong column SQL_ReadResult(query, 1) column One is for the name right? If I'm not mistaken?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-19-2019 at 01:13.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
mrshark45
Member
Join Date: Jan 2016
Old 09-19-2019 , 13:34   Re: Loading player's name on client_putinserver returns null (maybe?)
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
Loop through using get_players array with these flags ch

Also you should check if player is connected first before checking if he's Bot in standard player loop the thing is the native might result in an error not continuing the rest of the code.

Also instead of passing the id in the data of the thread query you should pass the name directly since if you have too many queries and it needs to take an amount of time to execute and in that time the player leaves (disconnect) the data is longer saved. Unless some1 else joined in his slot.

Also seems like you are getting the value of the wrong column SQL_ReadResult(query, 1) column One is for the name right? If I'm not mistaken?
Thanks for all the info, SQL_ReadResult(query, 1) returns the Timeplayed,, SQL_ReadResult(query, 0) returns the name.
I'll change the column name in nickname , because someone pointed it out that it may be a problem.
mrshark45 is offline
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

Forum Jump


All times are GMT -4. The time now is 17:29.


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