• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved item:getDescription()

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
212
Hi! guys I'm trying make a script that give to player some mount using the description of an item ... look
Code:
local mounts {
    [1] = {name = 'test1', id = 1},
        [2] = {name = 'test2', id = 3},
        [3] = {name = 'test3', id = 3}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #mounts do
        if item:getDescription() == 'mounts.name' then
            local mount = mounts.name, mounts.id
            break
        end
    end
    player:addMount(mount)
    return true
end
I know that is wrong it ... but how make it works perfectly? get the description of an item and give the mount ...
it's an exemple of mine script, just to you try understand what I want...
thanks all!
<3 love you


TFS 1.2 !!!! Always!
 
I don't know what item is but hopefully this is helpful :)
Code:
local mounts {
    [1] = {name = 'test1', id = 1},
    [2] = {name = 'test2', id = 3},
    [3] = {name = 'test3', id = 3}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #mounts do
        if item:getDescription() == 'mounts[i].name' then
            player:addMount(mounts[i].id)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations!!, You have recieved a "..(mounts[i].name).." mount.")
            break
        end
    end
    return true
end
 
I don't know what item is but hopefully this is helpful :)
Code:
local mounts {
    [1] = {name = 'test1', id = 1},
    [2] = {name = 'test2', id = 3},
    [3] = {name = 'test3', id = 3}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #mounts do
        if item:getDescription() == 'mounts[i].name' then
            player:addMount(mounts[i].id)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations!!, You have recieved a "..(mounts[i].name).." mount.")
            break
        end
    end
    return true
end
not work ... I use the item and nothing happen .. no have errors in console, no message to player ;/

edit: i try some prints, the script print all, but not enter in the "if"
 
Last edited:
delete the single codes in:
Code:
if item:getDescription() == 'mounts[i].name' then

it should look like:
Code:
local mounts {
[1] = {name = 'test1', id = 1},
[2] = {name = 'test2', id = 3},
[3] = {name = 'test3', id = 3}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
for i = 1, #mounts do
if item:getDescription() == mounts[i].name then
player:addMount(mounts[i].id)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations!!, You have recieved a "..(mounts[i].name).." mount.")
break
end
end
return true
end

whats happening is you are trying to compare item:getDescription() to a string with literal value "mounts.name" so it will never execute unless the item description is mounts.name
 
not work the same way...
delete the single codes in:
Code:
if item:getDescription() == 'mounts[i].name' then

it should look like:
Code:
local mounts {
[1] = {name = 'test1', id = 1},
[2] = {name = 'test2', id = 3},
[3] = {name = 'test3', id = 3}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
for i = 1, #mounts do
if item:getDescription() == mounts[i].name then
player:addMount(mounts[i].id)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations!!, You have recieved a "..(mounts[i].name).." mount.")
break
end
end
return true
end

whats happening is you are trying to compare item:getDescription() to a string with literal value "mounts.name" so it will never execute unless the item description is mounts.name
he don't enter in "if"
 
not work the same way...

he don't enter in "if"
That is because the description of the item doesn't match the mounts.name, how many items do you know of that have a description of test1, test2 & test3?

if your goal is to compare an item name to the name in your table then this should be written something like
Code:
local mounts {
    [1] = {name = 'steel boots', id = 1, mountName =''},
    [2] = {name = 'assasin star', id = 3, mountName =''},
    [3] = {name = 'mana potion', id = 3, mountName =''}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #mounts do
        if ItemType(item.itemid):getName() == 'mounts[i].name' then
            player:addMount(mounts[i].id)
           -- since i don't know the names of the mounts i will comment this out
           --  player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations!!, You have recieved a "..(mounts[i].mountName).." mount.")
            break
        end
    end
    return true
end
 
Last edited:
That is because the description of the item doesn't match the mounts.name, how many items do you know of that have a description of test1, test2 & test3?

if your goal is to compare an item name to the name in your table then this should be written something like
Code:
local mounts {
    [1] = {name = 'steel boots', id = 1, mountName =''},
    [2] = {name = 'assasin star', id = 3, mountName =''},
    [3] = {name = 'mana potion', id = 3, mountName =''}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #mounts do
        if ItemType(item.itemid):getName() == 'mounts[i].name' then
            player:addMount(mounts[i].id)
           -- since i don't know the names of the mounts i will comment this out
           --  player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations!!, You have recieved a "..(mounts[i].mountName).." mount.")
            break
        end
    end
    return true
end
Already solved !! with another thing I create two new vars calling the string values and later compare ;3
works perfectly
 
I solved this with it
Code:
if item:hasAttribute(ITEM_ATTRIBUTE_DESCRIPTION) then
        for i = 1, #mounts do
            local text = item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            local mount = "contains a " ..mounts[i].name.. "."
            if mount == text then
                player:addMount(mounts[i].Id)
                        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Congratulations! You have recieved a ' ..(mounts[i].name).. ' mount.')
                      item:remove(1)
                break
            end
          end
    else
        player:say("Your paper contains nothing useful.", TALKTYPE_MONSTER_SAY)
    end
    return true
end
 
Back
Top