• Civilization 7 has been announced. For more info please check the forum here .

Starting Units for Player

PinkHammurabi

Warlord
Joined
Jul 11, 2008
Messages
249
Location
Sewell, NJ (but from Philly!)
Hey guys. First, I'd like to say sorry if this info is somewhere in the modding forums already but I haven't found it; though, I wouldn't be surprised if I just missed it.

Secondly, my dilemma: I'm looking to add a Scout to the player's (and not the AI's as well) starting units, and I cannot for the life of me find out how to do this.

The big kick in the pants? I've done this before. At some point, I got the player to start with two Warriors and a Worker. But, I've searched high and low and can't find out where in the files this is. I know it's still there, because those Warriors and Workers are still showing up every game.

I thought it might be difficulty-related, but I can't find it in the handicap files either. Also, I'm not looking to make it Civ-specific (I think I found a workaround by doing this, but I'd have to remember to remove/change it every new game I play).

Can anyone help me out here? This would be super-duper appreciated. Thanks in advance to such a helpful community!

Moderator Action: As this is a question, moved to main C&C forum.
 
If it's for Player 0 only, then I think you'd have to use Lua.
You're lucky I just whipped up something similar for someone else, so it's something like:
Code:
function AddScoutForPlayer(iPlayer)
	local turn = Game.GetElapsedGameTurns()
	if (turn == 0 and iPlayer == 0) then
		local pPlayer = Players[0]
		for unit in pPlayer:Units() do
			if (unit:GetUnitType() == GameInfoTypes["UNIT_SETTLER"]) then
				pScout = pPlayer:InitUnit(GameInfoTypes["UNIT_SCOUT"], unit:GetX(), unit:GetY(), GameInfoTypes["UNITAI_EXPLORE"], unit:GetFacingDirection())
				pScout:JumpToNearestValidPlot()
				break
			end
		end
	else
		GameEvents.PlayerDoTurn.Remove(AddScoutForPlayer)
	end
end
GameEvents.PlayerDoTurn.Add(AddScoutForPlayer)

[NOTE: Not tested!]
 
PlayerDoTurn won't run for the Human player in this scenario (though it should almost always be the Human player as Player 0, unless the game is set up strangely.)

At least in my experience, when you first load into a game, any functions attached to PlayerDoTurn do not fire on "Turn 0" for Player 0! Once you hit "End Turn" and it begins processing turns for the AI, "Player 1" will fire the first round of PlayerDoTurn functions.

It might be better to use ActivePlayerTurnStart or even LoadScreenClose or SequenceGameInitComplete.
 
Code:
------------------------------------------------------------
---- Spawns a Scout when Capital City is founded
------------------------------------------------------------
gScout = GameInfoTypes.UNIT_SCOUT

function HumanCapitalFounded(iPlayer, iCityX, iCityY)
	local pPlayer = Players[iPlayer]
	if not pPlayer:IsHuman() then return end
	if not pPlayer:IsAlive() then return end

	if pPlayer:GetNumCities() < 2 then
		pPlayer:InitUnit(gScout, iCityX, iCityY)
	end
end
GameEvents.PlayerCityFounded.Add(HumanCapitalFounded)
Works only for human player. So in a multiplayer game it would work for all of them. Theoretically it could also fire if all of a player's cities were taken and then the player were resurrected later, but is highly unlikely and only relevant in multiplayer or in "complete kill" games.

[edit] here is a tutorial on how to activate an lua in Modbuddy. whoward69's what ModBuddy setting for what file types tutorial
  • You need to create an lua file using ModBuddy's Add > New Item > Lua Script menu options.
  • You will need to use the InGameUIAddin method shown in the tutorial for lua files
  • You cannot really use any of the suggested lua codes shown in this thread by plopping them into an existing game lua-file. You need to create a mod
 
I assumed that part of the reason for the scout is finding the place to found the capital, so you wouldn't want to wait until it's founded...
oh, OK, duh. Requires more thinkery to a degree....

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

How about this:
Code:
gScoutClass = GameInfoTypes.UNITCLASS_SCOUT
gScout = GameInfoTypes.UNIT_SCOUT
gSettler = GameInfoTypes.UNIT_SETTLER

function AddScoutForPlayer()
	local turn = Game.GetElapsedGameTurns()
	if turn ~= 0 then return end
	local pPlayer = Players[0]
	if pPlayer:GetUnitClassCount(gScoutClass) == 0 then
		for unit in pPlayer:Units() do
			if unit:GetUnitType() == gSettler then
				pScout = pPlayer:InitUnit(gScout, unit:GetX(), unit:GetY(), GameInfoTypes["UNITAI_EXPLORE"], unit:GetFacingDirection())
				pScout:JumpToNearestValidPlot()
				break
			end
		end
	end
end
Events.LoadScreenClose.Add(AddScoutForPlayer)
 
Top Bottom