• 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 Addon System

cosmopolitan

Well-Known Member
Joined
Sep 16, 2012
Messages
46
Reaction score
66
Hello everyone, can anyone tell me what is wrong with this script? I keep getting the error

'end' expected <to close 'for' at line 19> near ' <eof>

Here's the script:

local outfitmale = 145
local outfitfemale = 149
local addons = 1


function onUse(cid, item, item2,item3, item 4, frompos, topos, pos)
local config = {
["Wizard Helmet Addon"] = {t1=2536,t2=2492,t3=2488,t4=2123},
}

local r1 = {x = 182, y = 262, z = 9, stackpos= 2} -- Position 1 ( NãO MEXA NO stackpos= 2 )
local r2 = {x = 183, y = 262, z = 9, stackpos= 2} -- Position 2 ( NãO MEXA NO stackpos= 2 )
local r3 = {x = 185, y = 262, z = 9, stackpos= 2} -- Position 3 ( NãO MEXA NO stackpos= 2 )
local r4 = {x = 186, y = 262, z = 9} -- Position 4

local q1 = getThingfromPos(r1)
local q2 = getThingfromPos(r2)
local q3 = getThingfromPos(r3)
local q4 = getThingfromPos(r4)
for i, x in pairs(config) do
if (q1.itemid == x.t1 and q2.itemid == x.t2 and q3.itemid == x.t3 and q4.itemid == x.t4) then
doRemoveItem(q1.uid, 1)
doRemoveItem(q2.uid, 1)
doRemoveItem(q3.uid, 1)
doRemoveItem(q4.uid, 1)
if getPlayerStorageValue(cid, storage) == -1 then
doPlayerAddOutfit(cid, outfitmale, addons)
doPlayerAddOutfit(cid, outfitfemale, addons)
doPlayerSendTextMessage(cid, 21, "You just earned the helmet of the Wizard outfit!")
doSendMagicEffect(getCreaturePosition(cid), 28)
setPlayerStorageValue(cid, storage, 1)
else
doPlayerSendCancel(cid, "You already have this addon.")
end
return true
end

Basically the player put the items ({t1=2536,t2=2492,t3=2488,t4=2123}) on a coal basin at the position set up there, uses a stone and get the addon, that's what I wanted to do.
Thanks everyone!
 
You should indent your code to make it easier to read.
Code:
local outfitmale = 145
local outfitfemale = 149
local addons = 1


function onUse(cid, item, item2,item3, item 4, frompos, topos, pos)
    local config = {
        ["Wizard Helmet Addon"] = {t1=2536,t2=2492,t3=2488,t4=2123},
    }

    local r1 = {x = 182, y = 262, z = 9, stackpos= 2} -- Position 1 ( NãO MEXA NO stackpos= 2 )
    local r2 = {x = 183, y = 262, z = 9, stackpos= 2} -- Position 2 ( NãO MEXA NO stackpos= 2 )
    local r3 = {x = 185, y = 262, z = 9, stackpos= 2} -- Position 3 ( NãO MEXA NO stackpos= 2 )
    local r4 = {x = 186, y = 262, z = 9} -- Position 4

    local q1 = getThingfromPos(r1)
    local q2 = getThingfromPos(r2)
    local q3 = getThingfromPos(r3)
    local q4 = getThingfromPos(r4)
    for i, x in pairs(config) do
        if (q1.itemid == x.t1 and q2.itemid == x.t2 and q3.itemid == x.t3 and q4.itemid == x.t4) then
            doRemoveItem(q1.uid, 1)
            doRemoveItem(q2.uid, 1)
            doRemoveItem(q3.uid, 1)
            doRemoveItem(q4.uid, 1)
            if getPlayerStorageValue(cid, storage) == -1 then
                doPlayerAddOutfit(cid, outfitmale, addons)
                doPlayerAddOutfit(cid, outfitfemale, addons)
                doPlayerSendTextMessage(cid, 21, "You just earned the helmet of the Wizard outfit!")
                doSendMagicEffect(getCreaturePosition(cid), 28)
                setPlayerStorageValue(cid, storage, 1)
            else
                doPlayerSendCancel(cid, "You already have this addon.")
            end
        return true
        end

You can clearly see here that you are missing an end statement, actually... It appears you are missing 2 end statements.
Code:
local outfitmale = 145
local outfitfemale = 149
local addons = 1


function onUse(cid, item, item2,item3, item 4, frompos, topos, pos)
    local config = {
        ["Wizard Helmet Addon"] = {t1=2536,t2=2492,t3=2488,t4=2123},
    }

    local r1 = {x = 182, y = 262, z = 9, stackpos= 2} -- Position 1 ( NãO MEXA NO stackpos= 2 )
    local r2 = {x = 183, y = 262, z = 9, stackpos= 2} -- Position 2 ( NãO MEXA NO stackpos= 2 )
    local r3 = {x = 185, y = 262, z = 9, stackpos= 2} -- Position 3 ( NãO MEXA NO stackpos= 2 )
    local r4 = {x = 186, y = 262, z = 9} -- Position 4

    local q1 = getThingfromPos(r1)
    local q2 = getThingfromPos(r2)
    local q3 = getThingfromPos(r3)
    local q4 = getThingfromPos(r4)
    for i, x in pairs(config) do
        if (q1.itemid == x.t1 and q2.itemid == x.t2 and q3.itemid == x.t3 and q4.itemid == x.t4) then
            doRemoveItem(q1.uid, 1)
            doRemoveItem(q2.uid, 1)
            doRemoveItem(q3.uid, 1)
            doRemoveItem(q4.uid, 1)
            if getPlayerStorageValue(cid, storage) == -1 then
                doPlayerAddOutfit(cid, outfitmale, addons)
                doPlayerAddOutfit(cid, outfitfemale, addons)
                doPlayerSendTextMessage(cid, 21, "You just earned the helmet of the Wizard outfit!")
                doSendMagicEffect(getCreaturePosition(cid), 28)
                setPlayerStorageValue(cid, storage, 1)
            else
                doPlayerSendCancel(cid, "You already have this addon.")
            end
        end -- Missing from previous code
    end -- Missing from previous code
    return true
end
 
Thanks for the help! But I'm still having some trouble, the script does not work! I click on the stone and nothing happens. I already have the actions.xml with the uniqueid on it and also the stone on the map with the same unique id.

That"s the script I'm using

Code:
local config = {
  ["Wizard Helmet Addon"] = {
      storage = 21000,
      outfit = {
        sex = {
            [0] = 149, -- Sex 0
            [1] = 145, -- Sex 1
        },
        addons = 1
      },
      items = {
        [2536] = {count = 1, pos = {x = 182, y = 262, z = 9}}, -- [Item1] = {posição 1}
        [2492] = {count = 1, pos = {x = 183, y = 262, z = 9}}, -- [Item2] = {posição 2}
        [2488] = {count = 1, pos = {x = 185, y = 262, z = 9}}, -- [Item3] = {posição 3}
        [2123] = {count = 1, pos = {x = 186, y = 262, z = 9}}, -- [Item4] = {posição 4}
      }
      -- Caso tenha a necessidade de usar mais itens é só ir adicionando mais à tabela
  },
}
function onUse(cid, item, frompos, item2, topos, pos)
  for i, v in pairs(config) do
      local ok = true
      for item_id, c in pairs(v.items) do
        local item = getTileItemById(c.pos, item_id)
        if item.uid < 100 or item.type < c.count then
            ok = false
            break
        end
      end
      if ok then
        if getPlayerStorageValue(cid, v.storage) > 0 then
            return doPlayerSendCancel(cid, "You already have this addon.")
        end
        for item_id, c in pairs(v.items) do
            local item = getTileItemById(c.pos, item_id)
            doRemoveItem(item.uid, c.count)
            doSendMagicEffect(c.pos, 6)
        end
        setPlayerStorageValue(cid, v.storage, 1)
        doPlayerSendTextMessage(cid, 21, "You just earned the ".. i ..".")
        doSendMagicEffect(getThingPos(cid), 28)
        doPlayerAddOutfit(cid, v.outfit.sex[getPlayerSex(cid)], v.outfit.addons)
        return true
      end
  end
  return true
end
 
Back
Top