Jump to content

Recommended Posts

I stole a bunch of code from the games trinkets.lua but nothing is happening.

Would i have to change the local function to a global function to overwrite the game script?

 

Code:

local assets={    Asset("ANIM", "anim/ground_bobblehead.zip"),    Asset("ATLAS", "images/inventoryimages/bobblehead.xml"),    Asset("IMAGE", "images/inventoryimages/bobblehead.tex"),}prefabs = {}local function MakeTrinket(num)    local function fn()        local inst = CreateEntity()        local inst = CreateEntity()        local trans = inst.entity:AddTransform()        local anim = inst.entity:AddAnimState()        local sound = inst.entity:AddSoundEmitter()        MakeInventoryPhysics(inst)        anim:SetBank("trinkets")        anim:SetBuild("trinkets")        inst.AnimState:PlayAnimation(tostring(num))        inst.entity:SetPristine()        if not TheWorld.ismastersim then            return inst        end        inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")        inst.components.inventoryitem.imagename = "Bobble Head"        inst.components.inventoryitem.atlasname = "images/inventoryimages/bobblehead.xml"        inst:AddComponent("stackable")        inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM        inst:AddComponent("tradable")        inst.components.tradable.goldvalue = TUNING.GOLD_VALUES.TRINKETS[num] or 3        return inst    end  return  Prefab("common/inventory/bobblehead", fn, assets, prefabs)endlocal ret = {}for k = 1, NUM_TRINKETS do    table.insert(ret, MakeTrinket(k))end

 

I tried debug spawn with the above code and nothing happened. Wondering how to fix this.

That code is for making the trinket prefabs, which go by the name of trinket_1, trinket_2, trinket_3

NUM_TRINKETS is just 27, it's normally used to give each of the trinkets the numbers they need.

 

If you want your bobblehead to work, remove the

local function MakeTrinket(num)

end

and just make it

 local function fn()        local inst = CreateEntity()        local trans = inst.entity:AddTransform()        local anim = inst.entity:AddAnimState()        local sound = inst.entity:AddSoundEmitter()        MakeInventoryPhysics(inst)         anim:SetBank("trinkets")--Change this to your bobbleheads bank name        anim:SetBuild("trinkets")--Change this to your bobbleheads build name        inst.AnimState:PlayAnimation("10") --Change this to your bobbleheads animation name        inst.entity:SetPristine()         if not TheWorld.ismastersim then            return inst        end         inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")        inst.components.inventoryitem.imagename = "bobblehead"        inst.components.inventoryitem.atlasname = "images/inventoryimages/bobblehead.xml"        inst:AddComponent("stackable")        inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM        inst:AddComponent("tradable")        inst.components.tradable.goldvalue = TUNING.GOLD_VALUES.TRINKETS[num] or 3         return inst     end   return  Prefab("common/inventory/bobblehead", fn, assets, prefabs)

Also get rid of this

local ret = {}for k = 1, NUM_TRINKETS do    table.insert(ret, MakeTrinket(k))end

and in your modmain, at the PrefabFiles section near the top

PrefabFiles = {	"bobblehead",}

I believe you'd have to postinit the "mound" prefab in order to get your bobble head to come out of it. I'm not sure if there is an easier way, but the "mound" prefab specifically checks for this

            if math.random() < .5 then                item = weighted_random_choice(LOOTS)            else                item = "trinket_"..tostring(math.random(NUM_TRINKETS))            end

What you could try is changing your "bobblehead" prefab's name to "trinket_28"

and make GLOBAL.NUM_TRINKETS = 28.

 

But if that doesn't work, you can try this

if GLOBAL.TheNet:GetIsServer() then	AddPrefabPostInit("mound",function(inst)		local old = inst.components.workable.onfinish		local new = function (inst, worker)			if worker ~= nil then				if worker.components.inventory ~= nil then					local item = nil					if math.random() < .1 then						item = "bobblehead"					end					if item ~= nil then						inst.components.lootdropper:SpawnLootPrefab(item)					end				end			end            if old then                old(inst,worker)            end		end		inst.components.workable:SetOnFinishCallback(new)	end)end

This makes mounds have a 10% chance to drop the bobblehead... ALONG with the other loot you'll get from a grave. This way you don't overwrite any changes that grave's get in patches. I'm sure there's a better way to do this, but I haven't tested any of it.

 

Edited by Zackreaver

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