Gokiburi Posted December 31, 2015 Share Posted December 31, 2015 (edited) I want to create a character which will have increased speed when not holding an tool or weapon or the likes in the hands equipment slot but have no idea how to check if it is holding something. Searched the internet for a while now but couldn't find a thing. What I currently tried was:inst:ListenForEvent("equip", function(inst, data) if data.weapon == nil then print("I am NOT holding a weapon.")end if data.weapon ~= nil then print("I AM holding a weapon.")end end)inst:ListenForEvent("unequip", function(inst, data)if data.weapon == nil then print("I am NOT holding a weapon.")endif data.weapon ~= nil then print("I AM holding a weapon.")end end)But the data.weapon doesn't work so it just thinks it is never holding anything.If someone could help me out than that would be much appreciated. Edited January 2, 2016 by Gokiburi Link to comment https://forums.kleientertainment.com/forums/topic/61646-how-to-check-if-character-is-holding-an-equipment/ Share on other sites More sharing options...
Gokiburi Posted January 1, 2016 Author Share Posted January 1, 2016 (edited) Figured it out here's the final code I got if someone else is struggling with it local function withoutWeaponsF(inst) print("I am NOT holding anything.")endlocal function withWeaponsF(inst) print("I AM holding something.")endlocal fn = function(inst) inst:ListenForEvent("equip", function(inst, data) if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) == nil then withoutWeaponsF(inst) end if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) ~= nil then withWeaponsF(inst) end end) inst:ListenForEvent("unequip", function(inst, data) if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) == nil then withoutWeaponsF(inst) end if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) ~= nil then withWeaponsF(inst) end end)end Edited January 2, 2016 by Gokiburi Link to comment https://forums.kleientertainment.com/forums/topic/61646-how-to-check-if-character-is-holding-an-equipment/#findComment-704096 Share on other sites More sharing options...
Blueberrys Posted January 1, 2016 Share Posted January 1, 2016 (edited) The equip and unequip events' data contain an eslot (equip slot) variable.local function equippedWeapon() -- ...endlocal function unequippedWeapon() -- ...endinst:ListenForEvent("equip", function(inst, data) if data.eslot == EQUIPSLOTS.HANDS then equippedWeapon() endend)inst:ListenForEvent("unequip", function(inst, data) if data.eslot == EQUIPSLOTS.HANDS then unequippedWeapon() endend) Edited January 3, 2016 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/61646-how-to-check-if-character-is-holding-an-equipment/#findComment-704229 Share on other sites More sharing options...
Gokiburi Posted January 2, 2016 Author Share Posted January 2, 2016 (edited) Tx, that seems a bit cleaner Edit: Hmmm, seems to be crashing if I do it like that. Edited January 2, 2016 by Gokiburi Link to comment https://forums.kleientertainment.com/forums/topic/61646-how-to-check-if-character-is-holding-an-equipment/#findComment-704411 Share on other sites More sharing options...
Blueberrys Posted January 3, 2016 Share Posted January 3, 2016 @Gokiburi Whoops, it's probably cause I used one equal sign instead of two. Fixed it now.Next time, please provide your log as well. It helps in figuring out why the crash occurred. Link to comment https://forums.kleientertainment.com/forums/topic/61646-how-to-check-if-character-is-holding-an-equipment/#findComment-704768 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