Wow, huge thanks Chrisy15 for taking the time to explain this to me! It actually sheds enormous light on how things work, as well as the earlier post. I think I'm starting to get the hang of it, but there still are some things that I - for some reason - can't get through my head. If it's okay to you, I'll describe my struggles via the strip of code you and LeeS provided earlier. I'll do it in two parts - one for each function.
So I put some print messages there to see in firetuner where we go. For some reason my firetuner just crashes on game start so I've never been actually able to see these printed, but at least none of the logs actually show them. Which leads me to believe that either A) I'd need a different command than print() to show things in any of the logs, or B) the script just doesn't run.
This would be, from my understanding, the first function to run. The other one, GetNameForGreatPerson would run after this one, so I'll get to it after this.
I can understand the logic of it all the way to this part:
Does this feed a new event to the system? Because I'm not really sure on how to understand this bit. Are the events in general just sort of functions in that the stuff inside the brackets are the values anything that uses this event would then feed in place of whatever variables they have? For example if I did a function like this
Would it then, in the event of a UnitNameChanged, check if the unit was a Finnish unit, and if so, give it the cool promotion and also check if it is a warrior and if it is, give it the other cool promotion? I know this function is pretty pointless but I just quickly did something to use the UnitNameChanged values it sets in the code LeeS gave.
Am I understanding it correctly? All I need to add the values from an event is to use GameEvents, and the .Add part and then define the function it feeds the values to in the brackets?
Okay, the other function:
These prints don't come up in the logs either, and as said, my firetuner dislikes me, so can't really tell why or if they're supposed to at all. But:
The table here is confusing me.
It's a little heavy in my eyes. So correct me if I'm wrong:
With the local define it creates the table, and then fills it with the table.insert line with the UniqueName of each row. The rows it seeks are in table Unit_UniqueNames, and it only goes through those that have UnitType= GameInfo.Units[pUnit:GetUnitType()].Type in it. I really don't understand what the whole UnitType= GameInfo.Units[pUnit:GetUnitType()].Type part really means. Would the UnitType= mean that it checks the UnitType column (and would this be a standard way to type it in?), and then the GameInfo.Units[pUnit.GetUnitType()].Type part just defines to look for the unittypes of pUnit. pUnit was not defined anywhere in the code, so I'm guessing it's a standard thing, but I really don't know what it means. Is it just a general tag for units that are in use for the player's civilization? The prefixes like "p" or "i" etc. still confuse me a little bit as well.
If I got the above part right, I'm guessing that tCorrectUnitNames then actually fills the table with every unittype that the civilization can use. Wouldn't this also add the names that aren't civ specific? So I would have to alter this bit of code to include the CivilizationType somehow. How would I go about it? I'm guessing the best way would be to add it in the
part. But I can't think of the commands to do that, so what I had just freestyled there earlier, made a whole new lines for that like this:
Does this make sense? In my head it now does both of the for loops before going to the table.insert part. But it doesn't exactly require both, I think it only kind of goes for either. So I'd need a way to sum them as a single query. I'm scratching my head here...
I'll stop here for now, otherwise there'll be too much stuff here and nobody cba to help me
EDIT: I'm guessing just a simple "and" can't be enough? If I did:
EDIT2:
Actually, I think I have a hunch now on how it should be done.
I'm guessing it can't be that easy but just messing around, I guess this is the best way to try and understand how to create this stuff.
Code:
function C15_GPBorn(playerID, unitID, iX, iY)
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UGP_FINN - C15_GPBorn function starts"
local pPlayer = Players [playerID]
if pPlayer:GetCivilizationType() == civilizationID then
local pUnit = pPlayer:GetUnitByID(unitID)
if pUnit ~= nil then
if tGreatPeopleClassesToProcess[pUnit:GetUnitClassType()] and not pUnit:IsHasPromotion(iPromotionUnitBorn) then
local sSelectedName = GetNameForGreatPerson(pUnit)
pUnit:SetName(sSelectedName)
Events.UnitNameChanged( pUnit:GetOwner(), pUnit:GetID() );
pUnit:SetHasPromotion(iPromotionUnitBorn)
if iPromotionUnitBorn ~= nil then
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UGP_FINN - Promotion has value, runs the function to the end!")
end
end
end
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UGP_FINN - C15_GPBorn function ran")
end
if JFD_IsCivilisationActive(civilizationID)
GameEvents.UnitSetXY.Add(C15_GPBorn)
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UGP_FINN - UnitSetXY event detected, adding values to C15_GPBorn - function should run")
end
So I put some print messages there to see in firetuner where we go. For some reason my firetuner just crashes on game start so I've never been actually able to see these printed, but at least none of the logs actually show them. Which leads me to believe that either A) I'd need a different command than print() to show things in any of the logs, or B) the script just doesn't run.
This would be, from my understanding, the first function to run. The other one, GetNameForGreatPerson would run after this one, so I'll get to it after this.
I can understand the logic of it all the way to this part:
Code:
Events.UnitNameChanged( pUnit:GetOwner(), pUnit:GetID() );
Does this feed a new event to the system? Because I'm not really sure on how to understand this bit. Are the events in general just sort of functions in that the stuff inside the brackets are the values anything that uses this event would then feed in place of whatever variables they have? For example if I did a function like this
Code:
function Example1(pUnit:GetOwner(), pUnit:GetID())
local UnitOwner = pUnit:GetOwner()
local civilizationID = ["CIVILIZATION_FINNS"]
if UnitOwner = civilizationID then
local TheCoolFinnsPromotion = GameInfoTypes["PROMOTION_THECOOLFINNS"]
pUnit:SetHasPromotion(TheCoolFinnsPromotion)
else
end
end
local TheUnit = pUnit:GetID()
if TheUnit = GameInfoTypes.UNIT_WARRIOR then
local TheCoolWarriorsPromotion = GameInfoTypes["PROMOTION_THECOOLWARRIORS"]
pUnit:SetHasPromotion(TheCoolWarriorsPromotion)
else
end
end
end
GameEvents.UnitNameChanged.Add(Example1)
Would it then, in the event of a UnitNameChanged, check if the unit was a Finnish unit, and if so, give it the cool promotion and also check if it is a warrior and if it is, give it the other cool promotion? I know this function is pretty pointless but I just quickly did something to use the UnitNameChanged values it sets in the code LeeS gave.
Am I understanding it correctly? All I need to add the values from an event is to use GameEvents, and the .Add part and then define the function it feeds the values to in the brackets?
Okay, the other function:
Code:
function GetNameForGreatPerson(pUnit)
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UGP_FINN - GetNameForGreatPerson function ran"
if pUnit ~= nil then
local sUnitType = GameInfo.Units[pUnit:GetUnitType()].Type
local tCorrectUnitNames = {}
for row in GameInfo.Unit_UniqueNames("UnitType='" .. sUnitType .. "'") do
table.insert(tCorrectUnitNames, row.UniqueName)
end
if #tCorrectUnitNames > 0 then
local sSelection = tCorrectUnitNames[1]
if #tCorrectUnitNames > 1 then
sSelection = tCorrectUnitNames[JFD_GetRandom(1, #tCorrectUnitNames)]
end
return sSelection
end
end
return "Tuntematon Sotilas"
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UGP_FINN - GetNameForGreatPerson function ran"
end
These prints don't come up in the logs either, and as said, my firetuner dislikes me, so can't really tell why or if they're supposed to at all. But:
The table here is confusing me.
Code:
local sUnitType = GameInfo.Units[pUnit:GetUnitType()].Type
local tCorrectUnitNames = {}
for row in GameInfo.Unit_UniqueNames("UnitType='" .. sUnitType .. "'") do
table.insert(tCorrectUnitNames, row.UniqueName)
end
It's a little heavy in my eyes. So correct me if I'm wrong:
With the local define it creates the table, and then fills it with the table.insert line with the UniqueName of each row. The rows it seeks are in table Unit_UniqueNames, and it only goes through those that have UnitType= GameInfo.Units[pUnit:GetUnitType()].Type in it. I really don't understand what the whole UnitType= GameInfo.Units[pUnit:GetUnitType()].Type part really means. Would the UnitType= mean that it checks the UnitType column (and would this be a standard way to type it in?), and then the GameInfo.Units[pUnit.GetUnitType()].Type part just defines to look for the unittypes of pUnit. pUnit was not defined anywhere in the code, so I'm guessing it's a standard thing, but I really don't know what it means. Is it just a general tag for units that are in use for the player's civilization? The prefixes like "p" or "i" etc. still confuse me a little bit as well.
If I got the above part right, I'm guessing that tCorrectUnitNames then actually fills the table with every unittype that the civilization can use. Wouldn't this also add the names that aren't civ specific? So I would have to alter this bit of code to include the CivilizationType somehow. How would I go about it? I'm guessing the best way would be to add it in the
Code:
for row in GameInfo.Unit_UniqueNames("UnitType='" .. sUnitType .. "'") do
part. But I can't think of the commands to do that, so what I had just freestyled there earlier, made a whole new lines for that like this:
Code:
local sUnitType = GameInfo.Units[pUnit:GetUnitType()].Type
local tCorrectUnitNames = {}
for row in GameInfo.Unit_UniqueNames("UnitType='" .. sUnitType .. "'") do
for row in GameInfo.Unit_UniqueNames("CivilizationType='" .. sUnitType .. "'") do
table.insert(tCorrectUnitNames, row.UniqueName)
end
Does this make sense? In my head it now does both of the for loops before going to the table.insert part. But it doesn't exactly require both, I think it only kind of goes for either. So I'd need a way to sum them as a single query. I'm scratching my head here...
I'll stop here for now, otherwise there'll be too much stuff here and nobody cba to help me
EDIT: I'm guessing just a simple "and" can't be enough? If I did:
Code:
local sUnitType = GameInfo.Units[pUnit:GetUnitType()].Type
local tCorrectUnitNames = {}
for row in GameInfo.Unit_UniqueNames("UnitType='" and "CivilizationType="CIVILIZATION_FINNS" .. sUnitType .. "'") do
table.insert(tCorrectUnitNames, row.UniqueName)
end
EDIT2:
Actually, I think I have a hunch now on how it should be done.
Code:
local sUnitType = GameInfo.Units[pUnit:GetUnitType()].Type
local tCorrectUnitNames = {}
for row in GameInfo.Unit_UniqueNames("UnitType='" .. sUnitType .. "'") and ("CivilizationType="CIVILIZATION_FINNS") do
table.insert(tCorrectUnitNames, row.UniqueName)
end
I'm guessing it can't be that easy but just messing around, I guess this is the best way to try and understand how to create this stuff.
Last edited: