[BNW] Free Promotion through traits

Proto_Noob

Chieftain
Joined
Jan 11, 2016
Messages
42
TL;DR: How do I add promotions to ONLY civilian or specific unit types THROUGH a civ's trait ability? I don't think I am running into any kind of bug, I just don't know the proper methodology. The solution should only be xml or sql based. If this is not possible, let me know.

________________________________________________________________________________

Hey, all. Been modding Civ 5 a while now and have a fair bit of confidence in my ability to mod through sql and xml files (still a noob on lua and dll modding). A problem I have run into is that I am unable to give civilian units free promotions through a civilization's trait.

So, in vox populi I notice that Denmark gives all its land units the Viking promotion. I have looked at the code, and it is simple enough. I have successfully given custom promotions to every kind of combat unit through a civilization's trait by inserting new lines into the <Trait_FreePromotionUnitCombats> table. Additionally, I have given the promotion in question to combat units through this method and it works perfectly (so I know the problem isn't the promotion or it's code). However, when I try giving it to ALL units (much less just civilians) through adding entries to the <Trait_FreePromotions> table, nothing happens. No promotions on civilians OR military units. Does that table even function? I went through the all the xml and sql files for both BNW and Vox Populi and found no instance of any file using it. Has it just been written off?

Anyway, maybe I am barking up the wrong tree. Let me know if this can be done and how. I could do a work around that utilizes unique units, but that would use up one of my two uniques, so I would really like to avoid that. Also, I am using the full vox populi mod so if there is a problem resulting from that or a work around opportunity created by that mod, take that into consideration.
 
Trait_FreePromotions as far as I recall is a dead table. I think it may be what we tend to refer to as an orphan table --> imported from Civ4 and then never implemented in Cvi5's DLL code, or deprecated from the DLL somewhere along the original Civ5 development process and never removed as being a valid table from the game.

So using the table does not result in errors in Database.log & etc., but neither is there any in-game effect.

Whether or not CP/VP/whatever-they're-calling-it-lately implements the table I have no idea.
 
Thanks for the confirmation Lee S. I would have likely banged my head against that wall for a while thinking I was just forgetting a close bracket in my code somewhere.

So, any suggestions on how to get civilian units free promotions through traits?
 
One way to do it that can work is through lua:
Code:
local promotionID        = GameInfoTypes["PROMOTION_NAME"]
local unitSettlerID        = GameInfoTypes["UNIT_SETTLER"]
local unitWorkerID        = GameInfoTypes["UNIT_WORKER"]
local unitArchaeologistID    = GameInfoTypes["UNIT_ARCHAEOLOGIST"]
local civilizationID = GameInfoTypes["CIVILIZATION_YOURCIV"]

function TraitFreePromotion(playerID, unitID)
    local pPlayer = Players[playerID]
    if pPlayer and pPlayer:IsAlive() and pPlayer:GetCivilizationType() == civilizationID then
        local unit = pPlayer:GetUnitByID(unitID)
        if unit:GetUnitType() == unitSettlerID or unit:GetUnitType() == unitWorkerID or unit:GetUnitType() == unitArchaeologistID then
            unit:SetHasPromotion(promotionID, true)
        end
    end
end
Events.SerialEventUnitCreated.Add(TraitFreePromotion)
This code says that whenever your civ creates a settler, worker or archaeologist it will give to them the promotion you created with sql or xml.
 
@jarcast2 Sooooo.... Have a question about an error I am suddenly getting from this code.

So, when I first applied this code to my mod, it worked... sort of. It was giving the promotion to everybody, but it was a step in the right direction. While working on a solution to that, it stopped working all together (i.e. Nobody was getting the promotion any more). After a lot of trial and error I remembered that your original code worked, so i just cleared the file and copied and pasted your code back in.

Still doesn't work. (WTF)

So I check the lua logs and I am getting this:

[18383.111] Syntax Error: C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Atlantis III (v 1)\lua/Assign_Unstoppable.lua:39: '<eof>' expected near 'end'
[18383.111] Runtime Error: Error loading C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Atlantis III (v 1)\lua/Assign_Unstoppable.lua.

I have cleared and relinked the InGameUIAddin link just in case it got wonky (didn't work). Could an error in my xml cause this issue? I am just stumped.
 
You have a syntax error in the lua file called Assign_Unstoppable.lua

Since the original code posted by @jarcast2 only has 16 lines, you must have added something more than just his code to the lua file. Without the actual code of the entire file it is impossible to determine what you've done. A reference to a missing "<eof>" is often misleading as to what the real problem is.
 
So, I tried running it again with no changes to the code and it is working. I think I might not have cleared the lua log like I thought I had and I was looking at an old log. I got it working again, but not exactly sure how. Thanks for all your help. If I find out what happened I will post it here so others might learn.
 
Top Bottom