• 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 TFS 1.4 OnStepIn

lordlazarus

New Member
Joined
Mar 28, 2016
Messages
15
Reaction score
0
Hi guys,

I need help on how I would make a function out of "onstepIn" to call the position of the effect. I know that inside the function would be easier, but would you be able to do it outside?

I think it would be something along those lines

local function itempos(item)
local pos = item:getPosition()
return true
end

function onStepIn(creature, item, position, fromPosition)
addEvent(itempos, 5000, creature.uid)
return true
end
 
Damn boiiiiii , why you passing creature.uid inside the arguments of function itempos which is related to item?!
What the HELLL is goin on here 🤔

Here, quick example
Lua:
function itemEffect(receivedItemObject)
    if not receivedItemObject then return false end

    local item = Item(receivedItemObject.uid)
    if not item then return false end

    local pos = item:getPosition()
    pos:sendMagicEffect(5)
    return true
end

function onStepIn(creature, item, position, fromPosition)
    -- addEvent arguments MUST be in following order : addEvent(function, time in miliseconds, other arguments that are used by function inside addEvent)
    addEvent(itemEffect, 5000, item)
    return true
end
 
Last edited:
Post automatically merged:

Damn boiiiiii , why you passing creature.uid inside the arguments of function itempos which is related to item?!
I don't know where my head was. Did this example work for you? Here nothing happens when I step on the item.

If i remove that part

if not receivedItemObject then return false end and
if not item then return false end

this error appears, so for some reason it is not recognizing the item that I step on in the function

attempt to index local 'item' (a nil value)
stack traceback:
[C]: in function '__index'
 
Last edited:
Edited, try now.
Also, are you have any item on Tile where u stepping?
Depends on what you want to do, if you don't have any item on that Tile it obviously won't work :p
I just showed you an example how to "safety" pass an object into function that will be executed after time (in your case 5 seconds (5000))

 
Last edited:
I have an item that when I step over it activates this example code you mentioned. But when I replaced this error appeared.

Lua:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/riftdemoniolv10.lua:onStepIn
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/movements/scripts/riftdemoniolv10.lua:133: in function <data/movements/scripts/riftdemoniolv10.lua:129>

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/movements/scripts/riftdemoniolv10.lua:37: attempt to index local 'receivedItemObject' (a number value)
stack traceback:
        [C]: in function '__index'
        data/movements/scripts/riftdemoniolv10.lua:37: in function <data/movements/scripts/riftdemoniolv10.lua:34>
 
Try this:
Lua:
function onStepIn(creature, item, position, fromPosition)
    addEvent(function()
        item:getPosition():sendMagicEffect(5)
    end, 5000)
    return true
end
 
Hi guys,

I need help on how I would make a function out of "onstepIn" to call the position of the effect. I know that inside the function would be easier, but would you be able to do it outside?

I think it would be something along those lines

local function itempos(item)
local pos = item:getPosition()
return true
end

function onStepIn(creature, item, position, fromPosition)
addEvent(itempos, 5000, creature.uid)
return true
end
there is no safe way to do it.
but if the item cannot be moved and will always stay in the same position and never transform into another, then you can do the following:
Lua:
local function callFunction(cid, pos, itemId)
    local creature = Creature(cid)
    if creature then
        local item = Tile(pos):getItemById(itemId)
        if item then
            -- OK
        end
    end
end

local moveEvent = MoveEvent()

function moveEvent.onStepIn(creature, item, pos, fromPosition)
    addEvent(callFunction, 1000, creature:getId(), pos, item:getId())
    return true
end

--moveEvent:id(ids)
--moveEvent:aid(ids)
--moveEvent:uid(ids)
--moveEvent:position(positions)
moveEvent:register()
 
Hi all,

@MorganaSacani this way works, however I need the function outside the function as described by @Sarah Wesker .

i got this error Sarah,


Lua:
Lua Script Error: [Test Interface]
data/movements/scripts/riftdemoniolv10.lua
LuaScriptInterface::luaCreateMoveEvent(). MoveEvents can only be registered in the Scripts interface.
stack traceback:
        [C]: in function 'MoveEvent'
        data/movements/scripts/riftdemoniolv10.lua:44: in main chunk
        [C]: in function 'reload'
        data/talkactions/scripts/reload.lua:81: in function <data/talkactions/scripts/reload.lua:59>

Lua Script Error: [Test Interface]
data/movements/scripts/riftdemoniolv10.lua
data/movements/scripts/riftdemoniolv10.lua:142: attempt to index local 'moveEvent' (a nil value)
stack traceback:
        [C]: in function '__newindex'
        data/movements/scripts/riftdemoniolv10.lua:142: in main chunk
        [C]: in function 'reload'
        data/talkactions/scripts/reload.lua:81: in function <data/talkactions/scripts/reload.lua:59>
[Warning - Event::checkScript] Can not load script: scripts/riftdemoniolv10.lua
 
Back
Top