Jump to content
  • 0
Angelmelody

limit 3 times per week how to write?

Question

if (frequency > 3 times per week) end;

 

dunno how to write, it would be appreciate  if someone can teach me :D

 

 

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

 

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

Edited by Angelmelody

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0

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

Share this post


Link to post
Share on other sites
  • 0

 

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

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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 by Angelmelody

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

 

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 by Angelmelody

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...

Important Information

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