• 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!

[TFS 1.0] Equipment spy

Syryniss

Member
Joined
Feb 13, 2014
Messages
206
Reaction score
20
Hi everybody. I'm moving my test server from old 0.3.6 to 1.0 and it's still hard for me to use metamethods correctly. I have a script for equipment spy (credits: Azi [ersiu]) for 0.3.6 and I wanted to modify it a bit to work on 1.0, but it got too hard for me to handle. I will provide 2 scripts, it would be really nice if someone could correct it and possibly say what and why I did wrong.
Original
Edited by me

Error with mine edited file:
Line 51: attempt to index local item ( a nil value).
 
Hi everybody. I'm moving my test server from old 0.3.6 to 1.0 and it's still hard for me to use metamethods correctly. I have a script for equipment spy (credits: Azi [ersiu]) for 0.3.6 and I wanted to modify it a bit to work on 1.0, but it got too hard for me to handle. I will provide 2 scripts, it would be really nice if someone could correct it and possibly say what and why I did wrong.
Original
Edited by me

Error with mine edited file:
Line 51: attempt to index local item ( a nil value).

Code:
<talkaction words="/spy" separator=" " script="spy.lua" />

Code:
-- Equipment spy by Azi [ersiu] --
function getItemsInContainer(cont, sep)
    local text = ""
    local tsep = ""
    local count = ""
    for i=1, sep do
        tsep = tsep.."-"
    end
    tsep = tsep..">"
    for i=0, cont:getSize()-1 do
        local item = cont:getItem(i)
        if not item:isContainer() then
            if item.type > 0 then
                count = "("..item.type.."x)"
            end
            text = text.."\n"..tsep..item:getName().." "..count
        else
            if item.uid:getSize() > 0 then
                text = text.."\n"..tsep..item:getName()
                text = text..getItemsInContainer(item, sep+2)
            else
                text = text.."\n"..tsep..item:getName()
            end
        end
    end
    return text
end

function onSay(player, words, param, channel)
    if not player:getGroup():getAccess() then
        return true
    end
    if(param == "") then
        player:sendCancelMessage("Command requires param.")
        return TRUE
    end
    local slotName = {"Head Slot", "Amulet Slot", "Backpack Slot", "Armor Slot", "Right Hand", "Left Hand", "Legs Slot", "Feet Slot", "Ring Slot", "Ammo Slot"}
    local target = Player(param)
    if target:isPlayer() then
        local text = target:getName().."'s Equipment: "   
        for i=1, 10 do
            text = text.."\n\n"
            local item = target:getSlotItem(i)
            if item then
                if item:isContainer() then
                    text = text..slotName[i]..": "..item:getName()..getItemsInContainer(item, 1)
                else
                    text = text..slotName[i]..": "..item:getName()
                end
            else
                text = text..slotName[i]..": Empty"
            end
        end
        player:showTextDialog(6579, text)
    else
        player:sendCancelMessage("This player is not online.")
    end
    return false
end
 
Code:
<talkaction words="/spy" separator=" " script="spy.lua" />

Code:
-- Equipment spy by Azi [ersiu] --
function getItemsInContainer(cont, sep)
    local text = ""
    local tsep = ""
    local count = ""
    for i=1, sep do
        tsep = tsep.."-"
    end
    tsep = tsep..">"
    for i=0, cont:getSize()-1 do
        local item = cont:getItem(i)
        if not item:isContainer() then
            if item.type > 0 then
                count = "("..item.type.."x)"
            end
            text = text.."\n"..tsep..item:getName().." "..count
        else
            if item.uid:getSize() > 0 then
                text = text.."\n"..tsep..item:getName()
                text = text..getItemsInContainer(item, sep+2)
            else
                text = text.."\n"..tsep..item:getName()
            end
        end
    end
    return text
end

function onSay(player, words, param, channel)
    if not player:getGroup():getAccess() then
        return true
    end
    if(param == "") then
        player:sendCancelMessage("Command requires param.")
        return TRUE
    end
    local slotName = {"Head Slot", "Amulet Slot", "Backpack Slot", "Armor Slot", "Right Hand", "Left Hand", "Legs Slot", "Feet Slot", "Ring Slot", "Ammo Slot"}
    local target = Player(param)
    if target:isPlayer() then
        local text = target:getName().."'s Equipment: "  
        for i=1, 10 do
            text = text.."\n\n"
            local item = target:getSlotItem(i)
            if item then
                if item:isContainer() then
                    text = text..slotName[i]..": "..item:getName()..getItemsInContainer(item, 1)
                else
                    text = text..slotName[i]..": "..item:getName()
                end
            else
                text = text..slotName[i]..": Empty"
            end
        end
        player:showTextDialog(6579, text)
    else
        player:sendCancelMessage("This player is not online.")
    end
    return false
end
with modalwindows this would be awesome
 
Thank you very much! I tested it and it didn't work, I think you forgot about one line.
I changed:
Code:
if item.type > 0 then
count = "("..item.type.."x)"
to:
Code:
if item:getType():getType() > 0 then
count = "("..item:getType():getType().."x)"
And it works. Wouldn't done it without You, so thank you once again.

Up
I like your idea, but I'm very new to metamethods so it's far beyond my skills. I would
appreciate if someone would done that though :)
 
Back
Top