• 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 Map Change Error

seto sazo

Member
Joined
Apr 27, 2009
Messages
162
Reaction score
21
Sup. Need some help with this script. Script works perfectly, except when I turn my server on it sets my town_id to 0 x=0 y=0 z=0, and no one can Login, It says temple position is wrong. I have to turn on my server, then add the script into globalevents and reload it for it to work. Anyone know how to make it so I don't have to do it everytime? Lol
local config, new = {
minTownId = 1,
maxTownId = 10
}, 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
local minutes = 5
doBroadcastMessage("It has been one hour! The map has been changed! | Online Players: "..#getPlayersOnline())
doPlayerSetTown(pid, new)
doTeleportThing(pid, getTownTemplePosition(new))
doRemoveCondition(pid, CONDITION_INFIGHT)
end
db.executeQuery("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end
I figure you have to do something with getTownTemplePosition(townId). But when no ones logged in to start then how does it set a town to begin with. Help please! :D ALSO! How can I make it so it says Map has been changed to "Hell" or "yalahar" etc etc depending on the town_id it was changed to,
 
Last edited:
Yea it's a war server. :). Anyhoo that doesn't work. Server turns on Town_ids set to 0. XYZ all = 0. I ran that SQL. It turned all ids to 1. But then I tried to login 1 char. "temple pos is wrong", then they all changed back to Town_id = 0.
 
Do the characters save? If not, you can safely remove the query from the script since it won't be needed, and correct the default town_ids.
 
Thanks, that worked. Heres my updated script. How do I make it so that it says Game map changing in 10 seconds. New Map:Yalahar.
local config, new = {
minTownId = 1,
maxTownId = 12
}, 0

function changeMap(interval, lastExecution)
for _, pid in ipairs(getPlayersOnline()) do
local town = getPlayerTown(pid)
new = town < config.maxTownId and town + 1 or config.minTownId
local minutes = 5
doBroadcastMessage("It has been one hour! The map has been changed! | Online Players: "..#getPlayersOnline())
doPlayerSetTown(pid, new)
doTeleportThing(pid, getTownTemplePosition(new))
doRemoveCondition(pid, CONDITION_INFIGHT)
end
db.executeQuery("UPDATE players SET town_id = ".. new .."")
return true
end

function onThink(interval, lastExecution)
doBroadcastMessage("The game map will be chaning in 10 seconds! | Online Players: "..#getPlayersOnline())
addEvent(changeMap, 10000)
return true
end
 
Try
LUA:
local config, new, temple = {
	min = 1,
	max = 12
}, 0

local function changeMap()
	for _, pid in ipairs(getPlayersOnline()) do
		doPlayerSetTown(pid, new)
		doTeleportThing(pid, temple)
		doRemoveCondition(pid, CONDITION_INFIGHT)
	end
	temple = nil
	doBroadcastMessage('It has been one hour! The map has been changed! | Online Players: '..#getPlayersOnline())
	db.executeQuery('UPDATE players SET town_id='.. new)
end

function onThink(interval, lastExecution)
	new = new < config.max and new + 1 or config.min
	temple = getTownTemplePosition(new)
	doBroadcastMessage('Game map changing in 10 seconds. New Map: ' .. getTownName(new) .. '.')
	addEvent(changeMap, 10000)
	return true
end
 
Can you go 3 for 3 Cykotitan? Lol. This is so it wont teleport players that are in a storage value(Players go to quests have 4000 storage).
I get this error :(
[19:3:57.910] [Error - GlobalEvent Interface]
[19:3:57.911] In a timer event called from:
[19:3:57.912] data/globalevents/scripts/mapchange.lua:onThink
[19:3:57.913] Description:
[19:3:57.913] (luaGetCreatureStorage) Creature not found

Script
local config, new, temple = {
min = 1,
max = 12
}, 0

local function changeMap()
for _, pid in ipairs(getPlayersOnline()) do
doPlayerSetTown(pid, new)
if(getPlayerStorageValue(cid, 4000) == 0) then
doTeleportThing(pid, temple)
doRemoveCondition(pid, CONDITION_INFIGHT)
end
end
temple = nil
doBroadcastMessage('It has been one hour! The map has been changed! | Online Players: '..#getPlayersOnline())
db.executeQuery('UPDATE players SET town_id='.. new)
end

function onThink(interval, lastExecution)
new = new < config.max and new + 1 or config.min
temple = getTownTemplePosition(new)
doBroadcastMessage('Game map changing in 5 minutes. New Map: ' .. getTownName(new) .. '.')
addEvent(changeMap, 1000)
return true
end
 
Now it isn't teleporting them to towns Lol. So somethings up with the getstorage, I changed it to pid. And they dont have the storage value 4000.
 
Nvm, I fixed it. Lol I promise il get better at scripting. Finished script for anyone who wants it.

Code:
local config, new, temple = {
	min = 1,
	max = 12
}, 0
 
local function changeMap()
	for _, pid in ipairs(getPlayersOnline()) do
		doPlayerSetTown(pid, new)
			if getPlayerStorageValue(pid, 4000) ~= 1 then
				doTeleportThing(pid, temple)
			doRemoveCondition(pid, CONDITION_INFIGHT)
			end
	end
	temple = nil
	doBroadcastMessage('It has been one hour! The map has been changed! | Online Players: '..#getPlayersOnline())
	db.executeQuery('UPDATE players SET town_id='.. new)
end
 
function onThink(interval, lastExecution)
	new = new < config.max and new + 1 or config.min
	temple = getTownTemplePosition(new)
	doBroadcastMessage('Game map changing in 5 minutes. New Map: ' .. getTownName(new) .. '.')
	addEvent(changeMap, 1000)
	return true
end
 
Back
Top