• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Script] How to make time based events (Fires once a day)

53
Posts
8
Years
    • Seen Aug 25, 2023
    I'm looking at the berry girl on route 120 since she has the thing where she gives you a rare berry once a day.

    Code:
    Route120_EventScript_BerryBeauty:: @ 81F5527
    	lock
    	faceplayer
    	dotimebasedevents
    	goto_if_set FLAG_DAILY_ROUTE_120_RECEIVED_BERRY, Route120_EventScript_ReceivedBerry
    	msgbox Route120_Text_BerriesExpressionOfLoveIsntIt, MSGBOX_YESNO
    	compare VAR_RESULT, YES
    	call_if_eq Route120_EventScript_BerryLove
    	compare VAR_RESULT, NO
    	call_if_eq Route120_EventScript_BerryNotLove
    	specialvar VAR_RESULT, GetPlayerTrainerIdOnesDigit
    	switch VAR_RESULT
    	case 0, Route120_EventScript_GiveFigyBerry
    	case 5, Route120_EventScript_GiveFigyBerry
    	case 1, Route120_EventScript_GiveWikiBerry
    	case 6, Route120_EventScript_GiveWikiBerry
    	case 2, Route120_EventScript_GiveMagoBerry
    	case 7, Route120_EventScript_GiveMagoBerry
    	case 3, Route120_EventScript_GiveAguavBerry
    	case 8, Route120_EventScript_GiveAguavBerry
    	case 4, Route120_EventScript_GiveIapapaBerry
    	case 9, Route120_EventScript_GiveIapapaBerry
    	end

    dotimebasedevents

    seems to be what does it with

    FLAG_DAILY_ROUTE_120_RECEIVED_BERRY

    Working like a normal flag. However logically I assume the flag gets reset the next day so you can talk to her and get a different berry. My question is how does all this work exactly as I have a bit of understanding but not totally. This is more of how to do time based events in general.
     

    Lunos

    Random Uruguayan User
    3,114
    Posts
    15
    Years
  • I'm looking at the berry girl on route 120 since she has the thing where she gives you a rare berry once a day.

    Code:
    Route120_EventScript_BerryBeauty:: @ 81F5527
    	lock
    	faceplayer
    	dotimebasedevents
    	goto_if_set FLAG_DAILY_ROUTE_120_RECEIVED_BERRY, Route120_EventScript_ReceivedBerry
    	msgbox Route120_Text_BerriesExpressionOfLoveIsntIt, MSGBOX_YESNO
    	compare VAR_RESULT, YES
    	call_if_eq Route120_EventScript_BerryLove
    	compare VAR_RESULT, NO
    	call_if_eq Route120_EventScript_BerryNotLove
    	specialvar VAR_RESULT, GetPlayerTrainerIdOnesDigit
    	switch VAR_RESULT
    	case 0, Route120_EventScript_GiveFigyBerry
    	case 5, Route120_EventScript_GiveFigyBerry
    	case 1, Route120_EventScript_GiveWikiBerry
    	case 6, Route120_EventScript_GiveWikiBerry
    	case 2, Route120_EventScript_GiveMagoBerry
    	case 7, Route120_EventScript_GiveMagoBerry
    	case 3, Route120_EventScript_GiveAguavBerry
    	case 8, Route120_EventScript_GiveAguavBerry
    	case 4, Route120_EventScript_GiveIapapaBerry
    	case 9, Route120_EventScript_GiveIapapaBerry
    	end

    dotimebasedevents

    seems to be what does it with

    FLAG_DAILY_ROUTE_120_RECEIVED_BERRY

    Working like a normal flag. However logically I assume the flag gets reset the next day so you can talk to her and get a different berry. My question is how does all this work exactly as I have a bit of understanding but not totally. This is more of how to do time based events in general.
    It'd take some time to explain this thoroughly because it's a nasty-looking rabbit hole of function calls, so I'm gonna limit myself to explain how are daily flags reset.
    The dotimebasedevents scripting command you're seeing there calls the DoTimeBasedEvents function located in src/clock.c.
    That function calls 2 more functions; UpdatePerDay which updates certain things once every 24hs, and UpdatePerMinute which updates things once every minute.
    Keep in mind that recursive update of things once per day and minute is not happening here though.
    You should read the functions directly, but the gist of it is that they call more functions, and sure enough, among the many functions called by UpdatePerDay there's ClearDailyFlags which clears the daily flags so they can be reused once per day.

    If you want to do any sort of daily event, you should probably focus on UpdatePerDay and take inspiration from the functions that it calls, which you can git grep to learn the location and the contents of.
     
    Last edited:
    Back
    Top