• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC +[Globalevent] Team Battle, easy to configure

this is a good script, if this was made into a mod and all your todo list was finished it would be in the top 5 script releases this year nice work
 
hah, wrote it fast
;d
Code:
local config = {
	redTeamStorage = 9238,
	blueTeamStorage = 9839,
	redTeamPos = {x = 100, y = 200, z = 7},
	blueTeamPos = {x = 100, y = 200, z = 7},
	redTeamGlobal = 3482,
	blueTeamGlobal = 3483,
	redPlayers = {},
	bluePlayers = {},
	inEvent = 3472
}
local function stopBattle()
	for i, v in ipairs(config.redPlayers) do
		for i, t in ipairs(config.bluePlayers) do
			if #v > #t then
				doTeleportThing(v, getTownTemplePosition(getPlayerTown(v)))
				table.remove(config.redPlayers, v)
				doTeleportThing(t, getTownTemplePosition(getPlayerTown(t)))
				table.remove(config.bluePlayers, t)
			elseif #t > #v then
				doTeleportThing(v, getTownTemplePosition(getPlayerTown(v)))
				table.remove(config.redPlayers, v)
				doTeleportThing(t, getTownTemplePosition(getPlayerTown(t)))
				table.remove(config.bluePlayers, t)
			end
		end
	end
	return true
end
local function startBattle(minutes)
	local teleportEvent = 0
	if minutes == 0 then
		for _, cid in ipairs(getPlayersOnline()) do
			if getPlayerStorageValue(cid, config.inEvent) == 1 then
				if math.random(1, 3) < 3 then
					doTeleportThing(cid, config.redTeamPos, true)
					setPlayerStorageValue(cid, config.redTeamStorage, 1)
					setGlobalStorageValue(config.redTeamGlobal, getGlobalStorageValue(config.redTeamGlobal)+1)
					table.insert(config.redPlayers, cid)
				else
					doTeleportThing(cid, config.blueTeamPos, true)
					setPlayerStorageValue(cid, config.blueTeamStorage, 1)
					setGlobalStorageValue(config.blueTeamGlobal, getGlobalStorageValue(config.blueTeamGlobal)+1)
					table.insert(config.bluePlayers, cid)
				end
			end
			if getGlobalStorageValue(config.redTeamGlobal) > getGlobalStorageValue(config.blueTeamGlobal) then
				if getPlayerStorageValue(cid, config.redTeamStorage) == 1 then
					setPlayerStorageValue(cid, config.redTeamStorage, -1)
					doTeleportThing(cid, config.blueTeamPos, true)
					setPlayerStorageValue(cid, config.blueTeamStorage, 1)
					setGlobalStorageValue(config.redTeamGlobal, getGlobalStorageValue(config.redTeamGlobal)-1)
				end
			elseif getGlobalStorageValue(config.blueTeamGlobal) > getGlobalStorageValue(config.redTeamGlobal) then
				if getPlayerStorageValue(cid, config.blueTeamStorage) == 1 then
					setPlayerStorageValue(cid, config.blueTeamStorage, -1)
					doTeleportThing(cid, config.redTeamPos, true)
					setPlayerStorageValue(cid, config.redTeamStorage, 1)
					setGlobalStorageValue(config.blueTeamGlobal, getGlobalStorageValue(config.blueTeamGlobal)-1)
				end
			end
		end
		return true
	end
	if minutes == 1 then
		doBroadcastMessage("Battle event will start in " .. minutes .. " minute!")
	elseif minutes <= 3 then
		doBroadcastMessage("Battle event will start in " .. minutes .. " minutes!")
	else
		doBroadcastMessage("Battle event will start in " .. minutes .. " minutes!")
	end
	teleportEvent = addEvent(startBattle, 60000, minutes - 1)
	return true
end
function onThink(interval, lastExecution)
	return startBattle(math.abs(math.ceil(5))) and addEvent(stopBattle, 25 * 60000)
end
 
Last edited:
I've made the full scripts and finished my to-do list and some more shit but I won't release it yet because it's so awesome XD Maybe i'll release it in a few months if nobody releases something like it before me :p
 
hah, wrote it fast
;d
Code:
local config = {
	redTeamStorage = 9238,
	blueTeamStorage = 9839,
	redTeamPos = {x = 100, y = 200, z = 7},
	blueTeamPos = {x = 100, y = 200, z = 7},
	redTeamGlobal = 3482,
	blueTeamGlobal = 3483,
	redPlayers = {},
	bluePlayers = {},
	inEvent = 3472
}
local function stopBattle()
	for i, v in ipairs(config.redPlayers) do
		for i, t in ipairs(config.bluePlayers) do
			if #v > #t then
				doTeleportThing(v, getTownTemplePosition(getPlayerTown(v)))
				table.remove(config.redPlayers, v)
				doTeleportThing(t, getTownTemplePosition(getPlayerTown(t)))
				table.remove(config.bluePlayers, t)
			elseif #t > #v then
				doTeleportThing(v, getTownTemplePosition(getPlayerTown(v)))
				table.remove(config.redPlayers, v)
				doTeleportThing(t, getTownTemplePosition(getPlayerTown(t)))
				table.remove(config.bluePlayers, t)
			end
		end
	end
	return true
end
local function startBattle(minutes)
	local teleportEvent = 0
	if minutes == 0 then
		for _, cid in ipairs(getPlayersOnline()) do
			if getPlayerStorageValue(cid, config.inEvent) == 1 then
				if math.random(1, 3) < 3 then
					doTeleportThing(cid, config.redTeamPos, true)
					setPlayerStorageValue(cid, config.redTeamStorage, 1)
					setGlobalStorageValue(config.redTeamGlobal, getGlobalStorageValue(config.redTeamGlobal)+1)
					table.insert(config.redPlayers, cid)
				else
					doTeleportThing(cid, config.blueTeamPos, true)
					setPlayerStorageValue(cid, config.blueTeamStorage, 1)
					setGlobalStorageValue(config.blueTeamGlobal, getGlobalStorageValue(config.blueTeamGlobal)+1)
					table.insert(config.bluePlayers, cid)
				end
			end
			if getGlobalStorageValue(config.redTeamGlobal) > getGlobalStorageValue(config.blueTeamGlobal) then
				if getPlayerStorageValue(cid, config.redTeamStorage) == 1 then
					setPlayerStorageValue(cid, config.redTeamStorage, -1)
					doTeleportThing(cid, config.blueTeamPos, true)
					setPlayerStorageValue(cid, config.blueTeamStorage, 1)
					setGlobalStorageValue(config.redTeamGlobal, getGlobalStorageValue(config.redTeamGlobal)-1)
				end
			elseif getGlobalStorageValue(config.blueTeamGlobal) > getGlobalStorageValue(config.redTeamGlobal) then
				if getPlayerStorageValue(cid, config.blueTeamStorage) == 1 then
					setPlayerStorageValue(cid, config.blueTeamStorage, -1)
					doTeleportThing(cid, config.redTeamPos, true)
					setPlayerStorageValue(cid, config.redTeamStorage, 1)
					setGlobalStorageValue(config.blueTeamGlobal, getGlobalStorageValue(config.blueTeamGlobal)-1)
				end
			end
		end
		return true
	end
	if minutes == 1 then
		doBroadcastMessage("Battle event will start in " .. minutes .. " minute!")
	elseif minutes <= 3 then
		doBroadcastMessage("Battle event will start in " .. minutes .. " minutes!")
	else
		doBroadcastMessage("Battle event will start in " .. minutes .. " minutes!")
	end
	teleportEvent = addEvent(startBattle, 60000, minutes - 1)
	return true
end
function onThink(interval, lastExecution)
	return startBattle(math.abs(math.ceil(5))) and addEvent(stopBattle, 25 * 60000)
end

Could you explain how it's working?
 
please release it! i was searching for a script like this!
rep++
 
Humm.. i have been making one like that but with teleports instead of the npc.
But found it not balanced like that.So i find this npc thing is a good idea i may use instead of tp :)
Rep++
 
Code:
 <globalevent name="TeamBattle" interval="30" event="script" value="BattleCheck.lua"/>

A question will that script be executed every 30 sec?
 
humm another question will it be executed again after 30sec when the full script is executed?i mean in the script there is some stuff wil be excuted after 25 min etc..
so this interval in global event will make this script be excuted every 30 sec even if the script is already being executed?or when the full script is executed and finished then it will wait 30 sec and will be reexcuted??

Hope you can get what i mean :)
 
"leave" isnt working : look
09:37 Mr Chinatown: Do you wish to join the battle? There is currently 1/1 players in Punishers team and 0/1 players in Tha Artards team.
09:38 Account Manager [1]: tha artards
09:38 Account Manager [1]: yes
09:38 Mr Chinatown: You are already signed up!
09:38 Account Manager [1]: hi
09:38 Account Manager [1]: leave
09:38 Mr Chinatown: Do you wish to leave the battle?
09:38 Account Manager [1]: yes
09:38 Mr Chinatown: You are not even signed up!

and this
[22/07/2010 09:38:37] [Error - Npc interface]
[22/07/2010 09:38:37] data/npc/scripts/BattleNPC.lua:eek:nCreatureSay
[22/07/2010 09:38:37] Description:
[22/07/2010 09:38:37] (luaGetCreatureStorage) Creature not found
 
Back
Top