Access ArmyBrain in mod

Is there a possibility to access this function: GetArmyBrain()

from inside a hook of a mod, when running a replay?

GetArmyBrain() returns the ArmyBrains global variable.
No matter how I try, I get error messages saying that I can not access that global variable or function.

Any pointers would be appreciated!
Cheers!

You need to pass the parameter of the brain's nickname.
e.g if you had 3 players called bob, jim, sam you would say

brain = GetArmyBrain('sam')

The function is not available during blueprint loading or on the user layer. It is only available in the sim layer. See also:

A work of art is never finished, merely abandoned

Hi Jip,

Thanks a lot.

So this would explain why for example the Phantom X mod has access to the ArmyBrains global variable, because it is not a UI mod?

https://github.com/FAForever/faf-phantomx/blob/b088e4b40c808174ad9bee4ab787758349e0a8dd/lua/PhantomSim.lua#L178

Because I guess if I UI mod would have access to ArmyBrains it could influence the game simulation.

In the end what I am trying to do work out, is how to fix Hussars Scoreboard Kill notification.
https://github.com/FA-mods/SupremeScoreBoard

What broke the kill notification is basically this change in the FA Core.
https://github.com/FAForever/fa/pull/4016

Earlier the DoGameResult would receive also the score results, after the change it is only the defeat.

So the Scoreboard UI mod does not know anymore who performed a kill, it only knows an ACU was defeated, hence it always shows that a ctrl+k happened.

So I wondered how I could get access to the kills information. This is why I wanted to read out the Armybrains, because it seems this info could be extracted from there.

Cheers!

Ok, I did some digging.
Surely the ArmyBrains can only be accessed if I were to use a mod, which is not a ui_only mod.

Hence my Idea: if a fellow streamer were to modify the fafreplay file saying to run it with a patched version of SupremeScoreBoard, which is patched to be a sim mod, and that has access to the armybrains.
Then the replay would still be replayed just as it was played (not causing desyncs), because the armybrains is only read, and never modified. Right?

This might be an ugly way to do it, but hey it should work, I guess.

The solution is to introduce a sync event that sends the information to the UI layer. We can look into that. Then in the UI layer you can interpret the event and create an announcement

A work of art is never finished, merely abandoned

@jip

Wow, that would be very cool.
I was wondering also about this solution, but was not sure I could recommend something that would introduce changes into the core of FAF.

I might even do it myself. The dev process is well documented.
I will come up with a pull request in the future then.

If I get stuck on the way I will seek help.

Cheers!

@rigomate said in Access ArmyBrain in mod:

I was wondering also about this solution, but was not sure I could recommend something that would introduce changes into the core of FAF.

Everyone can make contributions 🙂

@rigomate said in Access ArmyBrain in mod:

I might even do it myself. The dev process is well documented.

I'm glad to read that, as we spent a lot of time to improve it in 2022.

@rigomate said in Access ArmyBrain in mod:

If I get stuck on the way I will seek help.

Find us on the official Discord server, the navigate to the suggestions channel:

7bc4c26f-1696-4307-9ddb-394648d51297-image.png

We're all there to help you with this and I'm looking forward to the pull request 🙂

A work of art is never finished, merely abandoned

@jip
Ok, the pull request is there and ready.

https://github.com/FAForever/fa/pull/4789

Thanks for your help, this had been fun.
I never did even a single line of Lua before.

But I have to say, Lua is cool.

Cheers!