Itutorial
Excellent OT User
- Joined
- Dec 23, 2014
- Messages
- 2,326
- Solutions
- 68
- Reaction score
- 999
I am trying to create a custom item attribute system. The problem is in string.find. It is acting like it finds strings in the items description that are not there.
The count (even if the item only has 1 attribute on it says it has counted 12. It also says that the item has the attribute added already even if it doesn't. Is there some bug in string.find that I do not know about?
Lua:
local runes = {2261, 2262}
local items = {7438}
local attributes = {
[1] = "[DMG1]",
[2] = "[HP Leech1]",
[3] = "[MP Leech1]",
[4] = "[Crit Chance1]",
[5] = "[Crit Damage1]",
[6] = "[Speed1]",
[7] = "[Max HP1]",
[8] = "[Max MP1]",
[9] = "[Soul Regen1]",
[10] = "[DMG Reduce1]",
[11] = "[Extra EXP1]",
[12] = "[Loot Bonus1]"
}
local maxAttributes = 3
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not isInArray(runes, item.itemid) then return false end
if not isInArray(items, target.itemid) then return false end
local ATTR = CustomItemAttributes[item.itemid]
local text = target:getAttribute('description')
local count = 0
for i = 1, #attributes do
if string.find(text, attributes[i]) then
count = count + 1
end
end
-- Problem here --
if string.find(text, ATTR.name) then
return player:sendCancelMessage("This attribute is already added to the item.")
end
-- Problem here too --
if count >= maxAttributes then
return player:sendCancelMessage("This items slots are full. You cannot add anymore attributes.")
end
text = text.."\n"..ATTR.name.." "..ATTR.value
item:remove(1)
target:setAttribute('description', text)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have added "..ATTR.value.." "..ATTR.desc.." to the item.")
return true
end
The count (even if the item only has 1 attribute on it says it has counted 12. It also says that the item has the attribute added already even if it doesn't. Is there some bug in string.find that I do not know about?
Last edited by a moderator: