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

Lua Perfect addon lever! BIG PROBLEM...

rexgandi

Member
Joined
Oct 22, 2011
Messages
189
Reaction score
9
Hello. I use this script, but it doesn't work properly .
Action - Perfect Addon Lever! (https://otland.net/threads/perfect-addon-lever.43839/)

When I put items for citizen addon, does the hunter addon get it. What should I do to get correct? What's wrong with this code?
Please Help Me :(

1585607132854.png

(Items for Second Citizen Addon and... You arleady have Second Hunter Addon.)
1585607166823.png

Lua:
local addons = { -- addons setting
        {
        which="Second",
        name="Citizen",
        addon = 2,
        outfits = {128,136},
        storage=9100,
        items = {
            {5890, 100}, -- Chikken Feather
            {5902, 50}     -- Honey Comb
            }
        },
      
        {
        which="First",
        name="Citizen",
        addon = 1,
        outfits = {128,136},
        storage=9101,
        items = {
            {5910, 100} -- Minotaur Leather
            }
        },
      
        {
        which="Second",
        name="Hunter",
        addon = 2,
        outfits = {129,137},
        storage=9102,
        items = {
            {5876, 100}, -- Lizard Leather
            {5948, 100}     -- Red Dragon Leather
            }
        },
      
        {
        which="First",
        name="Hunter",
        addon = 1,
        outfits = {129,137},
        storage=9103,
        items = {
            {5880, 100} -- Sniper Gloves
            }
        },
      
  
    }
local config = {
    itemsPos = {1904, 1235, 6}, --  items table position
    stackpos = {1,2,3,4,5,6,7,8,9,10} -- stackpos to scan for items.
}
local addonID = 0
local getItems = 0
local timer = (timer~=nil) and timer or 0
local str=""
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isPremium(cid) == FALSE then
        doPlayerSendCancel(cid, "Sorry, only premium players may use addon lever.")
        return TRUE
    end
  
    for id,addon in ipairs(addons) do
        local needItems = #addon.items
        for i=1, #addon.items do
            for j=1,#config.stackpos do
                local getAddonItems = getThingfromPos({x=config.itemsPos[1],y=config.itemsPos[2],z=config.itemsPos[3],stackpos=config.stackpos[j]})
                if getAddonItems.itemid > 0 then
                    if addon.items[i][1] == getAddonItems.itemid and addon.items[i][2] == getAddonItems.type then
                        getItems = getItems+1
                        break
                    end
                end
            end
            if getItems == needItems then
                addonID = id
                break
            end
        end
    end
  
  
    if addonID ~= 0 then
        if getPlayerStorageValue(cid,addons[addonID].storage) == -1 then 
            for i=1,getItems do
                local getItem = getThingfromPos({x=config.itemsPos[1],y=config.itemsPos[2],z=config.itemsPos[3],stackpos=1})
                if getItem.itemid > 0 then
                    doRemoveItem(getItem.uid,getItem.type)
                else
                    break
                end
            end
            setPlayerStorageValue(cid,addons[addonID].storage,1)
            for i=1, #addons[addonID].outfits do
                doPlayerAddOutfit(cid,addons[addonID].outfits[i],addons[addonID].addon)
            end
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, You have unlocked "..addons[addonID].which.." "..addons[addonID].name.." addon!")
            doSendMagicEffect({x=config.itemsPos[1],y=config.itemsPos[2],z=config.itemsPos[3]}, CONST_ME_HITBYFIRE)
            if(item.itemid == 1945) then
                doTransformItem(item.uid, 1946)
            elseif(item.itemid == 1946) then
                doTransformItem(item.uid, 1945)
            end
        else
            doPlayerSendCancel(cid, "You arleady have "..addons[addonID].which.." "..addons[addonID].name.." addon! Or your items are not in exact quantity!!!")
        end
    else
        if (os.time()-timer) > 0 then
            timer = os.time()
            doPlayerSendCancel(cid, "Please collect items for addon and go back!")
        else
            timer = 0
            for _, i in ipairs(addons) do
                local status = (getPlayerStorageValue(cid,i.storage) == 1) and " (done) " or ""
                str=str..i.which.." "..i.name.." addon"..status..":"
                for _, j in ipairs(i.items) do
                    str=str.."\n - "..j[2].." "..getItemNameById(j[1])
                end
                str=str.."\n\n"
            end
            doShowTextDialog(cid, 6579, str)
        end
    end
    str = ""
    getItems = 0
    addonID = 0
    return TRUE
end
 
Last edited:
Back
Top