• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Login
FAForever Forums
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Login

Need some help on modding functions

Scheduled Pinned Locked Moved I need help
35 Posts 6 Posters 2.0k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    SupCom_16-12-20 @speed2
    last edited by 13 Jan 2021, 23:13

    @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.

    1 Reply Last reply Reply Quote 0
    • S
      SupCom_16-12-20
      last edited by SupCom_16-12-20 13 Jan 2021, 23:16

      unit:GetBlueprint().Veteran.Level1
      

      Am I right to say Veteran.Level1 means, it is 1 star as shown below ?

      17a572a9-c7aa-48c3-aba4-d0fc85f82c55-image.png

      and

      unit:GetBlueprint().Veteran.Level2
      

      means 2 stars ?

      S 1 Reply Last reply 14 Jan 2021, 09:27 Reply Quote 0
      • S
        SupCom_16-12-20 @Uveso
        last edited by 13 Jan 2021, 23:20

        @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

        1 Reply Last reply Reply Quote 0
        • U
          Uveso
          last edited by 14 Jan 2021, 00:16

          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
          
          1 Reply Last reply Reply Quote 0
          • S
            SupCom_16-12-20 @SupCom_16-12-20
            last edited by SupCom_16-12-20 14 Jan 2021, 09:27

            @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 ?

            17a572a9-c7aa-48c3-aba4-d0fc85f82c55-image.png

            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
            

            e4a51295-b6a0-4596-b873-8cd77612e2f5-image.png

            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
            
            1 Reply Last reply Reply Quote 0
            • S
              speed2
              last edited by 14 Jan 2021, 11:50

              Veterancy isnt based on the number of kills but on a killed mass.

              D 1 Reply Last reply 19 Jan 2021, 15:40 Reply Quote 0
              • S
                speed2
                last edited by 14 Jan 2021, 11:51

                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.

                S 1 Reply Last reply 15 Jan 2021, 12:07 Reply Quote 0
                • S
                  SupCom_16-12-20 @speed2
                  last edited by SupCom_16-12-20 15 Jan 2021, 12:07

                  @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)

                  fa8a8d65-1b01-4f5d-b5d8-d54c787e3534-image.png

                  1 Reply Last reply Reply Quote 0
                  • S
                    speed2
                    last edited by 15 Jan 2021, 13:48

                    https://github.com/FAForever/fa/blob/deploy/fafdevelop/lua/ui/game/unitview.lua#L176-L191
                    and then lines 404-411

                    1 Reply Last reply Reply Quote 0
                    • S
                      SupCom_16-12-20
                      last edited by 19 Jan 2021, 09:21

                      Thank you guys for helping guess I will have to give this up, not getting any result.

                      1 Reply Last reply Reply Quote 0
                      • D
                        Dragun101 @speed2
                        last edited by 19 Jan 2021, 15:40

                        @speed2 said in Need some help on modding functions:

                        Veterancy isnt based on the number of kills but on a killed mass.

                        As a reminder that is FA > FAF Change. Not that I imagine that has particularly changed the how code would be hooked here.

                        I’m a shitty 1k Global. Any balance or gameplay suggestions should be understood or taken as such.

                        Project Head and current Owner/Manager of SCTA Project

                        1 Reply Last reply Reply Quote 0
                        34 out of 35
                        • First post
                          34/35
                          Last post