Totopon_XD Posted November 22, 2020 Share Posted November 22, 2020 so i need help with the code of my "tool"/item that can take Items from afar thats the idea but i don't know how to make it work and how to do it, The idea is simple, one item/"tool" that the character hold like any other "tool"/item, but when you "pick" any item the "tool" will take the item for you, Like the Lazy forager!, but least annoying. Link to comment Share on other sites More sharing options...
Ziro2k Posted November 27, 2020 Share Posted November 27, 2020 (edited) You will want to create a new component action to do this. It should be of type "EQUIPPED" since you want it to depend on having a particular tool equipped. First, you must define a new component file (in my example I called it "telepicker") and add it to the tool in order for the component action to trigger. Here is a basic framework I wrote for this ability. local TELEPICKUP = AddAction("TELEPICKUP", "Retrieve", function(act) --Replace "Retrieve" with whatever you want the tooltip to say. if act.target and act.invobject and act.doer and act.doer.components.inventory then act.doer.components.inventory:GiveItem(act.target, nil, act.target:GetPosition()) end return true end) TELEPICKUP.priority = 10 TELEPICKUP.distance = 36 --Same range as Lazy Forager, but you can change it to whatever you want. local PICKUP_CANT_TAGS = { "INLIMBO", "NOCLICK", "knockbackdelayinteraction", "catchable", "fire", "minesprung", "mineactive" } AddComponentAction("EQUIPPED", "telepicker", function(inst, doer, target, actions, right) --Below, "right" makes it so that the action is triggered by right clicking the mouse. Remove it if you want. if right and target and target.replica.inventoryitem and target.replica.inventoryitem:CanBePickedUp() then for i, tag in ipairs (PICKUP_CANT_TAGS) do if target:HasTag(tag) then return end end table.insert(actions, TELEPICKUP) end end) --These make the action use the "quickcastspell" animation, but if you want it to be instant then you remove these and put "TELEPICKUP.instant = true" AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(TELEPICKUP, "quickcastspell")) AddStategraphActionHandler("wilson_client", GLOBAL.ActionHandler(TELEPICKUP, "quickcastspell")) The above code will make it so that a player can right click on an item in the world that's in range while your tool is equipped, and the item will be put in their inventory. You can add your own FX to make it look nice, similar to the Lazy Forager, if you wish. Edited November 27, 2020 by Ziro2k 1 Link to comment Share on other sites More sharing options...
Totopon_XD Posted November 27, 2020 Author Share Posted November 27, 2020 1 hour ago, Ziro2k said: You will want to create a new component action to do this. It should be of type "EQUIPPED" since you want it to depend on having a particular tool equipped. First, you must define a new component file (in my example I called it "telepicker") and add it to the tool in order for the component action to trigger. Here is a basic framework I wrote for this ability. local TELEPICKUP = AddAction("TELEPICKUP", "Retrieve", function(act) --Replace "Retrieve" with whatever you want the tooltip to say. if act.target and act.invobject and act.doer and act.doer.components.inventory then act.doer.components.inventory:GiveItem(act.target, nil, act.target:GetPosition()) end return true end) TELEPICKUP.priority = 10 TELEPICKUP.distance = 36 --Same range as Lazy Forager, but you can change it to whatever you want. local PICKUP_CANT_TAGS = { "INLIMBO", "NOCLICK", "knockbackdelayinteraction", "catchable", "fire", "minesprung", "mineactive" } AddComponentAction("EQUIPPED", "telepicker", function(inst, doer, target, actions, right) --Below, "right" makes it so that the action is triggered by right clicking the mouse. Remove it if you want. if right and target and target.replica.inventoryitem and target.replica.inventoryitem:CanBePickedUp() then for i, tag in ipairs (PICKUP_CANT_TAGS) do if target:HasTag(tag) then return end end table.insert(actions, TELEPICKUP) end end) --These make the action use the "quickcastspell" animation, but if you want it to be instant then you remove these and put "TELEPICKUP.instant = true" AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(TELEPICKUP, "quickcastspell")) AddStategraphActionHandler("wilson_client", GLOBAL.ActionHandler(TELEPICKUP, "quickcastspell")) The above code will make it so that a player can right click on an item in the world that's in range while your tool is equipped, and the item will be put in their inventory. You can add your own FX to make it look nice, similar to the Lazy Forager, if you wish. Omg thank you, another question i have to put that in the (Toolname).lua? Link to comment Share on other sites More sharing options...
Ziro2k Posted November 27, 2020 Share Posted November 27, 2020 1 minute ago, Totopon_XD said: Omg thank you, another question i have to put that in the (Toolname).lua? You need to put AddComponent("telepicker") in (toolname).lua, the rest would go in modmain. Link to comment Share on other sites More sharing options...
Totopon_XD Posted November 27, 2020 Author Share Posted November 27, 2020 3 hours ago, Ziro2k said: You need to put AddComponent("telepicker") in (toolname).lua, the rest would go in modmain. oh good, Thank you again! Link to comment Share on other sites More sharing options...
Totopon_XD Posted November 28, 2020 Author Share Posted November 28, 2020 On 11/27/2020 at 2:09 PM, Ziro2k said: You need to put AddComponent("telepicker") in (toolname).lua, the rest would go in modmain. how a component is created, and where i have to put it? (sorry for all the question, i am new on modding for dst) Link to comment Share on other sites More sharing options...
Ziro2k Posted November 29, 2020 Share Posted November 29, 2020 14 hours ago, Totopon_XD said: how a component is created, and where i have to put it? (sorry for all the question, i am new on modding for dst) You create a component by defining a new lua file and putting it in scripts/components folder. You're not really using the component for anything else, so the component itself can be completely barebones. It's really just a way for the game to recognize that this component action should be associated with the item. Put the following in the new lua file: local TelePicker = Class(function(self, inst) end) return TelePicker Then name it "telepicker.lua" and put it in the folder I mentioned above. The game will automatically recognize it when you call AddComponent("telepicker"). 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