• 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!

[Request]MAP CHANGE SCRIPT

Mindzer

!N00B!
Joined
Jun 8, 2009
Messages
100
Reaction score
0
Location
Slovenia
can anyone make script to change map every 30 min....Just make script with 4 positions and I'll put cordinates in...I'll give rep++ thankyou :D
 
I have problem that Map is changing but when player logins after map was changed he spawns in town 1 not in town where players were teleported
 
function onLogin(cid)
doPlayerSetTown(cid, getGlobalStorageValue(config.storage))
doTeleportThing(cid, getPlayerMasterPos(cid))
return true
end

that is included in the script which is the failsafe to prevent that, but It seems that the newest TFS fucks up my global storages :S
 
mmm I haven't really experimented and tried but its messing up my scripts too soo let me know if you learn how to fix the global storages ;p
 
Could you show me in this script where to change that :D pleasee post under what You mean with updating. I'll give you rep++



Lua:
<?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>
 
I made one
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
Not tested, choose time in xml :)
 
While it was loading i got this error



PHP:
[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 '{'


I just copied your script and changed number of towns then saved it as mapchange.lua after that opened globalevents.xml and add

PHP:
<globalevent name="MapChange" interval="15" event="script" value="mapchange.lua"/>


Any idea why that error happened :D?
 
oh sorry
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
 
hehe np But now there's other error showing in console :D

PHP:
[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


Hope you can fix that :)

Thankyou Mindzer
 
Damn, try this again :)
Lua:
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
 
Now the problem shows in this way :D

PHP:
[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.


Thankyou for you patience xDD

Mindzer
 
Code:
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
Should be also faster because we only execute 1 query in total.
 
Hello Thank you it's working now :D

rep++ too both for your help but could you tell me what to change to make right towns because now players setting change to 0/0/0/0


PHP:
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

Thankyou Mindzer
 
Back
Top