• 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 Need help with script

fire_shock666

New Member
Joined
Jun 3, 2014
Messages
24
Reaction score
0
Location
Netherlands
hey there,

i found a script here on otland,
but i have an error in it and i dont know the error.
so if some1 want to take a look at it?
i use cryingdamson 0.3.6 (8.60) V8.2
and this is the error

HTML:
[14/06/2015 15:54:28] [Error - CreatureScript Interface]
[14/06/2015 15:54:28] In a timer event called from:
[14/06/2015 15:54:28] mods/scripts/treasure_goblin/treasure_goblin.lua:onStatsChange
[14/06/2015 15:54:28] Description:
[14/06/2015 15:54:28] (luaGetThingPosition) Thing not found

[14/06/2015 15:54:28] [Error - CreatureScript Interface]
[14/06/2015 15:54:28] In a timer event called from:
[14/06/2015 15:54:29] mods/scripts/treasure_goblin/treasure_goblin.lua:onStatsChange
[14/06/2015 15:54:29] Description:
[14/06/2015 15:54:29] mods/scripts/treasure_goblin/treasure_goblin.lua:90: attempt to index local 'pos' (a boolean value)
[14/06/2015 15:54:29] stack traceback:
[14/06/2015 15:54:29]     mods/scripts/treasure_goblin/treasure_goblin.lua:90: in function <mods/scripts/treasure_goblin/treasure_goblin.lua:82>

and this is the script:

HTML:
local offset = {
    [NORTH] = { 0, -1 },
    [EAST] = { 1, 0 },
    [SOUTH]    = { 0, 1 },
    [WEST]    = { -1, 0 },
    [SOUTHWEST] = { -1, 1 },
    [SOUTHEAST] = { 1, 1 },
    [NORTHWEST] = { -1, -1 },
    [NORTHEAST] =  { 1, -1 }
}

-- for how long the goblin will run away before opening the portal
local TIMEOUT_SECONDS = 40
-- how long is the delay between opening the portal and going through it
local TIMEOUT_ESCAPE_ROUTINE = 6

local TELEPORT_ITEMID = 1387



-- how many coins the goblin has in the beggining
-- he drops a small amount from this reserve each time he's hit
local GOLD_RESERVE = 100
-- what type of coins he has
local GOLD_ITEMID = 2152 -- platinum coin
local bank = nil

local tppos = { x = 1, y = 1, z = 1}
local lastpos = { x = 1, y = 1, z = 1}


function onStatsChange(creature, cid, type, combat, value)

    if type ~= STATSCHANGE_HEALTHLOSS then
        return true
    end
   
    if not bank then
        -- that's the first hit so start the timer
        bank = GOLD_RESERVE
        getawayRoutine(creature, 0)
        CURRENT_STATE = STATE_RUNNING
    end

    -- now it's time to drop some gold

    if bank > 0 then
        local drop = math.random(1, math.ceil(bank / 15))
        bank = bank - drop
        doCreateItem(GOLD_ITEMID, drop, getCreaturePosition(creature))
    end
    return true
end

function getawayRoutine(creature, timer)

    if timer >= TIMEOUT_SECONDS then
        escapeRoutine(creature, 0)
    else
        addEvent(getawayRoutine, 1000, creature, timer + 1)
        -- drop some minor amounts of gold while running away
        local pos = getCreaturePosition(creature)
        if pos.x ~= lastpos.x or pos.y ~= lastpos.y then
            doCreateItem(2148, math.random(1, 9), pos)
            lastpos = pos
        end
    end
end

function getTeleportPosition(creature)
    local pos = getCreaturePosition(creature)
    local dir = getCreatureLookDirection(creature)

    pos.x = pos.x + offset[dir][1]
    pos.y = pos.y + offset[dir][2]
    return pos           
end

function escapeRoutine(creature, timer)

    if not isCreature(creature) then
        return
    elseif timer >= TIMEOUT_ESCAPE_ROUTINE then
        finishEscapeRoutine(creature)
    else
        if timer == 0 then
            tppos = getTeleportPosition(creature)
            tppos.stackpos = 253
            doCreateItem(TELEPORT_ITEMID, 1, tppos)
           
            -- doCreatureSetNoMove(creature, true) doesn't seem to work on monsters - tested on TFS 0.3.7-preview
            -- so let's slow him down a bit...
           
            doChangeSpeed(creature, -getCreatureBaseSpeed(creature))
        end
       
        addEvent(escapeRoutine, 1000, creature, timer + 1)
    end
end

function finishEscapeRoutine(creature)
    doSendMagicEffect(getCreaturePosition(creature), CONST_ME_TELEPORT)
    doRemoveCreature(creature)
    doRemoveItem(getTileItemById(tppos, TELEPORT_ITEMID).uid)
end

i hope you guys can help me out, thanks anyway
 
Post the scripts you are actually using, then take new screens so we get the lines that are bugged, I downloaded the files and the lines do not match your script.

Also don't double post within 24h.
 
Post the scripts you are actually using, then take new screens so we get the lines that are bugged, I downloaded the files and the lines do not match your script.

Also don't double post within 24h.

oh, yeah you are right. i removed some lines above in the script.
Error:
HTML:
[15/06/2015 14:42:41] [Error - CreatureScript Interface]
[15/06/2015 14:42:41] In a timer event called from:
[15/06/2015 14:42:41] mods/scripts/treasure_goblin/treasure_goblin.lua:onStatsChange
[15/06/2015 14:42:41] Description:
[15/06/2015 14:42:41] (luaGetThingPosition) Thing not found

[15/06/2015 14:42:41] [Error - CreatureScript Interface]
[15/06/2015 14:42:41] In a timer event called from:
[15/06/2015 14:42:41] mods/scripts/treasure_goblin/treasure_goblin.lua:onStatsChange
[15/06/2015 14:42:41] Description:
[15/06/2015 14:42:41] mods/scripts/treasure_goblin/treasure_goblin.lua:64: attempt to index local 'pos' (a boolean value)
[15/06/2015 14:42:41] stack traceback:
[15/06/2015 14:42:41]     mods/scripts/treasure_goblin/treasure_goblin.lua:64: in function <mods/scripts/treasure_goblin/treasure_goblin.lua:56>

Script:
HTML:
local offset = {
    [NORTH] = { 0, -1 },
    [EAST] = { 1, 0 },
    [SOUTH]    = { 0, 1 },
    [WEST]    = { -1, 0 },
    [SOUTHWEST] = { -1, 1 },
    [SOUTHEAST] = { 1, 1 },
    [NORTHWEST] = { -1, -1 },
    [NORTHEAST] =  { 1, -1 }
}

-- for how long the goblin will run away before opening the portal
local TIMEOUT_SECONDS = 40
-- how long is the delay between opening the portal and going through it
local TIMEOUT_ESCAPE_ROUTINE = 6

local TELEPORT_ITEMID = 1387



-- how many coins the goblin has in the beggining
-- he drops a small amount from this reserve each time he's hit
local GOLD_RESERVE = 100
-- what type of coins he has
local GOLD_ITEMID = 2152 -- platinum coin
local bank = nil

local tppos = { x = 1, y = 1, z = 1}
local lastpos = { x = 1, y = 1, z = 1}


function onStatsChange(creature, cid, type, combat, value)

    if type ~= STATSCHANGE_HEALTHLOSS then
        return true
    end
  
    if not bank then
        -- that's the first hit so start the timer
        bank = GOLD_RESERVE
        getawayRoutine(creature, 0)
        CURRENT_STATE = STATE_RUNNING
    end

    -- now it's time to drop some gold

    if bank > 0 then
        local drop = math.random(1, math.ceil(bank / 15))
        bank = bank - drop
        doCreateItem(GOLD_ITEMID, drop, getCreaturePosition(creature))
    end
    return true
end

function getawayRoutine(creature, timer)

    if timer >= TIMEOUT_SECONDS then
        escapeRoutine(creature, 0)
    else
        addEvent(getawayRoutine, 1000, creature, timer + 1)
        -- drop some minor amounts of gold while running away
        local pos = getCreaturePosition(creature)
        if pos.x ~= lastpos.x or pos.y ~= lastpos.y then
            doCreateItem(2148, math.random(1, 9), pos)
            lastpos = pos
        end
    end
end

function getTeleportPosition(creature)
    local pos = getCreaturePosition(creature)
    local dir = getCreatureLookDirection(creature)

    pos.x = pos.x + offset[dir][1]
    pos.y = pos.y + offset[dir][2]
    return pos          
end

function escapeRoutine(creature, timer)

    if not isCreature(creature) then
        return
    elseif timer >= TIMEOUT_ESCAPE_ROUTINE then
        finishEscapeRoutine(creature)
    else
        if timer == 0 then
            tppos = getTeleportPosition(creature)
            tppos.stackpos = 253
            doCreateItem(TELEPORT_ITEMID, 1, tppos)
          
            -- doCreatureSetNoMove(creature, true) doesn't seem to work on monsters - tested on TFS 0.3.7-preview
            -- so let's slow him down a bit...
          
            doChangeSpeed(creature, -getCreatureBaseSpeed(creature))
        end
      
        addEvent(escapeRoutine, 1000, creature, timer + 1)
    end
end

function finishEscapeRoutine(creature)
    doSendMagicEffect(getCreaturePosition(creature), CONST_ME_TELEPORT)
    doRemoveCreature(creature)
    doRemoveItem(getTileItemById(tppos, TELEPORT_ITEMID).uid)
end

sorry for double post.
 
No ide why it's throwing that error in that case, try replacing all getCreaturePosition(creature) with getThingPos(creature).
 
No ide why it's throwing that error in that case, try replacing all getCreaturePosition(creature) with getThingPos(creature).

there is no difference, still got the same error

HTML:
[15/06/2015 16:00:02] [Error - CreatureScript Interface]
[15/06/2015 16:00:02] In a timer event called from:
[15/06/2015 16:00:02] mods/scripts/treasure_goblin/treasure_goblin.lua:onStatsChange
[15/06/2015 16:00:02] Description:
[15/06/2015 16:00:02] (luaGetThingPosition) Thing not found

[15/06/2015 16:00:03] [Error - CreatureScript Interface]
[15/06/2015 16:00:03] In a timer event called from:
[15/06/2015 16:00:03] mods/scripts/treasure_goblin/treasure_goblin.lua:onStatsChange
[15/06/2015 16:00:03] Description:
[15/06/2015 16:00:03] mods/scripts/treasure_goblin/treasure_goblin.lua:64: attempt to index local 'pos' (a boolean value)
[15/06/2015 16:00:03] stack traceback:
[15/06/2015 16:00:03]     mods/scripts/treasure_goblin/treasure_goblin.lua:64: in function <mods/scripts/treasure_goblin/treasure_goblin.lua:56>
 
Try to print out pos, either your engine is fu**ed up or something like that, it should print out table 0x235235~ not true or false.
 
Code:
function getawayRoutine(creature, timer)

Code:
local pos = getCreaturePosition(creature)
print(pos)
if pos.x ~= lastpos.x or pos.y ~= lastpos.y then
     doCreateItem(2148, math.random(1, 9), pos)
     lastpos = pos
end
 
x4nqxt.jpg


this is the script with the edit and the error in the console. i dont see anything from print.....
 
Back
Top