Looking for Lua for a UU and UB.

DoktorApplejuce

Champion of Kirkwall
Joined
Apr 9, 2015
Messages
582
Location
Canada
I'm looking to get the lua required to make the abilities of the following unit and building to work;

Battle Moose - Upon researching computers, any city with a battle moose stationed in it will be impossible to spy on. (Also, I want to make this unit increase in combat strength with technological advancements, so as to be slightly weaker than whatever the strongest researched armoured unit is. I know how to do this, but I'd also like to have its production cost increase each time as well, so as to reflect that - this, I don't know how to do.)

Chocolate and Whiskey fund - replaces the market, and can be built in any city. If the city it's build in has access to wheat, it provides a copy of the luxury resource Whiskey. If the city it's build in has access to cocoa, it provides a copy of the luxury resource Chocolate, and it can provide both luxuries. (This one would, as Lees has explained to me before, simply require spawning in dummy buildings that provide said luxuries, and I know how to code in the dummy buildings with XML... all I need is the lua that spawns them in).


I realize it is a lot to ask, but as I know very little about Lua, if someone could provide me the coding required to do this, I would greatly appreciate it. In exchange, I'm willing to provide any 2D art you may need.
 
For the anti-spy mechanism, are you looking to outright remove that city from the list or just decrease it's potential by some ridiculous amount? The latter wouldn't be too difficult outside of finding an event to add/remove a dummy building on. The former, well... let's not talk about the former.

To increase the production cost you'll have to make multiple "versions" of the same unit that become obsolete and get replaced (all XML afaik). Additionally, you'll need a function that hooks into "OnTeamTechReaserched" and replaces the obsolete unit(s) that have already been produced.
 
For the anti-spy mechanism, are you looking to outright remove that city from the list or just decrease it's potential by some ridiculous amount? The latter wouldn't be too difficult outside of finding an event to add/remove a dummy building on.

Code:
function RCMPHappinessPower(PlayerID)
	local pPlayer = Players[PlayerID]
	local pCiv = pPlayer:GetCivilizationType()
	
	if pCiv == GameInfoTypes.CIVILIZATION_COLONIALCANADA then
		for pCity in pPlayer:Cities() do
			print(pCity:GetName())
			--local CityX = pCity:GetX()
			--local CityY = pCity:GetY()
			local standOnGuardForThee = false
			local pPlot = pCity:Plot()
			--check each city to see if there is a Shado-Pan Monk
			for i = 0, pPlot:GetNumUnits() - 1, 1 do
				local pUnit = pPlot:GetUnit(i)
				if (pUnit ~= nil and pUnit:IsDelayedDeath() == false and pUnit:IsCargo() == false) then
					if pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_ROYALCANADIANMOUNTIES) then
						--set standOnGuardForThee to YES
						standOnGuardForThee = true
						--otherwise do nothing
					end
				end
			end
			if standOnGuardForThee == true then
				if pCity:GetNumBuilding(GameInfoTypes.BUILDING_CANADIANRCMPHAPPINESS) > 0  then
				elseif (pCity:GetNumBuilding(GameInfoTypes.BUILDING_CANADIANRCMPHAPPINESS) == 0 or pCity:GetNumBuilding(BUILDING_CANADIANRCMPHAPPINESS) == nil) then
					pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_CANADIANRCMPHAPPINESS, 1)
				end
			elseif (standOnGuardForThee == false) or (standOnGuardForThee == nil) then
				if pCity:GetNumBuilding(GameInfoTypes.BUILDING_CANADIANRCMPHAPPINESS) > 0  then
					pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_CANADIANRCMPHAPPINESS, 0)
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(RCMPHappinessPower)

This is from the Colonial Legacies Canada mod, which yields happiness in every city that has a mounted unit garrisoned inside it. I would assume that this could be modified so as to spawn in a dummy building that decreases spy potential; the only question, for me at least, is how would it be modified so as to only do so after researching computers?
 
Is Computers one of the techs you plan on using to obsolete and replace the unit? If so, that makes this easy; only give the free promotion to that version of the unit and above. If not, you'd need to add another check.

Code:
function OnDoTurn(PlayerID)
	local pPlayer = Players[PlayerID]
	local pCiv = pPlayer:GetCivilizationType()
	
	if pCiv == GameInfoTypes.CIVILIZATION_##### then
	--local pTeam = pPlayer:GetTeam()
	--if pTeam:IsHasTech(GameInfoTypes.#####) --Optional check
		for pCity in pPlayer:Cities() do
			--print(pCity:GetName())
			local bAddBuilding = false
			local pPlot = pCity:Plot()
			for i = 0, pPlot:GetNumUnits() - 1, 1 do
				local pUnit = pPlot:GetUnit(i)
				if (pUnit ~= nil and pUnit:IsDelayedDeath() == false and pUnit:IsCargo() == false) then
					if pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_#####) then
						bAddBuilding = true
						break
					end
				end
			end
			if bAddBuilding == true and pCity:GetNumBuilding(GameInfoTypes.BUILDING_#####) < 1 then
				pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_#####, 1)
			else
				pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_#####, 0)
			end
		end
	--end
	end
end
GameEvents.PlayerDoTurn.Add(OnDoTurn)
 
Back
Top Bottom