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

Solved a nil value

bybbzan

mapper
Joined
Aug 4, 2012
Messages
809
Solutions
2
Reaction score
136
Location
Sweden
SOLVED BY @WibbenZ


SOLUTION

Code:
local function revert(item)
    local spectators = getSpectators({x = 1008, y = 989, z = 8}, 1, 0)
    if spectators ~= nil then
        for i = 1, #spectators do
            local thing = spectators[i]
            if isPlayer(thing) then
                doTeleportThing(thing, {x = 1006, y = 989, z = 8})
            end   
        end
        doSendMagicEffect({x = 1000, y = 989, z = 8}, CONST_ME_POFF)
    end

    for i = 1007, 1009 do
        doRemoveItem(getTileItemById({x = i, y = 989, z = 8}, 1284).uid, 1)
        doCreateItem(598, 1, {x = i, y = 989, z = 8})
    end

    doTransformItem(item.uid, item.itemid - 1)
    doCreateItem(4811, 1, {x = 1007, y = 989, z = 8})
    doCreateItem(4809, 1, {x = 1009, y = 989, z = 8})
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1945 then
        doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 4811).uid, 1)
        doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 4809).uid, 1)
        for i = 1007, 1009 do
            doCreateItem(1284, 1, {x = i, y = 989, z = 8})
        end

        doTransformItem(item.uid, item.itemid + 1)
        doCreatureSay(cid, "You just opened a secret passage!", TALKTYPE_ORANGE_1)
        addEvent(revert, 10 * 1000, getThingfromPos(getThingPos(item.uid)))
    elseif item.itemid == 1946 then
        doPlayerSendCancel(cid, "You can't use this yet.")
    end
    return true
end
 
Last edited:
Code:
getSpectators(centerPos, rangex, rangey[, multifloor = false])
The function is called getSpectators, you can find the Lua functions in luascript.cpp (source file).
 
Code:
getSpectators(centerPos, rangex, rangey[, multifloor = false])
The function is called getSpectators, you can find the Lua functions in luascript.cpp (source file).
Yea i know. I found that in the luascript.cpp file, but it doesnt work.
Do i have to add it in some way?
 
Example how to use the function getSpectators: https://otland.net/threads/movements-max-player-idol-kick.223116/#post-2145080
If there are problems, explain what happens and post the errors and the full script.

I get this error now. Tried to add / delete ends but didnt get it to work anyway.
Code:
[Error - LuaScriptInterface::loadFile] data/actions/scripts/addedbyme/bridgelever.lua:44: '<eof>' expected near 'end'

script
Code:
function eventual(cid, item)
    doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 1284).uid, 1)
    doRemoveItem(getTileItemById({x = 1008, y = 989, z = 8}, 1284).uid, 1)
    doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 1284).uid, 1)   
    doTransformItem(item.uid, item.itemid - 1)

    doCreateItem(598, 1, {x = 1007, y = 989, z = 8})
    doCreateItem(598, 1, {x = 1008, y = 989, z = 8})
    doCreateItem(598, 1, {x = 1009, y = 989, z = 8})
   
    doCreateItem(4811, 1, {x = 1007, y = 989, z = 8})
    doCreateItem(4809, 1, {x = 1009, y = 989, z = 8})
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1945 then
        doCreateItem(1284, 1, {x = 1007, y = 989, z = 8})
        doCreateItem(1284, 1, {x = 1008, y = 989, z = 8})
        doCreateItem(1284, 1, {x = 1009, y = 989, z = 8})
        doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 4811).uid, 1)
        doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 4809).uid, 1)       
        doTransformItem(item.uid, item.itemid + 1)
        doCreatureSay(cid, "You just opened a secret passage!", TALKTYPE_ORANGE_1)
        addEvent(eventual, 10000, cid, getThingfromPos(getThingPos(item.uid)))
    elseif item.itemid == 1946 then
        doPlayerSendCancel(cid, "You can't use this yet.")
    end
return true
end

local spec = getSpectators({x = 1007, y = 989, z = 8}, 1, 0, false)
     if spec ~= nil then
         for _, s in pairs(spec) do
             if isPlayer(s) then
                 doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There is already someone in the area.")
                 doTeleportThing(cid, fromPosition)
                 doSendMagicEffect(fromPosition, CONST_ME_POFF)
                 return true
             end    
         end
     end
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to the area.")
     return true
end
 
You had an extra end and return true. This is why tabbing is important. Not only does it help keep the code "pretty" but helps diagnose issues.

33en2wx.png
 
Last edited:
You had an extra end and return true. This is why tabbing is important. Not only does it help keep the code "pretty" but helps diagnose issues.

33en2wx.png

Wow i still get the same error, could you send that code in a copyable text field?
 
Post the script with the changes.
Code:
function eventual(cid, item)
    doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 1284).uid, 1)
    doRemoveItem(getTileItemById({x = 1008, y = 989, z = 8}, 1284).uid, 1)
    doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 1284).uid, 1)   
    doTransformItem(item.uid, item.itemid - 1)

    doCreateItem(598, 1, {x = 1007, y = 989, z = 8})
    doCreateItem(598, 1, {x = 1008, y = 989, z = 8})
    doCreateItem(598, 1, {x = 1009, y = 989, z = 8})
   
    doCreateItem(4811, 1, {x = 1007, y = 989, z = 8})
    doCreateItem(4809, 1, {x = 1009, y = 989, z = 8})
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1945 then
        doCreateItem(1284, 1, {x = 1007, y = 989, z = 8})
        doCreateItem(1284, 1, {x = 1008, y = 989, z = 8})
        doCreateItem(1284, 1, {x = 1009, y = 989, z = 8})
        doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 4811).uid, 1)
        doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 4809).uid, 1)       
        doTransformItem(item.uid, item.itemid + 1)
        doCreatureSay(cid, "You just opened a secret passage!", TALKTYPE_ORANGE_1)
        addEvent(eventual, 10000, cid, getThingfromPos(getThingPos(item.uid)))
    elseif item.itemid == 1946 then
        doPlayerSendCancel(cid, "You can't use this yet.")
end

local spec = getSpectators({x = 1007, y = 989, z = 8}, 1, 0, false)
     if spec ~= nil then
         for _, s in pairs(spec) do
             if isPlayer(s) then
                doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There is already someone in the area.")
                doTeleportThing(cid, fromPosition)
                doSendMagicEffect(fromPosition, CONST_ME_POFF)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to the area.")
                end
           end    
    end
    return true
end
 
https://otland.net/threads/how-to-tab-lua-scripts.203763/

If there is a player in the area it does this.
Code:
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There is already someone in the area.")
doTeleportThing(cid, fromPosition)
doSendMagicEffect(fromPosition, CONST_ME_POFF)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to the area.")
It gives 2 messages: "There is already someone in the area." and "Welcome to the area." at the same time.
It teleports to fromPosition, which is the position where you click use on the item.

If it should do something else, then change that.
 
https://otland.net/threads/how-to-tab-lua-scripts.203763/

If there is a player in the area it does this.
Code:
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There is already someone in the area.")
doTeleportThing(cid, fromPosition)
doSendMagicEffect(fromPosition, CONST_ME_POFF)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to the area.")
It gives 2 messages: "There is already someone in the area." and "Welcome to the area." at the same time.
It teleports to fromPosition, which is the position where you click use on the item.

If it should do something else, then change that.
Well actually, it doesnt do anything at all. And i do not get any messages either.
The lever is quite some SQMs away from the bridge.
What i want it to do is, when the bridge disappears you should not get stuck in the middle here, but it should "teleport" you
away from there in any way.
8y9p1g_th.png
 
There are a couple ways to do it, but yes. You can add another position to the table, and then add: doCreateItem(5770, 1, v[#])

# = position within the table (e.g. 2)

You also need to remove another water/lava tile. Same concept but with: doRemoveItem(water)
 
Try using the relocate feature.. Not sure it's in 0.3.6 though.
It moves all items and creatures from one tile to another tile.
Code:
local relocate = {
   [1] = {x = 1008, y = 989, z = 8},
   [2] = {x = 1006, y = 989, z = 8}
}

function eventual(cid, item)
  doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 1284).uid, 1)
  doRemoveItem(getTileItemById({x = 1008, y = 989, z = 8}, 1284).uid, 1)
  doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 1284).uid, 1)
  doTransformItem(item.uid, item.itemid - 1)

  doCreateItem(598, 1, {x = 1007, y = 989, z = 8})
  doCreateItem(598, 1, {x = 1008, y = 989, z = 8})
  doCreateItem(598, 1, {x = 1009, y = 989, z = 8})

  doCreateItem(4811, 1, {x = 1007, y = 989, z = 8})
  doCreateItem(4809, 1, {x = 1009, y = 989, z = 8})
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if item.itemid == 1945 then
  doRelocate(relocate[1], relocate[2]) -- move from [1] to [2]
  doCreateItem(1284, 1, {x = 1007, y = 989, z = 8})
  doCreateItem(1284, 1, {x = 1008, y = 989, z = 8})
  doCreateItem(1284, 1, {x = 1009, y = 989, z = 8})
  doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 4811).uid, 1)
  doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 4809).uid, 1)
  doTransformItem(item.uid, item.itemid + 1)
  doCreatureSay(cid, "You just opened a secret passage!", TALKTYPE_ORANGE_1)
  addEvent(eventual, 10000, cid, getThingfromPos(getThingPos(item.uid)))
  elseif item.itemid == 1946 then
  doPlayerSendCancel(cid, "You can't use this yet.")
   end
return true
end
 
Try using the relocate feature.. Not sure it's in 0.3.6 though.
It moves all items and creatures from one tile to another tile.
Code:
local relocate = {
   [1] = {x = 1008, y = 989, z = 8},
   [2] = {x = 1006, y = 989, z = 8}
}

function eventual(cid, item)
  doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 1284).uid, 1)
  doRemoveItem(getTileItemById({x = 1008, y = 989, z = 8}, 1284).uid, 1)
  doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 1284).uid, 1)
  doTransformItem(item.uid, item.itemid - 1)

  doCreateItem(598, 1, {x = 1007, y = 989, z = 8})
  doCreateItem(598, 1, {x = 1008, y = 989, z = 8})
  doCreateItem(598, 1, {x = 1009, y = 989, z = 8})

  doCreateItem(4811, 1, {x = 1007, y = 989, z = 8})
  doCreateItem(4809, 1, {x = 1009, y = 989, z = 8})
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if item.itemid == 1945 then
  doRelocate(relocate[1], relocate[2]) -- move from [1] to [2]
  doCreateItem(1284, 1, {x = 1007, y = 989, z = 8})
  doCreateItem(1284, 1, {x = 1008, y = 989, z = 8})
  doCreateItem(1284, 1, {x = 1009, y = 989, z = 8})
  doRemoveItem(getTileItemById({x = 1007, y = 989, z = 8}, 4811).uid, 1)
  doRemoveItem(getTileItemById({x = 1009, y = 989, z = 8}, 4809).uid, 1)
  doTransformItem(item.uid, item.itemid + 1)
  doCreatureSay(cid, "You just opened a secret passage!", TALKTYPE_ORANGE_1)
  addEvent(eventual, 10000, cid, getThingfromPos(getThingPos(item.uid)))
  elseif item.itemid == 1946 then
  doPlayerSendCancel(cid, "You can't use this yet.")
   end
return true
end

No errors. Still i do not get teleported off the bridge :/
 
Back
Top