Jump to content

Recommended Posts

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 :( 

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 :p 

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

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...