• 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 action script 0.4 tfs

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,306
Reaction score
129
Hello i added this

Lua:
local cfg = {
        ClickHere = 8669, -- Item you click.
        GATE_ID = 8836, -- The gate item id.
        ClickUID = 5074, -- Item you click, unique ID.
        gateTime = 60, -- Minutes to leave gate open.
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local gatePosition = {x=2114, y=458, z=11, stackpos=1} -- Position of the gate.
        local getGate = getThingFromPos(gatePosition)
                if (item.itemid == cfg.ClickHere) and (getGate.itemid == cfg.GATE_ID) then
                        doRemoveItem(getGate.uid)
                        doSendMagicEffect(fromPosition, 6)
                        addEvent(doCreateItem, cfg.gateTime * 60 * 1000, cfg.GATE_ID, 1, gatePosition)
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The statue appears to already be missing.")
                end
                return true
end

and in game after i try click thing to remove the wall it says "The statue appears to already be missing. " , but its not removed at all.. so the script aint working . can someone help ? i tryed changing stackpos but didint help :(

the ids are all set good i checked it like 100x times
 
Solution
Lua:
local n = {
    pos = {x=2114, y=458, z=11},
    duration = 60 * 60 * 1000,
}

local function Create(t)
    return true, doRelocate(t, {x=t.x+1, y=t.y, z=t.z}), doCreateItem(8836, 1, t)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

    local thing = getTileItemById(n.pos, 8836).uid
    if thing < 1 then
        return true, doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The statue appears to already be missing.")
    end
 
    doRemoveItem(thing)
    doSendMagicEffect(fromPosition, 6)
    addEvent(Create, n.duration, n.pos)
    return true
end
Lua:
local n = {
    pos = {x=2114, y=458, z=11},
    duration = 60 * 60 * 1000,
}

local function Create(t)
    return true, doRelocate(t, {x=t.x+1, y=t.y, z=t.z}), doCreateItem(8836, 1, t)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

    local thing = getTileItemById(n.pos, 8836).uid
    if thing < 1 then
        return true, doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The statue appears to already be missing.")
    end
 
    doRemoveItem(thing)
    doSendMagicEffect(fromPosition, 6)
    addEvent(Create, n.duration, n.pos)
    return true
end
 
Last edited:
Solution
Lua:
local n = {
    pos = {x=2114, y=458, z=11},
    duration = 60 * 60 * 1000,
}

local function Create(t)
    return true, doRelocate(t, {x=t.x+1, y=t.y, z=t.z}), doCreateItem(8836, 1, t)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

    local thing = getTileItemById({x=2114, y=458, z=11}, 8836).uid
 
    if thing ~= 1 then
        return true, doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The statue appears to already be missing.")
    end
 
    doRemoveItem(thing)
    doSendMagicEffect(fromPosition, 6)
    addEvent(Create, n.duration, n.pos)
    return true
end
testing :) <3
doesnt work , same thing happening . it has to be something about stackpos maybe no ?
 
Stack shouldn't be an issue since the function is basically looking for a specific item on a specific position and turning it into userdata. Anyway, I changed updated the script, see if it works now.
 
My attempt, tell me if it works
Lua:
local cfg = {
        ClickHere = 8669, -- Item you click.
        GATE_ID = 8836, -- The gate item id.
        ClickUID = 5074, -- Item you click, unique ID.
        gateTime = 60, -- Minutes to leave gate open.
        gatePos = {x=2114, y=458, z=11} -- Position of the gate.
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local getGate = getThingFromPos(cfg.gatePos)
        local gate = getThingFromPos(cfg.gatePos).itemid == cfg.GATE_ID
                if gate then
                        doRemoveItem(getGate)
                        doSendMagicEffect(fromPosition, 6)
                        addEvent(function()
                            doCreateItem(cfg.GATE_ID,1,gatePos)
                        end, cfg.gateTime * 60 * 1000)
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The statue appears to already be missing.")
                end
     return true
end
In actions you should have something of the sort:
XML:
    <action uniqueid="5074" script="gatescript.lua" />
 
My attempt, tell me if it works
Lua:
local cfg = {
        ClickHere = 8669, -- Item you click.
        GATE_ID = 8836, -- The gate item id.
        ClickUID = 5074, -- Item you click, unique ID.
        gateTime = 60, -- Minutes to leave gate open.
        gatePos = {x=2114, y=458, z=11} -- Position of the gate.
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local getGate = getThingFromPos(cfg.gatePos)
        local gate = getThingFromPos(cfg.gatePos).itemid == cfg.GATE_ID
                if gate then
                        doRemoveItem(getGate)
                        doSendMagicEffect(fromPosition, 6)
                        addEvent(function()
                            doCreateItem(cfg.GATE_ID,1,gatePos)
                        end, cfg.gateTime * 60 * 1000)
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The statue appears to already be missing.")
                end
     return true
end
In actions you should have something of the sort:
XML:
    <action uniqueid="5074" script="gatescript.lua" />
same thing happening it says gate already apears missing...
all 3 scripts seems fine , there is some glitch , what about stackpos ? you dont think it can cause problem ?
 
Stack shouldn't be an issue since the function is basically looking for a specific item on a specific position and turning it into userdata. Anyway, I changed updated the script, see if it works now.
Thanks , it worked. can you tell me whats the problem was ? :) i guess my script was to good , it was able to fix easy ? :)
 
Thanks , it worked. can you tell me whats the problem was ? :) i guess my script was to good , it was able to fix easy ? :)
I don't know what the issue was with your script. But I can recommend you to use getTileItemById, getTileThingByPos, getTopCreature and so on instead of using getThingfromPos.

I will try to explain quickly:

Lua:
-- Table with information (used here for easier configuration, not necessary)
local n = {
    pos = {x=2114, y=458, z=11},
    duration = 60 * 60 * 1000,
}

-- function that operates inside this script due to it being local
-- Note that you can shorten scripts in some cases with a comma sign
local function Create(t)
    return true, doRelocate(t, {x=t.x+1, y=t.y, z=t.z}), doCreateItem(8836, 1, t)
end


function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- Thing unique
    local thing = getTileItemById({x=2114, y=458, z=11}, 8836).uid

   
    -- if thing is less than 1 then return (return ends script)
    if thing < 1 then
        return true, doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The statue appears to already be missing.")
    end

    -- since script didn't end:
   
    -- To make you understand what thing is. Thing becomes data in form of a number.
    -- you could add a unique id to the gate, let's say 1714, and then just use it like:
    -- doRemoveItem(1714) would work the same way   
    doRemoveItem(thing)
   
    -- Magic effect on fromPos
    doSendMagicEffect(fromPosition, 6)
   
    -- Schedules callback (function) with name Create, how long before execute, position. Note that I parsed position through a parameter (t in Create(t))
    addEvent(Create, n.duration, n.pos)
    return true
end
 
Back
Top