Page 6 of 7 FirstFirst ... 4567 LastLast
Results 51 to 60 of 63

Thread: Saving a variable client-side (persistently)

  1. #51
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,616
    Thanks
    17
    Thanked 957 Times in 599 Posts
    Just use the above stuff.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  2. #52
    Private
    Join Date
    Apr 2020
    Posts
    22
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by IzNoGoD View Post
    PHP Code:
    getrankname(rank)
    {
        if(
    rank >= && rank game["rankname"].size)
            
    self.hud_rank setText(game["rankname"][rank]);
    }
        
        
    ranknamesinit()
    {
        
    game["rankname"] = [];
        
    game["rankname"][0] = &"Private First Class";
        
    game["rankname"][1] = &"Private First Class I"
        
    game["rankname"][2] = &"Private First Class II";
        
    game["rankname"][3] = &"Lance Corporal";
        
    game["rankname"][4] = &"Lance Corporal I";
        
    game["rankname"][5] = &"Lance Corporal II";
        
    game["rankname"][6] = &"Corporal";
        
    game["rankname"][7] = &"Corporal I";
        
    game["rankname"][8] = &"Corporal II";
        
    game["rankname"][9] = &"Sergeant";
        
    game["rankname"][10] = &"Sergeant I";
        
    game["rankname"][11] = &"Sergeant II";
        
    game["rankname"][12] = &"Staff Sergeant";
        
    game["rankname"][13] = &"Staff Sergeant I";
        
    game["rankname"][14] = &"Staff Sergeant II";
        
    game["rankname"][15] = &"Gunnery Sergeant";
        
    game["rankname"][16] = &"Gunnery Sergeant I";
        
    game["rankname"][17] = &"Gunnery Sergeant II";
        
    game["rankname"][18] = &"Master Sergeant";
        
    game["rankname"][19] = &"Master Sergeant I";
        
    game["rankname"][20] = &"Master Sergeant II";
        
    game["rankname"][21] = &"Master Gunnery Sergeant";
        
    game["rankname"][22] = &"Master Gunnery Sergeant I";
        
    game["rankname"][23] = &"Master Gunnery Sergeant II";
        
    game["rankname"][24] = &"2nd Lieutenant";
        
    game["rankname"][25] = &"2nd Lieutenant I";
        
    game["rankname"][26] = &"2nd Lieutenant II";
        
    game["rankname"][27] = &"1st Lieutenant";
        
    game["rankname"][28] = &"1st Lieutenant I";
        
    game["rankname"][29] = &"1st Lieutenant II";
        
    game["rankname"][30] = &"Captain";
        
    game["rankname"][31] = &"Captain I";
        
    game["rankname"][32] = &"Captain II";
        
    game["rankname"][33] = &"Major";
        
    game["rankname"][34] = &"Major I";
        
    game["rankname"][35] = &"Major II";
        
    game["rankname"][36] = &"Lt. Colonel";
        
    game["rankname"][37] = &"Lt. Colonel I";
        
    game["rankname"][38] = &"Lt. Colonel II";
        
    game["rankname"][39] = &"Colonel";
        
    game["rankname"][40] = &"Colonel I";
        
    game["rankname"][41] = &"Colonel II";
        
    game["rankname"][42] = &"Brigadier General";
        
    game["rankname"][43] = &"Brigadier General I";
        
    game["rankname"][44] = &"Brigadier General II";
        
    game["rankname"][45] = &"Major General";
        
    game["rankname"][46] = &"Major General I";
        
    game["rankname"][47] = &"Major General II";
        
    game["rankname"][48] = &"Lieutenant General";
        
    game["rankname"][49] = &"Lieutenant General I";
        
    game["rankname"][50] = &"Lieutenant General II";
        
    game["rankname"][51] = &"General";
        
    game["rankname"][52] = &"General I";
        
    game["rankname"][53] = &"General II";
        
    game["rankname"][54] = &"Commander";
        for(
    0game["rankname"].sizei++)
            
    precachestring(game["rankname"][i]);

    Works fine thanks

  3. #53
    Private
    Join Date
    Apr 2020
    Posts
    22
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Hi i need a little of your expertise again.
    I decided to use libcod to get mysql function. I used this version https://github.com/voron00/libcod. I set up the database and create the table. Along with the "login, playername, challenge, response" colums i added some more to store the player stats. So far so good. I modified the createnewaccount() function to fil up the rest of the columns and it works ok i think. Also I modified the updatestats() as shown below and it also seem to work ok. The only thing i cannot get to work is to load the values back to self.stats array. The loadtstats() function i got is shown below. Please point me in the right direction.
    Code:
    createnewaccount()
    {
    	created = false;
    	str = "";
    	chl = "";
    	chl_resp = "";
    	while(!created)
    	{
    		str = "";
    		src = "abcdefghijklmnopqrstuvwxyz0123456789";
    		chl = "Challenge_";
    		chl_resp = "";
    		for(i = 0; i < 30; i++)
    		{
    			str += src[randomint(src.size)];
    			chl += src[randomint(src.size)];
    			chl_resp += src[randomint(src.size)];
    		}
    		self.izno["login_challenge"] = chl;
    		self.izno["login_response"] = chl_resp;
    		
    		
    		
    		
    			
    		result =  [[level.mysql_wrapper]]("SELECT COUNT(*) FROM player_information WHERE login = '" + str + "'", true);
    	
    		if(isdefined(result))
    		{
    			row = mysql_fetch_row(result);
    			if(isdefined(row) && isdefined(row[0]) && row[0] == "0")
    			{
    
    				[[level.mysql_wrapper]]("INSERT IGNORE INTO player_information (login, playername, challenge, response) VALUES ('" + str + "', '" + maps\mp\gametypes\_mysql::stripstring(self.name) + "', '" + chl + "', '" + chl_resp + "')", false);
    				for(i=0;i<level.stats.size;i++)
    				{
    				[[level.mysql_wrapper]]("UPDATE player_information set " + level.stats[i] +"= 0 WHERE login = '" + str + "'",false);
    				}
    				created = true;
    
    			}
    			mysql_free_result(result);
    		}
    	}
    	self.izno["login"] = str;
    	self thread monitorsave(str, chl, chl_resp);
    }
    Code:
    updatestats()
    {
    	
    	result =  [[level.mysql_wrapper]]("SELECT COUNT(*) FROM player_information WHERE login = '" + self.izno["login"] + "'", true);
    	if(isdefined(result))
    		{
    
    			{
    				
    				for(i=0;i<level.stats.size;i++)
    				{
    				[[level.mysql_wrapper]]("UPDATE player_information set " + level.stats[i] +"="+self.stats[level.stats[i]]+"  WHERE login = '" + self.izno["login"] + "'",false);
    				}
    				
    
    			}
    			mysql_free_result(result);
    		}
    	
    		
    	self notify("update_playerhud_score");
    	self maps\mp\gametypes\_myhud::updatePlayerScoreHUD();
    }

    Code:
    loadstats()
    {
        result =  [[level.mysql_wrapper]]("SELECT COUNT(*) FROM player_information WHERE login = '" + self.izno["login"] + "'", true);
    	if(isdefined(result))
    	{
    
    			{
    				
    				for(i=0;i<level.stats.size;i++)
    				{
    				self.stats[i]=[[level.mysql_wrapper]]("Select "+self.stats[level.stats[i]]+" from player_information WHERE login = '" + self.izno["login"] + "'",true);
    				
    				}
    				
    
    			}
    			mysql_free_result(result);
    		}
    	
    	self checkrank();
        self thread counter();
        self thread checkban();
    }

  4. #54
    Private
    Join Date
    Apr 2020
    Posts
    22
    Thanks
    5
    Thanked 3 Times in 3 Posts
    After some more research i figured out that i need a function in the database. Something like this.
    But i can not get it to work properly.
    Code:
    CREATE  FUNCTION `return_value`(login_ char(30), stat_ char(10)) RETURNS int(11)
    BEGIN
    declare ret int(11);
    set ret = null;
    select stat_  from cod2stats.player_information where login = login_ into ret;
    RETURN ret;
    END
    When i try executing it in MYSQL Workbench it gives me "Error Code: 1366. Incorrect integer value: 'kills' for column 'ret' at row 1".
    But if i change it to "select kills from cod2stats.player_information where login = login_ into ret;" it returns the correct value. Any suggestions?

  5. #55
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,616
    Thanks
    17
    Thanked 957 Times in 599 Posts
    You're not properly retrieving the stuff from the database. You're storing the "result" pointer (!) in the self.stats array, which is a seemingly random number. Instead use the result to fetch_row.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  6. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (31st May 2020)

  7. #56
    Private
    Join Date
    Apr 2020
    Posts
    22
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Omg i am so noob... Thank you very much

  8. #57
    Private
    Join Date
    Apr 2020
    Posts
    22
    Thanks
    5
    Thanked 3 Times in 3 Posts
    I managed to retrieve the stats from the database using this function.
    Code:
    loadstats()
    {
        result =  [[level.mysql_wrapper]]("SELECT * FROM player_information WHERE login = '" + self.izno["login"] + "'", true);
    
    		if(isdefined(result))
    		{
    			row = mysql_fetch_row(result);
    			if(isdefined(row) )
    			{
    
    				for(i=0;i<level.stats.size;i++)
    				{
    					self.stats[level.stats[i]] = int(row[i+4]);
    				}
    			}
    			mysql_free_result(result);
    		}
    	self checkrank();
        self thread counter();
        self thread checkban();
    }
    Last edited by agribilos; 27th May 2020 at 20:34.

  9. #58
    Private
    Join Date
    Apr 2020
    Posts
    22
    Thanks
    5
    Thanked 3 Times in 3 Posts
    I tested the mysql functions on my server. Although it loads and saves the data fine and showing properly on the custom hud it really starts to lag the game if there are more than 10 players.
    The main suspect is this function. I know it is not optimized because it write all the player stats every time it is called.
    Code:
    updatestats()
    {
    	
    	result =  [[level.mysql_wrapper]]("SELECT * FROM player_information WHERE login = '" + self.izno["login"] + "'", true);
    	if(isdefined(result))
    		{
    			row = mysql_fetch_row(result);
    			if(isdefined(row))
    			{
    				
    				for(i=0;i<level.stats.size;i++)
    				{
    				[[level.mysql_wrapper]]("UPDATE player_information set " + level.stats[i] +" = "+self.stats[level.stats[i]]+"  WHERE login = '" + self.izno["login"] + "'",false);
    				}
    				[[level.mysql_wrapper]]("UPDATE player_information set playername = '"+self.name+"'  WHERE login = '" + self.izno["login"] + "'",false);
    				
    			}
    			mysql_free_result(result);
    		}
    	
    		
    	self notify("update_playerhud_score");
    	self maps\mp\gametypes\_myhud::updatePlayerScoreHUD();
    }
    It is called several times by every player like on every kill ,death etc. So one solution to make it more efficient would be to make it update one stat at a time and call it like updatestats(stat). I don't know if it would make a big difference so i decided to use asyncronous mysql queries since they are better.
    I started reading this thread https://killtube.org/showthread.php?...ll=1#post13719 but i got more confused.


    Code:
    asyncQuery(query, function, args)
    {
        id = mysql_async_createQuery(query);
        task = spawnstruct();
        task.query = query;
        task.invoker = self;
        task.function = function;
        task.args = args;
        level.JH_mysqlAsync["" + id] = task;
    }
    How is it supposed to be called in my situation? Any help please??

  10. The Following User Says Thank You to agribilos For This Useful Post:

    kung foo man (31st May 2020)

  11. #59
    Private
    Join Date
    Apr 2020
    Posts
    22
    Thanks
    5
    Thanked 3 Times in 3 Posts
    After some trial and error i came up with this:
    Code:
    updatestats()
    {
        async_id = maps\mp\gametypes\_mysql::asyncQuery("SELECT * FROM player_information WHERE login = '" + self.izno["login"] + "'",::actualupdate );
    	//mysql_async_getresult_and_free(async_id);
    	
    }
    
    actualupdate(rows,args)
    {
    	if(isDefined(rows))
    	{	
    		for(i=0;i<level.stats.size;i++)
    				{
    					async_id = maps\mp\gametypes\_mysql::asyncQuery("UPDATE player_information set " + level.stats[i] +" = "+self.stats[level.stats[i]]+"  WHERE login = '" + self.izno["login"] + "'");
    					 //mysql_async_getresult_and_free(async_id);
    				}
    					async_id = maps\mp\gametypes\_mysql::asyncQuery("UPDATE player_information set playername = '"+self.name+"'  WHERE login = '" + self.izno["login"] + "'");
    					// mysql_async_getresult_and_free(async_id);
    	}
    		self notify("update_playerhud_score");
    	self maps\mp\gametypes\_myhud::updatePlayerScoreHUD();
    If i try to use mysql_async_getresult_and_free(async_id); I get this error. If i don't use it it stores the data and does not give any error. Is it ok like this? Does it need anything else? I plan to make it more efficient by specifing the stat i need to update. But for now i first want to get it to work properly.
    Code:
    ******* script runtime error *******
    gsc_mysql_async_getresult_and_free() argument is undefined or has a wrong type: (file 'maps/mp/gametypes/_stattracking.gsc', line 209)
     mysql_async_getresult_and_free(async_id);

  12. The Following User Says Thank You to agribilos For This Useful Post:

    kung foo man (31st May 2020)

  13. #60
    Private
    Join Date
    Dec 2016
    Posts
    23
    Thanks
    5
    Thanked 2 Times in 2 Posts
    try:

    PHP Code:
    asyncQuery("SELECT * FROM table", ::queryRow);

    queryRow(result)
    {
        return 
    getRows();

    Last edited by caldas; 1st June 2020 at 03:04.

  14. The Following User Says Thank You to caldas For This Useful Post:

    agribilos (1st June 2020)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •