Need some help on modding functions
if unit:IsInCategory('MOBILE') then
(1) How do you use IsInCategory to select only units that moves around and is an attacking type of units.
I tried the above but it also consider Factory and Engineer as Mobile ?
(2) Any blueprint for Tech 3 Transport unit ?
Thanks.
Here's a list of categories https://wiki.faforever.com/index.php?title=Mission_Scripting#Categories
hello SupCom_16-12-20 ,
i guess you already figured out how to use table in tables ?
If not, let me know.
You will maybe find custom LUA commands inside the game.
Here is a list of all commands you can use in SIM-STATE of the game:
https://github.com/FAForever/fa/blob/deploy/fafdevelop/engine/Sim.lua
And here a List of all commands you can use in the UI-STATE of the game:
https://github.com/FAForever/fa/blob/deploy/fafdevelop/engine/User.lua
You can't use SIM-STATE commands in UI-STATE of the game and vise versa.
SIM-STATE commands are for the gamesimulation like moving units etc.
UI-STATE commands are for the user Interface
@speed2 said in Need some help on modding functions:
Here's a list of categories https://wiki.faforever.com/index.php?title=Mission_Scripting#Categories
Thanks. I will use this if I am doing a mission scripting. Now I am trying to work on skirmish game play.
Actually I am looking for these 2 things.
(1) category list for unit that is moving around (mobile type) and an attacking unit.
(2) Blueprint for Tech 3 Transport unit.
Thanks.
To your question - Table in tables. After spending some time reading "Cobrand" code ... I think I roughly know how tables work. I know saying it, is easier than doing it ie. to actually write codes out that actually works without a bug.
I think I will know that when I reach that point.
But right now actually I am stuck in this code here.
local NameTable = import("/mods/Veterename/tables.lua").GetTable()
local allUnits = {} ;
local username = nil ;
function UpdateAllUnits()
-- Add unit being built by others
for _, unit in allUnits do
if not unit:IsDead() and unit:GetFocus() and not unit:GetFocus():IsDead() then
allUnits[unit:GetFocus():GetEntityId()] = unit:GetFocus()
end
end
-- Remove dead
for entityid, unit in allUnits do
if unit:IsDead() then
allUnits[entityid] = nil
end
end
end
function RenameVet()
for index, unit in allUnits do
local Ukills = unit:GetStat('KILLS', 0).Value
if Ukills >= unit:GetBlueprint().Veteran.Level1 and Ukills != 0 and unit:GetCustomName(unit) == nil then
local unitname = unit:GetBlueprint().General.UnitName
local newName ;
-- commander upgraded name
if unit:IsInCategory('COMMAND') == true then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "[~[Top Rank: Chief Commander]~]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[=[2nd Rank: General]=]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<+>3rd Rank: Colonel<+>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 then
newName = "<<4th Rank: Major>>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "<5th Rank: First Lieutenant>"
else
newName = username
end
end
else
-- ONLY Tech 3 Transport Air units upgraded name
if unit:IsInCategory('TRANSPORT') and unit:IsInCategory('TECH3') then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "[~[Top Rank: Whitehorse]~]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[=[2nd Rank: Hawk]=]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<+>3rd Rank: Pegasus<+>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 then
newName = "<<4th Rank: Wolfhound>>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "<5th Rank: Puma>"
-- else
-- newName = username
end
else
-- others mobile units that moves around such as land, air and naval units upgraded name
if unit:IsInCategory('DIRECTFIRE') and ( unit:IsInCategory('NAVAL') or unit:IsInCategory('LAND') or unit:IsInCategory('AIR') ) then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "[~[Top Rank: Chief General]~]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[=[2nd Rank: General]=]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<+>3rd Rank: Captain<+>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 then
newName = "<<4th Rank: Lieutenant>>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "<5th Rank: Sergeant>"
end
end
end
--
if newName != nil then
unit:SetCustomName(newName)
else
unit:SetCustomName("test")
end
end
end
end
-- ForkThread
function Repeat()
-- this piece of code will actually select units at the beginning of the game
-- every other unit is eventually created by other units at some point, hence we are adding them via that way
local selection = GetSelectedUnits()
UISelectionByCategory("ALLUNITS", false, false, false, false)
for _, unit in (GetSelectedUnits() or {}) do
username = unit:GetCustomName(unit);
allUnits[unit:GetEntityId()] = unit
end
SelectUnits(selection); -- select back what was previously selected
--
while true do -- while there are units alive out there
WaitSeconds(1)
UpdateAllUnits()
RenameVet()
end
end
-- Init
function VetInit() --
if SessionIsReplay() == true then
LOG("Veterename: Disabled ; Watching replay")
else
LOG("Veterename: Enabled")
local newSelectionsMap = {
['shift-Backspace'] = {action = 'UI_Lua import("/mods/Veterename/autorename.lua").RenameVet()'},
} -- shortcut
IN_AddKeyMapTable(newSelectionsMap)
ForkThread(Repeat)
end
end
The complete code above. Last night I ran the code using this and game still runs okay but I still cannot find out if this thing works or not as I cannot get a unit to stay on battle field long enough to see it's effect.
The last 2 blocks of code, I know for sure it won't work because I have no info as how to trap a unit that is a mobile type ie. moving type of unit and also an attacking type. And also how to trap a Transport Tech 3 unit.
-- others mobile units that moves around such as land, air and naval units upgraded name
if unit:IsInCategory('DIRECTFIRE') and ( unit:IsInCategory('NAVAL') or unit:IsInCategory('LAND') or unit:IsInCategory('AIR') ) then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
I don't know how to check if a unit is a mobile type and an attacking type of unit.
-- ONLY Tech 3 Transport Air units upgraded name
if unit:IsInCategory('TRANSPORT') and unit:IsInCategory('TECH3') then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
And also don't know how to check if a unit is a Tech 3 Transport unit.
Thanks.
Use LOG commands to print debug text to the game.log.
Like:
if unit:IsInCategory('TRANSPORT') and unit:IsInCategory('TECH3') then
LOG('Found Unit with category TRANSPORT*TECH3')
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
To Check For mobil units, you can use
unit:IsInCategory('MOBILE')
units have layer category, so you can ask for land air or naval units:
unit:IsInCategory('LAND')
unit:IsInCategory('AIR')
unit:IsInCategory('NAVAL')
random Examples:
MOBILE * LAND * INDIRECTFIRE * DIRECTFIRE
for land units that can attack other land units
MOBILE * LAND * ANTIAIR
for mobile Anti Air
MOBILE * AIR * HIGHALTAIR
for ASF
MOBILE * AIR * TRANSPORTFOCUS
for Air Transporter
(if unit:IsInCategory('MOBILE') and unit:IsInCategory('AIR') and unit:IsInCategory('TRANSPORTFOCUS') then
)
@Uveso said in Need some help on modding functions:
Use LOG commands to print debug text to the game.log.
Like:if unit:IsInCategory('TRANSPORT') and unit:IsInCategory('TECH3') then LOG('Found Unit with category TRANSPORT*TECH3') if Ukills >= unit:GetBlueprint().Veteran.Level5 then
Is there any way we could use LOG to extract the blueprint of a specific unit ?
@Uveso said in Need some help on modding functions:
To Check For mobil units, you can use
unit:IsInCategory('MOBILE')
units have layer category, so you can ask for land air or naval units:
unit:IsInCategory('LAND')
unit:IsInCategory('AIR')
unit:IsInCategory('NAVAL')
random Examples:
MOBILE * LAND * INDIRECTFIRE * DIRECTFIRE
for land units that can attack other land units
MOBILE * LAND * ANTIAIR
for mobile Anti Air
MOBILE * AIR * HIGHALTAIR
for ASF
MOBILE * AIR * TRANSPORTFOCUS
for Air Transporter
(if unit:IsInCategory('MOBILE') and unit:IsInCategory('AIR') and unit:IsInCategory('TRANSPORTFOCUS') then
)
This might help me complete the coding. I will get back to you. Thanks a lot for these.
@SupCom_16-12-20 said in Need some help on modding functions:
@speed2 said in Need some help on modding functions:
Here's a list of categories https://wiki.faforever.com/index.php?title=Mission_Scripting#Categories
Thanks. I will use this if I am doing a mission scripting. Now I am trying to work on skirmish game play.
Actually I am looking for these 2 things.
(1) category list for unit that is moving around (mobile type) and an attacking unit.(2) Blueprint for Tech 3 Transport unit.
Thanks.
Just bcause its in a mission scripting guide doesnt mean its not valid for the rest of the game.
@speed2 said in Need some help on modding functions:
@SupCom_16-12-20 said in Need some help on modding functions:
@speed2 said in Need some help on modding functions:
Here's a list of categories https://wiki.faforever.com/index.php?title=Mission_Scripting#Categories
Thanks. I will use this if I am doing a mission scripting. Now I am trying to work on skirmish game play.
Actually I am looking for these 2 things.
(1) category list for unit that is moving around (mobile type) and an attacking unit.(2) Blueprint for Tech 3 Transport unit.
Thanks.
Just bcause its in a mission scripting guide doesnt mean its not valid for the rest of the game.
Ok, I keep that in mind.
unit:GetBlueprint().Veteran.Level1
Am I right to say Veteran.Level1 means, it is 1 star as shown below ?
and
unit:GetBlueprint().Veteran.Level2
means 2 stars ?
@Uveso said in Need some help on modding functions:
LOG( repr(BluePrint) )
repr()
will print tables.Don't use this on units or other user/c-objects.
Ok thanks
unit:GetBlueprint().Veteran.Level2
unit:GetBlueprint()
will get the blueprint from a unit.
local TableFromBlueprint = unit:GetBlueprint()
LOG(TableFromBlueprint) -- this will print the whole blueprint into the game.log
You can do it directly without storing it in TableFromBlueprint :
LOG(unit:GetBlueprint()) -- this will print the whole blueprint into the game.log
unit:GetBlueprint().Veteran
local TableFromBlueprint = unit:GetBlueprint()
LOG(TableFromBlueprint.Veteran) -- this will only print the Veteran table from the blueprint
same as before:
LOG(unit:GetBlueprint().Veteran) -- this will only print the Veteran table from the blueprint
output:
Veteran = {
Level1 = 6,
Level2 = 12,
Level3 = 18,
Level4 = 24,
Level5 = 30,
},
unit:GetBlueprint().Veteran.Level2
local TableFromBlueprint = unit:GetBlueprint()
LOG(TableFromBlueprint.Veteran.Level2) -- this will print the value stored in Veteran/Level2
same as before:
LOG(unit:GetBlueprint().Veteran.Level2) -- this will print the value stored in Veteran/Level2
output:
12
@SupCom_16-12-20 said in Need some help on modding functions:
unit:GetBlueprint().Veteran.Level1
Am I right to say Veteran.Level1 means, it is 1 star as shown below ?
and
unit:GetBlueprint().Veteran.Level2
means 2 stars ?
if it is, then something is wrong with my modified codes. I don't know where the bug is. The Star increased from 1 to 3 stars but the Ranking don't increase ?
The code for Tech 3 Air Transport unit
-- ONLY Tech 3 Transport Air units upgraded name
if unit:IsInCategory('TRANSPORTFOCUS') and unit:IsInCategory('AIR') and unit:IsInCategory('TECH3') then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "[~[Top Rank: Whitehorse]~]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[=[2nd Rank: Hawk]=]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<+>3rd Rank: Pegasus<+>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 then
newName = "<<4th Rank: Wolfhound>>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "<5th Rank: Puma>"
end
end
Below is the complete codes.
local NameTable = import("/mods/Veterename/tables.lua").GetTable()
local allUnits = {} ;
local username = nil ;
function UpdateAllUnits()
-- Add unit being built by others
for _, unit in allUnits do
if not unit:IsDead() and unit:GetFocus() and not unit:GetFocus():IsDead() then
allUnits[unit:GetFocus():GetEntityId()] = unit:GetFocus()
end
end
-- Remove dead
for entityid, unit in allUnits do
if unit:IsDead() then
allUnits[entityid] = nil
end
end
end
function RenameVet()
for index, unit in allUnits do
local Ukills = unit:GetStat('KILLS', 0).Value
if Ukills >= unit:GetBlueprint().Veteran.Level1 and Ukills != 0 and unit:GetCustomName(unit) == nil then
local unitname = unit:GetBlueprint().General.UnitName
local newName ;
-- commander upgraded name
if unit:IsInCategory('COMMAND') == true then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "[~[Top Rank: Chief Commander]~]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[=[2nd Rank: General]=]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<+>3rd Rank: Colonel<+>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 then
newName = "<<4th Rank: Major>>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "<5th Rank: First Lieutenant>"
else
newName = username
end
else
-- others mobile units that moves around such as land, air and naval units upgraded name
if ( unit:IsInCategory('NAVAL') or unit:IsInCategory('LAND') or unit:IsInCategory('AIR') ) and ( unit:IsInCategory('TECH2') or unit:IsInCategory('TECH3') or unit:IsInCategory('EXPERIMENTAL') ) then
if unit:IsInCategory('DIRECTFIRE') or unit:IsInCategory('INDIRECTFIRE') then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "[~[Top Rank: Commander]~]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[=[2nd Rank: Genaral]=]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<<3rd Rank: Colonel>>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 or Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "3 stars for promotion"
end
end
end
end
-- ONLY Tech 3 Transport Air units upgraded name
if unit:IsInCategory('TRANSPORTFOCUS') and unit:IsInCategory('AIR') and unit:IsInCategory('TECH3') then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "[~[Top Rank: Whitehorse]~]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[=[2nd Rank: Hawk]=]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<+>3rd Rank: Pegasus<+>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 then
newName = "<<4th Rank: Wolfhound>>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "<5th Rank: Puma>"
end
end
--
if newName != nil then
unit:SetCustomName(newName)
else
unit:SetCustomName("test")
end
end
end
end
-- ForkThread
function Repeat()
-- this piece of code will actually select units at the beginning of the game
-- every other unit is eventually created by other units at some point, hence we are adding them via that way
local selection = GetSelectedUnits()
UISelectionByCategory("ALLUNITS", false, false, false, false)
for _, unit in (GetSelectedUnits() or {}) do
username = unit:GetCustomName(unit);
allUnits[unit:GetEntityId()] = unit
end
SelectUnits(selection); -- select back what was previously selected
--
while true do -- while there are units alive out there
WaitSeconds(1)
UpdateAllUnits()
RenameVet()
end
end
-- Init
function VetInit() --
if SessionIsReplay() == true then
LOG("Veterename: Disabled ; Watching replay")
else
LOG("Veterename: Enabled")
local newSelectionsMap = {
['shift-Backspace'] = {action = 'UI_Lua import("/mods/Veterename/autorename.lua").RenameVet()'},
} -- shortcut
IN_AddKeyMapTable(newSelectionsMap)
ForkThread(Repeat)
end
end
Just check the code that adds the starts or the veterancy progress bar and you'll understand how it works. You can even hook that to rename your units so you dont have to do the same check again in your code.
@speed2 said in Need some help on modding functions:
Just check the code that adds the starts or the veterancy progress bar and you'll understand how it works. You can even hook that to rename your units so you dont have to do the same check again in your code.
I am hungry and just want to buy a loaf of bread, that is all. But in a foreign country it is that hard to do when people speak in language (Lua programming) I don't understand. I did try to clear this hurdle myself by checking the codes and testing the gameplay well into the night but without any good result.
I just need to know how to determine how many stars I have earned (stars shown in image below)