• 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 WTH am I missing? addEvent resetLever -- item not found

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,813
Solutions
585
Reaction score
5,379
0.3.7 Crying Damson

Short Story.. Skip down 2 paragraphs if you want.

Creating a simple script. Pull lever, check if two separate levers are flopped, teleport 2 players. Nice and simple. 15 minute script at most, right? Nope.
3 weeks ago I started this script, and after 2 hours of frustration, I stopped trying to fix it, and never looked back.

Found the script earlier this morning, figured I'd take another crack at it, and still the same problem as before.
for whatever ******* reason the lever gives me the same error, over and over again. Cannot find the bloody item. << So mad! I've copy and pasted this lever script into at least 20 other scripts.. and even copy pasted it into this script replacing the original code, and resetting the co-ordinates.. and also relocating my test levers.. with no luck.

So.. Can someone tell me where this error is coming from? Please! :eek: :oops:

Error Received 2.5 seconds after hitting lever.
Code:
[8:3:23.702] [Error - Action Interface]
[8:3:23.702] In a timer event called from:
[8:3:23.702] data/actions/scripts/aaCarlExampleScripts/firstDoubleLever.lua:onUse

Actions.xml
Code:
<action actionid="46000" event="script" value="aaCarlExampleScripts/firstDoubleLever.lua"/>

firstDoubleLever.lua
Code:
local lever_pos = {
   [1] = {x = 1390, y = 1424, z = 7, stackpos=1}, -- Other lever
   [2] = {x = 1387, y = 1424, z = 7, stackpos=1}  -- Lever that your using
}
--local old_player_pos =   {
--   [1] = {x = 1390, y = 1425, z = 7, stackpos=1}, -- Other Player Position
--   [2] = {x = 1387, y = 1425, z = 7, stackpos=1}  -- This lever Position
--}
--local new_player_pos =   {
--   [1] = {x = 1389, y = 1423, z = 7, stackpos=1}, -- Other player
--   [2] = {x = 1388, y = 1423, z = 7, stackpos=1}  -- Player using this lever
--}


function resetLever()
  doTransformItem(getTileItemById(lever_pos[2], 1946).uid, 1945)
end

function onUse(cid, item, frompos, item2, topos)

   -- transform lever
   if item.itemid == 1945 then
     doTransformItem(item.uid, 1946)
     addEvent(resetLever, 2500)
   else
     return false -- so that I can flop the switch back over when it fails
   end
 
   -- Check other lever
   --local leverCheck = getThingFromPos(lever_pos[1])
   --if leverCheck.itemid == 1946 then
   --   for i = 1, #old_player_pos do
   --     local player = getThingfromPos(old_player_pos[i])
   --     doTeleportThing(player[i].uid, new_player_pos[i], FALSE)
   --   end
   --end
 
   -- return onUse function
   return true
end

In-Game text of lever.
Code:
08:14 You see a switch.
ItemID: [1946], ActionID: [46000].
TransformTo: [1945] (onUse).
Position: [X: 1387] [Y: 1424] [Z: 7].

Thanks in advance!

Xikini

(Note: The script is clearly not finished. I'm just trying to figure out why this lever won't automatically flop back.. and is giving me the error.
I have tried with and without stackpos.. and for some reason using getthingfrompos finds no item on that square.. but a magic effect will definitely send to the same location.
As I said, I spent 2 hours before and another 30 minutes today.. so frustrating for the simplest part of the script.)
 
Last edited:
Wtf!
I added local in front of the resetLever function and it's now working.
BUT I've never had to do that before.
Can someone explain? Thanks.

(For instance I have this script directly beside it.. and it works perfectly without needing the local added.
Code:
--[[
actions.xml
<action actionid="11111111" event="script" value="randommonsterswitch.lua"/>
]]

local config = {
   [1] = {monsterName = "cave rat"},
   [2] = {monsterName = "cave rat"},
   [3] = {monsterName = "rat"}
}

local amount = 3 -- Max amount of monsters allowed at once
local monster_pos = {x = 1398, y = 1416, z = 7} -- position you want the monster to spawn

local timer = 1 -- time in minutes till lever reset
local top_left_corner = {x = 1396, y = 1414, z = 7} -- top left corner of area
local bottom_right_corner = {x = 1400, y = 1418, z = 7} -- bottom right corner of area

local lever_pos = {x = 1401, y = 1416, z = 7, stackpos=1} -- position of the lever

function resetLever()
  doTransformItem(getTileItemById(lever_pos, 1946).uid, 1945)
end

function onUse(cid, item, frompos, item2, topos)
   
   -- if lever already used
   if item.itemid == 1946 then
     return doPlayerSendCancel(cid, "Sorry not possible.")
   end
   
   -- check for spawned creatures
   search = 0
   for t = top_left_corner.x, bottom_right_corner.x do
     for f = top_left_corner.y, bottom_right_corner.y do
       pos = {x = t, y = f, z = 7}
       pid = getTopCreature(pos).uid
       if isMonster(pid) then
         search = search + 1
       end
     end
   end
   if search >= amount then
     return doPlayerSendCancel(cid, "There are too many creatures spawned in area.")
   end
   
   -- transform lever
   if item.itemid == 1945 then
     doTransformItem(item.uid, 1946)
     addEvent(resetLever, 1000 * timer)
   end
   
   -- spawn random creature
   local rand = config[math.random(#config)]
   doCreateMonster(rand.monsterName, getClosestFreeTile(cid, monster_pos, true))
   
   -- return onUse function
   return true
end
 
Thank you for posting your solution. I, however, don't have an answer as to why "local" is needed in one file and not the other, but this may help a future member that has the same problem!
 
For kicks and giggles here's the completed script I was working on.
XUyTHnS.png

Code:
local lever_pos = {
   [1] = {x = 1387, y = 1426, z = 7, stackpos=1}, -- First Lever
   [2] = {x = 1390, y = 1426, z = 7, stackpos=1}  -- Second Lever
}
local current_player_pos =   {
   [1] = {x = 1390, y = 1425, z = 7, stackpos=1}, -- First Lever Player Square
   [2] = {x = 1387, y = 1425, z = 7, stackpos=1}  -- Second Lever Player Square
}
local new_player_pos =   {
   [1] = {x = 1389, y = 1423, z = 7, stackpos=1}, -- First Lever Teleport Location
   [2] = {x = 1388, y = 1423, z = 7, stackpos=1}  -- Second Lever Teleport Location
}

local function resetLever1()
  doTransformItem(getTileItemById(lever_pos[1], 1946).uid, 1945)
end
local function resetLever2()
  doTransformItem(getTileItemById(lever_pos[2], 1946).uid, 1945)
end

function onUse(cid, item, frompos, item2, topos)

   count = 0
   lever_check = 0
 
   -- transform lever 1
   if item.itemid == 1945 and (frompos.x == lever_pos[1].x and frompos.y == lever_pos[1].y and frompos.z == lever_pos[1].z) then
     doTransformItem(item.uid, 1946)
     addEvent(resetLever1, 200)
     lever_check = lever_check + 2
   -- transform lever 2
   elseif item.itemid == 1945 and (frompos.x == lever_pos[2].x and frompos.y == lever_pos[2].y and frompos.z == lever_pos[2].z) then
     doTransformItem(item.uid, 1946)
     addEvent(resetLever2, 200)
     lever_check = lever_check + 1
   end

   -- if other lever is activated
   local leverCheck = getTileThingByPos(lever_pos[lever_check])
   if leverCheck.itemid == 1946 then
     -- check if players on squares
     for i = 1, #current_player_pos do
       thing = getThingfromPos(current_player_pos[i])
       if isPlayer(thing.uid) == true then
         count = count + 1
       end
     end
     -- if players on squares, teleport them
     if count == #current_player_pos then
       for i = 1, #current_player_pos do
         cid = getThingfromPos(current_player_pos[i])
         doTeleportThing(cid.uid, new_player_pos[i], FALSE)
       end
     end
   end
 
   -- return onUse function
   return true
end
 
Last edited:
I shrunk it down a bit I hope it still works :)
Code:
local lever_pos = {
   [1] = {x = 1387, y = 1426, z = 7, stackpos=1}, -- First Lever
   [2] = {x = 1390, y = 1426, z = 7, stackpos=1}  -- Second Lever
}
local current_player_pos =   {
   [1] = {x = 1390, y = 1425, z = 7, stackpos=1}, -- First Lever Player Square
   [2] = {x = 1387, y = 1425, z = 7, stackpos=1}  -- Second Lever Player Square
}
local new_player_pos =   {
   [1] = {x = 1389, y = 1423, z = 7, stackpos=1}, -- First Lever Teleport Location
   [2] = {x = 1388, y = 1423, z = 7, stackpos=1}  -- Second Lever Teleport Location
}

local lever_check = 0

function onUse(cid, item, frompos, item2, topos)
    local count = 0
    -- because it is defined within onUse item becomes global to fromLever
    local function fromLever(from, lever)
        doTransformItem(item.uid, 1946)
        -- addEvent(function, time, arguments[,])
        addEvent(doTransformItem, 1000, getTileItemById(lever, 1946).uid, 1945)
        return from.x == lever.x and from.y == lever.y and from.z == lever.z
    end
    -- transform lever 1
    if item.itemid == 1945 and fromLever(frompos, lever_pos[1]) then
        -- were only concerned with 2 values because there is only 2 switches
        lever_check = 2
    -- transform lever 2
    elseif item.itemid == 1945 and fromLever(frompos, lever_pos[2]) then
        lever_check = 1
    end

    -- if other lever is activated
    if getTileThingByPos(lever_pos[lever_check]).itemid == 1946 then
        -- check if players on squares
        for _, playerPos in ipairs(current_player_pos) do
            if isPlayer(getThingfromPos(playerPos).uid) then
                count = count + 1
                -- if players on squares, teleport them
                if count == #current_player_pos then
                    -- we can nest this for loop since our objective is to determine if count
                    -- is equal the size of the table
                    for __, toPos in ipairs(new_player_pos) do
                        -- shouldn't this be cid? not cid.uid? 
                        doTeleportThing(cid, toPos, FALSE)
                    end
                end
            end
        end
     end
   -- return onUse function
   return true
end
 
Last edited:
Back
Top