• 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 Lua again...

Harter

New Member
Joined
Mar 4, 2013
Messages
5
Reaction score
1
So this time i do not get any problems like "callback parameter..." etc. This time its just doesnt do anything.
My script should work like this. When you turn the light on, you will have 2 seconds to click on the other light to remove the stone. When it will take longer than 2 sec, the light of the first lantern will turn off again. So my script is working till the addevent. The light goes on, but there is no timer. It wont turn off after 2 sec :(. What am i doing wrong?? Codex NG please help haha :p

Code:
local config = {
messageGood = "Stone has been removed!",
messageSlow = "You are to slow.",
stonepos = {x=296, y=365, z=8, stackpos=1},
delay = 2
}

function onUse(cid, item, frompos, item2, topos)
local function turnLight(cid)
if  item.itemid == 3710 and item.uid == 1207 then
doTransformItem(item.uid,item.itemid-1)
end
end

local getpiece1 = getThingfromPos(config.stonepos)
if item.itemid == 3709 and item.uid == 1207 and getGlobalStorageValue(1200) < 0 then
doTransformItem(item.uid,item.itemid+1)
doSendMagicEffect(topos,14)
doPlayerAddHealth(cid, -10000)
setGlobalStorageValue(1200,0)
doPlayerSendTextMessage(cid,22, "There are 4 lights left.")
addEvent(turnLight, config.delay * 1000, cid)

elseif item.uid == 1208 and item.itemid == 3709 and getGlobalStorageValue(1200) == 0 then
doRemoveItem(getpiece1.uid,1)
doTransformItem(item.uid,item.itemid+1)
doPlayerSendTextMessage(cid,22,config.messageGood)

else

doPlayerSendTextMessage(cid,22,"Ha ha ha! Burn!")
doSendMagicEffect(topos,14)
doPlayerAddHealth(cid, -15000)

end
return true
end
 
Last edited by a moderator:
Code:
    local config = {
        messageGood = "Stone has been removed!",
        messageSlow = "You are to slow.",
        stonepos = { x = 296, y = 365, z = 8, stackpos = 1 },
        delay = 2
    }

    function onUse(cid, item, frompos, item2, topos)
        local function turnLight()
            if  item.itemid == 3710 then
                doTransformItem(item.uid, item.itemid - 1)
            end
        end

        local getpiece1 = getThingfromPos(config.stonepos)
        if item.itemid == 3709 and getGlobalStorageValue(1200) < 0 then
            doTransformItem(item.uid, item.itemid + 1)
            doSendMagicEffect(topos, 14)
            doPlayerAddHealth(cid, -10000)
            setGlobalStorageValue(1200, 0)
            doPlayerSendTextMessage(cid, 22, "There are 4 lights left.")
            addEvent(turnLight, config.delay * 1000)
        elseif item.itemid == 3709 and getGlobalStorageValue(1200) == 0 then
            doRemoveItem(getpiece1.uid, 1)
            doTransformItem(item.uid, item.itemid + 1)
            doPlayerSendTextMessage(cid, 22, config.messageGood)
        else
            doPlayerSendTextMessage(cid, 22, "Ha ha ha! Burn!")
            doSendMagicEffect(topos, 14)
            doPlayerAddHealth(cid, -15000)
        end
    return true
    end
 
Hey Codex Ng, thank you for your reply. With your script it says: callback parameter should be a function. :(
Code:
    local config = {
        messageGood = "Stone has been removed!",
        messageSlow = "You are to slow.",
        stonepos = { x = 296, y = 365, z = 8, stackpos = 1 },
        delay = 2
    }

    function onUse(cid, item, frompos, item2, topos)
        local getpiece1 = getThingfromPos(config.stonepos)
        if item.itemid == 3709 and getGlobalStorageValue(1200) < 0 then
            doTransformItem(item.uid, item.itemid + 1)
            doSendMagicEffect(topos, 14)
            doPlayerAddHealth(cid, -10000)
            setGlobalStorageValue(1200, 0)
            doPlayerSendTextMessage(cid, 22, "There are 4 lights left.")
            -- no need for a seperate function, just call doTransformItem directly with addEvent
            addEvent(doTransformItem, config.delay * 1000, item.uid, (item.itemid - 1))
        elseif item.itemid == 3709 and getGlobalStorageValue(1200) == 0 then
            doRemoveItem(getpiece1.uid, 1)
            doTransformItem(item.uid, item.itemid + 1)
            doPlayerSendTextMessage(cid, 22, config.messageGood)
        else
            doPlayerSendTextMessage(cid, 22, "Ha ha ha! Burn!")
            doSendMagicEffect(topos, 14)
            doPlayerAddHealth(cid, -15000)
        end
    return true
    end
 
It still says Callback parameter should be a function.

But when i added eventname and Item in the addevent function, the timer started working and i got following problem after 2 sec: Attempt to index local 'item' <a nil value>.
And here the code
Code:
local config = {
messageGood = "Stone has been removed!",
messageSlow = "You are to slow.",
stonepos = {x=296, y=365, z=8, stackpos=1},
delay = 2
}


function onUse(cid, item, frompos, item2, topos)
local function turnLight(turnLight, item)
if  item.itemid == 3710 and item.uid == 1207 then
doTransformItem(item.uid,item.itemid-1)
setGlobalStorageValue(1200,-1)
end
end

local getpiece1 = getThingfromPos(config.stonepos)
if item.itemid == 3709 and item.uid == 1207 and getGlobalStorageValue(1200) < 0 then
doTransformItem(item.uid,item.itemid+1)
doSendMagicEffect(topos,14)
doPlayerAddHealth(cid, -10000)
setGlobalStorageValue(1200,0)
doPlayerSendTextMessage(cid,22, "There are 4 lights left.")
addEvent(turnLight, config.delay * 1000, item)

elseif item.uid == 1208 and item.itemid == 3709 and getGlobalStorageValue(1200) == 0 then
doRemoveItem(getpiece1.uid,1)
doTransformItem(item.uid,item.itemid+1)
doPlayerSendTextMessage(cid,22,config.messageGood)

else
doPlayerSendTextMessage(cid,22,"Ha ha ha! Burn!")
doSendMagicEffect(topos,14)
doPlayerAddHealth(cid, -15000)

end
return true
end
 
Last edited by a moderator:
Sorry can't read stuff not in code tags it hurts my eyes :p

When you call addEvent the syntax is like so
Code:
addEvent(function name, time to execute, arguments)

Reviewing your code we have this function definition
Code:
    local function turnLight(turnLight, item)
        if item.itemid == 3710 and item.uid == 1207 then
            doTransformItem(item.uid,item.itemid-1)
            setGlobalStorageValue(1200,-1)
        end
    end

Now take a look at the call to addEvent
Code:
addEvent(turnLight, config.delay * 1000, item)

The way your passing item to turnLight in addEvent does not match turnLight's definition, you have 2 parameters, turnLight & item, so when you pass item to addEvent as an argument for the turnLight function you are passing the data to the 1st argument which is turnLight, which doesn't do anything inside your function definition.

It is important to understand how the code should execute even if it doesn't execute :p
The parameters turnLight & item are just place holders for the function they could be named anything like a & b, your not actually passing the variables to the turnLight function, what you are doing is passing the value to the function (aka pass by value) in the form known as an argument.

The only reason a function should ever be considered local or defined inside of an interface in this case onUse is when that function has no parameters, since the turnLight function does have parameters (e.g. turnLight & item) it could very well be defined outside of the onUse interface.

So lets do that now
Code:
    local config = {
        messageGood = "Stone has been removed!",
        messageSlow = "You are to slow.",
        stonepos = { x = 296, y = 365, z = 8, stackpos = 1 },
        delay = 2
    }
  
    function turnLight(item)
        if item.itemid == 3710 and item.uid == 1207 then
            doTransformItem(item.uid, item.itemid - 1)
            setGlobalStorageValue(1200, -1)
        end
        -- not really need but it couldn't hurt either :d
        return true
    end
  
    function onUse(cid, item, frompos, item2, topos)
        local getpiece1 = getThingfromPos(config.stonepos)
        if item.itemid == 3709 and getGlobalStorageValue(1200) < 0 then
            doTransformItem(item.uid, item.itemid + 1)
            doSendMagicEffect(topos, 14)
            doPlayerAddHealth(cid, -10000)
            setGlobalStorageValue(1200, 0)
            doPlayerSendTextMessage(cid, 22, "There are 4 lights left.")
            -- pass turnLight to addEvent, pass a table to turnLight as an argument
            -- that will be used to reference the itemid & uid of item
            addEvent(turnLight, config.delay * 1000, {uid = item.uid, itemid = item.itemid })
        elseif item.itemid == 3709 and getGlobalStorageValue(1200) == 0 then
            doRemoveItem(getpiece1.uid, 1)
            doTransformItem(item.uid, item.itemid + 1)
            doPlayerSendTextMessage(cid, 22, config.messageGood)
        else
            doPlayerSendTextMessage(cid, 22, "Ha ha ha! Burn!")
            doSendMagicEffect(topos, 14)
            doPlayerAddHealth(cid, -15000)
        end
    return true
    end
 
Last edited by a moderator:
Back
Top