• 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 Beginner Tutorial

I'm glad you guys liked it and learned something from it :)

If i wouldn't be that busy, I would have finished up the Advanced Tutorial already but I'll prolly do that within a few days ;)


kind regards, Evil Hero
 
i think i still doesnt know where to put "end" and "return"
whats wrong with this script?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local container = 0
    local cost = 20000
    local potion_id = 2273
    local backpack_id = 2000
    if item.uid == 10203 and item.itemid == 1740 then
            container = doPlayerAddItem(cid, backpack_id, 1)
            for i = 1, 20 do
                doAddContainerItem(container, potion_id, 2268, 2294)
            end
return TRUE
end
i get a "end" error :confused:
 
it would be good if you could fix so you can buy promotion instead of having it when you start
 
i think i still doesnt know where to put "end" and "return"
whats wrong with this script?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local container = 0
    local cost = 20000
    local potion_id = 2273
    local backpack_id = 2000
    if item.uid == 10203 and item.itemid == 1740 then
            container = doPlayerAddItem(cid, backpack_id, 1)
            for i = 1, 20 do
                doAddContainerItem(container, potion_id, 2268, 2294)
            end
return TRUE
end
i get a "end" error :confused:

You forgot the ending "end" which declares the function to be ended now.

If you start a function you have to end the function aswell.

example:

Lua:
function youHaveToCloseThis(cid)
-- code
end -- this end belongs to the function "youHaveToCloseThis(cid)"

Lua:
function youHaveToCloseThis(cid)
     if blablabla(cid) then
          -- code
     end -- this end belongs to the previous "if"
end -- this end belongs to the function "youHaveToCloseThis(cid)"

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local container = 0
    local cost = 20000
    local potion_id = 2273
    local backpack_id = 2000
    if item.uid == 10203 and item.itemid == 1740 then
            container = doPlayerAddItem(cid, backpack_id, 1)
            for i = 1, 20 do
                doAddContainerItem(container, potion_id, 2268, 2294)
            end
    end
    return TRUE
end

I hope that you can understand it now :)


kind regards, Evil Hero
 
can you explain why it is 3 "end"? its only 1 "if" and one function.

and can you edit the script so its like a quest, you can only do it 1 time.

and when im rightclicking on the chest i get a backpack but no runes inside.. i get a error:
Code:
[08/07/2009  02:29:00] Lua Script Error: [Action Interface] 
[08/07/2009  02:29:00] data/actions/scripts/own made/bprunor.lua:onUse

[08/07/2009  02:29:00] luaDoAddContainerItem(). Container not found

Thank you for helping me.
 
Last edited:
02:42AM: You advanced in scripting.

Thanks dude! I really needed that!

xD
 
sorry TriWear, didn't saw your post lately.

try this:
Lua:
  function onUse(cid, item, fromPosition, itemEx, toPosition)
    local container = 0
    local cost = 20000
    local potion_id = 2273
    local backpack_id = 2000
    if item.uid == 10203 and item.itemid == 1740 then
            container = doPlayerAddItemEx(cid, backpack_id, 1)
            for i = 1, 20 do
                doAddContainerItem(container, potion_id, 2268, 2294)
            end
    end
    return TRUE
end
 
Back
Top