Hi. Im trying to write a new script for upgrading an item.
I have this in my global.lua:
And this is my script attached to in-game item:
Everytime I use script it returns:
16:48 item_attribute_name: jacket
16:48 item:getname: jacket
Why does it happen? item attribute name and name seems to be the same, so why a~=b is true?
I have this in my global.lua:
Code:
function getItemAttribute(uid, key)
local i = ItemType(Item(uid):getId())
local string_attributes = {
[ITEM_ATTRIBUTE_NAME] = i:getName(),
[ITEM_ATTRIBUTE_ARTICLE] = i:getArticle(),
[ITEM_ATTRIBUTE_PLURALNAME] = i:getPluralName(),
["name"] = i:getName(),
["article"] = i:getArticle(),
["pluralname"] = i:getPluralName()
}
local numeric_attributes = {
[ITEM_ATTRIBUTE_WEIGHT] = i:getWeight(),
[ITEM_ATTRIBUTE_ATTACK] = i:getAttack(),
[ITEM_ATTRIBUTE_DEFENSE] = i:getDefense(),
[ITEM_ATTRIBUTE_EXTRADEFENSE] = i:getExtraDefense(),
[ITEM_ATTRIBUTE_ARMOR] = i:getArmor(),
[ITEM_ATTRIBUTE_HITCHANCE] = i:getHitChance(),
[ITEM_ATTRIBUTE_SHOOTRANGE] = i:getShootRange(),
["weight"] = i:getWeight(),
["attack"] = i:getAttack(),
["defense"] = i:getDefense(),
["extradefense"] = i:getExtraDefense(),
["armor"] = i:getArmor(),
["hitchance"] = i:getHitChance(),
["shootrange"] = i:getShootRange()
}
local attr = Item(uid):getAttribute(key)
if tonumber(attr) then
if numeric_attributes[key] then
return attr ~= 0 and attr or numeric_attributes[key]
end
else
if string_attributes[key] then
if attr == "" then
return string_attributes[key]
end
end
end
return attr
end
function doItemSetAttribute(uid, key, value)
return Item(uid):setAttribute(key, value)
end
function doItemEraseAttribute(uid, key)
return Item(uid):removeAttribute(key)
end
And this is my script attached to in-game item:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
cid = player:getId()
itemEx = target
local it = ItemType(itemEx.itemid)
local a = it.getName();
local b = getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_NAME);
if( a ~= b )then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "item_attribute_name: "..getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_NAME))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "item:getname: "..it:getName())
end
Everytime I use script it returns:
16:48 item_attribute_name: jacket
16:48 item:getname: jacket
Why does it happen? item attribute name and name seems to be the same, so why a~=b is true?