schmosby 0 Posted November 30, 2019 I am trying to make a daily supplies NPC which rewards individual character items. Everytime a player gets reward, "variable" set to 1 The character need to wait until the next day to claim the rewards again Is it possible to use "OnClock0000:" to set the "variable" to 0 of every character? Quote Share this post Link to post Share on other sites
1 meko 170 Posted November 30, 2019 no need for SQL nor a timer: just store the date instead of a true/false boolean // check whether the last reward was given today or another day if (gettime(GETTIME_DAYOFYEAR) == #LAST_REWARD) { mes("you already got a reward today"); } else { mes("here's your reward"); ... // give reward #LAST_REWARD = gettime(GETTIME_DAYOFYEAR); // set it to today } 1 schmosby reacted to this Quote Share this post Link to post Share on other sites
1 Kenpachi 65 Posted November 30, 2019 You can do this in OnClock0000 by running a simple SQL query. If your variable is a character variable: query_sql("DELETE FROM `char_reg_num_db` WHERE `key` = 'your_var_name'"); If it's an account variable: query_sql("DELETE FROM `acc_reg_num_db` WHERE `key` = '#your_var_name'"); ~Kenpachhi Quote Share this post Link to post Share on other sites
1 astralprojection 35 Posted December 1, 2019 // Deleting #VARIABLE using query is NOT enough, you need to reset ONLINE players too. OnClock0000: query_sql( "SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1 ", .@total ); freeloop(true); while( .@count < .@total ){ // Reset variable to ONLINE players query_sql( "SELECT `account_id`,`char_id`,`name` FROM `char` WHERE `online` = 1 ORDER BY `char_id` LIMIT 128 OFFSET "+.@offset, .@aid,.@cid,.@name$ ); set .@i,0; set .@size,getarraysize( .@cid ); while( .@i < .@size ){ if (isloggedin(.@aid[.@i], .@cid[.@i])) { attachrid(.@aid[.@i]); #VARIABLE = 0; } set .@count,.@count + 1; set .@i,.@i + 1; } set .@offset,.@offset + .@size; deletearray .@cid,.@size; deletearray .@name$,.@size; } // Reset variable to OFFLINE players query_sql("DELETE FROM `char_reg_num_db` WHERE `key` = '#VARIABLE'"); freeloop(false); announce "[ System ] All variable has been reset. Enjoy the game!", bc_all, C_AQUA, FW_BOLD, 16; end; Quote Share this post Link to post Share on other sites
0 schmosby 0 Posted December 1, 2019 13 hours ago, meko said: no need for SQL nor a timer: just store the date instead of a true/false boolean // check whether the last reward was given today or another day if (gettime(GETTIME_DAYOFYEAR) == #LAST_REWARD) { mes("you already got a reward today"); } else { mes("here's your reward"); ... // give reward #LAST_REWARD = gettime(GETTIME_DAYOFYEAR); // set it to today } // check whether the last reward was given today or another day if (gettime(GETTIME_DAYOFYEAR) == #LAST_REWARD) { mes("you already got a reward today"); } else { mes("here's your reward"); ... // give reward #LAST_REWARD = gettime(GETTIME_DAYOFYEAR); // set it to today } This solved my problem! The other solutions are useful too for other purposes. Thank you everyone! Quote Share this post Link to post Share on other sites
I am trying to make a daily supplies NPC which rewards individual character items. Everytime a player gets reward, "variable" set to 1
The character need to wait until the next day to claim the rewards again
Is it possible to use "OnClock0000:" to set the "variable" to 0 of every character?
Share this post
Link to post
Share on other sites