Need help: SimSync, GUI, Unlocking things

Everything about mods can be found here.

Moderator: Morax

Need help: SimSync, GUI, Unlocking things

Postby Locutus » 10 Mar 2015, 19:09

Hey guys,

a few days ago I started modding FA and I already ran into a bunch of problems I can't solve.
I'm not new to modding itself but I'm not familiar with how FA works, so please go easy on me.
I'm currently working on the basics to get a new resource - research points - into the game. Somewhat similar to SC2, I'd like a research station to produce this new resource. I managed to get some ugly UI elements into the game which display the current points and offer the possibility to open a new window which should be used to unlock tech.
The major problem I am facing right now is how UI and Sim are connected. Without really knowing what I'm doing I managed to slap some code together so that every time a player builds a wall a number gets incremented in my GUI. So that worked in a way but I don't really understand what I am doing.
I figured that Domino is for SupCom what Zerted is for SWBF2 and took a look at his mods. The CTF mode is quite close to what I need (I think) but boy, no idea whats going on there. Without an IT background I have a hard time understanding anything from those scripts. Unfortunately the forums.gaspowered site seems to be offline and Google cache isn't really helpful...

Could someone help me understand the basics?

1) I'd need a rough understand on how UserSync and SimSync work. Taking a look at the source files wasn't really helpful to me, there's too much I don't understand yet.
Or would it be easier, instead of putting a function in the building script itself, to have a global script which counts all research stations on the map and calculates the point income based on that? If so, where would I start?

2) I somehow need to count the points for each player separately. Is it correct that "army" is the word I need to look for in the scripts?
Are there simple mods you could suggest as learning examples?

3) In the campaign new units get unlocked all the time. I haven't really looked for it yet but I think that should work in multiplayer too, right? Is it also possible to unlock new abilities? I believe a cheaty solution would be to lock the old unit and unlock a new one in the factory but would it be also possible for all units that are already on the field?

Thanks,

Locutus
Locutus
 
Posts: 4
Joined: 07 Mar 2015, 19:06
Has liked: 0 time
Been liked: 0 time
FAF User Name: Locutus

Re: Need help: SimSync, GUI, Unlocking things

Postby Myxir » 10 Mar 2015, 19:30

Locutus wrote:1) I'd need a rough understand on how UserSync and SimSync work. Taking a look at the source files wasn't really helpful to me, there's too much I don't understand yet.
Or would it be easier, instead of putting a function in the building script itself, to have a global script which counts all research stations on the map and calculates the point income based on that? If so, where would I start?


you can pass information from sim to ui by using UserSync.lua

as example, use
Code: Select all
Sync.researchpoints = {0 = 13, 1 = 342, 2 = 23, 3 = 98}

somewhere in the code, Sync is a global var and you don't need to import it

then, hook UserSync.lua:
Code: Select all
local baseOnSync = OnSync
function OnSync()
   baseOnSync()

   if Sync.researchpoints then
      import('/mods/researchMod/modules/myUi.lua').updateUi(Sync.researchpoints)
   end
end

(in this case, you'd send all data to every player, but you get the idea)


Locutus wrote:2) I somehow need to count the points for each player separately. Is it correct that "army" is the word I need to look for in the scripts?
Are there simple mods you could suggest as learning examples?


you can try something like this in the sim code:
Code: Select all
for army, brain in ArmyBrains do
   myPointTable[army] = hisResearchPoints
end
Sync.researchpoints = myPointTable




Locutus wrote:3) In the campaign new units get unlocked all the time. I haven't really looked for it yet but I think that should work in multiplayer too, right? Is it also possible to unlock new abilities? I believe a cheaty solution would be to lock the old unit and unlock a new one in the factory but would it be also possible for all units that are already on the field?

unsure about this, i suggest to take a look at some blackops/extremewars code, they might do stuff like that
Unhappy with balance http://i.imgur.com/q5G2BlM.png
User avatar
Myxir
Evaluator
 
Posts: 791
Joined: 09 Apr 2012, 14:01
Has liked: 94 times
Been liked: 306 times
FAF User Name: Washy (irc)

Re: Need help: SimSync, GUI, Unlocking things

Postby Locutus » 10 Mar 2015, 23:00

Thanks for your answer!

Myxir wrote:you can pass information from sim to ui by using UserSync.lua

as example, use
Code: Select all
Sync.researchpoints = {0 = 13, 1 = 342, 2 = 23, 3 = 98}

somewhere in the code, Sync is a global var and you don't need to import it

then, hook UserSync.lua:
Code: Select all
local baseOnSync = OnSync
function OnSync()
   baseOnSync()

   if Sync.researchpoints then
      import('/mods/researchMod/modules/myUi.lua').updateUi(Sync.researchpoints)
   end
end


Thanks, got that working!
Whenever the research station is constructed points do nicely increase :D


Myxir wrote:(in this case, you'd send all data to every player, but you get the idea)

This is the part were I'm stuck. How does the GUI even differentiate between players?
Currently I got this:
--code of the research station
Code: Select all
OnCreate = function(self)
      TWallStructureUnit.OnCreate(self)
         print('RM: A research station has been built')
         self:ForkThread(self.GenerateResearchThread)   
    end,
   
   GenerateResearchThread = function(self)
      while true do
         local army = self:GetArmy()
                     
         if not Sync.ResearchPoints then
            Sync.ResearchPoints = {Army = army, ResearchPoints1 = 3}
         end
         WaitSeconds(1.00)
         end
   end,


--UI Code
Code: Select all
function UpdateScores(ResearchPoints)   
   if not ResearchPoints then
      return   
   end
   local rsp = ResearchPoints.ResearchPoints1
   research_points_1 = research_points_1 + rsp
   if research_points_1 >= research_points_1_max then
      research_points_1 = research_points_1 - research_points_1_max
      research_points_2 = research_points_2 + 1
      treePointView.Group.ResearchPoints2:SetText(research_points_2)
   end
   treePointView.Group.ResearchPoints1:SetText(LOCF('%s / %s', research_points_1, research_points_1_max))
end

No idea how I could display individual scores for the players...


Myxir wrote:unsure about this, i suggest to take a look at some blackops/extremewars code, they might do stuff like that

Thanks, I'll take a look! :D
Locutus
 
Posts: 4
Joined: 07 Mar 2015, 19:06
Has liked: 0 time
Been liked: 0 time
FAF User Name: Locutus

Re: Need help: SimSync, GUI, Unlocking things

Postby Locutus » 14 Mar 2015, 00:34

Thank you for your help, Myxir! :D

I got nearly everything working now: I have separate points for each player and each player got it's own score in the panel. (Un-)locking units works as well.
There's one issue left though:

How can I sync into the other direction, from GUI to Sim?
Say, when the player clicks on a certain GUI element I'd like to update a few variables which I have stor'ed in the SIM. How would I do that?

Thanks,

~Locutus
Locutus
 
Posts: 4
Joined: 07 Mar 2015, 19:06
Has liked: 0 time
Been liked: 0 time
FAF User Name: Locutus

Re: Need help: SimSync, GUI, Unlocking things

Postby Domino » 15 Mar 2015, 11:52

Hey,

Some good info above regarding the Sync table. :)

to reverse it and send info back to the sim, you would use simcallbacks the only differance here is that from the userlayer you are only sending info back from the focus army (player army) and not to all armies like when using sim sync. you can use GetFocusArmy() in the user layer to get your armyindex.

you say you want to use a new resource?

if so, why not set up the resource in the sim using the Aibrain to run a thread that updates used/produced of said resource every second and update the values in the ui, just set it up like the energy resource, you can duplicate alot of the energy core code but changing the resource type. its actually not that difficult, ive actually got some core code added already in my DMS mod to add new resource, i have actually already added base code for black matter which i want exp to use in future.

to use the AIbrain method, you would have to add the resource producing/using unit to a table and have the aibrain loop those units and get then set the values for the ui.
you can then call a function in the unit(s) script to trigger when no resource or resource low/full/depleted etc.

there is a learning curve, but i think you can do it.. :)

good job so far.. welcome to supcom modding!

Domino
Domino
Priest
 
Posts: 315
Joined: 14 Mar 2012, 21:07
Has liked: 3 times
Been liked: 75 times


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest