Steps to add an event that triggers at the start of the game

shandelman

Chieftain
Joined
Nov 2, 2014
Messages
13
I'm messing with loadout options and I want to add one which spawns resources when you land (this may or may not be balanced / a good idea, but I want to make it work.)

So I have a good example of a lua script which checks for unimproved plots and spawns resources on them ( http://steamcommunity.com/sharedfiles/filedetails/?id=334311837&searchtext= ), but I don't know how to set a function to run on your capital at the start of the game.

I assume this requires a Lua script as well as some event attached to startup in the way that (presumably) things like the existing starting buildings are attached? Will Mod Builder set all this up automatically with just the usual InGameUIAddin pointing to the .lua file or do I need to set up an additional entry point?

But, primary thing, I can't figure out which Lua files contain the code which executes the stuff in the existing xml for loadout ( C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization Beyond Earth\assets\Gameplay\XML\Civilizations )? As an alternative, I'm thinking I could *maybe* sub in a modified GenerateLuxuryPlotListsAtCitySite - except that I can't find that either (it's called in AssignStartingPlots.lua but it doesn't seem to be coded in there or in MapmakerUtilities.lua... I did a search for all the files in gameplay/lua and found nothing... )

For the second option, I *also* don't know what all steps I would need to override a function declaration, or if that is even possible would I need to fork the entire lua file to change the function used in the local scope?

Thanks.
 
This is a function I wrote that I've used a LOT in my faction mods so far. You're free to adapt it if you'd like.

Code:
--This function gets called approximately when the player immediately starts the game.
--It takes advantage of the capital being founded on the initial turn to allow setting up 
--the civ when a city exists. Certain things like spawning explorers and other units will
--occur after this method.
function LGF_InitialTurn(player, x, y)
	local pPlayer = Players[player]
	if pPlayer == nil then
		return
	end

	--civilisationID is the modded sponsor's ID declared elsewhere in the code
	if pPlayer:GetCivilizationType() == civilisationID then 
		local pCapital = pPlayer:GetCapitalCity()
		if pCapital == nil then
			return
		end

		if pCapital:GetX() == x and pCapital:GetY() == y then
			--Call functions you want called on the initial turn only
		end
	end
end

GameEvents.PlayerCityFounded.Add(LGF_InitialTurn)
 
Back
Top Bottom