limit 3 times per week how to write?

Angelmelody

(\ /) ( . .)
Messages
772
Points
0
Age
32
Location
new_1-1,53,111
Github
Angelmelody
Emulator
if (frequency > 3 times per week) end;

dunno how to write, it would be appreciate  if someone can teach me
default_biggrin.png


--------------------------------------------------------------------------------------------------

sorry  post  wrong section , I should post  in  script support  section >_<

 
Last edited by a moderator:
source edit?
default_tongue.png
don't you wanna mean script?

 
Try something like this?

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

 
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.

 
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

 
Last edited by a moderator:
I don't quite understand what you've got, but glad you got it working!  
default_ani_meow.gif


 
Why not use gettime(4) to determine the day of the week?

Code:
/*=========================================================Limited NPCby Via===========================================================Request: [URL="http://goo.gl/Du8yRC===========================================================Description:Allows"]http://goo.gl/Du8yRC===========================================================Description:Allows[/URL] 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;        }
 
Last edited by a moderator:
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

 
Last edited by a moderator:
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.

 
Last edited by a moderator:
Back
Top