[BNW] Lua questions about diplomatic opinion modifiers

Raitaki

Chieftain
Joined
Oct 19, 2015
Messages
25
I'm trying to write a Lua script that can either eliminate certain diplomatic penalties for a civ, or at least get as close to that as possible by using positive opinion modifiers to try to cancel out the penalties. I have some questions regarding this topic:

1. What's the difference between GameEvents.GetScenarioDiploModifier1 and GameEvents.GetScenarioDiploModifier2? Judging from the way GSDM1 is used in ViceVirtuoso's Diarmuid mod (http://steamcommunity.com/sharedfiles/filedetails/?id=180615578) and the examples shown for GSDM1 and 2 on the modding wiki, they seem to both apply a decrease in opinion (with negative value = increase) for one AI towards another player.

2. Is there any way for me to directly "erase" a player's history of disliked behaviours (e.g. make it so that Player.GetWarmongerThreat reports no warmonger threat, and Player.GetNumTimesRobbedBy, GetWeDenouncedFriend, etc. return 0 for the human player)?

3. If 2. is impossible, requires DLL or impractical, does anyone happen to know how the warmonger levels returned by Player.GetWarmongerThreat are converted into negative opinion modifiers?
 
GameEvents.GetScenarioDiploModifier1 is exactly the same as GameEvents.GetScenarioDiploModifier2 and GameEvents.GetScenarioDiploModifier3. However, only one mod will be able to use each, so the Diarmuid mod is incompatible with any other mod that also utilizes GameEvents.GetScenarioDiploModifier1.

VMC and the CP fix this issue by adding a new GameEvent (GameEvents.GetDiploModifier). Here's an example of how to use that one:
Code:
--Unknown's IsModActive (I lost the original author)
--Checks if a given mod is enabled
function IsModActive(sId)
    local tInstalledMods = Modding.GetInstalledMods()
    for key, modInfo in pairs(tInstalledMods) do
        if modInfo.ID == sId and modInfo.Enabled then
            print(modInfo.Name.." (v"..modInfo.Version..") is enabled! ("..sId..")");
            --modInfo.Name .. " (v " .. modInfo.Version
            return true;
        end
    end
    print("Mod with ModId="..sId.." is NOT enabled!");
    return false;
end
--The modID of William Howard's "Various Mod Components", or the "Community (Balance) Patch" (CP/CBP)
local sModdedDLLid = 'd1b6328c-ff44-4b0d-aad7-c657f83610cd';
local bModdedDLLIsActive = IsModActive(sModdedDLLid)

--[snipped]
--function LeaderHasMustache(sLeader) is defined somewhere over here and is not worth pasting here (as it doesn't really add anything to the example)
--[snipped]

--DLLDiplomacyModifiers:
function OnGetMustacheDiploModifier(iDiploModifier, iFromPlayer, iToPlayer)
    local iModifier = 0
    local pToPlayer = Players[iToPlayer]
    local pFromPlayer = Players[iFromPlayer];
    local sToLeader = GameInfo.Leaders[pToPlayer:GetLeaderType()].Type;

    --The receiving player is King Bob-omb
    if pFromPlayer:GetCivilizationType() == iCiv then
        if iDiploModifier == GameInfoTypes.DIPLOMODIFIER_TRL_MUSTACHE and LeaderHasMustache(sToLeader) then
            iModifier = -1; --positive modifier (very insignificant value tho)
        elseif iDiploModifier == GameInfoTypes.DIPLOMODIFIER_TRL_NO_MUSTACHE and not LeaderHasMustache(sToLeader) then
            iModifier = 1; --negative modifier (very insignificant value tho)
        end
    end
 
    print(string.format("OnGetMustacheDiploModifier(%s, %i, %s, %s)", GameInfo.DiploModifiers[iDiploModifier].Type, iModifier, Players[iFromPlayer]:GetCivilizationDescription(), Players[iToPlayer]:GetCivilizationDescription()))
    return iModifier
end

if IsCivInPlay(iCiv) and bModdedDLLIsActive then
    GameEvents.GetDiploModifier.Add(OnGetMustacheDiploModifier)
end
This Event is however not enabled by default, and you will have to add your DiploModifier to a table, which you can do like this:
Code:
--==================================================================================================================

--NOTE: Ignore error messages caused by this file in Database.log when VMC/CP/CBP is not installed or enabled.

--==================================================================================================================
--Enable the CustomDiploModifier system
UPDATE CustomModOptions
SET Value=1
WHERE Name='EVENTS_DIPLO_MODIFIERS';

--Insert into the Diplomodifiers table
INSERT INTO DiploModifiers
        (Type,                                Description)
VALUES    ('DIPLOMODIFIER_TRL_MUSTACHE',        'TXT_KEY_TRL_DIPLOMODIFIER_TRL_MUSTACHE'),
        ('DIPLOMODIFIER_TRL_NO_MUSTACHE',    'TXT_KEY_TRL_DIPLOMODIFIER_TRL_NO_MUSTACHE');

--Add language entries
INSERT INTO Language_en_Us
        (Tag,                                            Text)
VALUES    ('TXT_KEY_TRL_DIPLOMODIFIER_TRL_MUSTACHE',        '{2_FromPlayer} approves of your splendid mustache ({1_Modifier})'),
        ('TXT_KEY_TRL_DIPLOMODIFIER_TRL_NO_MUSTACHE',    '{2_FromPlayer} disapproves of bald-faced fellows like you ({1_Modifier})');
The code above adds a very insignificant positive diplomodifier from King Bob-omb to leaders with a mustache, and a very insignficant negative diplomodifier from King Bob-omb to leaders without a mustache.
The opinion of leaders towards King Bob-omb (regardless of whether they have a mustache or not) is unchanged.
Why? Well, why not?

------

I have no idea to erase a modifier history though, so 'cancelling out penalties' like you already stated sounds like a good option. I have a strong feeling that the negative opinion values from GetWarmongerThreat are hardcoded into the DLL (or are at least a global value, so they affect every civ in the game). You could of course always check out the DLL yourself to confirm that. :)
 
Back
Top Bottom