reset player variable daily

schmosby

New member
Messages
8
Points
0
Age
57
Emulator
Client Version
2015-11-04a
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?

 
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

 
no need for SQL nor a timer: just store the date instead of a true/false boolean

Code:
// 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
}
 
Code:
// 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;
 
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!

 
Back
Top