Heres a race event that i made;
global events:

raceTP.lua -- creates a TP in event room every ~ minutes for event
[LUA]local createpos = {x = 818, y = 1205, z = 7} -- Where tp will appear
local topos = {x = 872, y = 1204, z = 7} -- Where will the Teleport take you
local msg = "Race TP is now closed. It will open again in 1 hour!"
local timetoclose = 120 -- in second

local function remove()
local tp = getTileItemById(createpos,1387).uid
if tp ~= 0 then
doRemoveItem(tp)
doBroadcastMessage(msg)
end
end

function onThink(interval)

doCreateTeleport(1387, topos, createpos)
doBroadcastMessage("Race TP is now open!\nCatch the teleport within "..timetoclose.." seconds! Teleport is Located in Events room.")
addEvent(remove,timetoclose*1000)
return true
end [/LUA]

race.lua -- if someone wins, will teleport everyone else out of event.. make sure event is PZ and NOlogout
[LUA]function onThink(cid, interval, lastExecution)
for _, name in ipairs(getOnlinePlayers()) do
local mage = {1, 5, 9, 13, 17, 21, 25, 29, 2, 6, 10, 14, 18, 22, 26, 30}
local paladin = {3, 7, 11, 15, 19, 23, 27, 31}
local player = getPlayerByName(name)
if getPlayerStorageValue(player, 70100) == 1 and getGlobalStorageValue(player, 80050) == 5 then
doTeleportThing(player, {x = 1343, y = 1424, z = 7})
doChangeSpeed(player, getPlayerStorageValue(player, 70101))
setPlayerStorageValue(player, 70100, 0)
doPlayerLearnInstantSpell(player, "utani hur")
if isInArray(mage,getPlayerVocation(player)) then
doPlayerLearnInstantSpell(player, "utani gran hur")
end
if isInArray(paladin,getPlayerVocation(player)) then
doPlayerLearnInstantSpell(player, "utani hur")
end
end
end
return true
end[/LUA]
globalevents.xml
Code:
<globalevent name="Race" interval="1" event="script" value="race.lua"/>
<globalevent name="RaceTP" interval="3600" event="script" value="raceTP.lua"/>
actions
race.lua -- modified anni, have 4 spots for players to stand, then lever.
[LUA]local config = {
daily = "no", -- allow only one enter per day? (like in global Tibia)
level = 100,
storage = 30015,
entry =
{
{x = 875, y = 1201, z = 7},
{x = 875, y = 1203, z = 7},
{x = 875, y = 1205, z = 7},
{x = 875, y = 1207, z = 7}
},
destination =
{
{x = 892, y = 1197, z = 7},
{x = 892, y = 1202, z = 7},
{x = 892, y = 1207, z = 7},
{x = 892, y = 1212, z = 7}
}
}

config.daily = getBooleanFromString(config.daily)
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(item.itemid == 1946) then
if(config.daily) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
else
doTransformItem(item.uid, item.itemid - 1)
end

return true
end

if(item.itemid ~= 1945) then
return true
end

local players = {}
for _, position in ipairs(config.entry) do
local pid = getTopCreature(position).uid
if(pid == 0 or not isPlayer(pid)) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
return true
end

table.insert(players, pid)
end

for i, pid in ipairs(players) do
local mage = {1, 5, 9, 13, 17, 21, 25, 29, 2, 6, 10, 14, 18, 22, 26, 30}
local paladin = {3, 7, 11, 15, 19, 23, 27, 31}
doSendMagicEffect(config.entry, CONST_ME_POFF)
doTeleportThing(pid, config.destination, false)
doPlayerSendTextMessage(pid, MESSAGE_STATUS_WARNING, "The race has begun! GO!")
setPlayerStorageValue(pid, 70101, getCreatureSpeed(pid))
doChangeSpeed(pid, 220 - getCreatureBaseSpeed(pid))
setPlayerStorageValue(pid, 70100, 1)
doPlayerUnlearnInstantSpell(pid, "utani hur")
if isInArray(mage,getPlayerVocation(pid)) then
doPlayerUnlearnInstantSpell(pid, "utani gran hur")
end
if isInArray(paladin,getPlayerVocation(pid)) then
doPlayerUnlearnInstantSpell(pid, "utani hur")
end
setGlobalStorageValue(cid, 80050, 0)
doSendMagicEffect(config.destination, CONST_ME_ENERGYAREA)
end

doTransformItem(item.uid, item.itemid + 1)
return true
end[/LUA]

actions.xml
Code:
<action uniqueid="15500-15503" event="script" value="other/race.lua"/>
movements

finishRace.lua -- put underneath the TP at end of race (dont actually put any co-ordinates in TP.. just for look)
[LUA]local t = {
prize = 2159,
name = "epic donation coin",
amount = 1,
temple = {x = 1343, y = 1424, z = 7},
}
function onStepIn(cid, item, position, fromPosition)
if getGlobalStorageValue(cid, 80050) ~= 5 then
doPlayerAddItem(cid, t.prize, t.amount)
doPlayerSendTextMessage(cid, 19, "Congratulations! Youve won "..t.amount.." "..t.name.."!")
local name = getCreatureName(cid)
doBroadcastMessage(name.." won the race!")
setGlobalStorageValue(cid, 80050, 5)
doTeleportThing(cid, t.temple)
else
doPlayerSendTextMessage(cid, 19, "Sorry you lost the race.")
doTeleportThing(cid, t.temple)
end
return true
end[/LUA]
movements.xml