[HELP] Giving a unit a promotion when they are stacking with another unit?

Harkodos

Warlord
Joined
Feb 9, 2016
Messages
197
I am currently working on a Unique Unit that requires it to stack with another unit (specifically Great People) in order for it to receive a unique promotion. I attempted to modify a bit of code I'd had help with earlier to achieve this effect, but it gives me an error message:

Code:
[113107.713] Runtime Error: C:\...\Sid Meier's Civilization 5\MODS\Harkodos' Venture Industries (BNW)\Lua/Venture_Promotions.lua:16: attempt to call method 'GetPromotionType' (a nil value)

This is the code I worked up below:
Code:
local iVentureIndustries = GameInfoTypes.CIVILIZATION_AMERICA
local iPromotion = GameInfoTypes.PROMOTION_OPERATION_RUSTYS_BLANKET
local iDummyPromotion = GameInfoTypes.PROMOTION_SECRET_INTELLIGENCE
local iCivilianPromotion = GameInfoTypes.PROMOTION_O_R_B

function VentureIndustriesUnitHeal(iPlayer, iUnitID)
	if iPlayer < GameDefines.MAX_MAJOR_CIVS then
		local pPlayer = Players[iPlayer]
		local pUnit = pPlayer:GetUnitByID(iUnitID)
		if pPlayer:GetCivilizationType() == iVentureIndustries then
			local pPlot = pUnit:GetPlot()
			if (pPlot:GetPromotionType() == iCivilianPromotion) and pUnit:IsHasPromotion(iDummyPromotion) then
				pUnit:SetHasPromotion(iPromotion, true)
				return
			end
		end
		pUnit:SetHasPromotion(iPromotion, false)
	end
end

GameEvents.UnitSetXY.Add(VentureIndustriesUnitHeal)
All of the proper promotions are programmed in, it's just the code that executes this particular one seems to be the problem. I should take it from the feedback of the .Lua log that GetPromotionType isn't recognized by the game data? Is there something along that line that will work for this purpose, or do I need a completely new .Lua code to achieve the desired effect?
 
Plots don't have promotions, units have promotions.

You'll need to loop each unit on the plot, check for it being a great person belonging to the same player as the moving unit, and then check for it having iCivilianPromotion

Before looping the units on the plot, you should also check that the moving unit is NOT a great person (or the moving GP will give themselves the promotion every time they move)
 
I guess I wasn't thinking on that part; it hadn't even occurred to me that it would be checking for different entities, just that whatever was on the plot would be somehow magically scanned through to see if whatever was there had the required promotion.

Well, then I have no idea of how to do that or where to go from here, so I don't suppose you or someone else would be willing to rig that up for me by any chance?
 
Back
Top Bottom