A_Wandering_Man
Chieftain
Hi all,
So for my next mod I'm looking to make, I want to make the UA have a static part (this will be trivial, as it is part of the existing tables, so will just have to turn it on) and a dynamic part that will rely on switching between two dummy policies. In my previous mod, I used a "listener" to see when a particular building was constructed, after which the lua triggered a dummy policy to be implemented. The policy side seems easy enough.
I did some digging and found that these two lua hooks exist which seem to be close to what I'm looking for: "GameEvents.MakePeace" and "GameEvents.DeclareWar". However, I immediately thought of an issue: If I make peace with one civ while still being at war with another, the policy would still switch to the peace version (presumably, anyway).
Is there something I can use that is a global check for being at war? Is it "Team.IsAtWar"? Presumably then I could code something in Lua to use "GameEvents.MakePeace", check if they're at war with anyone else, and then change the policy to the peace one, else end?
Would something like this rough outline work? I'm sure there's plenty of stuff wrong here (missing defines and suchlike), but am I on the right track?
So for my next mod I'm looking to make, I want to make the UA have a static part (this will be trivial, as it is part of the existing tables, so will just have to turn it on) and a dynamic part that will rely on switching between two dummy policies. In my previous mod, I used a "listener" to see when a particular building was constructed, after which the lua triggered a dummy policy to be implemented. The policy side seems easy enough.
I did some digging and found that these two lua hooks exist which seem to be close to what I'm looking for: "GameEvents.MakePeace" and "GameEvents.DeclareWar". However, I immediately thought of an issue: If I make peace with one civ while still being at war with another, the policy would still switch to the peace version (presumably, anyway).
Is there something I can use that is a global check for being at war? Is it "Team.IsAtWar"? Presumably then I could code something in Lua to use "GameEvents.MakePeace", check if they're at war with anyone else, and then change the policy to the peace one, else end?
Would something like this rough outline work? I'm sure there's plenty of stuff wrong here (missing defines and suchlike), but am I on the right track?
Code:
--called to set peace policy
function SetPeacePolicy()
for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local pPlayer = Players[iPlayerLoop]
if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NCLJ_HYRULE) then
pPlayer:SetNumFreePolicies(1)
pPlayer:SetNumFreePolicies(0)
pPlayer:SetHasPolicy(GameInfoTypes.NCLJ_HYRULE_PEACE_POLICY, true)
end
end
end
-- for loading saves
if (Modding.OpenSaveData().GetValue("HyrulePolicyCheck") == nil) then
if pActiveTeam.IsAtWar() == 1 then
SetPeacePolicy()
SetWarPolicy()
Modding.OpenSaveData().SetValue("HyrulePolicyCheck", 1)
end
else
SetPeacePolicy()
Modding.OpenSaveData().SetValue("HyrulePolicyCheck", 1)
end
-- called to set war policy
function SetWarPolicy()
for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local pPlayer = Players[iPlayerLoop]
if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NCLJ_HYRULE) then
pPlayer:SetHasPolicy(GameInfoTypes.NCLJ_HYRULE_PEACE_POLICY, false)
pPlayer:SetHasPolicy(GameInfoTypes.NCLJ_HYRULE_WAR_POLICY, true)
end
end
end
GameEvents.DeclareWar(teamId,otherTeamId).Add(SetWarPolicy)
--checks if player is at war with anyone else when peace is declared, if not, then sets peace policy
function CheckForOngoingWars()
local bWar = pActiveTeam:IsAtWar(iTeam)
if bWar == 1 then
end
else SetPeacePolicy()
end
GameEvents.MakePeace(teamId,otherTeamId).Add(CheckForOngoingWars)
Last edited: