--=======================================================================================================================
-- Foreign Emissaries
--------------------------------------------------------------------------------------------------------------------------
local activeCivs = {} -- define a local table where all active players are going to be stored
local count = 1 -- counter for the spot that the active player is going to take in the table
for playerID = 0, GameDefines.MAX_MAJOR_CIVS - 1 do -- loop over all major civs
local otherPlayer = Players[playerID] -- define the player object for the major civ in the loop
if not (otherPlayer:IsHuman()) and Teams[otherPlayer :GetTeam()]:IsHasMet(player:GetTeam()) then -- make sure the other player isn't the human player (AI's don't need this flavour, and if you're getting the event, we don't want to be talking about ourselves.) And make sure the player receiving the event knows the civ. Though you can use as conditions you see fit.
activeCivs[count] = otherPlayer -- add them to the table
count = count + 1 -- tell the counter to make room for the next player in the loop
end
end
randomCiv = randomCivs[GetRandom(1, #randomCivs)] -- choose a random civ from the table we just filled out, between 1 and the number of civs in that table
if randomCiv == nil then return false end
local Event_WallachiaEmissaries = {}
Event_WallachiaEmissaries.Name = "TXT_KEY_EVENT_WALLACHIA_EMISSARIES"
Event_WallahicaEmissaries.Desc = "TXT_KEY_EVENT_WALLACHIA_EMISSARIES_DESC"
Event_WallachiaEmissaries.Weight = 5
Event_WallachiaEmissaries.CanFunc = (
function(pPlayer)
if load(pPlayer, "Event_WallachiaEmissaries") == true then return false end
Event_WallachiaEmissaries.Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES_DESC", pPlayer:GetName(), pPlayer:GetCivilizationShortDescription())
if not pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_WALLACHIA"] then return false end
return true
end
)
Event_WallachiaEmissaries.Outcomes = {}
--=========================================================
-- Outcome 1
--=========================================================
Event_WallachiaEmissaries.Outcomes[1] = {}
Event_WallachiaEmissaries.Outcomes[1].Name = "TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_1"
Event_WallachiaEmissaries.Outcomes[1].Desc = "TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_1"
Event_WallachiaEmissaries.Outcomes[1].Weight = 5
Event_WallachiaEmissaries.Outcomes[1].CanFunc = (
function(pPlayer)
local iFaithReward = math.ceil(200 * iMod)
Event_JFDRussiaPeterPatriarchDeath.Outcomes[1].Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_1", iFaithReward)
return true
end
)
Event_WallachiaEmissaries.Outcomes[1].DoFunc = (
function(pPlayer)
local randomCiv
local iFaithReward = math.ceil(200 * iMod)
local random = JFD_GetRandom(1, 100)
if random <= 5 then
if Players[playerID]:GetCivilizationType() == GameInfoTypes[randomCiv] and not Players[playerID]:IsHuman() then
Teams[Players[playerID]:GetTeam()]

eclareWar(pPlayer:GetTeam())
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_1_ALT_NOTIFICATION", Players[playerID]:GetCivilizationDescription()), Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES"))
if not pPlayer:IsHuman() then Events.GameplayAlertMessage(Locale.ConvertTextKey("[COLOR_POSITIVE_TEXT]{1_LeaderName}[ENDCOLOR] has returned emissaries sent to their empire with their hats nailed to their heads, sparking war with {2_CivName}.", pPlayer:GetName(), randomCiv:GetName())) end
else
pPlayer:ChangeFaith(iFaithReward)
end
elseif random <= 10 then
if Players[playerID]:GetCivilizationType() == GameInfoTypes[randomCiv] and not Players[playerID]:IsHuman() then
Players[playerID]

oForceDenounce(pPlayer:GetID())
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_1_ALT_2_NOTIFICATION", Players[playerID]:GetCivilizationDescription()), Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES"))
if not pPlayer:IsHuman() then Events.GameplayAlertMessage(Locale.ConvertTextKey("[COLOR_POSITIVE_TEXT]{1_LeaderName}[ENDCOLOR] has mistreated emissaries from {2_CivName}, sparking contention between their empires.", pPlayer:GetName(), randomCiv:GetName())) end
else
pPlayer:ChangeFaith(iFaithReward)
end
else
pPlayer:ChangeFaith(iFaithReward)
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_1_NOTIFICATION"), Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES"))
if not pPlayer:IsHuman() then Events.GameplayAlertMessage(Locale.ConvertTextKey("[COLOR_POSITIVE_TEXT]{1_LeaderName}[ENDCOLOR] has nailed the hats of emissaries from another empire to their heads as a warning to obey their customs.", pPlayer:GetName())) end
end
end
end
end
save(pPlayer, "Event_WallachiaEmissaries", true)
end)
--=========================================================
-- Outcome 2
--=========================================================
Event_WallachiaEmissaries.Outcomes[2] = {}
Event_WallachiaEmissaries.Outcomes[2].Name = "TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_2"
Event_WallachiaEmissaries.Outcomes[2].Desc = "TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_2"
Event_WallachiaEmissaries.Outcomes[2].Weight = 1
Event_WallachiaEmissaries.Outcomes[2].CanFunc = (
function(pPlayer)
local iGoldReward = math.ceil(100 * iMod)
Event_WallachiaEmissaries.Outcomes[2].Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_2")
return true
end
)
Event_WallachiaEmissaries.Outcomes[2].DoFunc = (
function(pPlayer)
local iGoldReward = math.ceil(100 * iMod)
if Players[playerID]:GetCivilizationType() == GameInfoTypes[randomCiv] and Players[playerID]:IsEverAlive() and Players[playerID] ~= pPlayer then
local random = JFD_GetRandom(1, 100)
if random <= 5 then
if Players[playerID]:GetCivilizationType() == GameInfoTypes[randomCiv] and not Players[playerID]:IsHuman() then
Teams[Players[playerID]:GetTeam()]

oForceDOF(pPlayer:GetTeam())
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES_OUTCOME_RESULT_1_ALT_NOTIFICATION", Players[playerID]:GetCivilizationDescription()), Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES"))
if not pPlayer:IsHuman() then Events.GameplayAlertMessage(Locale.ConvertTextKey("[COLOR_POSITIVE_TEXT]{1_LeaderName}[ENDCOLOR]'s good treatment of emissaries of {2_CivName} has resulted in a Declaration of Friendship between the empires.", pPlayer:GetName(), randomCiv:GetName())) end
else
pPlayer:ChangeGold(iGoldReward)
end
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_WALLACHIA_EMISSARIES_OUTCOME_RESULT_2_NOTIFICATION"), Locale.ConvertTextKey("TXT_KEY_EVENT_WALLACHIA_EMISSARIES"))
save(pPlayer, "Event_WallachiaEmissaries", true)
end)
for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local slotStatus = PreGame.GetSlotStatus(iSlot)
if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
local iCiv = PreGame.GetCivilization(iSlot)
local sCiv = GameInfo.Civilizations[iCiv].Type
if Event_JFDPrussiaAllGermanCrown.tValidCivs[sCiv] then
tEvents.Event_JFDPrussiaAllGermanCrown = Event_JFDPrussiaAllGermanCrown
break
end
end
end