Wonderlarr Posted July 10, 2020 Share Posted July 10, 2020 How exactly would I, for example, throw an item at wherever the cursor is inside a function? I'm trying to set up a way to throw an explosive I've modded, but only when wearing a specific hat, and pressing a key to throw it, since the hand slot takes up the normal throw key. Link to comment https://forums.kleientertainment.com/forums/topic/119956-activate-an-item-inside-a-function/ Share on other sites More sharing options...
rawii22 Posted July 12, 2020 Share Posted July 12, 2020 (edited) I would check out the orange staff section of the staff.lua prefab file since that's the first prefab I can think of that let's you cast a spell wherever your mouse is. You can later alter that action to be throw instead of cast spell. Also, you can modify the throw action to only be available if certain things are true such as if the head slot has a certain hat in it. player.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD).prefab == "myhat" for example. As for the key, just add this to modmain GLOBAL.TheInput:AddKeyUpHandler( cmd.keybind:lower():byte(), --in this context, cmd.keybind is a letter such as "c". YOU MUST DO THIS WHOLE :lower():byte THING OR IT WON'T WORK FOR SOME REASON. It wants a byte value, not just a letter weirdly. --you can literally just change cmd.keybind here to "r" (with quotes of course) or whatever letter function() if --[[the hat is on (like shown earlier) AND if the player has an explosive (or if it is equipped? however that works...)]] then --Do an action here that would not otherwise happen end end ) Also, I think these handlers don't work when caves are on or something like that, I still haven't figured out a fix, but just to be safe, test it on a normal world without caves. EDIT: Now that I think of it, you might be best served if you checked out the throwable spears mod. I'm not seeing anything in the code that will let you do a whole "throw" type of action. Staffs that let you use them anywhere only really spawn things on a specified location. You can try adopting the throwable component from that mod (and mention the creator in your description). Hopefully it won't be too hard to retrofit, maybe you can just do AddComponent("throwable"), in which case you will have to make the bomb something that you equip to the hands first. The mod really is just a component and it alters the spear a little. Edited July 12, 2020 by rawii22 Link to comment https://forums.kleientertainment.com/forums/topic/119956-activate-an-item-inside-a-function/#findComment-1353179 Share on other sites More sharing options...
Wonderlarr Posted July 12, 2020 Author Share Posted July 12, 2020 53 minutes ago, rawii22 said: I would check out the orange staff section of the staff.lua prefab file since that's the first prefab I can think of that let's you cast a spell wherever your mouse is. You can later alter that action to be throw instead of cast spell. Also, you can modify the throw action to only be available if certain things are true such as if the head slot has a certain hat in it. player.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD).prefab == "myhat" for example. As for the key, just add this to modmain GLOBAL.TheInput:AddKeyUpHandler( cmd.keybind:lower():byte(), --in this context, cmd.keybind is a letter such as "c". YOU MUST DO THIS WHOLE :lower():byte THING OR IT WON'T WORK FOR SOME REASON. It wants a byte value, not just a letter weirdly. --you can literally just change cmd.keybind here to "r" (with quotes of course) or whatever letter function() if --[[the hat is on (like shown earlier) AND if the player has an explosive (or if it is equipped? however that works...)]] then --Do an action here that would not otherwise happen end end ) Also, I think these handlers don't work when caves are on or something like that, I still haven't figured out a fix, but just to be safe, test it on a normal world without caves. EDIT: Now that I think of it, you might be best served if you checked out the throwable spears mod. I'm not seeing anything in the code that will let you do a whole "throw" type of action. Staffs that let you use them anywhere only really spawn things on a specified location. You can try adopting the throwable component from that mod (and mention the creator in your description). Hopefully it won't be too hard to retrofit, maybe you can just do AddComponent("throwable"), in which case you will have to make the bomb something that you equip to the hands first. The mod really is just a component and it alters the spear a little. I'll be taking a look at everything here, thank you for the suggestions! I'll reply back once I'm done implementing, and taking a look at throw able spears. Link to comment https://forums.kleientertainment.com/forums/topic/119956-activate-an-item-inside-a-function/#findComment-1353194 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