UPDATE players SET town_id = 2;
doPlayerSetTown(cid, 2)
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Map Change" version="2.0" author="Syntax" contact="[email protected]" enabled="yes">
<description>
This should teleport all players to a new random town in intervals.
</description>
<config name="mapchange_config"><![CDATA[
config = {
access = 3, -- minimum access to bypass teleportation.
temples = {1,2,5,3}, -- townids to teleport to.
storage = 3454, -- number to store map status in.
changetime = 10 -- time to change in seconds (change in globalevents too)
}
]]></config>
<event type="login" name="Map Login" event="script"><![CDATA[
loadmodlib('mapchange_config')
function onLogin(cid)
doPlayerSetTown(cid, getGlobalStorageValue(config.storage))
doTeleportThing(cid, getPlayerMasterPos(cid))
return true
end
]]></event>
<globalevent name="Map Change" interval="10" event="script"><![CDATA[
domodlib('mapchange_config')
function onThink(interval, lastExecution, thinkInterval)
repeat
RDM = math.random(1,#config.temples)
until RDM ~= getGlobalStorageValue(config.storage) and isInArray(config.temples, RDM)
if getWorldCreatures(0) > 0 then
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerAccess(pid) < config.access and getPlayerAccountManager(pid) == MANAGER_NONE then
doPlayerSetTown(pid, config.temples[RDM])
doTeleportThing(pid, getTownTemplePosition(config.temples[RDM]), false)
doSendMagicEffect(getCreaturePosition(pid), 37)
doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
doCreatureAddMana(pid, getCreatureMaxMana(pid))
doRemoveConditions(pid, FALSE)
end
doBroadcastMessage("Round over. Map switched to " ..getTownName(config.temples[RDM]).. ".", MESSAGE_EVENT_ADVANCE)
setGlobalStorageValue(config.storage, config.temples[RDM])
end
else
print ("[MAP] No players online, aborting map change!")
end
return true
end
]]></globalevent>
</mod>
function onThink(interval, lastExecution)
local config {
minTownId = 1,
maxTownId = 5
}
if(getPlayerTown(cid) < config.maxTownId) then
doPlayerSetTown(cid, getPlayerTown(cid) + 1)
doTeleportThing(cid, getTemplePositionById(getPlayerTown(cid)))
db.executeQuery("UPDATE players SET town_id = ".. getPlayerTown(cid).."+ 1, posx = 0, posy = 0, posz = 0;")
return true
end
if(getPlayerTown(cid) >= config.maxTownId) then
doPlayerSetTown(cid, config.minTownId)
doTeleportThing(cid, getTemplePositionById(getPlayerTown(cid)))
db.executeQuery("UPDATE players SET town_id = ".. getPlayerTown(cid)..", posx = 0, posy = 0, posz = 0;")
end
return true
end
[07/02/2010 12:22:07] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/mapchange.lua:2: unexpected symbol near '{'
[07/02/2010 12:22:07] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/mapchange.lua)
[07/02/2010 12:22:07] data/globalevents/scripts/mapchange.lua:2: unexpected symbol near '{'
<globalevent name="MapChange" interval="15" event="script" value="mapchange.lua"/>
function onThink(interval, lastExecution)
local config = {
minTownId = 1,
maxTownId = 5
}
if(getPlayerTown(cid) < config.maxTownId) then
doPlayerSetTown(cid, getPlayerTown(cid) + 1)
doTeleportThing(cid, getTemplePositionById(getPlayerTown(cid)))
db.executeQuery("UPDATE players SET town_id = ".. getPlayerTown(cid).."+ 1, posx = 0, posy = 0, posz = 0;")
return true
end
if(getPlayerTown(cid) >= config.maxTownId) then
doPlayerSetTown(cid, config.minTownId)
doTeleportThing(cid, getTemplePositionById(getPlayerTown(cid)))
db.executeQuery("UPDATE players SET town_id = ".. getPlayerTown(cid)..", posx = 0, posy = 0, posz = 0;")
end
return true
end
[07/02/2010 16:39:15] [Error - GlobalEvent Interface]
[07/02/2010 16:39:15] data/globalevents/scripts/mapchange.lua:onThink
[07/02/2010 16:39:15] Description:
[07/02/2010 16:39:15] (internalGetPlayerInfo) Player not found when requesting player info #7
[07/02/2010 16:39:15] [Error - GlobalEvent Interface]
[07/02/2010 16:39:15] data/globalevents/scripts/mapchange.lua:onThink
[07/02/2010 16:39:15] Description:
[07/02/2010 16:39:15] data/globalevents/scripts/mapchange.lua:6: attempt to compare boolean with number
[07/02/2010 16:39:15] stack traceback:
[07/02/2010 16:39:15] data/globalevents/scripts/mapchange.lua:6: in function <data/globalevents/scripts/mapchange.lua:1>
[07/02/2010 16:39:15] [Error - GlobalEvents::think] Couldn't execute event: MapChange
function onThink(interval, lastExecution)
local config = {
minTownId = 1,
maxTownId = 5
}
for _, pid in ipairs(getPlayersOnline()) do
if(getPlayerTown(pid) < config.maxTownId) then
doPlayerSetTown(pid, getPlayerTown(pid) + 1)
doTeleportThing(pid, getTemplePositionById(getPlayerTown(pid)))
db.executeQuery("UPDATE players SET town_id = town_id + 1, posx = 0, posy = 0, posz = 0;")
return true
end
if(getPlayerTown(pid) >= config.maxTownId) then
doPlayerSetTown(pid, config.minTownId)
doTeleportThing(pid, getTemplePositionById(getPlayerTown(pid)))
db.executeQuery("UPDATE players SET town_id = "..config.minTownId..", posx = 0, posy = 0, posz = 0;")
end
end
return true
end
[07/02/2010 20:54:00] [Error - GlobalEvent Interface]
[07/02/2010 20:54:00] data/globalevents/scripts/Mapchange.lua:onThink
[07/02/2010 20:54:00] Description:
[07/02/2010 20:54:00] data/globalevents/scripts/Mapchange.lua:9: attempt to call global 'getTemplePositionById' (a nil value)
[07/02/2010 20:54:00] stack traceback:
[07/02/2010 20:54:00] data/globalevents/scripts/Mapchange.lua:9: in function <data/globalevents/scripts/Mapchange.lua:1>
[07/02/2010 20:54:00] [Error - GlobalEvents::think] Couldn't execute event: mapchange
[07/02/2010 20:54:10] Reloaded global events.
local config, new = {
minTownId = 1,
maxTownId = 5
}, 0
function onThink(interval, lastExecution)
for _, pid in ipairs(getPlayersOnline()) do
local town = getPlayerTown(pid)
new = town < config.maxTownId and town + 1 or config.minTownId
doPlayerSetTown(pid, new)
doTeleportThing(pid, getTownTemplePosition(new))
end
db.executeQuery("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end
local config, new = {
minTownId = 1,
maxTownId = 4
}, 0
function onThink(interval, lastExecution)
for _, pid in ipairs(getPlayersOnline()) do
local town = getPlayerTown(pid)
new = town < config.maxTownId and town + 1 or config.minTownId
doPlayerSetTown(pid, new)
doTeleportThing(pid, getTownTemplePosition(new))
end
db.executeQuery("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end