• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Help with the script

Dorianek

Member
Joined
Nov 29, 2018
Messages
252
Reaction score
10
Location
Poland
I wrote a script that, when pressed on the levers, teleports me to place X

I would like to add scripts to this line but I can not do it, I searched the internet and unfortunately some errors every time

1) only 1 player can enter place X.
2) the player after entering X can stay for 10 minutes.
3) after 10 minutes, automatically teleport to temple 161,51.7.


My script:

function onUse(cid, item, frompos, item2, topos)
if item.uid == 1010 then
doTeleportThing(cid,{x=366, y=8, z=9})
doPlayerSendTextMessage(cid,25, "Go")
else
return 0
end
return 1
end
 
Couldn't test it, it's up to you.
Code:
local area = {
    fromPos = {x = 1, y = 1, z = 1},
    toPos = {x = 1, y = 1, z = 1}
}
local playerPos = {x = 366, y = 8, z = 9}
local templePos = {x = 161, y = 57, z = 7}
local areaTimer = 10 * 60

function kickPlayer()
    for a = area.fromPos.x, area.toPos.x do
        for b = area.fromPos.y, area.toPos.y do
            pos = {x = a, y = b, z = 9, stackpos = 255}
            if(isPlayer(getTopCreature(pos).uid)) then
                doPlayerSendTextMessage(cid, 25, "Time's up.")
                doTeleportThing(cid, templePos)
            end
        end
    end
return true
end

function onUse(player, item, frompos, item2, topos)
    if item.uid == 1010 and item.itemid == 1945 then
        for a = area.fromPos.x, area.toPos.x do
            for b = area.fromPos.y, area.toPos.y do
                pos = {x = a, y = b, z = 9, stackpos = 255}
                if(isPlayer(getTopCreature(pos).uid)) then
                    doPlayerSendTextMessage(cid, 25, "A player is already inside the area.")
                else
                    doTeleportThing(cid, playerPos)
                    Position(playerPos.x, playerPos.y, playerPos.z):sendMagicEffect(CONST_ME_TELEPORT)
                    stopEvent(kickPlayer)
                    addEvent(kickPlayer, areaTimer * 1000)
                end
            end
        end
    end
  
    item:transform(item.itemid == 1946 and 1945 or 1946)
return true
end

Remeber to configure the Area at the top, fromPos should be the top left corner of the area, toPos the bottom right corner of it.
Try it and let me know.
--EDIT--
I've setted it to work with a lever ID 1945. I hope i'm right haha
 
Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/compat.lua:737: attempt to compare number with nil
stack traceback:
[C]: in function '__le'
data/compat.lua:737: in function 'doTeleportThing'
data/actions/scripts/switchtp1.lua:30: in function <data/actions/scripts/switchtp1.lua:22>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/compat.lua:737: attempt to compare number with nil
stack traceback:
[C]: in function '__le'
data/compat.lua:737: in function 'doTeleportThing'
data/actions/scripts/switchtp1.lua:30: in function <data/actions/scripts/switchtp1.lua:22>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/compat.lua:737: attempt to compare number with nil
stack traceback:
[C]: in function '__le'
data/compat.lua:737: in function 'doTeleportThing'
data/actions/scripts/switchtp1.lua:30: in function <data/actions/scripts/switchtp1.lua:22>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/compat.lua:737: attempt to compare number with nil
stack traceback:
[C]: in function '__le'
data/compat.lua:737: in function 'doTeleportThing'
data/actions/scripts/switchtp1.lua:30: in function <data/actions/scripts/switchtp1.lua:22>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/compat.lua:737: attempt to compare number with nil
stack traceback:
[C]: in function '__le'
data/compat.lua:737: in function 'doTeleportThing'
data/actions/scripts/switchtp1.lua:30: in function <data/actions/scripts/switchtp1.lua:22>

Lua Script Error: [Action Interface]
data/actions/scripts/switchtp1.lua:onUse
data/compat.lua:737: attempt to compare number with nil
stack traceback:
[C]: in function '__le'
data/compat.lua:737: in function 'doTeleportThing'
data/actions/scripts/switchtp1.lua:30: in function <data/actions/scripts/switchtp1.lua:22>
 
Remember to include tfs version next time
made some edits to Ramirow's script
if item.uid == 1010 and item.itemid == 1945 then
You can set these conditions in actions.xml so this line is only useful if the script should be triggered by more than 1 item/uid and they should make the script perform different actions :p
LUA:
local storage = 30001 -- used to display remaining time
local area = {
    fromPos = {x = 1, y = 1, z = 1},
    toPos = {x = 1, y = 1, z = 1}
}
local playerPos = {x = 366, y = 8, z = 9}
local areaTimer = 10 * 60

local function getPlayerFromArea()
    for x = area.fromPos.x, area.toPos.x do
        for y = area.fromPos.y, area.toPos.y do
            for z = area.fromPos.z, area.toPos.z do
                local t = Tile(x,y,z)
                if t and t:getTopCreature() and t:getTopCreature():isPlayer() then
                    return t:getTopCreature()
                end
            end
        end
    end
    return nil
end

local function kickPlayer()
    local p = getPlayerFromArea()
    if not p then return end
    p:teleportTo(p:getTown():getTemplePosition())
    p:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end

function onUse(player, item, frompos, item2, topos)
    local p = getPlayerFromArea()
    if not p then
        player:teleportTo(playerPos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        Game.setStorageValue(storage,os.time()+areaTimer)
        item:transform(item.itemid == 1946 and 1945 or 1946)
        stopEvent(kickPlayer)
        addEvent(kickPlayer, areaTimer * 1000)
        return true
    end
    player:sendCancelMessage("A player is inside the area & has "..Game.getStorageValue(storage) - os.time().." seconds remaining")
    return true
end
 
Last edited:
and you can set some timer in this script? that the second player will press him to show him how much time he has until the end the player in the arena?
 
now after uploading the script above everything works fine but the error appears:

[C]: in function 'doChallengeCreature'
data/actions/scripts/Arena3/dzwignia potworow4.lua:10: in function <data/actions/scripts/Arena3/dzwignia potworow4.lua:4>

Script error :

local nazwyPotworow = {"The Noxious Spawn"} -- Nazwy potworów, jakie skrypt może robić
local exh = 2 -- Ile sekund exhaused
local storage = 10019
function onUse(cid, item, frompos, item2, topos)
local monster = nazwyPotworow[math.random(1,#nazwyPotworow)]

if(getPlayerStorageValue(cid,storage) <= os.time()) then
local summon = doSummonCreature(monster,getPlayerPosition(cid))
doChallengeCreature(cid, summon)
doChallengeCreature(summon, cid)
setPlayerStorageValue(cid,storage,os.time()+exh)
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"Czeka cie walka z ".. monster .."!")
else
doPlayerSendCancel(cid,"You are exhausted.")
end
return TRUE
end


should I care about this message? and what did it mean if anyone knows?
 
You are trying to execute doChallengeCreature on a player when it only works on monsters
remove line:
doChallengeCreature(summon, cid)
 
Back
Top