Jump to content

Recommended Posts

As the title says.

I need to override "Mainfunctions.lua" from "scripts" folder, adding it into my mods "scripts" folder doesnt work.


Is it passable to override Stategragh OR edit its single functions? (espicially: SpawnPrefab)?  Just need the way to listen ALL mob spawns.

Link to comment
https://forums.kleientertainment.com/forums/topic/32661-editing-mainfunctions/
Share on other sites

Everything in mainfunctions.lua is globally defined. You can just redefine it.

You probably want to hook into SpawnPrefabFromSim instead of SpawnPrefab, as it is where prefab post inits are handled (I believe SpawnPrefabFromSim gets called from within TheSim:SpawnPrefab which is what the Lua function SpawnPrefab calls)

-- if in modmain, pull the function from the global environmentlocal SpawnPrefabFromSim_base = GLOBAL.SpawnPrefabFromSim-- overwriteGLOBAL.SpawnPrefabFromSim = function(name)    local spawned_guid = SpawnPrefabFromSim_base(name)    if spawned_guid ~= -1 then        local spawned_prefab = GLOBAL.Ents[spawned_guid]        print("Spawned "..tostring(spawned_prefab))    end    return spawned_guidend
EDIT: Updated with fixed (and tested) code Edited by squeek

Everything in mainfunctions.lua is globally defined. You can just redefine it.

You probably want to hook into SpawnPrefabFromSim instead of SpawnPrefab, as it is where prefab post inits are handled (I believe SpawnPrefabFromSim gets called from within TheSim:SpawnPrefab which is what the Lua function SpawnPrefab calls)

 

Thanks for help!

  But I think I need require something else to make this work. Got this error on testing:

....................

...iles/DontStarve/data/../mods/online-coop/modmain.lua:133: attempt to index global 'Ents' (a nil value) 

......................

 

Do I need something else to be  required ? 

Edited by Desblat

Thanks for help!

  But I think I need require something else to make this work. Got this error on testing:

....................

...iles/DontStarve/data/../mods/online-coop/modmain.lua:133: attempt to index global 'Ents' (a nil value) 

......................

 

Do I need something else to be  required ?

Whoops, should be GLOBAL.Ents. Edited my post above. Edited by squeek

Whoops, should be GLOBAL.Ents. Edited my post above.

 

Hm, looks like game doesnt want to edit main functions, got this on testing new variant:

........

...gram Files/DontStarve/data/scripts/mainfunctions.lua:153: bad argument #-2 to 'SpawnPrefab' (number expected, got nil)

LUA ERROR stack traceback:

=[C] in function 'SpawnPrefab'

D:/Program Files/DontStarve/data/scripts/mainfunctions.lua(153,1) in function 'SpawnPrefab'

D:/Program Files/DontStarve/data/scripts/prefabs/world.lua(183,1) in function 'fn'

D:/Program Files/DontStarve/data/scripts/mainfunctions.lua(123,1) in function 'SpawnPrefabFromSim_base'

D:/Program Files/DontStarve/data/../mods/online-coop/modmain.lua(115,1)

=[C] in function 'SpawnPrefab'

..........

 

If you have not ideas how to fix this, I am going to try another variants of tracking.

Hm, looks like game doesnt want to edit main functions, got this on testing new variant:

........

...gram Files/DontStarve/data/scripts/mainfunctions.lua:153: bad argument #-2 to 'SpawnPrefab' (number expected, got nil)

LUA ERROR stack traceback:

=[C] in function 'SpawnPrefab'

D:/Program Files/DontStarve/data/scripts/mainfunctions.lua(153,1) in function 'SpawnPrefab'

D:/Program Files/DontStarve/data/scripts/prefabs/world.lua(183,1) in function 'fn'

D:/Program Files/DontStarve/data/scripts/mainfunctions.lua(123,1) in function 'SpawnPrefabFromSim_base'

D:/Program Files/DontStarve/data/../mods/online-coop/modmain.lua(115,1)

=[C] in function 'SpawnPrefab'

..........

 

If you have not ideas how to fix this, I am going to try another variants of tracking.

Forgot to return the GUID. Fixed (and tested) code:

-- if in modmain, pull the function from the global environmentlocal SpawnPrefabFromSim_base = GLOBAL.SpawnPrefabFromSim -- overwriteGLOBAL.SpawnPrefabFromSim = function(name)    local spawned_guid = SpawnPrefabFromSim_base(name)    if spawned_guid ~= -1 then        local spawned_prefab = GLOBAL.Ents[spawned_guid]        print("Spawned "..tostring(spawned_prefab))    end    return spawned_guidend

Forgot to return the GUID. Fixed (and tested) code:

-- if in modmain, pull the function from the global environmentlocal SpawnPrefabFromSim_base = GLOBAL.SpawnPrefabFromSim -- overwriteGLOBAL.SpawnPrefabFromSim = function(name)    local spawned_guid = SpawnPrefabFromSim_base(name)    if spawned_guid ~= -1 then        local spawned_prefab = GLOBAL.Ents[spawned_guid]        print("Spawned "..tostring(spawned_prefab))    end    return spawned_guidend

Thanks for help! This function is fine for out spawn tracking. True-lan-coop is a bit closer to working version. )

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...