Just use the above stuff.
Just use the above stuff.
"Does not work" is an error report for a bug between keyboard and chair.
All hail Artie Effem
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(); }
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.
When i try executing it in MYSQL Workbench it gives me "Error Code: 1366. Incorrect integer value: 'kills' for column 'ret' at row 1".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
But if i change it to "select kills from cod2stats.player_information where login = login_ into ret;" it returns the correct value. Any suggestions?
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
kung foo man (31st May 2020)
Omg i am so noob... Thank you very much
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.
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.
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.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(); }
I started reading this thread https://killtube.org/showthread.php?...ll=1#post13719 but i got more confused.
How is it supposed to be called in my situation? Any help please??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; }
kung foo man (31st May 2020)
After some trial and error i came up with this:
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: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();
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);
kung foo man (31st May 2020)
try:
PHP Code:
asyncQuery("SELECT * FROM table", ::queryRow);
queryRow(result)
{
return getRows();
}
Last edited by caldas; 1st June 2020 at 03:04.
agribilos (1st June 2020)