Desblat Posted March 12, 2014 Share Posted March 12, 2014 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 More sharing options...
squeek Posted March 12, 2014 Share Posted March 12, 2014 (edited) 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_guidendEDIT: Updated with fixed (and tested) code Edited March 13, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32661-editing-mainfunctions/#findComment-429631 Share on other sites More sharing options...
Desblat Posted March 12, 2014 Author Share Posted March 12, 2014 (edited) 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 March 12, 2014 by Desblat Link to comment https://forums.kleientertainment.com/forums/topic/32661-editing-mainfunctions/#findComment-429660 Share on other sites More sharing options...
squeek Posted March 12, 2014 Share Posted March 12, 2014 (edited) 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 March 12, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32661-editing-mainfunctions/#findComment-429671 Share on other sites More sharing options...
Desblat Posted March 13, 2014 Author Share Posted March 13, 2014 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. Link to comment https://forums.kleientertainment.com/forums/topic/32661-editing-mainfunctions/#findComment-430811 Share on other sites More sharing options...
squeek Posted March 13, 2014 Share Posted March 13, 2014 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 Link to comment https://forums.kleientertainment.com/forums/topic/32661-editing-mainfunctions/#findComment-430821 Share on other sites More sharing options...
Desblat Posted March 14, 2014 Author Share Posted March 14, 2014 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_guidendThanks for help! This function is fine for out spawn tracking. True-lan-coop is a bit closer to working version. ) Link to comment https://forums.kleientertainment.com/forums/topic/32661-editing-mainfunctions/#findComment-431593 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now