Hekkaryk Posted December 29, 2017 Share Posted December 29, 2017 Hi everybody I'm working on my mod and there is a reoccuring issue I found myself fighting with. How can one replace existing function - for example DefaultBurntStructureFn(inst) in standardcomponents.lua? I'm adding aggressive approach to griefers with prevents all types of containers from dropping its content - works when hammered down, does not work when burned. I would show code but there is none since all attempts end up with failure to replace this function I can replace functions for prefabs and classes (fixed Bearger bug when it crashes the game when it tries to do its WorkEntities - there is no check if targets have workable component and changed onhit/onhammered for icebox, treasurechest, dragonflychest - no drop when destroyed/hit) but this one always escapes me Link to comment https://forums.kleientertainment.com/forums/topic/85923-question-how-to-overwrite-default-functions/ Share on other sites More sharing options...
Ricoom Posted December 30, 2017 Share Posted December 30, 2017 require the file and then write a function with same name Link to comment https://forums.kleientertainment.com/forums/topic/85923-question-how-to-overwrite-default-functions/#findComment-988386 Share on other sites More sharing options...
Hekkaryk Posted December 30, 2017 Author Share Posted December 30, 2017 Tried: require "standardcomponents" function DefaultBurntStructureFn(inst) -- modified function end and (obviously stupid): local standardcomponents = require "standardcomponents" function standardcomponents.DefaultBurntStructureFn(inst) --modified function end and (also hopeless): standardcomponents = require "standardcomponents" function new_DefaultBurntStructureFn(inst) --modified function end standardcomponents.DefaultBurntStructureFn = new_DefaultBurntStructureFn I'm sorry that I ask stupid questions... but I do not know the answer, that's why I'm here. I did use require to make stack size larger: local _G = GLOBAL local _T = _G.TUNING local maxstacksize = GetModConfigData("maxstacksize") local net_ushortint = _G.net_ushortint local stackable_replica = require "components/stackable_replica" _T.STACK_SIZE_LARGEITEM = maxstacksize _T.STACK_SIZE_MEDITEM = maxstacksize _T.STACK_SIZE_SMALLITEM = maxstacksize function stackable_replica._ctor(self, inst) self.inst = inst self._stacksize = net_ushortint(inst.GUID, "stackable._stacksize", "stacksizedirty") --max 65535 for net_ushortint self._maxsize = maxstacksize end function stackable_replica:SetMaxSize(_) --maxsize) self._maxsize = maxstacksize end function stackable_replica:MaxSize() return self._maxsize end but it's entirely different situation - stackable_replica is a class I can manipulate that way standard_components.lua is... plain lua. Not a class. Just a bunch of good ol' global functions here for the glory of Don't Starve Together Link to comment https://forums.kleientertainment.com/forums/topic/85923-question-how-to-overwrite-default-functions/#findComment-988388 Share on other sites More sharing options...
CarlZalph Posted December 30, 2017 Share Posted December 30, 2017 Should be able to just replace it in modmain: GLOBAL.DefaultBurntStructureFn = function(inst, ...) -- Do stuff end Link to comment https://forums.kleientertainment.com/forums/topic/85923-question-how-to-overwrite-default-functions/#findComment-988389 Share on other sites More sharing options...
Hekkaryk Posted December 30, 2017 Author Share Posted December 30, 2017 Thank you @CarlZalph, that did the trick! ^_^ And wow, that open whole new world for more changes to game logic for me and my mod ^_^ Link to comment https://forums.kleientertainment.com/forums/topic/85923-question-how-to-overwrite-default-functions/#findComment-988521 Share on other sites More sharing options...
Miki_Tiki Posted January 22, 2025 Share Posted January 22, 2025 I faced the same problem. I wanted to replace a function in recipes.lua: -- Walter local function calc_slingshotammo_numtogive(recipe, doer) local level = doer.components.skilltreeupdater and doer.components.skilltreeupdater:CountSkillTag("slingshoteconomy") or 0 return (level >= 2 and recipe.numtogive * 1.5) or (level >= 1 and recipe.numtogive * 1.2) or nil end I wanted to modify it so that recipe.numtogive would simply be multiplied by a larger number, but for some reason, I couldn't do this in the way shown below. It's probably because it is defined locally Link to comment https://forums.kleientertainment.com/forums/topic/85923-question-how-to-overwrite-default-functions/#findComment-1787383 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