Angelmelody 221 Posted October 20, 2013 (edited) if (frequency > 3 times per week) end; dunno how to write, it would be appreciate if someone can teach me -------------------------------------------------------------------------------------------------- sorry post wrong section , I should post in script support section >_< Edited October 21, 2013 by Angelmelody Quote Share this post Link to post Share on other sites
0 evilpuncker 503 Posted October 20, 2013 source edit? don't you wanna mean script? Quote Share this post Link to post Share on other sites
0 Angelmelody 221 Posted October 20, 2013 source edit? don't you wanna mean script? sorry, I got it wrong and should open my eyes Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted October 20, 2013 Try something like this? - script your_week_test -1,{if (next_week > gettimetick(2)) { // It's not next week yet or user doesn't have anything if (times > .max_times) { mes "Sorry, you can't use me until next week."; close; }}else { set times, 0; set next_week, gettimetick(2) + (7 * 24 * 60 * 60); // 7 days, 24 hours, 60 mins, 60 secs (delay starting from first time he's spoken, start of the week can be calculated but it's a bit more messy) mes "This is the first time you talk to me this week!";}// Something goodset times, times+1;mes "You have talked to me " + times + " times this week total.";close;OnInit:set .max_times, 3;end;} Quote Share this post Link to post Share on other sites
0 Angelmelody 221 Posted October 21, 2013 Try something like this? - script your_week_test -1,{if (next_week > gettimetick(2)) { // It's not next week yet or user doesn't have anything if (times > .max_times) { mes "Sorry, you can't use me until next week."; close; }}else { set times, 0; set next_week, gettimetick(2) + (7 * 24 * 60 * 60); // 7 days, 24 hours, 60 mins, 60 secs (delay starting from first time he's spoken, start of the week can be calculated but it's a bit more messy) mes "This is the first time you talk to me this week!";}// Something goodset times, times+1;mes "You have talked to me " + times + " times this week total.";close;OnInit:set .max_times, 3;end;} Thanks,but Would it be possible for player who reached max limitation on Saturday can run the script again on Monday Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted October 21, 2013 This counts a week from the first time you talk to the NPC. I could calculate next Monday for you but I'll do that when I'm back home or have some free time, if anybody else hasn't already done that. P.S.: It's easier if you calculate next Sunday instead of Monday. 1 Angelmelody reacted to this Quote Share this post Link to post Share on other sites
0 Angelmelody 221 Posted October 21, 2013 (edited) ok , someone teach me using sql query method i post the code prontera,151,186,5 script asdfjkl 721,{ query_sql("SELECT YEARWEEK(now(),1)",.@yw$);//-->assume Monday is the first day of a week set .@cn,atoi(.@yw$)*100; set .@ln,.@cn+.max_limit; if(#rn < .@cn ) set #rn,.@cn; if(#rn >=.@ln){ mes "3 times per week only"; close; } getitem 501, 1; set #rn,#rn+1; close; Oninit: set .max_limit,3;} anyway, thank to jaBote always help me a lot Edited October 21, 2013 by Angelmelody Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted October 21, 2013 I don't quite understand what you've got, but glad you got it working! Quote Share this post Link to post Share on other sites
0 Mumbles 193 Posted October 27, 2013 Why not use gettime(4) to determine the day of the week? /*=========================================================Limited NPCby Via===========================================================Request: http://goo.gl/Du8yRC===========================================================Description:Allows for limited NPC use up to a preconfigured amount.=========================================================*/prontera,150,150,5 script Limited NPC#via::weekly_limit 998,{ // Function prototypes function getDayName; // Check if limit can be reset if (gettime(4) == .limit_reset) { // Check if limit has not yet been reset if (!#resetted) #limit_count = 0; // Reset limit #resetted++; // Reset identifier } else #resetted = 0; // Reset the reset identifer // Check if weekly limit has been reached if (#limit_count == .weekly_limit) { mes .npc_name$; mes "I'm sorry, but you may only use my services "+ .weekly_limit +" times per week. Limitations are lifted every "+ getDayName() +"."; close; } #limit_count++; // Increase limit count mes .npc_name$; mes "Hello there! I've spoken to you "+ #limit_count +" out of "+ .weekly_limit +" times this week."; close; // Return the name of the current day function getDayName { switch(gettime(4)) { case 0: return "Sunday"; case 1: return "Monday"; case 2: return "Tuesday"; case 3: return "Wednesday"; case 4: return "Thursday"; case 5: return "Friday"; case 6: return "Saturday"; } } OnInit: // Configuration settings .npc_name$ = "[^0000FFLimited NPC^000000]"; .weekly_limit = 3; // Usage limit per week .limit_reset = 1; // Day of the week to reset limits (0 = Sunday, 1 = Monday, etc.) end; } Quote Share this post Link to post Share on other sites
0 Angelmelody 221 Posted October 27, 2013 (edited) Why not use gettime(4) to determine the day of the week? /*=========================================================Limited NPCby Via===========================================================Request: http://goo.gl/Du8yRC===========================================================Description:Allows for limited NPC use up to a preconfigured amount.=========================================================*/prontera,150,150,5 script Limited NPC#via::weekly_limit 998,{ // Function prototypes function getDayName; // Check if limit can be reset if (gettime(4) == .limit_reset) { // Check if limit has not yet been reset if (!#resetted) #limit_count = 0; // Reset limit #resetted++; // Reset identifier } else #resetted = 0; // Reset the reset identifer // Check if weekly limit has been reached if (#limit_count == .weekly_limit) { mes .npc_name$; mes "I'm sorry, but you may only use my services "+ .weekly_limit +" times per week. Limitations are lifted every "+ getDayName() +"."; close; } #limit_count++; // Increase limit count mes .npc_name$; mes "Hello there! I've spoken to you "+ #limit_count +" out of "+ .weekly_limit +" times this week."; close; // Return the name of the current day function getDayName { switch(gettime(4)) { case 0: return "Sunday"; case 1: return "Monday"; case 2: return "Tuesday"; case 3: return "Wednesday"; case 4: return "Thursday"; case 5: return "Friday"; case 6: return "Saturday"; } } OnInit: // Configuration settings .npc_name$ = "[^0000FFLimited NPC^000000]"; .weekly_limit = 3; // Usage limit per week .limit_reset = 1; // Day of the week to reset limits (0 = Sunday, 1 = Monday, etc.) end; } if (gettime(4) == .limit_reset) {...} //-->this also means only the day can be reseted right? if player forgot to login on that day,var limit_count won't be reseted until he run the script on .limit_reset day of next week or next n week Edited October 27, 2013 by Angelmelody Quote Share this post Link to post Share on other sites
0 Mumbles 193 Posted October 27, 2013 True, I guess I overlooked that. Perhaps it could be rewritten (or added onto) with a OnPCLoginEvent with a proper check. gettime(8), which returns the day of the year, could possibly be utilised here to make such a check. Quote Share this post Link to post Share on other sites
if (frequency > 3 times per week) end;
dunno how to write, it would be appreciate if someone can teach me
--------------------------------------------------------------------------------------------------
sorry post wrong section , I should post in script support section >_<
Edited by AngelmelodyShare this post
Link to post
Share on other sites