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

Solved Change map only if < 30 players online

Ghazer

Member
Joined
Mar 13, 2009
Messages
350
Reaction score
6
Change map only if &lt; 30 players online

Hello guys, this is changemap created by Summ... its great but I want add one feauture...
*If this is impossible please say to me...


I want this actions work only if server have 30- players online
Code:
		        doTeleportThing(pid, temple)
		        doRemoveConditions(pid)
		        doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
		        doCreatureAddMana(pid, getCreatureMaxMana(pid))


Changemap:
LUA:
local towns = {7, 5, 4, 2, 6, 3, 1}
local tp = {
		id = 1387,
		position = {x = 986, y = 1118, z = 6}
}
 
-- Do not change
local currentTown = 1
local function removeTp(pos, id)
	local thing = getTileItemById(pos, id)
	if thing.uid > 0 then
		doRemoveItem(thing.uid)
	end
end	
 
function onThink(interval, lastExecution, thinkInterval)
    local toPos = getTownTemplePosition(towns[currentTown])
        for _, pid in ipairs(getPlayersOnline()) do
	            local temple = { x = 986, y = 1116, z = 6 }
		        doTeleportThing(pid, temple)
		        doRemoveConditions(pid)
		        doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
		        doCreatureAddMana(pid, getCreatureMaxMana(pid))
    	        doBroadcastMessage("The map has been changed and all players have been teleported to the temple. Next map change will be in: 30 minutes!", MESSAGE_STATUS_WARNING)
		end		
 
	currentTown = currentTown + 1
	if not(towns[currentTown]) then
		currentTown = 1
	end
	
	removeTp(tp.position, tp.id)
    doCreateTeleport(tp.id, toPos, tp.position)
	return true
end

- - - Updated - - -

This work to know when server have 30- players online...
LUA:
    local online = getWorldCreatures()
    if isPlayer(cid) then
	if online < 30 then

But I dont know how to apply to work only in
Code:
		        doTeleportThing(pid, temple)
		        doRemoveConditions(pid)
		        doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
		        doCreatureAddMana(pid, getCreatureMaxMana(pid))
 
Last edited:
Add this under function onThink(interval, lastExecution, thinkInterval)
LUA:
	if #getPlayersOnline() < 30 do
		return true
	end
 
Last edited:
Edited for better system..


LUA:
local towns = {7, 5, 4, 2, 6, 3, 1}
 
local currentTown = 1
 
function onThink(interval, lastExecution, thinkInterval)
	if getPlayersOnline() > 30 then
		if getGlobalStorageValue(currentmap) == 0 then
local temple = towns[1]
	elseif getGlobalStorageValue(currentmap) == 1 then
local temple = towns[2]
	elseif getGlobalStorageValue(currentmap) == 2 then
local temple = towns[3]
	elseif getGlobalStorageValue(currentmap) == 3 then
local temple = towns[4]
	elseif getGlobalStorageValue(currentmap) == 4 then
local temple = towns[5]
	elseif getGlobalStorageValue(currentmap) == 5 then
local temple = towns[6]
	elseif getGlobalStorageValue(currentmap) == 6 then
local temple = towns[1]
	setGlobalStorageValue(currentmap) - 6
end


end
    for _, pid in ipairs(getPlayersOnline()) do -- for each PID that is recieved when checking players online --
		doTeleportThing(pid, getTownName(temple)) -- teleport player to the town selected --
			doRemoveConditions(pid) -- remove conditions --
				doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
			doCreatureAddMana(pid, getCreatureMaxMana(pid))
	end	
setGlobalStorageValue(currentmap) + 1
return true
end
 
Last edited:
Im pretty sure this script is made long time ago. But anyway you could always skip the teleport part and make them teleport to temple. I could do it, but since i dont get your appreciate, why would i then?

GL
 
okay, i see what your trying to do, and your first script is acually inaccurate aswell.. Here.


Ill fix a better system up..
LUA:
local towns = {7, 5, 4, 2, 6, 3, 1}
 
local currenttown = 1
 
function onthink(interval, lastexecution, thinkinterval)
if getplayersonline() < 30 then
if getglobalstoragevalue(currentmap) <= 0 then  -- if global storage currentmap says the map is on 1 (town 1 if u want) then --
        for _, pid in ipairs(getplayersonline()) do -- for each pid that is recieved when checking players online --
	            local temple = towns[1]  -- set town to town id of towns[1] so that means 7 because its towns = {7, 6, 5} the first value is 7.
		        Doteleportthing(pid, gettownname(temple)) -- teleport player to the town selected --
		        doremoveconditions(pid) -- remove conditions --
		        docreatureaddhealth(pid, getcreaturemaxhealth(pid))
		        docreatureaddmana(pid, getcreaturemaxmana(pid))
				setglobalstoragevalue(currentmap) + 1
		end	
 
elseif getglobalstoragevalue(currentmap) == 1 then
        for _, pid in ipairs(getplayersonline()) do -- for each pid that is recieved when checking players online --
	            local temple = towns[2]  -- set town to town id of towns[1] so that means 7 because its towns = {7, 6, 5} the first value is 7.
		        Doteleportthing(pid, gettownname(temple)) -- teleport player to the town selected --
		        doremoveconditions(pid) -- remove conditions --
		        docreatureaddhealth(pid, getcreaturemaxhealth(pid))
		        docreatureaddmana(pid, getcreaturemaxmana(pid))
				setglobalstoragevalue(currentmap) + 1
		end	
elseif getglobalstoragevalue(currentmap) == 2 then
        for _, pid in ipairs(getplayersonline()) do -- for each pid that is recieved when checking players online --
	            local temple = towns[3]  -- set town to town id of towns[1] so that means 7 because its towns = {7, 6, 5} the first value is 7.
		        Doteleportthing(pid, gettownname(temple)) -- teleport player to the town selected --
		        doremoveconditions(pid) -- remove conditions --
		        docreatureaddhealth(pid, getcreaturemaxhealth(pid))
		        docreatureaddmana(pid, getcreaturemaxmana(pid))
				setglobalstoragevalue(currentmap) + 1
		end	
elseif getglobalstoragevalue(currentmap) == 3 then
        for _, pid in ipairs(getplayersonline()) do -- for each pid that is recieved when checking players online --
	            local temple = towns[4]  -- set town to town id of towns[1] so that means 7 because its towns = {7, 6, 5} the first value is 7.
		        Doteleportthing(pid, gettownname(temple)) -- teleport player to the town selected --
		        doremoveconditions(pid) -- remove conditions --
		        docreatureaddhealth(pid, getcreaturemaxhealth(pid))
		        docreatureaddmana(pid, getcreaturemaxmana(pid))
				setglobalstoragevalue(currentmap) + 1
		end	
elseif getglobalstoragevalue(currentmap) == 4 then
        for _, pid in ipairs(getplayersonline()) do -- for each pid that is recieved when checking players online --
	            local temple = towns[5]  -- set town to town id of towns[1] so that means 7 because its towns = {7, 6, 5} the first value is 7.
		        Doteleportthing(pid, gettownname(temple)) -- teleport player to the town selected --
		        doremoveconditions(pid) -- remove conditions --
		        docreatureaddhealth(pid, getcreaturemaxhealth(pid))
		        docreatureaddmana(pid, getcreaturemaxmana(pid))
				setglobalstoragevalue(currentmap) + 1
		end	
elseif getglobalstoragevalue(currentmap) == 5 then
        for _, pid in ipairs(getplayersonline()) do -- for each pid that is recieved when checking players online --
	            local temple = towns[6]  -- set town to town id of towns[1] so that means 7 because its towns = {7, 6, 5} the first value is 7.
		        Doteleportthing(pid, gettownname(temple)) -- teleport player to the town selected --
		        doremoveconditions(pid) -- remove conditions --
		        docreatureaddhealth(pid, getcreaturemaxhealth(pid))
		        docreatureaddmana(pid, getcreaturemaxmana(pid))
				setglobalstoragevalue(currentmap) + 1
		end	
elseif getglobalstoragevalue(currentmap) == 6 then
        for _, pid in ipairs(getplayersonline()) do -- for each pid that is recieved when checking players online --
	            local temple = towns[7]  -- set town to town id of towns[1] so that means 7 because its towns = {7, 6, 5} the first value is 7.
		        Doteleportthing(pid, gettownname(temple)) -- teleport player to the town selected --
		        doremoveconditions(pid) -- remove conditions --
		        docreatureaddhealth(pid, getcreaturemaxhealth(pid))
		        docreatureaddmana(pid, getcreaturemaxmana(pid))
				setglobalstoragevalue(currentmap) - 6
		end
		end
		end
	return true
end

enjoy.

I took out the create teleport script...

you you, omg from 50 lines to 200+ lines gl! -.-
 
If its not a post to help, dont post it. Not hard rule to follow. Gzz looking like idiot.


edited system, decided to take longer then 2 minutes to script.
 
It was like a help, since your old script caused memory leaks. -.-
The new one is better, Congratz.
 
Gigastar, but when I use this script if 30+ players online teleport continue changing but without teleport players to temple? I want this...

The same question to Summ, because I think if I put this on script map not continue change position... I want continue changing position if 30+ online but without teleport players understand?

Uderstand my idea? My english is bad bad bad :/ please help


_____________________________
 
Last edited:
Like this?

LUA:
local towns = {7, 5, 4, 2, 6, 3, 1}
local tp = {
		id = 1387,
		position = {x = 986, y = 1118, z = 6}
}
 
-- Do not change
local currentTown = 1
local function removeTp(pos, id)
	local thing = getTileItemById(pos, id)
	if thing.uid > 0 then
		doRemoveItem(thing.uid)
	end
end	
 
function onThink(interval, lastExecution, thinkInterval)
    local toPos = getTownTemplePosition(towns[currentTown])
    if #getPlayersOnline() > 30 then
        for _, pid in ipairs(getPlayersOnline()) do
            local temple = { x = 986, y = 1116, z = 6 }
            doTeleportThing(pid, temple)
            doRemoveConditions(pid)
            doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
            doCreatureAddMana(pid, getCreatureMaxMana(pid))
            doBroadcastMessage("The map has been changed and all players have been teleported to the temple. Next map change will be in: 30 minutes!", MESSAGE_STATUS_WARNING)
        end		
    end
 
	currentTown = currentTown + 1
	if not(towns[currentTown]) then
		currentTown = 1
	end
 
	removeTp(tp.position, tp.id)
	doCreateTeleport(tp.id, toPos, tp.position)
	return true
end

I did not understand whether you want to teleport players if more or less than 30 ppl.
 
Transport players if -30 players.

If server have 30+ not transport players but continue changing position of teleport its possible?
 
Back
Top