Jump to content
  • 0
schmosby

reset player variable daily

Question

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

4 answers to this question

Recommended Posts

  • 1

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
}

 

Share this post


Link to post
Share on other sites
  • 1

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

Share this post


Link to post
Share on other sites
  • 1
// 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;

 

Share this post


Link to post
Share on other sites
  • 0
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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.