RomanticRedGeek Posted May 8, 2015 Share Posted May 8, 2015 So, the long and short of it is I'm a first time modder and I'm making a custom Character. The character himself is mostly done, some small graphics tweaking and setting up his lua with custom stats is about all that's left. The next thing I want to do with this character is create a custom item for him. Far warning: I may be a bit overzealous on the ambitions for said item but the answer's no unless you ask. The premise of the item is that it is a bag, similar to a backpack with a VERY large carrying capacity. However, it is also similar to a hand-held item as I want him to be able to pickup the bag and carry it with his hands. I don't want the bag to be accessible unless it's on the ground, like a chest. The reason for this is I want to balance out such a huge carrying capacity with some offsets like not being able to open it up and use it unless it's on the ground as well as not actually being able to keep it in your inventory (to keep it from becoming a bag within a bag. Also, I don't even know if that part will be possible). The bag itself will be indestructible and emit a small amount of light, similar to Willow's fire (It's a magic bag after all) that can't be put out by the hands. It's going to have a very simple sprite, opened and closed, similar to the chest, but I haven't started working on the graphics for it yet until I finish my character. Let me know your thoughts and where I need to start on this undertaking. Like I said I don't know if it's possible to make an item with all of the qualities I want. Thank you for your help!! Link to comment Share on other sites More sharing options...
Mobbstar Posted May 8, 2015 Share Posted May 8, 2015 Sure sounds like a strange item. The following is my opinion on how to do the unique code, featuring links to the Unofficial DS API Documentation with respective articles (they're good if you can't understand the actual lua scripts well yet). If you add the container component and don't set an overflow (like the backpacks do), it won't quite suffice to disable the HUD when equipped, but at least prevent auto-stashing. For the rest, you can listen for the events "ondropped" and "onpickup" to toggle canbeopened (Ideally force-close the container when picked up). Also, here's an article on light. Take other items as examples for the properties. You should enable the light whenever it's dropped or equipped (there's an event for that too), and disable un-enable it when picked up or unequipped. Link to comment Share on other sites More sharing options...
RomanticRedGeek Posted May 8, 2015 Author Share Posted May 8, 2015 Thank you for getting me started in the right direction! Sure sounds like a strange item. It sure is lol Link to comment Share on other sites More sharing options...
RomanticRedGeek Posted May 18, 2015 Author Share Posted May 18, 2015 If you add the container component and don't set an overflow (like the backpacks do), it won't quite suffice to disable the HUD when equipped, but at least prevent auto-stashing. For the rest, you can listen for the events "ondropped" and "onpickup" to toggle canbeopened (Ideally force-close the container when picked up). How would that work out exactly? I had this and the game freaked out so I'm sure I'm not writing it out correctly. inst:ListenForEvent("ondropped", canbeopened = true) inst:ListenForEvent("onpickup", canbeopened = false) Link to comment Share on other sites More sharing options...
Blueberrys Posted May 18, 2015 Share Posted May 18, 2015 @RomanticRedGeeklocal function function_to_run(inst, data) -- data table contains information depending on eventendinst:ListenForEvent("event_name", function_to_run) Link to comment Share on other sites More sharing options...
RomanticRedGeek Posted May 24, 2015 Author Share Posted May 24, 2015 Is it supposed to be like this? Is there anything else I need for the coding to work in the lua?local function fn(Sim) local inst = CreateEntity() [...] inst:ListenForEvent("ondropped", canbeopened = true) return instendlocal function fn(Sim) local inst = CreateEntity() [...] inst:ListenForEvent("onpickup", canbeopened = false) return instend Link to comment Share on other sites More sharing options...
Mobbstar Posted May 24, 2015 Share Posted May 24, 2015 Is it supposed to be like this? Is there anything else I need for the coding to work in the lua?local function fn(Sim) local inst = CreateEntity() [...] inst:ListenForEvent("ondropped", canbeopened = true) return instendlocal function fn(Sim) local inst = CreateEntity() [...] inst:ListenForEvent("onpickup", canbeopened = false) return instend Why do you make two functions? Are you going to make two items or don't you know what functions are? Put the two "ListenForEvent"s right next to each other. Link to comment Share on other sites More sharing options...
RomanticRedGeek Posted May 24, 2015 Author Share Posted May 24, 2015 I don't know what the functions are. I have no idea how to write it. Link to comment Share on other sites More sharing options...
Blueberrys Posted May 24, 2015 Share Posted May 24, 2015 @RomanticRedGeek You've got a lot to learn about functions and function syntax. Please read a little more on that. It's difficult to help with complex problems without a solid understanding of basic concepts. Ideally, you will be able to tell what's wrong with this line.inst:ListenForEvent("ondropped", canbeopened = true)Keep in mind that the syntax I provided was as such:inst:ListenForEvent("event_name", function_to_run) Link to comment Share on other sites More sharing options...
RomanticRedGeek Posted May 24, 2015 Author Share Posted May 24, 2015 This is where I am at currently. I've managed to have it lighted at all times, when equipped and when on the ground. I will lessen the intensity however. The plan is that when the bag is open, it will produce the amount of light currently because of the "magic" inside of it. I've managed to get the bag to not be able to be opened when held and not be able to go into the inventory, but it doesn't open when it's on the ground. I do have an open, idle_open, and close animation already setup in spriter. I included the inst:ListenForEvent("ondropped", canbeopened = true) inst:ListenForEvent("ondropped", canbeopened = true) codes and showed where I put it in, but it broke my game. It made my entire UI disappear when I spawned the item. When I turned off the can't be opened on equip the bag is able to be opened with my custom container image and the custom animations show when I drop the item but it's glitchy so I know it's working to some extent. I'm the kind of person that needs to reverse engineer something. If I can see how it works, when it's functional, I can understand it. The fact that nothing like this exists is what's challenging. I have been taking bits and pieces from TONS of mods and trying to learn how they work. That's the way I learn coding. local assets={ Asset("ANIM", "anim/mbag.zip"), Asset("ANIM", "anim/swap_mbag.zip"), Asset("ANIM", "anim/ui_chest_3x3.zip"), Asset("ATLAS", "images/inventoryimages/mbag.xml"), Asset("IMAGE", "images/inventoryimages/mbag.tex"),}prefabs = {} local function onopen(inst) inst.AnimState:PlayAnimation("open") inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_open", "open")end local function onclose(inst) inst.AnimState:PlayAnimation("close") inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_close", "open") end local slotpos = {}for y = 2, 0, -1 do for x = 0, 2 do table.insert(slotpos, Vector3(80*x-80*2+80, 80*y-80*2+80,0)) endendlocal function fn() local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_mbag", "swap_mbag") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") inst.components.container.canbeopened = false inst.Light:Enable(true) end local function OnUnequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") inst.Light:Enable(true) end local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) anim:SetBank("mbag") anim:SetBuild("mbag") anim:PlayAnimation("idle") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "mbag" inst.components.inventoryitem.atlasname = "images/inventoryimages/mbag.xml" inst.components.inventoryitem.cangoincontainer = false inst.components.inventoryitem.foleysound = "dontstarve/movement/foley/backpack" inst:AddComponent("container") inst.components.container:SetNumSlots(#slotpos) inst.components.container.widgetslotpos = slotpos inst.components.container.widgetanimbank = "ui_chest_3x3" inst.components.container.widgetanimbuild = "ui_chest_3x3" inst.components.container.widgetpos = Vector3(0,200,0) inst.components.container.side_align_tip = 160 inst.components.container.type = "pack" inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose inst:AddComponent("equippable") inst.components.equippable:SetOnEquip( OnEquip ) inst.components.equippable:SetOnUnequip( OnUnequip ) inst:ListenForEvent("ondropped", canbeopened = true) inst:ListenForEvent("onpickup", canbeopened = false)--Lightinst.entity:AddLight() --light is not a component inst.Light:SetColour(255/255, 2555/255, 0/255) --clever way you can use the rgb-systeminst.Light:SetIntensity(0.6) inst.Light:SetRadius(3) inst.Light:SetFalloff(.9) return instend Link to comment Share on other sites More sharing options...
Mobbstar Posted May 24, 2015 Share Posted May 24, 2015 This is where I am at currently. I've managed to have it lighted at all times, when equipped and when on the ground. I will lessen the intensity however. The plan is that when the bag is open, it will produce the amount of light currently because of the "magic" inside of it. I've managed to get the bag to not be able to be opened when held and not be able to go into the inventory, but it doesn't open when it's on the ground. I do have an open, idle_open, and close animation already setup in spriter. I included the inst:ListenForEvent("ondropped", canbeopened = true) inst:ListenForEvent("ondropped", canbeopened = true) codes and showed where I put it in, but it broke my game. It made my entire UI disappear when I spawned the item. When I turned off the can't be opened on equip the bag is able to be opened with my custom container image and the custom animations show when I drop the item but it's glitchy so I know it's working to some extent. I'm the kind of person that needs to reverse engineer something. If I can see how it works, when it's functional, I can understand it. The fact that nothing like this exists is what's challenging. I have been taking bits and pieces from TONS of mods and trying to learn how they work. That's the way I learn coding. ListenForEvent asks for a function as the second parameter. You need to make either a local function somewhere above and pass it onto ListenForEvent... e.g.:local function OnDropped(inst) --that is a function (means the same as "local OnDropped = function(inst)" inst.components.container.canbeopened = true --go to the container component, then tell it to unlockend --that signals the end of a function, loop or if-statement [...] inst:ListenForEvent("ondropped",OnDropped) --same name ...or make an unnamed function straight in ListenForEvent. (Using that method, you can skip the "inst" parameter in the function because all variables from the parent functions are passed on. It is not the ideal way to do it, but good enough for this application.) e.g.:inst:ListenForEvent("ondropped",function() --the function is only available to ListenForEvent in this case inst.components.container.canbeopened = true --go to the container component, then tell it to unlockend) --remember to close the function with "end" and ListenForEvent with a bracket Link to comment Share on other sites More sharing options...
RomanticRedGeek Posted May 24, 2015 Author Share Posted May 24, 2015 Yeah it's not working I wonder if it's because I have the item setup to model a hand-equipped item and it needs to be modeled more like the treasurechest? Or maybe Chester? Maybe I need to setup states in a stategraph that would change it's demographics from a structure to an item? Do you guys know of any other modded item being able to do this? I can open the chest when he's holding it by right clicking on it and hitting open, but when I drop it on the ground it only ever gives me the option to pick it back up. Link to comment Share on other sites More sharing options...
Corrosive Posted May 26, 2015 Share Posted May 26, 2015 I don't think demographics is the word you're looking for there o.O http://en.m.wikipedia.org/wiki/Demographics Also there isn't a difference between a structure and an item. Something could be both. But that's not anything that the stategraph has to do with. Link to comment Share on other sites More sharing options...
RomanticRedGeek Posted May 28, 2015 Author Share Posted May 28, 2015 I know the word I used didn't exactly meet the context. I swear I'm never going to figure this thing out. Link to comment Share on other sites More sharing options...
Corrosive Posted May 28, 2015 Share Posted May 28, 2015 @RomanticRedGeek, It might seem like "meh, effort" now, but if you take some time to learn about Lua fundamentals, it'll save you a ton of time in the long run. When you can understand what things are doing and how they're interacting, it's so much easier to understand how you need to do it. Link to comment Share on other sites More sharing options...
RedRock911 Posted May 29, 2015 Share Posted May 29, 2015 @RomanticRedGeek, When you can understand what things are doing and how they're interacting. I soooooo wish I would hurry up and do that. in saying that, Saiai, a modder here, pointed me to THIS website. And it has helped immensely. And it explains basic programing fairly easy, with tutorials and everything. I still need help with very basic script writing, but I can say, I can now trouble shoot most of my problems now, without asking for too much help. Other then of course my current situation, where I kind of just gaze at my prefabs lua, to my folders, and back again, hoping that some how I can see the relationship of why my mod isnt working. But that's only because it's a somewhat advanced task, and I just havent learned the right answer just yet. But Corrosive is right, you have to read up on it regardless. It will help you gain some experiance Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.