Results 1 to 10 of 69

Thread: Saving a variable client-side (persistently)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Private
    Join Date
    Apr 2020
    Posts
    66
    Thanks
    28
    Thanked 14 Times in 13 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();
    }

  2. #2
    Private
    Join Date
    Apr 2020
    Posts
    66
    Thanks
    28
    Thanked 14 Times in 13 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?

Posting Permissions

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