• 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 Removing a Teleport on an event

Justin123456

New Member
Joined
Mar 24, 2011
Messages
177
Reaction score
4
Can someone help me edit this script so when it says "The Battle begins. Survive for glory!" it will remove the teleport that is at x=968, y=1306, z=6?
I tried but as you can see... I kinda failed haha :p

Here is mine:

PHP:
local config = {
	temporaryArea = {
		{x = 951, y = 1314, z = 6}, -- northwest corner of area where players must stand in order to join the event
		{x = 957, y = 1320, z = 6} -- south east corner
	},
	arenaArea = {
		{x = 964, y = 1313, z = 7}, -- nw corner of arena
		{x = 987, y = 1327, z = 7}, -- se corner of arena
		{x = 977, y = 1321, z = 7} -- center of arena
	},

	minPlayers = 1, -- min players required to start the battle
	prize = {2160, 5467} -- rewards
}
	gatepos = {x=968, y=1306, z=6, stackpos=1}
	getgate = getThingfromPos(gatepos)
	
function onThink(interval, lastExecution, thinkInterval)

	local players, arenaPlayers = {}, {}
	for x = (config.temporaryArea)[1].x, (config.temporaryArea)[2].x do
		for y = (config.temporaryArea)[1].y, (config.temporaryArea)[2].y do
			for z = (config.temporaryArea)[1].z, (config.temporaryArea)[2].z do
				if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
					table.insert(players, getTopCreature({x = x, y = y, z = z}).uid)
				end
			end
		end
	end
	for x = (config.arenaArea)[1].x, (config.arenaArea)[2].x do
		for y = (config.arenaArea)[1].y, (config.arenaArea)[2].y do
			for z = (config.arenaArea)[1].z, (config.arenaArea)[2].z do
				if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
					table.insert(arenaPlayers, getTopCreature({x = x, y = y, z = z}).uid)
				end
			end
		end
	end	

	if(table.maxn(arenaPlayers) == 1) then
		doTeleportThing(arenaPlayers[1], getPlayerMasterPos(arenaPlayers[1]))
		doSendMagicEffect(getPlayerMasterPos(arenaPlayers[1]), CONST_ME_TELEPORT)
		doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You win a battle and recived your reward.")
		doPlayerAddItem(arenaPlayers[1], (config.prize)[math.random(1, table.maxn(config.prize))], 1)
	elseif(table.maxn(arenaPlayers) < 1) then
		if(table.maxn(players) >= config.minPlayers) then
			for i = 1, config.minPlayers do
				doTeleportThing(players[i], (config.arenaArea)[3])
				doSendMagicEffect((config.arenaArea)[3], CONST_ME_TELEPORT)
				doPlayerSendTextMessage(players[i], MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
				if getgate.itemid == 1355 then
				doRemoveItem(getgate.uid,1)
			end
		end
	end
	return true
end

Here is original:

PHP:
local config = {
	temporaryArea = {
		{x = 951, y = 1314, z = 6}, -- northwest corner of area where players must stand in order to join the event
		{x = 957, y = 1320, z = 6} -- south east corner
	},
	arenaArea = {
		{x = 964, y = 1313, z = 7}, -- nw corner of arena
		{x = 987, y = 1327, z = 7}, -- se corner of arena
		{x = 977, y = 1321, z = 7} -- center of arena
	},
	minPlayers = 1, -- min players required to start the battle
	prize = {2160, 5467} -- rewards
}
 
function onThink(interval, lastExecution, thinkInterval)
	local players, arenaPlayers = {}, {}
	for x = (config.temporaryArea)[1].x, (config.temporaryArea)[2].x do
		for y = (config.temporaryArea)[1].y, (config.temporaryArea)[2].y do
			for z = (config.temporaryArea)[1].z, (config.temporaryArea)[2].z do
				if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
					table.insert(players, getTopCreature({x = x, y = y, z = z}).uid)
				end
			end
		end
	end
	for x = (config.arenaArea)[1].x, (config.arenaArea)[2].x do
		for y = (config.arenaArea)[1].y, (config.arenaArea)[2].y do
			for z = (config.arenaArea)[1].z, (config.arenaArea)[2].z do
				if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
					table.insert(arenaPlayers, getTopCreature({x = x, y = y, z = z}).uid)
				end
			end
		end
	end
	if(table.maxn(arenaPlayers) == 1) then
		doTeleportThing(arenaPlayers[1], getPlayerMasterPos(arenaPlayers[1]))
		doSendMagicEffect(getPlayerMasterPos(arenaPlayers[1]), CONST_ME_TELEPORT)
		doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You win a battle and recived your reward.")
		doPlayerAddItem(arenaPlayers[1], (config.prize)[math.random(1, table.maxn(config.prize))], 1)
	elseif(table.maxn(arenaPlayers) < 1) then
		if(table.maxn(players) >= config.minPlayers) then
			for i = 1, config.minPlayers do
				doTeleportThing(players[i], (config.arenaArea)[3])
				doSendMagicEffect((config.arenaArea)[3], CONST_ME_TELEPORT)
				doPlayerSendTextMessage(players[i], MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
			end
		end
	end
	return true
end

Btw I'm using TFS 0.3.6! I'll REP whoever helps! :)
 
try this
Lua:
local config = {
    temporaryArea = {
        {x = 951, y = 1314, z = 6}, -- northwest corner of area where players must stand in order to join the event
        {x = 957, y = 1320, z = 6} -- south east corner
    },
    arenaArea = {
        {x = 964, y = 1313, z = 7}, -- nw corner of arena
        {x = 987, y = 1327, z = 7}, -- se corner of arena
        {x = 977, y = 1321, z = 7} -- center of arena
    },

    minPlayers = 1, -- min players required to start the battle
    prize = {2160, 5467} -- rewards
}
    gatepos = {x=968, y=1306, z=6, stackpos=1}
    getgate = getThingfromPos(gatepos)
    
function onThink(interval, lastExecution, thinkInterval)

    local players, arenaPlayers = {}, {}
    for x = (config.temporaryArea)[1].x, (config.temporaryArea)[2].x do
        for y = (config.temporaryArea)[1].y, (config.temporaryArea)[2].y do
            for z = (config.temporaryArea)[1].z, (config.temporaryArea)[2].z do
                if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
                    table.insert(players, getTopCreature({x = x, y = y, z = z}).uid)
                end
            end
        end
    end
    for x = (config.arenaArea)[1].x, (config.arenaArea)[2].x do
        for y = (config.arenaArea)[1].y, (config.arenaArea)[2].y do
            for z = (config.arenaArea)[1].z, (config.arenaArea)[2].z do
                if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
                    table.insert(arenaPlayers, getTopCreature({x = x, y = y, z = z}).uid)
                end
            end
        end
    end    

    if(table.maxn(arenaPlayers) == 1) then
        doTeleportThing(arenaPlayers[1], getPlayerMasterPos(arenaPlayers[1]))
        doSendMagicEffect(getPlayerMasterPos(arenaPlayers[1]), CONST_ME_TELEPORT)
        doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You win a battle and recived your reward.")
        doPlayerAddItem(arenaPlayers[1], (config.prize)[math.random(1, table.maxn(config.prize))], 1)
    elseif(table.maxn(arenaPlayers) < 1) then
        if(table.maxn(players) >= config.minPlayers) then
            for i = 1, config.minPlayers do
                doTeleportThing(players[i], (config.arenaArea)[3])
                doSendMagicEffect((config.arenaArea)[3], CONST_ME_TELEPORT)
                doPlayerSendTextMessage(players[i], MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
                local get = getThingfromPos(cfg.gatepos)
		     if get.itemid == 1387 then
			doRemoveItem(get.uid, 1)
            end
        end
    end
    return true
end
 
Nope, I get this error now...
Code:
[23/07/2012 14:39:35] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/LMS.lua:58: 'end' expected (to close 'function' at line 18) near '<eof>'
[23/07/2012 14:39:35] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/LMS.lua)
[23/07/2012 14:39:36] data/globalevents/scripts/LMS.lua:58: 'end' expected (to close 'function' at line 18) near '<eof>'

EDIT: I added an extra end at the end to get rid of that error but now I get this one....
Code:
[23/07/2012 14:44:28] [Error - GlobalEvent Interface] 
[23/07/2012 14:44:28] data/globalevents/scripts/LMS.lua:onThink
[23/07/2012 14:44:28] Description: 
[23/07/2012 14:44:28] data/globalevents/scripts/LMS.lua:51: attempt to index global 'cfg' (a nil value)
[23/07/2012 14:44:28] stack traceback:
[23/07/2012 14:44:28] 	data/globalevents/scripts/LMS.lua:51: in function <data/globalevents/scripts/LMS.lua:18>
[23/07/2012 14:44:28] [Error - GlobalEvents::think] Couldn't execute event: LMS
 
try now
Lua:
local config = {
    temporaryArea = {
        {x = 951, y = 1314, z = 6}, -- northwest corner of area where players must stand in order to join the event
        {x = 957, y = 1320, z = 6} -- south east corner
    },
    arenaArea = {
        {x = 964, y = 1313, z = 7}, -- nw corner of arena
        {x = 987, y = 1327, z = 7}, -- se corner of arena
        {x = 977, y = 1321, z = 7} -- center of arena
    },

    minPlayers = 1, -- min players required to start the battle
    prize = {2160, 5467} -- rewards
}
    gatepos = {x=968, y=1306, z=6, stackpos=1}
    getgate = getThingfromPos(gatepos)
    
function onThink(interval, lastExecution, thinkInterval)

    local players, arenaPlayers = {}, {}
    for x = (config.temporaryArea)[1].x, (config.temporaryArea)[2].x do
        for y = (config.temporaryArea)[1].y, (config.temporaryArea)[2].y do
            for z = (config.temporaryArea)[1].z, (config.temporaryArea)[2].z do
                if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
                    table.insert(players, getTopCreature({x = x, y = y, z = z}).uid)
                end
            end
        end
    end
    for x = (config.arenaArea)[1].x, (config.arenaArea)[2].x do
        for y = (config.arenaArea)[1].y, (config.arenaArea)[2].y do
            for z = (config.arenaArea)[1].z, (config.arenaArea)[2].z do
                if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
                    table.insert(arenaPlayers, getTopCreature({x = x, y = y, z = z}).uid)
                end
            end
        end
    end    

    if(table.maxn(arenaPlayers) == 1) then
        doTeleportThing(arenaPlayers[1], getPlayerMasterPos(arenaPlayers[1]))
        doSendMagicEffect(getPlayerMasterPos(arenaPlayers[1]), CONST_ME_TELEPORT)
        doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You win a battle and recived your reward.")
        doPlayerAddItem(arenaPlayers[1], (config.prize)[math.random(1, table.maxn(config.prize))], 1)
    elseif(table.maxn(arenaPlayers) < 1) then
        if(table.maxn(players) >= config.minPlayers) then
            for i = 1, config.minPlayers do
                doTeleportThing(players[i], (config.arenaArea)[3])
                doSendMagicEffect((config.arenaArea)[3], CONST_ME_TELEPORT)
                doPlayerSendTextMessage(players[i], MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
                local get = getThingfromPos(config.gatepos)
		     if get.itemid == 1387 then
			doRemoveItem(get.uid, 1)
            end
        end
    end
    return true
end
 
Nope, I got this error:
Code:
[23/07/2012 15:41:49] [Error - GlobalEvent Interface] 
[23/07/2012 15:41:49] data/globalevents/scripts/LMS.lua:onThink
[23/07/2012 15:41:49] Description: 
[23/07/2012 15:41:49] attempt to index a nil value
[23/07/2012 15:41:49] stack traceback:
[23/07/2012 15:41:49] 	[C]: in function 'getThingfromPos'
[23/07/2012 15:41:49] 	data/globalevents/scripts/LMS.lua:51: in function <data/globalevents/scripts/LMS.lua:18>
[23/07/2012 15:41:49] [Error - GlobalEvents::think] Couldn't execute event: LMS
 
Lua:
local config = {
    temporaryArea = {
        {x = 951, y = 1314, z = 6}, -- northwest corner of area where players must stand in order to join the event
        {x = 957, y = 1320, z = 6} -- south east corner
    },
    arenaArea = {
        {x = 964, y = 1313, z = 7}, -- nw corner of arena
        {x = 987, y = 1327, z = 7}, -- se corner of arena
        {x = 977, y = 1321, z = 7} -- center of arena
    },
 
    minPlayers = 1, -- min players required to start the battle
    prize = {2160, 5467} -- rewards
}

function onThink(interval, lastExecution, thinkInterval)
 
    local players, arenaPlayers = {}, {}
    for x = (config.temporaryArea)[1].x, (config.temporaryArea)[2].x do
        for y = (config.temporaryArea)[1].y, (config.temporaryArea)[2].y do
            for z = (config.temporaryArea)[1].z, (config.temporaryArea)[2].z do
                if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
                    table.insert(players, getTopCreature({x = x, y = y, z = z}).uid)
                end
            end
        end
    end
    for x = (config.arenaArea)[1].x, (config.arenaArea)[2].x do
        for y = (config.arenaArea)[1].y, (config.arenaArea)[2].y do
            for z = (config.arenaArea)[1].z, (config.arenaArea)[2].z do
                if(isPlayer(getTopCreature({x = x, y = y, z = z}).uid)) then
                    table.insert(arenaPlayers, getTopCreature({x = x, y = y, z = z}).uid)
                end
            end
        end
    end    
 
    if(table.maxn(arenaPlayers) == 1) then
        doTeleportThing(arenaPlayers[1], getPlayerMasterPos(arenaPlayers[1]))
        doSendMagicEffect(getPlayerMasterPos(arenaPlayers[1]), CONST_ME_TELEPORT)
        doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You win a battle and recived your reward.")
        doPlayerAddItem(arenaPlayers[1], (config.prize)[math.random(1, table.maxn(config.prize))], 1)
    elseif(table.maxn(arenaPlayers) < 1) then
        if(table.maxn(players) >= config.minPlayers) then
            for i = 1, config.minPlayers do
                doTeleportThing(players[i], (config.arenaArea)[3])
                doSendMagicEffect((config.arenaArea)[3], CONST_ME_TELEPORT)
                doPlayerSendTextMessage(players[i], MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
		local gatepos = {x=968, y=1306, z=6, stackpos=1}
		local tp = getTileItemById(gatepos, 1387)
		doRemoveItem(tp.uid, 1)
            end
        end
    end
    return true
end
 
Back
Top