PlayerAdoptPolicyBranch Not Working

Starrynite120

Prince
Joined
Jul 15, 2015
Messages
472
As the title says, I'm trying to use PlayerAdoptPolicyBranch but its not working. I'm not sure why. This is what I've got for code, and I got no errors on Firetuner

Code:
function OnPolicyAdopted (playerID, policyID)
	local policyInfo = GameInfo.Policies["POLICY_PROSPERITY_1"]
	local virtueID = policyInfo.ID
	local Player = Players[playerID];
	local City = Player:GetCapitalCity();
	local bonus = (City:GetPopulation() + 2);

	if (policyID == virtueID) then
		City:SetPopulation(bonus);
	end
end
GameEvents.PlayerAdoptPolicyBranch.Add(OnPolicyAdopted);

I did have this working until I changed PlayerAdoptPolicy to PlayerAdoptPolicyBranch.
 
There are some subtle differences between the two events:

PlayerAdoptPolicy(playerID, policyID)
Fires when a player adopts a policy with two exceptions. Does not fire for synergy (aka kicker) policies. Does not fire when a player takes the first policy in a tree.

PlayerAdoptPolicyBranch(playerID, policyBranchID)
Covers the second exception mentioned above. Note that it provides the policy branch ID not the policyID. You want to do the following:
Code:
function OnPolicyBranchAdopted(playerID, policyBranchID)
	local player = Players[playerID];

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

	FunctionWhereStuffHappens(playerID, policyID);
end
GameEvents.PlayerAdoptPolicyBranch.Add(OnPolicyBranchAdopted);

On a separate note, you can use city:ChangePopulation(2) to add two population.
 
Top Bottom