Unit:CanBuild?

Enginseer

Salientia of the Community Patch
Supporter
Joined
Nov 7, 2012
Messages
3,674
Location
Somewhere in California
Code:
function NoCitadelGenerals(iPlayer)
	local pPlayer = Players[iPlayer]
	for pUnit in pPlayer:Units() do
		if pUnit:GetUnitClassType() == GameInfoTypes.UNITCLASS_GREAT_GENERAL then
			if pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_NO_CITADEL) then
				pUnit:CanBuild(0, GameInfoTypes.BUILD_CITADEL, 1, 0)
			end
		end
	end	
end
GameEvents.PlayerDoTurn.Add(NoCitadelGenerals)

Anyone know how Unit:CanBuild works? I tried flipping some values around, but great generals with a promotion still can build citadels. Or is it that LUA cannot prevent a unit from building something?
 
pUnit:CanBuild() says "can this unit build this thing", and not, as you are trying to use it, "tell this unit it can't build this thing"
 
Do you want all Great General units to not be able to build citadels, or only specific unique replacement versions for a specific civ ?
All Great General units to not be able to build citadels unless they are allowed to with a promotion.

pUnit:CanBuild() says "can this unit build this thing", and not, as you are trying to use it, "tell this unit it can't build this thing"
Must have recalled something in the other threads that wasn't there because I remembered something about using this function to prevent other units from building it.. all well.


Guess, I might have to resort to using the CP DLL to delete out the Great General's build on citadel, and then have a promotion allow it to build the citadel again(like the Samurai's fishing boat)
 
Back
Top Bottom