Sergio A V Posted November 14, 2018 Share Posted November 14, 2018 Hi everyone, I want to make an item mod that; - It's an item with, Health?, Just like a Panflute, Fire staff, etc - Can be stored in normal containers (player's inventory, chests, etc) - Can be dropped to the ground - Can be used only while it's in the player's inventory (Right click to Use), but cannot be equipped in hand, armor slot or gem slot - On use, it reactivates all deactivated tooth traps around the player (I don't know how to look for deactivated traps. components.mine.inactive maybe?) - It loses X Health after using it, but it never breaks. It should remain at 0% durability (not coded yet) I've tried it by making the remote control an instrument and an useableitem with no success, so I tried to make my own component. This is the resulting mod which won't work Trap Remote Control.rar I've seen that if I want to use ACTIONS.PLAY or ACTIONS.USEITEM I need to make my item an instrument or useableitem, so I've thought about making my own custom ACTION as well, thing I don't even know how to do. I hope you can help me with this little project so I can learn a little bit more about lua. Link to comment Share on other sites More sharing options...
Backtalker Posted December 10, 2018 Share Posted December 10, 2018 Before you read, I'm only beginning modding DS as well but I have heavy knowledge in general lua, and I don't exactly know if this'll work on my first try either. I hope it does for you though! For the 'Health', it's called durability, just so you know ;p. To get the durability, you'd use the "finiteuses" component like this, I recommend this thread to learn more about components init:AddComponent("finiteuses") init.components.finiteuses:SetMaxUses(10) init.components.finiteuses:SetUses(10) init.components.finiteuses:SetOnFinished(function(i) i:Remove() end) Although I am not too sure on how you'd make a custom degradation of the durability, my apologies. To store it in an inventory, you'd just use the "inventoryitem" component like this, I recommend this thread to learn more about how to make an item local assets = { Asset("ANIM", "anim/nameofitem.zip"), -- dropped item Asset("ATLAS", "images/inventoryimages/nameofitem.xml"), Asset("IMAGE", "images/inventoryimages/nameofitem.tex"), } -- put this at the top to load before everything init:AddComponent("inventoryitem") init.components.inventoyitem.imagename = "nameofitem" inst.components.inventoryitem.atlasname = "path/to/nameofitem.xml" You don't need to follow the swap part of it, since you don't want the remote control to be held but you will have to use spriter to make an animation to create the ground item One way you could possibly use this, is by using the instrument component from the panflute, here is the children to it that should be useful to you, Basically just change the range to however far you want the remote control to work, and I think you can make an onheard function like this inst:AddComponent("instrument") inst.components.instrument.range = 50 inst.components.instrument.onheard = function(inst) if inst.prefab == "trap_teeth" and inst.components.mine.inactive then inst.components.mine:Reset() end end This is how it would look local assets = { Asset("ANIM", "anim/nameofitem.zip"), Asset("ATLAS", "images/inventoryimages/nameofitem.xml"), Asset("ATLAS", "images/inventoryimages/nameofitem.tex"), } local prefabs = {} function fn(color) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() MakeInventoryPhysics(inst) anim:SetBank("nameofitem") anim:SetBuild("nameofitem") anim:PlayAnimation("idle") inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(10) inst.components.finiteuses:SetUses(10) inst.components.finiteuses:SetOnFinished(function(i) i:Remove() end) inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "nameofitem" inst.components.inventoryitem.atlasname = "path/to/nameofitem.xml" inst:AddComponent("instrument") inst.components.instrument.range = 50 inst.components.instrument.onheard = function(init) if init.prefab == "trap_teeth" and not init.components.mine.inactive then init.components.mine:Reset() end end return inst end return Prefab("common/inventory/nameofitem", fn, assets, prefabs) Next, you would make a file named "scripts", then a folder named "prefabs" inside scripts, then create your item as a lua file here. Now, in your modmain.lua, add local PrefabFiles = { "nameoftem" }, EDIT: I noticed I swapped between inst and init between alot of them, just use whatever variable you set in the function, my bad. This general post is pretty rough, but I hope it helps out. Here is a gif of me trying the instrument concept, and it works flawlessly Link to comment Share on other sites More sharing options...
Sergio A V Posted December 17, 2018 Author Share Posted December 17, 2018 I really appreciate all the help and effort you did trying to help me, but the Malacath guide is half wrong and I had most of the code (the easy one) already done, the thing is I don't know what am I doing wrong in the code. I'm trying to create a new component and a new action for future mods I may create, but the item won't work. Below is the current mod after I tried the malacath guide (which has a lot of mistakes). If someone has the free time to help this newbie and let me know which abysmal mistakes I did, I would appreciate it a lot. Thanks in advance. Trap Remote Control.rar Edit: I also tried the code above and it doesn't work. The item shows the "right click to play" little image but rightclicking does nothing (same problem happens with the code I made) Link to comment Share on other sites More sharing options...
Sergio A V Posted February 21, 2019 Author Share Posted February 21, 2019 ↑ 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.