MidrealmDM Posted May 23, 2019 Share Posted May 23, 2019 (edited) within the Shadowmeteor.lua is a function [ local function SetSize (inst, sz, mod ) ] which determines what items get spawned from meteor impact. local function SetSize(inst, sz, mod) Spoiler if inst.autosizetask ~= nil then inst.autosizetask:Cancel() inst.autosizetask = nil end if inst.striketask ~= nil then return end if sizes[sz] == nil then sz = "small" end inst.size = sizes[sz] inst.workdone = work[sz] inst.warnshadow = SpawnPrefab("meteorwarning") if mod == nil then mod = 1 end if sz == "medium" then inst.loot = { { prefab = "rocks", chance = TUNING.METEOR_CHANCE_INVITEM_OFTEN * mod }, { prefab = "rocks", chance = TUNING.METEOR_CHANCE_INVITEM_RARE * mod }, { prefab = "flint", chance = TUNING.METEOR_CHANCE_INVITEM_ALWAYS * mod }, { prefab = "flint", chance = TUNING.METEOR_CHANCE_INVITEM_VERYRARE * mod }, { prefab = "moonrocknugget", chance = TUNING.METEOR_CHANCE_INVITEM_SOMETIMES * mod }, } elseif sz == "large" then local rand = math.random() if rand <= TUNING.METEOR_CHANCE_BOULDERMOON * mod then inst.loot = { { prefab = "rock_moon", chance = 1, }, } elseif rand <= TUNING.METEOR_CHANCE_BOULDERFLINTLESS * mod then rand = math.random() -- Randomize which flintless rock we use inst.loot = { { prefab = (rand <= .33 and "rock_flintless") or (rand <= .67 and "rock_flintless_med") or "rock_flintless_low", chance = 1, }, } else -- Don't check for chance or mod this one: we need to pick a boulder inst.loot = { { prefab = "moonrocknugget", chance = TUNING.METEOR_CHANCE_INVITEM_SOMETIMES * mod }, { prefab = "rock1", chance = 1, }, } end else -- "small" or other undefined inst.loot = {} end inst.Transform:SetScale(inst.size, inst.size, inst.size) inst.warnshadow.Transform:SetScale(inst.size, inst.size, inst.size) -- Now that we've been set to the appropriate size, go for the gusto inst.striketask = inst:DoTaskInTime(warntime, dostrike) inst.warnshadow.entity:SetParent(inst.entity) inst.warnshadow.startfn(inst.warnshadow, warntime, .33, 1) end In the section for the large items, I would like to insert this.. ... elseif rand <= 0.05 * mod then rand = math.random() -- Randomize which chessjunk inst.loot = { { prefab = (rand <= .33 and "chessjunk1") or (rand <= .67 and "chessjunk2") or "chessjunk3", chance = 1, }, } ... However, I haven't been able to figure out how to modify an existing function. Any idea? Thank you Edited May 25, 2019 by MidrealmDM Link to comment https://forums.kleientertainment.com/forums/topic/106608-mod-existing-prefab-function/ Share on other sites More sharing options...
CarlZalph Posted May 23, 2019 Share Posted May 23, 2019 A fairly straightforward method on doing this is to create a post-hook for it and do some checks for the outcome. Caveat is that if Klei updates the code to change it for whatever reason, then the code may become nonfunctional. AddPrefabPostInit the shadowmeteor prefab, and in the callback: local SetSize_old = inst.SetSize inst.SetSize = function(inst, sz, mod, ...) local retval = SetSize_old(inst, sz, mod, ...) if sz == "large" and inst.loot[1].prefab == "moonrocknugget" and math.random() <= 0.05 * mod then -- Code to edit the inst.loot table end return retval end The '...' and 'retval' are to help future proof the function in case something changes to have a return result or more parameters. It won't help if Klei edits the drop table generation internally. Link to comment https://forums.kleientertainment.com/forums/topic/106608-mod-existing-prefab-function/#findComment-1199321 Share on other sites More sharing options...
MidrealmDM Posted May 24, 2019 Author Share Posted May 24, 2019 (edited) =-=-=-=- After several test, I was able to get the chessjunk to appear!. thank you. Edited May 24, 2019 by MidrealmDM Link to comment https://forums.kleientertainment.com/forums/topic/106608-mod-existing-prefab-function/#findComment-1199619 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