Jump to content

Recommended Posts

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 by Gokiburi

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.")end
local 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 by Gokiburi

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 by Blueberrys

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...