Commex Posted August 14, 2015 Share Posted August 14, 2015 Hello, I have an idea for a mod to add a new trinket into the game but I am not sure how I would go about doing this. I'm creating a character mod and want to add a trinket you could dig up in graves. Curious to what I would add to my modmain and such. Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/57060-new-trinket/ Share on other sites More sharing options...
UnionGaming Posted August 14, 2015 Share Posted August 14, 2015 < Why skins should exist XD Jokes aside, if you take a look at the current trinkets' prefabs, and the pig king prefab, it shouldn't be hard to do, I will try it later. Link to comment https://forums.kleientertainment.com/forums/topic/57060-new-trinket/#findComment-663264 Share on other sites More sharing options...
Commex Posted August 14, 2015 Author Share Posted August 14, 2015 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. Link to comment https://forums.kleientertainment.com/forums/topic/57060-new-trinket/#findComment-663355 Share on other sites More sharing options...
UnionGaming Posted August 14, 2015 Share Posted August 14, 2015 Not actually sure. http://forums.kleientertainment.com/user/390644-mobbstar/ is the most likely person to help you. Yeah, I don't know how you tag people. Link to comment https://forums.kleientertainment.com/forums/topic/57060-new-trinket/#findComment-663419 Share on other sites More sharing options...
Zackreaver Posted August 15, 2015 Share Posted August 15, 2015 (edited) That code is for making the trinket prefabs, which go by the name of trinket_1, trinket_2, trinket_3NUM_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 thelocal function MakeTrinket(num)endand 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 thislocal ret = {}for k = 1, NUM_TRINKETS do table.insert(ret, MakeTrinket(k))endand in your modmain, at the PrefabFiles section near the topPrefabFiles = { "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)) endWhat 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 thisif 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)endThis 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 August 15, 2015 by Zackreaver Link to comment https://forums.kleientertainment.com/forums/topic/57060-new-trinket/#findComment-663536 Share on other sites More sharing options...
Commex Posted August 15, 2015 Author Share Posted August 15, 2015 Thanks, about to test that method out. Link to comment https://forums.kleientertainment.com/forums/topic/57060-new-trinket/#findComment-663603 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