Welcome to the Builder Academy

Question How hard is adding events - Happyhour specifically

More
26 Jun 2025 20:13 #10773 by wlessard1
Been trying to figure out the code for events in order to make "happyhour" randomly begin and a variable duration if possible.

Just wondering if this can be done and how difficult it might be. Still trying to find the files that are needed to be changed.

Thanks for any suggestions. I did look through the Coder Doc  to see if there was anything in it.

Please Log in or Create an account to join the conversation.

More
27 Jun 2025 22:48 - 27 Jun 2025 22:48 #10775 by thomas
Not so hard, really.

To trigger a happy hour, you just need to set the HAPPY_TIME to the number of ticks it should last.
github.com/tbamud/tbamud/blob/master/src/act.other.c#L926

So, in the game loop, add a function call to something that does this (browser code):
Code:
void should_we_start_happy_hour() {   if (HAPPY_TIME) {     return; // already in a happy hour.   }   if (rand_number(1, 10000) < 5) { // adjust numbers to vary chance of starting a happy hour this tick     // also adjust these if you wish     HAPPY_EXP = 100;     HAPPY_GOLD = 50;     HAPPY_QP  = 50;     HAPPY_TIME = rand_number(30, 70);     game_info("A Happyhour has started!");   } }
 
Last edit: 27 Jun 2025 22:48 by thomas.
The following user(s) said Thank You: wlessard1

Please Log in or Create an account to join the conversation.

More
06 Jul 2025 15:41 #10782 by wlessard1
I was more looking to setup happyhour to kick off randomly during the day.

Start MUD.... game running... Happyhour will kick off randomly during the day for a random time, though this is secondary to getting it to kick off randomly during the day.

Please Log in or Create an account to join the conversation.

More
06 Jul 2025 17:23 #10785 by Salty

I was more looking to setup happyhour to kick off randomly during the day.


That's what Thomas' supplied example does.

Essentially, you create a function to roll a random happyhour.  I implemented a working example on my game as follows:

in act.other.c I added:
Code:
void check_random_happyhour() {   if (HAPPY_TIME)   { /* Feel free to remove this mudlog, I did it for testing */     mudlog(NRM, LVL_GOD, TRUE, "check_random_happyhour called with HAPPY_TIME == TRUE");     return;   }   else   {     if (!rand_number(0,999)) /* A one in a thousand chance */     {       HAPPY_EQ = rand_number(1,100); /* This is unique to my game */       HAPPY_EXP = rand_number(50,500);       HAPPY_TIME = rand_number(60,600); /* Add more values like HAPPY_GOLD or HAPPY_QP if you wish */       game_info("A Happyhour has started!");     }   } }

in act.h I added:
Code:
void check_random_happyhour();

in comm.c, there is a function:  void heartbeat(int heart_pulse)
I added our check_random_happyhour() to the tick update portion of the heartbeat.  This will call the check whenever the mud hour begins.
Code:
  if (!(heart_pulse % (SECS_PER_MUD_HOUR * PASSES_PER_SEC)))   {                                /* Tick ! */     next_tick = SECS_PER_MUD_HOUR; /* Reset tick coundown */     weather_and_time(1);     check_time_triggers();     affect_update();     point_update();     check_timed_quests();     check_random_happyhour(); /* Our new random happyhour */   }

Now, on to example:
Code:
< Salty | 100(100)hp 100(100)mana 100(100)mv > TICK! [Info] : A Happyhour has started! < Salty | 100(100)hp 100(100)mana 100(100)mv > happyh show tbaMUD Happy Hour! ------------------ +328% to Experience per kill +98% to equipment repop percentage Time Remaining: 5 hours 53 mins 54 secs < Salty | 100(100)hp 100(100)mana 100(100)mv >

And here's when it calls the function again with an active happyhour:
Code:
TICK! [ check_random_happyhour called with HAPPY_TIME == TRUE ] < Salty | 100(100)hp 100(100)mana 100(100)mv >

So yeah, Thomas gave you the solution.  Thanks for the idea.

Salty
The following user(s) said Thank You: wlessard1

Please Log in or Create an account to join the conversation.

More
09 Jul 2025 10:39 #10788 by wlessard1
I am truly trying to learn, I hate being dense and missing things.

Thanks for all the Help Thomas and Salty.

Please Log in or Create an account to join the conversation.

Time to create page: 0.219 seconds