• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Map change and exeptions

Phemus

Member
Joined
Jun 16, 2012
Messages
150
Solutions
2
Reaction score
13
Hello! I was working on a script for a friend where the map has to change on a certain time, but if someone is doing a quest, they don't get teleported to the new town.
Here is the script:
PHP:
local config, new = {
minTownId = 1,
maxTownId = 3
}, 0
local t = {
fromPos = {x = 1004, y = 1023, z = 7},
toPos = {x = 1015, y = 1032, z = 7}
}

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))
doRemoveConditions(pid)
doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
doCreatureAddMana(pid, getCreatureMaxMana(pid))
doBroadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
elseif isInRange(getThingPos(cid), t.fromPos, t.toPos) then
db.executeQuery("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
end
db.executeQuery("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end

How this has to work is that if a player is doing a quest, they don't get teleported to the new town. In other words, if the player is inside of the are of fromPos toPos they can't get telepoted.
However, I don't think the script is right. I get this error:


I hope you understand and someone can help me. Thank you and sorry for my bad english.
 
The error you get is telling you that you need an "end" to close "for" in line 11, and it's near "elseif" in line 20. I'm no expert but perhaps adding an "end" after that "end" in line 22 may fix the error.
 
My bad. I put a "else if" instead of an "if"
However, now i get this error and i don't get teletranspoted. It says the message and gives you health and mana but it does not teleport.
17ddhh.jpg
 
Replace function isInRange in 032-position.lua with this.
Code:
function isInRange(position, fromPosition, toPosition)
   return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end
 
Back
Top