Home » MODDING HQ 1.13 » v1.13 Idea Incubation Lab  » Mini events feature
Mini events feature[message #363481] Thu, 08 July 2021 07:30
rftr is currently offline rftr

 
Messages:32
Registered:August 2020
https://i.imgur.com/vQlL5sr.png

What are Mini Events?
I created this feature to add a little bit of role-playing to JA2. During the course of a campaign, brief scenarios can pop up. You can select one of two responses to them, which can be positive and/or negative. They can affect a variety of things, but it'll mostly be your mercs. Pretty simple!

I wanted to keep things simple for now, so by default the events aren't very intrusive and can show up every 5-10 days.

At the time of writing, there are only ~30 events, mostly because I'm no writer. I'm hoping some motivated folks will step up to add some more happy

This feature can be toggled on or off with the MINI_EVENTS_ENABLED flag in JA2_Options.ini.

How does it work?
Mini events are set up in a new lua file, MiniEvents.lua. This means that it's fairly easy to add/edit/remove events - no need to touch any C++, which just provides hooks for the lua script to call into.

Here's what the event template looks like:
	[<index>] = -- index must be a positive nonzero integer
	{
		INIT = function(mercList)
			-- in here, you can define how an event behaves. Note that mercList contains *all* of the player's mercs, formatted { nickname = profileId }
			-- this function MUST return a table with four elements: BodyText, TopButtonText, BottomButtonText, and Resolution
			-- Resolution is a function which contains one input parameter: a boolean indicating whether the player clicked the top button or not
			-- *IMPORTANT* Resolution MUST call CResolveEvent() at some point. This call wraps up the event and queues up the next one. If an integer value is passed as CResolveEvent's second parameter,
			   then the next mini event will be called through BeginSpecificEvent.
			-- example:

			return {
				BodyText = "This text appears in the main message box body.",
				TopButtonText = "This is the top button's text.",
				BottomButtonText = "This is the bottom button's text.",
				Resolution = function(result)
					if result then
						CResolveEvent("You clicked the top button")
					else
						CResolveEvent("You clicked the bottom button", 3)
					end
				end
			}
		end
	}


And as a more concrete example, here's what the event in the above screenshot looks like:
	[2] = -- berries
	{
		INIT = function(mercList)
			local mercs, sector = GetAllMercsInRandomSector(mercList)
			local sectorStr = CGetSectorIDString(sector.X, sector.Y, sector.Z)

			return {
				BodyText = string.format("[%s] Your mercs are feeling a tad hungry when they come across a thicket of bushes covered in green berries. The berries look delicious, but they hesitate. They could be poisonous.", sectorStr),
				TopButtonText = "Eat the berries.",
				BottomButtonText = "Ignore the berries.",
				Resolution = function(topButton)
					if (topButton) then
						for name, id in pairs(mercs) do
							CAdjustMorale(id, 3)
						end
						CResolveEvent("[All: +Morale] The squad grabs berries by the handful and devours them. They are the most delicious berries that they've ever tasted. This is the best decision they've made all day.")
					else
						CResolveEvent("[No effect] Not wanting to regret making a stupid decision, the mercs refrain from eating the berries and continue about their day.")
					end
				end
			}
		end
	}

On the C++ side, this feature works by queuing up a strategic event that kicks off a mini event. This strategic event may or may not have a parameter attached to it, which determines its entry point into the lua script.

By default, I've organised events into two tables - one with unrelated, random events, and one which contains events that follow-up on others. The lua script has two entry points - a parameterless one that picks from the random table, and one that picks a specific event from the follow-up events table. However, you don't need to follow this format. It's definitely possible to set things up events differently.

The lua file itself also serves as a general example of what kinds of things can be done happy

Edit: This has been checked in at r9137 and requires gamedir >= r2599.

[Updated on: Sat, 10 July 2021 07:43]

Report message to a moderator

Private 1st Class
 
Read Message
Previous Topic: Melee combat thoughts
Next Topic: New Meta-Feature: In-Game Feature Toggling
Goto Forum:
  


Current Time: Thu Apr 18 20:41:44 GMT+3 2024

Total time taken to generate the page: 0.00774 seconds