IF (a mod is present) THEN

Everything about mods can be found here.

Moderator: Morax

IF (a mod is present) THEN

Postby DDDX » 03 Apr 2018, 15:48

Hi guys!

Have not yet seen this before in a map script.
How would one go around letting the map script know there's a specific mod activated, in a form of a if-then (or similar)?
I want to make values in a map script dependant on mods that are used with it, but to do that I need to make the map aware if the mod is being used or not.
Any maps that do this already, from whom I can get it?

Thank you.
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: IF (a mod is present) THEN

Postby Uveso » 03 Apr 2018, 16:32

Found this in simInit.lua:

Code: Select all
LOG('Active mods in sim: ', repr(__active_mods))


This was in Blueprint.lua:
Code: Select all
    if not mods then
        mods = __active_mods or import('/lua/mods.lua').GetGameMods()
    end


Also found somewhere:

Code: Select all
for index, moddata in __active_mods do
      LOG( 'Active Mod - Directory='..( moddata.location ) )
end


Usefull to see the data inside a table:
Code: Select all
LOG( repr( moddata ) )
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: IF (a mod is present) THEN

Postby DDDX » 03 Apr 2018, 19:45

Thanx. Tried implementing it but I am lacking the knowhow as to what goes where.
Sofar:
Added the LOG code to the siminit.lua,
made this Blueprints.lua inside 'hook/lua/system (BlueprintS plural, right?).
Code: Select all
do
        if not mods then
        mods = __active_mods or import('/lua/mods.lua').GetGameMods()
        end

        for index, moddata in __active_mods do
      LOG( 'Active Mod - Directory='..( moddata.location ) )
      end

end

Next, made
Code: Select all
for index, moddata in __active_mods do
           if moddata == "Survival Mayhem&BO balance" then ..etc


yeah I got no idea how to get it working :/
Sorry to yet again rely on your coding skills instead of mine, Uveso.
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: IF (a mod is present) THEN

Postby speed2 » 03 Apr 2018, 20:02

Well you have to edit the map script. The mods are saved in the global variable __active_mods as Uveso posted.

You can access it like this for example (map script):
Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
   
function OnPopulate()
    ScenarioUtils.InitializeArmies()
    local mods = __active_mods
    LOG('Map Script ... active mods in sim: ', repr(__active_mods))
end
   
function OnStart()
end
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: IF (a mod is present) THEN

Postby DDDX » 03 Apr 2018, 20:17

Ty Speed2, I figured I lacked the link to the map script.
Off to try and make it function.
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: IF (a mod is present) THEN

Postby DDDX » 03 Apr 2018, 20:44

Nope. I'm too noobish a coder for this.
I tried, honest I did.

My Blueprints.lua cause the map to load super fast and blank, looks like this (inside /hook/lua/system)
Code: Select all
do
        if not mods then
        mods = __active_mods or import('/lua/mods.lua').GetGameMods()
        end

        for index, moddata in __active_mods do
      LOG( 'Active Mod - Directory='..( moddata.location ) )
      end

end

That's the whole Blueprints.lua, did not need one till now.

Added this code into the OnPopulate function of the survival map script file
Code: Select all
   local mods = __active_mods
    LOG('Map Script ... active mods in sim: ', repr(__active_mods))

Then tried referencing it with
Code: Select all
      for index, moddata in __active_mods do
           if moddata == 'Survival Mayhem&BO balance' then


Uff...I know it's probably simple...ish, but I'm stuck at 'nope'.

Tthe Blueprints.lua is the culprit for the whole thing not working at all, I guess I need to add something else in it.
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: IF (a mod is present) THEN

Postby speed2 » 03 Apr 2018, 20:46

I thought you were trying to work with mods in the map script. In that case you don't need to hook or edit any files.

Just change the script to what I posted above and it will work (for sim mods).
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: IF (a mod is present) THEN

Postby DDDX » 04 Apr 2018, 11:56

Ty for the reply.

Can't.
Either it needs something more, or I made the if-then segment wrong (look above).
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: IF (a mod is present) THEN

Postby speed2 » 04 Apr 2018, 14:49

Use this map script and it will work, I've tested it.

speed2 wrote:Well you have to edit the map script. The mods are saved in the global variable __active_mods as Uveso posted.

You can access it like this for example (map script):
Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
   
function OnPopulate()
    ScenarioUtils.InitializeArmies()
    local mods = __active_mods
    LOG('Map Script ... active mods in sim: ', repr(__active_mods))
end
   
function OnStart()
end
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: IF (a mod is present) THEN

Postby DDDX » 04 Apr 2018, 15:22

I did, as soon as you posted it the first time. Like this:

Code: Select all
function OnPopulate()
   LOG("----- Survival MOD: OnPopulate()");

   -- start the armies
   ScenarioUtils.InitializeArmies();

   -- prepare all the survival stuff
   Survival_InitGame();

   -- which mods are active?
   local mods = __active_mods
    LOG('Map Script ... active mods in sim: ', repr(__active_mods))

end

-- function OnStart()
-- end

This is my map's OnPopulate function, and this is the OnStart
Code: Select all
function OnStart(self)

   LOG("----- Survival MOD: Initializing game start sequence...");

   -- start the survival tick
   ForkThread(Survival_Tick);

end


And this is what I hope to use to call the mod up, if it is used or not.
Code: Select all
      for index, moddata in __active_mods do
           if moddata == 'Survival Mayhem&BO balance' then


It does nothing, as if the condition is not met. Don't know why.
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Next

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest