Wonderlarr Posted December 7, 2020 Share Posted December 7, 2020 (edited) Hello! I'm adding a feature to my mod, where the player is able to make craftable upgrades to their character's custom gear. In the case I'm trying to add this to a Hat item. The upgrades will go in a custom slot above the item, similar to how ammo is loaded into Walter's Slingshot (See image 1 and 2). The slot appears when the item is equipped, and disappears when it isn't equipped. Image 1: Normal Hotbar Image 2: Walter Slingshot Equipped I've looked into the slingshot's prefab file and figured out how to add this slot to my own items, but I've run into a few problems: 1. The slot still only accepts Slingshot Ammo 2. How I have it written seems to crash on servers with caves enabled. 3. The slot always only appears above the Hand Slot. I don't know how I can solve the 2nd problem, but the 1st and 3rd problems I believe I could solve by coding my own container, I just have no idea how I could go about doing that. Here is the code of my prefab, which contains all the container code as well as some extra effects the Hat already does. https://pastebin.com/f9a8tJQP I hope you can help me, and I hope I wasn't too confusing trying to explain my problem. Edit: Here is my client crash log when I equip the related Hat when I wasn't the host. https://pastebin.com/rJWKmJJA Edited December 7, 2020 by TheSkylarr added crash lag Link to comment Share on other sites More sharing options...
Thomas Die Posted December 7, 2020 Share Posted December 7, 2020 if you only want the slot you probably need to make a custom ui, or reuse the one for walter's slingshot but i'd assume that'd be diffrent since it's going ontop of the hat, no? Link to comment Share on other sites More sharing options...
Thomas Die Posted December 7, 2020 Share Posted December 7, 2020 sorry i just realised how useless that was uhh gimme a sec local Vector3 = GLOBAL.Vector3 local params = {} params.hat_stuff = { widget = { slotpos = { Vector3(0, 32 + 4, 0), }, slotbg = { { image = "slingshot_ammo_slot.tex" }, }, animbank = "ui_chest_3x2", animbuild = "ui_chest_3x2", pos = Vector3(0, 15, 0), }, usespecificslotsforitems = true, type = "hand_inv", } function params.hat_stuff.itemtestfn(container, item, slot) return item:HasTag("Your_Tag") or item.prefab == "item_prefab" end local containers = GLOBAL.require("containers") containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, params.hat_stuff.widget.slotpos ~= nil and #params.hat_stuff.widget.slotpos or 0) local old_wsetup = containers.widgetsetup function containers.widgetsetup(container, prefab, data) if params[prefab or container.inst.prefab] and not data then data = params[prefab or container.inst.prefab] end old_wsetup(container, prefab, data) end Sorry i think this should make a new widget to use but i'm not entirely sure, this is from rosalinas code Link to comment Share on other sites More sharing options...
Wonderlarr Posted December 7, 2020 Author Share Posted December 7, 2020 6 hours ago, thomas4846 said: sorry i just realised how useless that was uhh gimme a sec local Vector3 = GLOBAL.Vector3 local params = {} params.hat_stuff = { widget = { slotpos = { Vector3(0, 32 + 4, 0), }, slotbg = { { image = "slingshot_ammo_slot.tex" }, }, animbank = "ui_chest_3x2", animbuild = "ui_chest_3x2", pos = Vector3(0, 15, 0), }, usespecificslotsforitems = true, type = "hand_inv", } function params.hat_stuff.itemtestfn(container, item, slot) return item:HasTag("Your_Tag") or item.prefab == "item_prefab" end local containers = GLOBAL.require("containers") containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, params.hat_stuff.widget.slotpos ~= nil and #params.hat_stuff.widget.slotpos or 0) local old_wsetup = containers.widgetsetup function containers.widgetsetup(container, prefab, data) if params[prefab or container.inst.prefab] and not data then data = params[prefab or container.inst.prefab] end old_wsetup(container, prefab, data) end Sorry i think this should make a new widget to use but i'm not entirely sure, this is from rosalinas code In this case, I'm assuming I would throw this into my modmain.lua, and specify my widget setup as hat_stuff in the component for my item? I would test it but I'm a little busy at the moment. Link to comment Share on other sites More sharing options...
Thomas Die Posted December 7, 2020 Share Posted December 7, 2020 probs, i tried something like this a while ago and it was something like that Link to comment Share on other sites More sharing options...
Wonderlarr Posted December 8, 2020 Author Share Posted December 8, 2020 7 hours ago, thomas4846 said: probs, i tried something like this a while ago and it was something like that Thanks for the guidance, this got me to a state where I it's almost where I want, but it still seems to crash with the same error on a world with caves, and doesn't show anything to do with my mod, but I know for sure it's because of it. The crash log is here.https://pastebin.com/FavMxWcX 21 minutes ago, TheSkylarr said: Thanks for the guidance, this got me to a state where I it's almost where I want, but it still seems to crash with the same error on a world with caves, and doesn't show anything to do with my mod, but I know for sure it's because of it. The crash log is here.https://pastebin.com/FavMxWcX I actually figured out how to fix this by studying some other mods. If you have a problem with containers with caves enabled servers, in your prefabs main function, add this inst.OnEntityReplicated = function(inst) inst.replica.container:WidgetSetup(WIDGET_VARIABLE) end inside the part of the function that DOESN'T run for the server, only clients. That should look similar, if not the same to this: if not TheWorld.ismastersim then return inst end Your result should look like this. What this does is replicate the right values for your container to the clients, as the clients don't look at the same variables for widgets and such things, they have their own. if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.container:WidgetSetup(WIDGET_VARIABLE) end return inst end 1 Link to comment Share on other sites More sharing options...
orlando gonzalez Posted May 19, 2021 Share Posted May 19, 2021 I like the idea of what they say but I don't understand how to do it and I need to add it to my project as well. Can you explain to me how it is done? Link to comment Share on other sites More sharing options...
Gleenus Posted May 19, 2021 Share Posted May 19, 2021 On 12/7/2020 at 12:23 AM, TheSkylarr said: Hello! I'm adding a feature to my mod, where the player is able to make craftable upgrades to their character's custom gear. In the case I'm trying to add this to a Hat item. The upgrades will go in a custom slot above the item, similar to how ammo is loaded into Walter's Slingshot (See image 1 and 2). The slot appears when the item is equipped, and disappears when it isn't equipped. Image 1: Normal Hotbar Image 2: Walter Slingshot Equipped I've looked into the slingshot's prefab file and figured out how to add this slot to my own items, but I've run into a few problems: 1. The slot still only accepts Slingshot Ammo 2. How I have it written seems to crash on servers with caves enabled. 3. The slot always only appears above the Hand Slot. I don't know how I can solve the 2nd problem, but the 1st and 3rd problems I believe I could solve by coding my own container, I just have no idea how I could go about doing that. Here is the code of my prefab, which contains all the container code as well as some extra effects the Hat already does. https://pastebin.com/f9a8tJQP I hope you can help me, and I hope I wasn't too confusing trying to explain my problem. Edit: Here is my client crash log when I equip the related Hat when I wasn't the host. https://pastebin.com/rJWKmJJA I think I have done something very similar with "rail cart" mod, where the Rail Cart Tool have a slot to place the rails Take a look if you still need some guidance Link to comment Share on other sites More sharing options...
Wonderlarr Posted May 19, 2021 Author Share Posted May 19, 2021 4 hours ago, Gleenus said: I think I have done something very similar with "rail cart" mod, where the Rail Cart Tool have a slot to place the rails Take a look if you still need some guidance That sounds like a nice example, though I ended up scrapping this feature in the end, I would still like to know how. Thank you. 1 Link to comment 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