• 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:
i want to make exhaust to this system.
I found this code
Code:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
Code:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if player:getExhaustion(1000) <= 0 then
        player:setExhaustion(1000, 10)
    else
        print('You\'re exhausted for: '..player:getExhaustion(1000)..' seconds.')
    end
    return true
end
i tested on tfs 1.2 and its working.
i try to rebuild teleport script and connect with exhaust script
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 Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
function back(cid)
    if Player(cid) then 
        doTeleportThing(cid, old)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
    end
end
  
function onUse(cid, player, item, fromPosition, itemEx, toPosition, isHotkey)
  
  
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        if player:getExhaustion(1000) <= 0 then
            if(math.random(1,1000) <= 900) then
                doRemoveItem(item.uid, 1)
                old = getPlayerPosition(cid)
                doTeleportThing(cid, random_positions[math.random(#random_positions)])
                doSendMagicEffect(old, CONST_ME_TELEPORT)
                doCreatureSay(cid, random_voices[math.random(#random_voices)], TALKTYPE_ORANGE_1, false, cid)
                addEvent(back, timeback * 1000, cid.uid)
                player:setExhaustion(1000, 10)
            else
                doRemoveItem(item.uid, 1)
                doCreatureAddHealth(cid,-10)
            end
          
        else
            doPlayerSendCancel(cid, 'You cannot eat more psychodelics yet.')
  
        end
    end
    return true
end
Nowyobrazmapybitowejf49b9.png
 
Last edited:
Ugh my brain hurts trying to look at 1.2 scripts.

try this.
Lua:
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
local function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
local function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
local function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
local function back(cid)
    if Player(cid) then 
        doTeleportThing(cid, old)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
    end
end
  
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
  
  
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        if cid:getExhaustion(1000) <= 0 then
            if(math.random(1,1000) <= 900) then
                doRemoveItem(item.uid, 1)
                old = getPlayerPosition(cid)
                doTeleportThing(cid, random_positions[math.random(#random_positions)])
                doSendMagicEffect(old, CONST_ME_TELEPORT)
                doCreatureSay(cid, random_voices[math.random(#random_voices)], TALKTYPE_ORANGE_1, false, cid)
                addEvent(back, timeback * 1000, cid.uid)
                cid:setExhaustion(1000, 10)
            else
                doRemoveItem(item.uid, 1)
                doCreatureAddHealth(cid,-10)
            end
        else
            doPlayerSendCancel(cid, 'You cannot eat more psychodelics yet.')
        end
    end
    return true
end
 
my(our) final code? thanks for help. someone have any tips for this code?
Code:
local random_positions = {
{x = 29990, y = 30125, z = 7},
{x = 29990, y = 30124, z = 7},
{x = 29990, y = 30000, z = 7}
}

local random_positions_spec = {
{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 random_voices_spec = {
'Bonus',
'Bonus xxx',
'SPECIAL'
}
local timeback = {
5,
10,
15
}

local psychodelics = {
    [26413] = {timeback[math.random(#timeback)], random_positions[math.random(#random_positions)], random_positions_spec[math.random(#random_positions_spec)]} -- carrot

}
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
function back(cid)
    if Player(cid) then
        doTeleportThing(cid, old)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
    end
end
 
function onUse(cid, item, fromPosition, itemEx, target, toPosition, isHotkey)
    local psychodelic = psychodelics[item.itemid]
    if not psychodelic then
        return false
    end
 
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        if cid:getExhaustion(1000) <= 0 then
            if(math.random(1,1000) <= 500) then
                if(math.random(1,1000) <= 1) then
                    doRemoveItem(item.uid, 1)
                    old = getPlayerPosition(cid)
                    doTeleportThing(cid, psychodelic[3])
                    doSendMagicEffect(old, CONST_ME_TELEPORT)
                    doCreatureSay(cid, random_voices_spec[math.random(#random_voices_spec)], TALKTYPE_ORANGE_1, false, cid)
                    addEvent(back, psychodelic[1] * 1000, cid.uid)
                    cid:setExhaustion(1000, psychodelic[1])
                else
                    doRemoveItem(item.uid, 1)
                    old = getPlayerPosition(cid)
                    doTeleportThing(cid, psychodelic[2])
                    doSendMagicEffect(old, CONST_ME_TELEPORT)
                    doCreatureSay(cid, random_voices[math.random(#random_voices)], TALKTYPE_ORANGE_1, false, cid)
                    addEvent(back, psychodelic[1] * 1000, cid.uid)
                    cid:setExhaustion(1000, psychodelic[1])
                end
            else
                doRemoveItem(item.uid, 1)
                doCreatureAddHealth(cid,-10)
            end
         
        else
            doPlayerSendCancel(cid, 'You cannot eat more psychodelics yet.')
 
        end
    end
    return true
end
 
Last edited:
Ugh my brain hurts trying to look at 1.2 scripts.

try this.
Lua:
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
local function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
local function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
local function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
local function back(cid)
    if Player(cid) then
        doTeleportThing(cid, old)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
    end
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
 
 
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        if cid:getExhaustion(1000) <= 0 then
            if(math.random(1,1000) <= 900) then
                doRemoveItem(item.uid, 1)
                old = getPlayerPosition(cid)
                doTeleportThing(cid, random_positions[math.random(#random_positions)])
                doSendMagicEffect(old, CONST_ME_TELEPORT)
                doCreatureSay(cid, random_voices[math.random(#random_voices)], TALKTYPE_ORANGE_1, false, cid)
                addEvent(back, timeback * 1000, cid.uid)
                cid:setExhaustion(1000, 10)
            else
                doRemoveItem(item.uid, 1)
                doCreatureAddHealth(cid,-10)
            end
        else
            doPlayerSendCancel(cid, 'You cannot eat more psychodelics yet.')
        end
    end
    return true
end
This is exactly how I feel when I'm looking at 0.4 scripts haha
 
How to add magic lvl on tfs 1.2

i use
Code:
doPlayerAddMagLevel(cid, 1)
but i get error
Nowyobrazmapybitowej255e0.png


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

local random_positions_spec = {
{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 random_voices_spec = {
'Bonus',
'Bonus xxx',
'SPECIAL'
}
local timeback = {
5,
10,
15
}

local psychodelics = {
    [26413] = {timeback[math.random(#timeback)], random_positions[math.random(#random_positions)], random_positions_spec[math.random(#random_positions_spec)], 900, 1000, -10, 500, 1000} -- marichuana

}

-- [item id] = timeback[1], random_positions[2], random_positions_spec[3], chance[4] 1-1000 (100=10%), chance_spec[5], Addhealt or addmana[6], chance Addhealt or addmana[7], chance add mlvl[8])
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
function back(cid)
    if Player(cid) then 
        doTeleportThing(cid, old)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
    end
end
  
function onUse(cid, item, fromPosition, itemEx, target, toPosition, add, isHotkey)
    local psychodelic = psychodelics[item.itemid]
    if not psychodelic then
        return false
    end
  
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        if cid:getExhaustion(1000) <= 0 then
            if(math.random(1,1000) <= psychodelic[4]) then --chance teleport or specials
                if(math.random(1,1000) <= psychodelic[5]) then -- chance 1% to specials
                    if(math.random(1,1000) <= psychodelic[8]) then -- chance to add skill
                        doPlayerAddMagLevel(cid, 1)
                    else
                        doRemoveItem(item.uid, 1)
                        old = getPlayerPosition(cid)
                        doTeleportThing(cid, psychodelic[3])
                        doSendMagicEffect(old, CONST_ME_TELEPORT)
                        doCreatureSay(cid, random_voices_spec[math.random(#random_voices_spec)], TALKTYPE_ORANGE_1, false, cid)
                        addEvent(back, psychodelic[1] * 1000, cid.uid)
                        cid:setExhaustion(1000, psychodelic[1])
                    end
                else
                    doRemoveItem(item.uid, 1)
                    old = getPlayerPosition(cid)
                    doTeleportThing(cid, psychodelic[2])
                    doSendMagicEffect(old, CONST_ME_TELEPORT)
                    doCreatureSay(cid, random_voices[math.random(#random_voices)], TALKTYPE_ORANGE_1, false, cid)
                    addEvent(back, psychodelic[1] * 1000, cid.uid)
                    cid:setExhaustion(1000, psychodelic[1])
                end
            else
                if(math.random(1,1000) <= psychodelic[7]) then
                    doRemoveItem(item.uid, 1)
                    doCreatureAddHealth(cid, psychodelic[6])
                else
                    doRemoveItem(item.uid, 1)
                    doCreatureAddMana(cid, psychodelic[6])
                end
            end
          
        else
            doPlayerSendCancel(cid, 'You cannot eat more psychodelics yet.')
  
        end
    end
    return true
end
 
like that?
Code:
if(math.random(1,1000) <= psychodelic[8]) then -- chance to add skill
                        (target:getBaseMagicLevel() + 1)
                        doRemoveItem(item.uid, 1)
                    else
i get syntax error
or i try this
Code:
player:addManaSpent(player:getVocation():getRequiredManaSpent(player:getBaseMagicLevel() + 1))

but i have error "attempt to index global 'player' <a nil value>

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

local random_positions_spec = {
{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 random_voices_spec = {
'Bonus',
'Bonus xxx',
'SPECIAL'
}
local timeback = {
5,
10,
15
}

local psychodelics = {
    [26413] = {timeback[math.random(#timeback)], random_positions[math.random(#random_positions)], random_positions_spec[math.random(#random_positions_spec)], 900, 1000, -10, 500, 1000} -- marichuana

}

-- [item id] = timeback[1], random_positions[2], random_positions_spec[3], chance[4] 1-1000 (100=10%), chance_spec[5], Addhealt or addmana[6], chance Addhealt or addmana[7], chance add mlvl[8])
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
function back(cid)
    if Player(cid) then
        doTeleportThing(cid, old)
        doSendMagicEffect(old, CONST_ME_TELEPORT)
    end
end
 
function onUse(cid, item, player, fromPosition, itemEx, target, toPosition, add, isHotkey)
    local psychodelic = psychodelics[item.itemid]
    if not psychodelic then
        return false
    end
 
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, 'You can\'t teleport while in fight.')
    else
        if cid:getExhaustion(1000) <= 0 then
            if(math.random(1,1000) <= psychodelic[4]) then --chance teleport or specials
                if(math.random(1,1000) <= psychodelic[5]) then -- chance 1% to specials
                    if(math.random(1,1000) <= psychodelic[8]) then -- chance to add skill
                        doPlayerAddMagLevel(cid, 1)
                        doRemoveItem(item.uid, 1)
                    else
                        doRemoveItem(item.uid, 1)
                        old = getPlayerPosition(cid)
                        doTeleportThing(cid, psychodelic[3])
                        doSendMagicEffect(old, CONST_ME_TELEPORT)
                        doCreatureSay(cid, random_voices_spec[math.random(#random_voices_spec)], TALKTYPE_ORANGE_1, false, cid)
                        addEvent(back, psychodelic[1] * 1000, cid.uid)
                        cid:setExhaustion(1000, psychodelic[1])
                    end
                else
                    doRemoveItem(item.uid, 1)
                    old = getPlayerPosition(cid)
                    doTeleportThing(cid, psychodelic[2])
                    doSendMagicEffect(old, CONST_ME_TELEPORT)
                    doCreatureSay(cid, random_voices[math.random(#random_voices)], TALKTYPE_ORANGE_1, false, cid)
                    addEvent(back, psychodelic[1] * 1000, cid.uid)
                    cid:setExhaustion(1000, psychodelic[1])
                end
            else
                if(math.random(1,1000) <= psychodelic[7]) then
                    doRemoveItem(item.uid, 1)
                    doCreatureAddHealth(cid, psychodelic[6])
                else
                    doRemoveItem(item.uid, 1)
                    doCreatureAddMana(cid, psychodelic[6])
                end
            end
         
        else
            doPlayerSendCancel(cid, 'You cannot eat more psychodelics yet.')
 
        end
    end
    return true
end

line 68
 
Last edited:
Back
Top