• 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!

TFS 0.X random tp for "killevent"

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
hi, i try create random tp after i click on item of id XXX but it not work ;/ its my code

Code:
function onUse(cid, item, pos)
if cid > 0 then
    if item.actionid == 10534 then
            local location = {
                {x=1163, y=883, z=7, stackpos=253},
                {x=1167, y=883, z=7, stackpos=253},
                {x=1169, y=883, z=7, stackpos=253},
                {x=1172, y=883, z=7, stackpos=253},
                {x=1162, y=885, z=7, stackpos=253},
                {x=1164, y=885, z=7, stackpos=253},
                {x=1171, y=885, z=7, stackpos=253},
                {x=1173, y=885, z=7, stackpos=253},
                {x=1162, y=887, z=7, stackpos=253},
                {x=1164, y=887, z=7, stackpos=253},
                {x=1171, y=887, z=7, stackpos=253},
                {x=1173, y=887, z=7, stackpos=253},
                {x=1163, y=889, z=7, stackpos=253},
                {x=1167, y=889, z=7, stackpos=253},
                {x=1169, y=889, z=7, stackpos=253},
                {x=1172, y=889, z=7, stackpos=253},
                {x=1165, y=891, z=7, stackpos=253},
                {x=1167, y=891, z=7, stackpos=253},
                {x=1169, y=891, z=7, stackpos=253},
                {x=1171, y=891, z=7, stackpos=253},
                {x=1173, y=891, z=7, stackpos=253}
            }
            local xd = math.random(1, #location)
            local playerteleported = 1
            for i=1,#location do
                getplayer = getThingFromPos(location[i])
                if getplayer == #location[i] then
                    if(value) == location[i] then
                    doTeleportThing(cid,{x=1168, y=893, z=7})
                    doPlayerSendTextMessage(cid,22,"[KillEvent] Boom!")
                    break
                end
                end
                end
                end
                end
end

I have 21 positions, if i click on item XXX match.random geting random pos and player get free teleport to XX pos
 
Solution
edit the local destination
Lua:
local locations = {
    {x = 1163, y = 883, z = 7},
    {x = 1167, y = 883, z = 7},
    {x = 1169, y = 883, z = 7},
    {x = 1172, y = 883, z = 7},
    {x = 1162, y = 885, z = 7},
    {x = 1164, y = 885, z = 7},
    {x = 1171, y = 885, z = 7},
    {x = 1173, y = 885, z = 7},
    {x = 1162, y = 887, z = 7},
    {x = 1164, y = 887, z = 7},
    {x = 1171, y = 887, z = 7},
    {x = 1173, y = 887, z = 7},
    {x = 1163, y = 889, z = 7},
    {x = 1167, y = 889, z = 7},
    {x = 1169, y = 889, z = 7},
    {x = 1172, y = 889, z = 7},
    {x = 1165, y = 891, z = 7},
    {x = 1167, y = 891, z = 7},
    {x = 1169, y = 891, z = 7},
    {x = 1171, y = 891, z = 7},
    {x = 1173, y = 891, z = 7}
}

local destination = {x...
hi, i try create random tp after i click on item of id XXX but it not work ;/ its my code

Code:
function onUse(cid, item, pos)
if cid > 0 then
    if item.actionid == 10534 then
            local location = {
                {x=1163, y=883, z=7, stackpos=253},
                {x=1167, y=883, z=7, stackpos=253},
                {x=1169, y=883, z=7, stackpos=253},
                {x=1172, y=883, z=7, stackpos=253},
                {x=1162, y=885, z=7, stackpos=253},
                {x=1164, y=885, z=7, stackpos=253},
                {x=1171, y=885, z=7, stackpos=253},
                {x=1173, y=885, z=7, stackpos=253},
                {x=1162, y=887, z=7, stackpos=253},
                {x=1164, y=887, z=7, stackpos=253},
                {x=1171, y=887, z=7, stackpos=253},
                {x=1173, y=887, z=7, stackpos=253},
                {x=1163, y=889, z=7, stackpos=253},
                {x=1167, y=889, z=7, stackpos=253},
                {x=1169, y=889, z=7, stackpos=253},
                {x=1172, y=889, z=7, stackpos=253},
                {x=1165, y=891, z=7, stackpos=253},
                {x=1167, y=891, z=7, stackpos=253},
                {x=1169, y=891, z=7, stackpos=253},
                {x=1171, y=891, z=7, stackpos=253},
                {x=1173, y=891, z=7, stackpos=253}
            }
            local xd = math.random(1, #location)
            local playerteleported = 1
            for i=1,#location do
                getplayer = getThingFromPos(location[i])
                if getplayer == #location[i] then
                    if(value) == location[i] then
                    doTeleportThing(cid,{x=1168, y=893, z=7})
                    doPlayerSendTextMessage(cid,22,"[KillEvent] Boom!")
                    break
                end
                end
                end
                end
                end
end

I have 21 positions, if i click on item XXX match.random geting random pos and player get free teleport to XX pos
XML:
<action itemid="1111111111111111" event="script" value="random_teleport_item.lua"/>
Lua:
local locations = {
    {x = 1163, y = 883, z = 7},
    {x = 1167, y = 883, z = 7},
    {x = 1169, y = 883, z = 7},
    {x = 1172, y = 883, z = 7},
    {x = 1162, y = 885, z = 7},
    {x = 1164, y = 885, z = 7},
    {x = 1171, y = 885, z = 7},
    {x = 1173, y = 885, z = 7},
    {x = 1162, y = 887, z = 7},
    {x = 1164, y = 887, z = 7},
    {x = 1171, y = 887, z = 7},
    {x = 1173, y = 887, z = 7},
    {x = 1163, y = 889, z = 7},
    {x = 1167, y = 889, z = 7},
    {x = 1169, y = 889, z = 7},
    {x = 1172, y = 889, z = 7},
    {x = 1165, y = 891, z = 7},
    {x = 1167, y = 891, z = 7},
    {x = 1169, y = 891, z = 7},
    {x = 1171, y = 891, z = 7},
    {x = 1173, y = 891, z = 7}
}

function onUse(cid, item, pos)
    local rand = math.random(#locations)
    doTeleportThing(cid, locations[rand])
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[KillEvent] Boom!")
    return true
end
 
Thanks, but your script teleport player to random location if he use Item, i want teleport player to xxx pos from random location if God use Item of id.

1. God use Item XXX
2. Script roll random location
3. If player is on this location he get freestyle to to XXX pos
 
if you want the script to keep pulling players from all positions instead of only 1 player, remove the break on line 34
Lua:
local locations = {
    {x = 1163, y = 883, z = 7},
    {x = 1167, y = 883, z = 7},
    {x = 1169, y = 883, z = 7},
    {x = 1172, y = 883, z = 7},
    {x = 1162, y = 885, z = 7},
    {x = 1164, y = 885, z = 7},
    {x = 1171, y = 885, z = 7},
    {x = 1173, y = 885, z = 7},
    {x = 1162, y = 887, z = 7},
    {x = 1164, y = 887, z = 7},
    {x = 1171, y = 887, z = 7},
    {x = 1173, y = 887, z = 7},
    {x = 1163, y = 889, z = 7},
    {x = 1167, y = 889, z = 7},
    {x = 1169, y = 889, z = 7},
    {x = 1172, y = 889, z = 7},
    {x = 1165, y = 891, z = 7},
    {x = 1167, y = 891, z = 7},
    {x = 1169, y = 891, z = 7},
    {x = 1171, y = 891, z = 7},
    {x = 1173, y = 891, z = 7}
}

function onUse(cid, item, pos)
    -- check each location for a player
    for _, position in ipairs(locations) do
        local creature = getTopCreature(position)
        -- checking for each top creature on the position
        if creature and creature.uid > 0 and isPlayer(creature.uid) then
            -- found a player to teleport, stop searching for more players
            doTeleportThing(creature.uid, locations[math.random(#locations)])
            doPlayerSendTextMessage(creature.uid, MESSAGE_STATUS_CONSOLE_ORANGE, "[KillEvent] Boom!")
            break
        end
    end
    return true
end
 
if you want the script to keep pulling players from all positions instead of only 1 player, remove the break on line 34
Lua:
local locations = {
    {x = 1163, y = 883, z = 7},
    {x = 1167, y = 883, z = 7},
    {x = 1169, y = 883, z = 7},
    {x = 1172, y = 883, z = 7},
    {x = 1162, y = 885, z = 7},
    {x = 1164, y = 885, z = 7},
    {x = 1171, y = 885, z = 7},
    {x = 1173, y = 885, z = 7},
    {x = 1162, y = 887, z = 7},
    {x = 1164, y = 887, z = 7},
    {x = 1171, y = 887, z = 7},
    {x = 1173, y = 887, z = 7},
    {x = 1163, y = 889, z = 7},
    {x = 1167, y = 889, z = 7},
    {x = 1169, y = 889, z = 7},
    {x = 1172, y = 889, z = 7},
    {x = 1165, y = 891, z = 7},
    {x = 1167, y = 891, z = 7},
    {x = 1169, y = 891, z = 7},
    {x = 1171, y = 891, z = 7},
    {x = 1173, y = 891, z = 7}
}

function onUse(cid, item, pos)
    -- check each location for a player
    for _, position in ipairs(locations) do
        local creature = getTopCreature(position)
        -- checking for each top creature on the position
        if creature and creature.uid > 0 and isPlayer(creature.uid) then
            -- found a player to teleport, stop searching for more players
            doTeleportThing(creature.uid, locations[math.random(#locations)])
            doPlayerSendTextMessage(creature.uid, MESSAGE_STATUS_CONSOLE_ORANGE, "[KillEvent] Boom!")
            break
        end
    end
    return true
end
He wants a random person to be teleported to X location.
The only way to become a random person is to stand on the designated locations.

You can see the location he wants to teleport them in his original post.

If nobody else posts the solution, I'll do it on my lunch break.
 
edit the local destination
Lua:
local locations = {
    {x = 1163, y = 883, z = 7},
    {x = 1167, y = 883, z = 7},
    {x = 1169, y = 883, z = 7},
    {x = 1172, y = 883, z = 7},
    {x = 1162, y = 885, z = 7},
    {x = 1164, y = 885, z = 7},
    {x = 1171, y = 885, z = 7},
    {x = 1173, y = 885, z = 7},
    {x = 1162, y = 887, z = 7},
    {x = 1164, y = 887, z = 7},
    {x = 1171, y = 887, z = 7},
    {x = 1173, y = 887, z = 7},
    {x = 1163, y = 889, z = 7},
    {x = 1167, y = 889, z = 7},
    {x = 1169, y = 889, z = 7},
    {x = 1172, y = 889, z = 7},
    {x = 1165, y = 891, z = 7},
    {x = 1167, y = 891, z = 7},
    {x = 1169, y = 891, z = 7},
    {x = 1171, y = 891, z = 7},
    {x = 1173, y = 891, z = 7}
}

local destination = {x = x, y = y, z = z}

function onUse(cid, item, pos)
    -- check each location for a player
    local location = locations[math.random(#locations)]
    local creature = getTopCreature(location)
    if creature and creature.uid > 0 and isPlayer(creature.uid) then
        doTeleportThing(creature.uid, destination)
        doPlayerSendTextMessage(creature.uid, MESSAGE_STATUS_CONSOLE_ORANGE, "[KillEvent] Boom!")
    end
    return true
end
 
Solution
Back
Top