• 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 Item for random teleport

CyberShaman21

New Member
Joined
Dec 9, 2017
Messages
52
Reaction score
4
hi
i want to make item for random teleport. After 5 seconds back to old position(where start teleport)

i have this code


Code:
local random_positions = {
["A1"] = {x = 29990, y = 30125, z = 7},
["A2"] = {x = 29990, y = 30133, z = 7},
["A3"] = {x = 29990, y = 30141, z = 7},
}

local timeback = 5

local old = getPlayerMasterPos(cid)

function back()
    doTeleportThing(cid, old)
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        doRemoveItem(item.uid)
    
        doTeleportThing(cid, random_positions[math.random(#random_positions)])
        doSendMagicEffect(old, CONST_ME_TELEPORT)
        doSendMagicEffect(new, CONST_ME_TELEPORT)
        doCreatureSay(cid, 'You have teleported.', TALKTYPE_ORANGE_1, false, cid)
        addEvent(back, timeback * 1000)
    end
    return true
end

but i have errors

Nowyobrazmapybitowej.png
 
Last edited:
Code:
local random_positions = {
{x = 29990, y = 30125, z = 7},
{x = 29990, y = 30133, z = 7},
{x = 29990, y = 30141, z = 7},
}

local timeback = 5

local zxc = {x = 29997, y = 30112, z = 7}

function back(cid) 
    doTeleportThing(cid, old)
 
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        doRemoveItem(item.uid, 1)
        old = getPlayerMasterPos(cid)
        doTeleportThing(cid, random_positions[math.random(#random_positions)])
        doSendMagicEffect(old, CONST_ME_TELEPORT)
        doSendMagicEffect(new, CONST_ME_TELEPORT)
        doCreatureSay(cid, 'You have teleported.', TALKTYPE_ORANGE_1, false, cid)
        addEvent(back, timeback * 1000)
    end
    return true
end

this code teleport me but i can go back after "timeback"
after 5 seconds i get error
Nowyobrazmapybitowejca84e.png


something wrong with function
Code:
function back(cid)
    doTeleportThing(cid, old)
 
end
but i dont know what, can you help>?
 
Last edited:
You removed
Code:
local old = getPlayerMasterPos(cid)
Add it again before function back() or use "zxc" (which I assume is the position where the player will be teleported back) as teleporting position instead of "old" inside the function.
 
Yes i removed because i testing with constant position.

I try in different ways
but i have still error "attempt to compare number with nil"
i starting eat my hair!
Thanks for showing interest
 
Lua:
    local random_positions = {
    ["A1"] = {x = 29990, y = 30125, z = 7},
    ["A2"] = {x = 29990, y = 30133, z = 7},
    ["A3"] = {x = 29990, y = 30141, z = 7},
    }

    local timeback = 5

    function back(table)
        doTeleportThing(table.cid, table.old)
    end

    function onUse(cid, item, fromPosition, itemEx, toPosition)
   
    local old = getPlayerMasterPos(cid)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        doRemoveItem(item.uid)
        local new = random_positions[math.random(#random_positions)]
        doTeleportThing(cid, new)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
        doSendMagicEffect(new, CONST_ME_TELEPORT)
        doCreatureSay(cid, 'You have teleported.', TALKTYPE_ORANGE_1, false, cid)
        local table = { cid = cid, old = old }
        addEvent(back, timeback * 1000, table)
    end

    return true
    end
 
You are my master :D thanks alot.

this is code
Code:
local random_positions = {
{x = 29990, y = 30125, z = 7},
{x = 29990, y = 30124, z = 7},
{x = 29990, y = 30000, z = 7}

}

local timeback = 5

function back(cid)   
    doTeleportThing(cid, old)
    doSendMagicEffect(old, CONST_ME_TELEPORT)
end
   
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        doRemoveItem(item.uid, 1)
        old = getPlayerPosition(cid)
        doTeleportThing(cid, random_positions[math.random(#random_positions)])
        doSendMagicEffect(old, CONST_ME_TELEPORT)
        doCreatureSay(cid, 'You have teleported.', TALKTYPE_ORANGE_1, false, cid)
        addEvent(back, timeback * 1000, cid.uid)
    end
    return true
end
 
Last edited:
Lua:
function back(cid)
    if Player(cid) then
        doTeleportThing(cid, zcx)
    end
end
Update that function and no, it should not lag at all since it's just calling a function.
 
I have modified little bit code for random_voices
But there are no subtitles in game. No errors.
What i do wrong?

Code:
local random_positions = {
{x = 29990, y = 30125, z = 7},
{x = 29990, y = 30124, z = 7},
{x = 29990, y = 30000, z = 7}

}

local random_voices = {
{'Xddd'},
{'zzzz'},
{'vvvv'}

}

local timeback = 5

function back(cid)
    if Player(cid) then  
        doTeleportThing(cid, old)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
    end
end
   
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        doRemoveItem(item.uid, 1)
        old = getPlayerPosition(cid)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
        doTeleportThing(cid, random_positions[math.random(#random_positions)])
        doCreatureSay(cid, random_voices[math.random(#random_voices)], TALKTYPE_ORANGE_1, false, cid)
        addEvent(back, timeback * 1000, cid.uid)
    end
    return true
end
 
Big thanks!
Actually to use item i must click on item right button in mouse and on player left button mouse.
How to make item active only right button? like "food" i click on food right button and disappear item
Which function is responsible for it
 
I'm sorry, maybe I wrote wrong.
To use this item i must click right button on mouse on this item and next to me(player).
How to make one click active item, without click on player.

Function food working that.
 
Back
Top