-EDIT-
I've now solved my problem and a fully working FaithFromDyingUnits routine. It is limited in scope, only providing Faith from land units that are not unique to other civilizations (adding in compatibility for the possible thousands of unique units of other civilizations, or heck, even just the ones from the base game and expansions, does not sound fun).
I may decide to post a modified version of the code later for use by other users, but right now I'd rather just enjoy the fruits of my labors.
-OLD-
Alright, let's try this once more. Still trying to get the "Units provide Faith from Dying" thing working, and now I've tweaked a code that formerly provided Specialist points in the Capital from killing enemy units. I'm trying to tweak it so it will simply provide Faith to a chosen Civilization when their units die, and I know that this code can work for what I need it to, I just don't have the proper knowledge to fully realize it. If anyone could help me tweak it to get the results I'm looking for, that'd be fantastic.
Code here:
And just to be safe and for reference, here's the original code I modified the above code from:
I've taken bits and pieces of different codes and seen them work to varying degrees of success, but I just know that this particular one hides the secrets to what I desire. I just need this particular code problem solved, and I can probably stop spamming this thread with requests as my other, early posts are mute at this point.
I've now solved my problem and a fully working FaithFromDyingUnits routine. It is limited in scope, only providing Faith from land units that are not unique to other civilizations (adding in compatibility for the possible thousands of unique units of other civilizations, or heck, even just the ones from the base game and expansions, does not sound fun).
I may decide to post a modified version of the code later for use by other users, but right now I'd rather just enjoy the fruits of my labors.
-OLD-
Alright, let's try this once more. Still trying to get the "Units provide Faith from Dying" thing working, and now I've tweaked a code that formerly provided Specialist points in the Capital from killing enemy units. I'm trying to tweak it so it will simply provide Faith to a chosen Civilization when their units die, and I know that this code can work for what I need it to, I just don't have the proper knowledge to fully realize it. If anyone could help me tweak it to get the results I'm looking for, that'd be fantastic.
Code here:
Code:
include("FLuaVector.lua")
include( "ModTools.lua" );
local defUnitID;
function GetVoPDeadUnit(player, unitID)
defUnitID = unitID;
return false;
end
GameEvents.CanSaveUnit.Add(GetVoPDeadUnit);
function FaithFromDyingUnit(attPlayerID,defPlayerID,defUnitTypeID)
local attPlayer = Players[attPlayerID];
local defPlayer = Players[defPlayerID];
local defUnit = defPlayer:GetUnitByID(defUnitID);
if defPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_AMERICA then return end
local fyModifier = 0;
local fy = 0;
local tempCount = 0;
local maxCount = 0;
local fyType = "YIELD_FAITH";
local fyYield = GameInfo.Yields["YIELD_FAITH"];
local fyID = fyYield.ID;
if not defUnit then
print("FaithFromDyingUnitNodefUnit!");
return;
end
local fyPlayer = defPlayer:GetCivilizationType();--local fyCity = defPlayer:GetCapitalCity();
local HexPos = ToHexFromGrid(Vector2( defUnit:GetX(), defUnit:GetY()));
if not defUnit:IsCombatUnit() then
print("FaithFromDyingUNitNotCombatUnit!");
return;
end
if not IsMajorCiv(defPlayer) or not IsMajorCiv(attPlayer) then return;
end
print("FaithFromDyingUnitStartCalculate");
local fyModifier = 50;
if fyModifier == 0 then
return;
end
local defCombat = defUnit:GetBaseCombatStrength();
fy = defCombat*fyModifier;
--for pPlayer in defPlayer:CivilizationType() do
for tempYield in GameInfo.Yields() do
local tempType = tempYield.Type;
if tempType == "YIELD_FAITH" then
local tempID = tempYield.ID;
tempCount =player:GetFaith(tempID);
print("FaithFromDyingUnitFaith="..tempCount);
if tempCount > maxCount then
maxCount = tempCount;
fyType = tempType;
fyID = tempID;
fyPlayer = pPlayer;--fyCity = pCity;
end
end
end
--end
print("FaithFromDyingUnitAddFaith");
local rand = Game.Rand(100,"Faith From Dying Promotion");
if fyPlayer then--if fyCity then
fyPlayer:ChangeFaith(fyID,fy);--fyCity:ChangeFaith(fyID,fy);
end
print("FaithFromDyingUnitComplete");
local popupstr = "+".. math.floor(fy/100).." [ICON_PEACE]" ;
Events.AddPopupTextEvent(HexToWorld(HexPos),popupstr, 2);
end
GameEvents.UnitKilledInCombat.Add(FaithFromDyingUnit);
Code:
include("FLuaVector.lua")
include( "ModTools.lua" );
local defUnitID;
function GetVoPDeadUnit(player, unitID)
defUnitID = unitID;
return false;
end
GameEvents.CanSaveUnit.Add(GetVoPDeadUnit);
function AwardGreatPersonPoint(attPlayerID,defPlayerID,defUnitTypeID)
local attPlayer = Players[attPlayerID];
local defPlayer = Players[defPlayerID];
local defUnit = defPlayer:GetUnitByID(defUnitID);
if attPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_AMERICA then return end
local gpModifier = 0;
local gp = 0;
local tempCount = 0;
local maxCount = 0;
local gpType = "SPECIALIST_SCIENTIST";
local gpSpecialist = GameInfo.Specialists["SPECIALIST_SCIENTIST"];
local gpID = gpSpecialist.ID;
if not defUnit then
print("AwardCombatGPPNodefUnit!");
return;
end
local gpCity = attPlayer:GetCapitalCity();
local HexPos = ToHexFromGrid(Vector2( defUnit:GetX(), defUnit:GetY()));
if not defUnit:IsCombatUnit() then --Uncombat units do not count.
print("AwardCombatGPPNotCombatUnit!");
return;
end
if not IsMajorCiv(defPlayer) or not IsMajorCiv(attPlayer) then return; -- City-States and Barbarian do not count;
end
print("AwardCombatGPPStartCalculate");
--local Trait = GetPlayerTrait(attPlayer);
local gpModifier = 50; --local gpModifier = Trait.CombatGPP;
if gpModifier == 0 then
return;
end
local defCombat = defUnit:GetBaseCombatStrength();
gp = defCombat*gpModifier;
for pCity in attPlayer:Cities() do
for tempSpecialist in GameInfo.Specialists() do
local tempType = tempSpecialist.Type;
if tempType == "SPECIALIST_SCIENTIST" then
local tempID = tempSpecialist.ID;
tempCount =pCity:GetSpecialistGreatPersonProgress(tempID);
print("AwardCombatGPPSpecialistGPP="..tempCount);
if tempCount > maxCount then
maxCount = tempCount;
gpType = tempType;
gpID = tempID;
gpCity = pCity;
end
end
end
end
print("AwardCombatGPPAddGPP");
local TextType=" ";
local name = gpCity:GetName();
if gpType == "SPECIALIST_SCIENTIST" then
TextType = TextType..Locale.ConvertTextKey("TXT_KEY_COMBAT_GREAT_SCIENTIST_POINT");
end
local Fin=" ";
Fin = Fin..Locale.ConvertTextKey("TXT_KEY_IN");
local rand = Game.Rand(100,"Great Scientist Points Promotion");
if gpCity then
gpCity:ChangeSpecialistGreatPersonProgressTimes100(gpID,gp);
end
print("AwardCombatGPPComplete");
local popupstr = "[COLOR:255:87:155:255]+".. math.floor(gp/100).."[ENDCOLOR] [ICON_GREAT_PEOPLE] " ..TextType..Fin.." "..name.."." ;
Events.AddPopupTextEvent(HexToWorld(HexPos),popupstr, 2);
end
GameEvents.UnitKilledInCombat.Add(AwardGreatPersonPoint); --Now works in quick combat mode.
Last edited: