Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,339
- Solutions
- 68
- Reaction score
- 1,024
Hello everyone,
I am trying to create an onEquip that will get the stats off all worn items and print them out. The script seems to work properly on some items but not on others. Do we know of any problem in tfs that might cause this?
In the code I have registered two items. Demon shield and leather armor. When I equip the demon shield the script runs properly and I see the defense of it printed out. When I equip the leather armor nothing is printed but when I equip the demon shield again I also see the armor value included from the leather armor.
I also want to add the equip event fires 3x even though I have added the fix that should of made it only fire 1x so idk wth is up with that but it is a seperate issue.
here is the code but I don't think the issue is here.
I am trying to create an onEquip that will get the stats off all worn items and print them out. The script seems to work properly on some items but not on others. Do we know of any problem in tfs that might cause this?
In the code I have registered two items. Demon shield and leather armor. When I equip the demon shield the script runs properly and I see the defense of it printed out. When I equip the leather armor nothing is printed but when I equip the demon shield again I also see the armor value included from the leather armor.
I also want to add the equip event fires 3x even though I have added the fix that should of made it only fire 1x so idk wth is up with that but it is a seperate issue.
Code:
Armor: 0 Defense: 21
Armor: 0 Defense: 21
Armor: 0 Defense: 56
here is the code but I don't think the issue is here.
Lua:
local moveeventEquip = MoveEvent()
moveeventEquip:type("equip")
local slots = {
CONST_SLOT_HEAD,
CONST_SLOT_NECKLACE,
CONST_SLOT_ARMOR,
CONST_SLOT_RIGHT,
CONST_SLOT_LEFT,
CONST_SLOT_LEGS,
CONST_SLOT_FEET,
CONST_SLOT_RING
}
function moveeventEquip.onEquip(player, item, slot, isCheck)
if not player then return true end
local armor = 0
local defense = 0
local dodge = 0
local block = 0
for i = 1, #slots do
local slotItem = player:getSlotItem(slots[i])
if slotItem then
local slotItemArmor = slotItem:getArmor()
local slotItemDefense = slotItem:getDefense()
-- Add dodge, and block
if slotItemArmor then armor = armor + slotItemArmor end
if slotItemDefense then defense = defense + slotItemDefense end
end
end
print("Armor: "..armor)
print("Defense: "..defense)
return true
end
local items = {2520, 2467}
for i = 1, #items do
moveeventEquip:id(items[i])
end
moveeventEquip:register()
Last edited: