Policy Grants Affinity

Starrynite120

Prince
Joined
Jul 15, 2015
Messages
472
I'm trying to get a policy to grant purity when it is adopted. I can't seem to get it working, and firetuner didn't show any errors. Anyone have an idea what's wrong?

function OnPolicyAdopted (playerID, policyID)
local policyInfo = GameInfo.Policies["POLICY_INDUSTRY_1"]
local virtueID = policyInfo.ID
local bonus = 0;
local policyBonus = 10
local Player = Players[playerID];

if (policyID == virtueID) then
bonus = policyBonus;
Affinity_ID = GameInfo.Affinity_Types["AFFINITY_TYPE_PURITY"].ID;
if (bonus > 0) then
Player:ChangeAffinityScore(Affinity_ID, bonus);
end
end
end
GameEvents.PlayerAdoptPolicy.Add(OnPolicyAdopted);
 
I have some code that does this, but I would need some time to separate it into its own mod so that others can use it. How quickly do you need it?
 
Within the next couple of days if possible, that would be greatly appreciated. I'm hoping to release a total conversion mod (Into the Nebula) within the next few weeks. Most of it is done, I just have a few things like virtues left to do, which is what I'm working on right now.
 
I decided to use a simple workaround for this. I have a script that gives affinity gain to buildings, so I used your policies grant buildings to have policies grant buildings in the capital which give affinity experience. Its a bit clunky, cause now you have these random buildings in your capital, but it works.
 
Ouch that is clunky. The short reason why your first attempt didn't work is that there are two events, PlayerAdoptPolicy and PlayerAdoptPolicyBranch. When a player gets Industry1 it won't fire PlayerAdoptPolicy but will fire PlayerAdoptPolicyBranch (for the industry branch id). You'll need to do something like: (code taken from my policies grant buildings)
Code:
function PolicyBuildings_PolicyBranchAdopted(playerID, policyBranchID)
	local player = Players[playerID];

	local freePolicy = GameInfo.PolicyBranchTypes[policyBranchID].FreePolicy;
	local policyID = GameInfo.Policies[freePolicy].ID;

	[COLOR="Lime"]DoStuff_PolicyAdopted(playerID, policyID);[/COLOR]
end
GameEvents.PlayerAdoptPolicyBranch.Add(PolicyBuildings_PolicyBranchAdopted);
The green chunk would be whatever function you have that needs to know the specific policy (ei: Industry1) the player just got.
 
Of course its a simple reason like that that my above code isn't working. I swear, its always some little detail like that haha. Thank you for pointing it out, I've got it working now. Thanks for the help!
 
Top Bottom