• 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 Mod capture the flag

Zistonick

Member
Joined
Mar 24, 2010
Messages
183
Reaction score
14
Hello to everyOne! I need know if this mod is for use the label or is a globalevent?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Capture The Flag" enabled="yes">
	<description>
		[[
		@actionids:
			actionid 6000:
				red team
			actionid 6001:
				blue team
		@fromPos
			@toPos:
				fromPos top left position
				toPos buttom right position
		@redPlayers, bluePlayers, redGoal, blueGoal:
			all are storages
		@ctf {
			@redPos:
				red team position (where they get teleported when they die)
			@bluePos:
				blue team position (/// same)
		}
		@temple:
			temple position.
		]]
	</description>
	<config name="ctf_config"><![CDATA[
		waitingRoom = {
			fromPos = {x = 1005, y = 1018, z = 7},
			toPos = {x = 1015, y = 1025, z = 7}
		}
		redPlayers = 1200
		bluePlayers = 2200

		redGoal = 3200
		blueGoal = 4200

		redFlag = 5200
		blueFlag = 5520

		ctf = {
			redPos = {x = 1009, y = 1014, z = 7},
			bluePos = {x = 1009, y = 1009, z = 7}
		}

		temple = {x = 1020, y = 1021, z = 7}
	]]></config>
	<globalevent name="onstartup_ctf" type="start" event="script"><![CDATA[
		domodlib("ctf_config")
		setGlobalStorageValue(redGoal, 0)
		setGlobalStorageValue(blueGoal, 0)
		setGlobalStorageValue(redFlag, -1)
		setGlobalStorageValue(blueFlag, -1)
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. redFlag .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. blueFlag .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key`= " .. redPlayers .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. bluePlayers .. ";")
		return true
	]]></globalevent>
	<globalevent name="start_ctf" interval="60000" event="script"><![CDATA[
		domodlib("ctf_config")
	local red, blue = {}, {}
	local conditionBlue =  createConditionObject(CONDITION_OUTFIT)
		setConditionParam(conditionBlue, CONDITION_PARAM_TICKS, 1800 * 1000)
		addOutfitCondition(conditionBlue, {lookType = 130, lookHead = 87, lookBody = 87, lookLegs = 87, lookFeet = 87})
	local conditionRed = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(conditionRed, CONDITION_PARAM_TICKS, 1800 * 1000)
		addOutfitCondition(conditionRed, {lookType = 130, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94})

	local function getPlayers(from, to)
		local list = {}
		for x = from.x, to.x do
			for y = from.y, to.y do
				for z = from.z, to.z do
					local creature = getTopCreature({x =x , y =y, z = z}).uid
					if isPlayer(creature) then
						table.insert(list, creature)
					end
				end
			end
		end
		return list
	end
	local function finishThis()
		local t = getPlayers(waitingRoom.fromPos, waitingRoom.toPos)
		if #t == 1 then
			doPlayerSendTextMessage(t[1], 27, "Find another player to play with.")
			doTeleportThing(t[1], temple, true)
		elseif #t == 2 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
		elseif #t == 3 then
			table.insert(red, t[2])
			table.insert(blue, t[3])
			table.insert(red, t[1])
		elseif #t == 4 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
			table.insert(red, t[3])
			table.insert(blue, t[4])
		else
			for _, v in ipairs(t) do
				if math.random(1, 3) < 3 then
					table.insert(red, v)
				else
					table.insert(blue, v)
				end
			end
		end
		if #red > 0 and #blue > 0 then
			for _, r in ipairs(red) do
				setPlayerStorageValue(r, redPlayers, 1)
				doAddCondition(r, conditionRed)
				doTeleportThing(r, ctf.redPos, true)
				red = {}
			end
			for _, b in ipairs(blue) do
				setPlayerStorageValue(b, bluePlayers, 1)
				doAddCondition(b, conditionBlue)
				doTeleportThing(b, ctf.bluePos, true)
				blue = {}
			end
		end
		return true
	end
	local function teleport()
		addEvent(doBroadcastMessage, 1000, "Capture The Flag will begin in 2 minutes.")
		addEvent(doBroadcastMessage, 60 * 1000, "Capture The Flag will begin in 1 minute.")
		addEvent(doBroadcastMessage, 120 * 1000, "Capture The Flag will begin now.")
		addEvent(finishThis, 120 * 1000)
	end
	function onThink(interval)
		return teleport()
	end
	]]></globalevent>
	<event type="login" name="ctf_login" event="script"><![CDATA[
		registerCreatureEvent(cid, "ctf_stats")
		return registerCreatureEvent(cid, "ctf_target")
	]]></event>
	<event type="statschange" name="ctf_stats" event="script"><![CDATA[
		domodlib("ctf_config")
	function onStatsChange(cid, attacker, type, combat, value)
		if type == 1 then
			if getCreatureHealth(cid) <= value then
				if isPlayer(cid) and isCreature(attacker) then
					if getPlayerStorageValue(cid, redFlag) == 1 then
						setPlayerStorageValue(cid, redFlag, -1)
						setGlobalStorageValue(redFlag, -1)
						doBroadcastMessage(getCreatureName(cid) .. " has dropped the red flag!")
					elseif getPlayerStorageValue(cid, blueFlag) == 1 then
						setPlayerStorageValue(cid, blueFlag, -1)
						setGlobalStorageValue(blueFlag, -1)
						doBroadcastMessage(getCreatureName(cid) .. " has dropped the blue flag!")
					end
					if getPlayerStorageValue(cid, redPlayers) == 1 then
						doTeleportThing(cid, ctf.redPos, true)
						doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
						doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
						return false
					elseif getPlayerStorageValue(cid, bluePlayers) == 1 then
						doTeleportThing(cid, ctf.bluePos, true)
						doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
						doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
						return false
					end
				end
			end
		end
		return true
	end
	]]></event>
	<event type="combat" name="ctf_target" event="script"><![CDATA[
		domodlib("ctf_config")
		if isPlayer(cid) and isPlayer(target) then
			if(getPlayerStorageValue(cid, redPlayers) == 1 and getPlayerStorageValue(target, redPlayers) == 1) or (getPlayerStorageValue(cid, bluePlayers) == 1 and getPlayerStorageValue(target, bluePlayers) == 1) then
				doPlayerSendCancel(cid, "You may not attack your team mates.")
				return false
			end
		end
		return true
	]]></event>
	<movevent type="StepIn" actionid="6000-6001" event="script"><![CDATA[
		domodlib("ctf_config")
	local function repeatFlag(cid)
		local k = getThingPos(cid)
		local r = {
			{pos = {x = k.x + 2, y = k.y - 2, z = k.z}, delay = 300},
			{pos = {x = k.x + 2, y = k.y + 2, z = k.z}, delay = 300},
			{pos = {x = k.x - 2, y = k.y + 2, z = k.z}, delay = 300},
			{pos = {x = k.x - 2, y = k.y, z = k.z}, delay = 300},
			{pos = {x = k.x - 2, y = k.y - 2, z = k.z}, delay = 300},
			{pos = {x = k.x, y = k.y - 2, z = k.z}, delay = 300}
		}
		local effects = {27, 28, 29, 30}
		if getPlayerStorageValue(cid, redFlag) == 1 or getPlayerStorageValue(cid, blueFlag) == 1 then
			for i = 1, 6 do
				addEvent(doSendDistanceShoot, r[i].delay, r[i].pos, k, CONST_ME_FIREWORK_YELLOW)
			end
			for i = 1, 4 do
				addEvent(doSendMagicEffect, 1000, getThingPos(cid), effects[i])
			end
			return addEvent(repeatFlag, 2 * 1000, cid)
		end
		return true
	end
	function onStepIn(cid, item, position, fromPosition, toPosition, lastPosition, actor)
		if isPlayer(cid) then
			if item.actionid == 6000 then --red team
				if getPlayerStorageValue(cid, bluePlayers) == 1 then
					if getPlayerStorageValue(cid, redFlag) == -1 and getGlobalStorageValue(redFlag) == -1 then
						setPlayerStorageValue(cid, redFlag, 1)
						setGlobalStorageValue(redFlag, 1)
						doBroadcastMessage(getCreatureName(cid) .. " has stolen the Red Flag!")
						repeatFlag(cid)
					else
						doCreatureSay(cid, "The flag is not at home!", 19)
						doTeleportThing(cid, fromPosition)
					end
				elseif getPlayerStorageValue(cid, redPlayers) == 1 then
					if getGlobalStorageValue(redFlag) == -1 then
						if getPlayerStorageValue(cid, blueFlag) == 1 and getGlobalStorageValue(blueFlag) == 1 then
							setPlayerStorageValue(cid, blueFlag, -1)
							setGlobalStorageValue(blueFlag, -1)
							doBroadcastMessage(getCreatureName(cid) .. " has scored 1 point to the Red Team!")
							setGlobalStorageValue(redGoal, getGlobalStorageValue(redGoal)+1)
							doBroadcastMessage("Current CTF Game Score:\nRed Team: " .. getGlobalStorageValue(redGoal) .. "\nBlue Team: " .. getGlobalStorageValue(blueGoal) .. "\nTen scores to win!", 19)
						else
							doCreatureSay(cid, "You dont have the flag!", 19)
							doTeleportThing(cid, fromPosition)
						end
					else
						doCreatureSay(cid, "Return your flag firstly", 19)
						doTeleportThing(cid, fromPosition)
					end
				else
					doPlayerSendTextMessage(cid, 27, "Your not in any team, try reporting this to gamemaster?")
					doTeleportThing(cid, temple, true)
				end
			elseif item.actionid == 6001 then --blue team
				if getPlayerStorageValue(cid, redPlayers) == 1 then
					if getPlayerStorageValue(cid, blueFlag) == -1 and getGlobalStorageValue(blueFlag) == -1 then
						setPlayerStorageValue(cid, blueFlag, 1)
						setGlobalStorageValue(blueFlag, 1)
						doBroadcastMessage(getCreatureName(cid) .. " has stolen the Blue Flag!")
						repeatFlag(cid)
					else
						doCreatureSay(cid, "The flag is not at home!", 19)
						doTeleportThing(cid, fromPosition)
					end
				elseif getPlayerStorageValue(cid, bluePlayers) == 1 then
					if getGlobalStorageValue(blueFlag) == -1 then
						if getPlayerStorageValue(cid, redFlag) == 1 and getGlobalStorageValue(redFlag) == 1 then
							setPlayerStorageValue(cid, redFlag, -1)
							setGlobalStorageValue(redFlag, -1)
							doBroadcastMessage(getCreatureName(cid) .. " has scored 1 point to Blue Team!")
							setGlobalStorageValue(blueGoal, getGlobalStorageValue(blueGoal)+1)
							doBroadcastMessage("Current CTF Game Score:\nRed Team: " .. getGlobalStorageValue(redGoal) .. "\nBlue Team: " .. getGlobalStorageValue(blueGoal) .. "\nTen scores to win!", 19)
						else
							doCreatureSay(cid, "You dont have the flag!", 19)
							doTeleportThing(cid, fromPosition)
						end
					else
						doCreatureSay(cid, "Return your flag firstly", 19)
						doTeleportThing(cid, fromPosition)
					end
				else
					doPlayerSendTextMessage(cid, 27, "Your not in any team, try reporting this to gamemaster?")
					doTeleportThing(cid, temple, true)
				end
			end
			if getGlobalStorageValue(redGoal) == 10 and getGlobalStorageValue(blueGoal) < 10 then
				doBroadcastMessage("Red Team has won the event!", 27)
				for _, cid in ipairs(getPlayersOnline()) do
					if getPlayerStorageValue(cid, redPlayers) == 1 then
						doPlayerAddItem(cid, 9020, math.random(1, 15))
						doTeleportThing(cid, temple, true)
						doRemoveCondition(cid, CONDITION_OUTFIT)
					elseif getPlayerStorageValue(cid, bluePlayers) == 1 then
						doTeleportThing(cid, temple, true)
						doRemoveCondition(cid, CONDITION_OUTFIT)
					end
					if getPlayerStorageValue(cid, redFlag) == 1 then
						setPlayerStorageValue(cid, redFlag, -1)
					end
					if getPlayerStorageValue(cid, blueFlag) == 1 then
						setPlayerStorageValue(cid, blueFlag, -1)
					end
				end
				setGlobalStorageValue(blueGoal, 0)
				setGlobalStorageValue(redGoal, 0)
				setGlobalStorageValue(redFlag, -1)
				setGlobalStorageValue(blueFlag, -1)
			elseif getGlobalStorageValue(blueGoal) == 10 and getGlobalStorageValue(redGoal) < 10 then
				doBroadcastMessage("Blue Team has won the event!", 27)
				for _, cid in ipairs(getPlayersOnline()) do
					if getPlayerStorageValue(cid, bluePlayers) == 1 then
						doPlayerAddItem(cid, 9020, math.random(1, 15))
						doTeleportThing(cid, temple, true)
						doRemoveCondition(cid, CONDITION_OUTFIT)
					elseif getPlayerStorageValue(cid, redPlayers) == 1 then
						doTeleportThing(cid, temple, true)
						doRemoveCondition(cid, CONDITION_OUTFIT)
					end
					if getPlayerStorageValue(cid, redFlag) == 1 then
						setPlayerStorageValue(cid, redFlag, -1)
					end
					if getPlayerStorageValue(cid, blueFlag) == 1 then
						setPlayerStorageValue(cid, blueFlag, -1)
					end
				end
				setGlobalStorageValue(blueGoal, 0)
				setGlobalStorageValue(redGoal, 0)
				setGlobalStorageValue(redFlag, -1)
				setGlobalStorageValue(blueFlag, -1)
			end
		else
			doRemoveCreature(cid)
		end
		return true
	end
	]]></movevent>
</mod>
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="CTF" version="1.0" author="Doggynub" contact="otland.net" enabled="yes">
<config name="toto"><![CDATA[
 
--[[ Storage Settings]]--
 
 
 Owner = 1900 -- put empty storage
 
 FLAG2_INn = 4000 -- put empty storage
 
 FLAG_IN = 4001 -- put empty storage
 
 TEAM1_FLAGS = 3030 -- put empty storage
 
 TEAM2_FLAGS = 3031 -- put empty storage
 
 Event_Start = 3032 -- put empty storage
 
 Event_timeend = 3033 -- put empty storage
 
 Event_Tile_Close = 3039 -- put empty storage
 
 joined = 2023 --put empty storage
 
 Timer = 1010 --put empty storage
 
--------------------------------------
 
 
--[[ Places setting ]]--
 
 
 BLUE_FLAG = {x=1262,y=1953,z=7} -- Blue flag Place
 
 RED_FLAG = {x=1332,y=2011,z=7} --red flag Place
 
 Tp_Place = {x=1004,y=991,z=6} -- Place where the event teleport will be created.
 
 Wait_Place = {x=1279, y=1975, z=7} -- Positions Players will  be sent when the enter event's teleport
 
 frompos = {x=1277,y=1970,z=7} --start sqm in the waiting room(1 floor)
 
 topos = {x=1281,y=1981,z=7} -- end sqm in the waiting room(1 floor)
 
 Red_Position = {x=1341,y=2018,z=7} -- Red team temple pos
 
 Blue_Position = {x=1271,y=1953,z=7} -- Blue team temple pos
 
 
 
---------------------------------------
 
 
--[[Event setting ]]--
 
 
 Event_WaitTime = 1 -- time for the collection of player then event will start (in minutes)
 
 Event_MaxTime = 7 --- in minutes ( this is the max time for an event to bb running )
 
 Players_Speed = 20000 -- put the level of base speed in event ( like if you want the speed of lvl 300 then wright 300)
 
 TEAM2_NAME = "Red" -- team 2 name
 
 TEAM1_NAME = "Green" -- team 1 name
 
 FLAG_SCORE = 3 -- score when team gets he wins
 
 Teleport_On_Score = true -- this teleport all players to their team main position when some one score a flag , make false to disable.
 
 Players_Least_Number = 2 -- this means if there is less than 2 players joined the event will be cancelled
 
 Min_Join_Level = 1000 -- min lvl for a player to join event
 
 rewards_random = {		
						[60] = { -- Rewards of 60% , if it is then it will randomly give one of the items in the items verible if there you put more than one item there
									items = {6542,2284,2433}
								},
 
						[30] = { -- Rewards of 30% 
									items = {3982,9928,2496}
								},
 
 
						[10] = { -- Rewards of 10% 
									items = {2309,6512,8890}
								}
					}
 
 
]]></config>
 <lib name="CTF-lib"><![CDATA[
function isTeamTwo(cid)
	return (isPlayer(cid) and getPlayerStorageValue(cid,5054) > -1)
end
function isTeamOne(cid)
	return (isPlayer(cid) and getPlayerStorageValue(cid,5055) > -1)
end
function resetTheTeams(cid)
	return (isPlayer(cid) and setPlayerStorageValue(cid,5054,-1) and setPlayerStorageValue(cid,5055,-1))
end
function setflagOwner(cid)
	return setPlayerStorageValue(cid,Owner,1)
end
function flagOwner(cid)
	return (isPlayer(cid) and getPlayerStorageValue(cid,Owner) > 0)
end
function releaseBF(cid)
	setGlobalStorageValue(FLAG_IN,-1)
	setPlayerStorageValue(cid,103, 0)
	setPlayerStorageValue(cid,Owner,-1)
return true
end
function releaseRF(cid)
	setGlobalStorageValue(FLAG2_INn,-1)
	setPlayerStorageValue(cid,103, 0)
	setPlayerStorageValue(cid,Owner,-1)
return true
end
function setFirstTeam(cid)
	return setPlayerStorageValue(cid,5055,1)
end
function setSecondTeam(cid)
	return setPlayerStorageValue(cid,5054,2)
end
function addToRed()
	return setGlobalStorageValue(TEAM2_FLAGS,getGlobalStorageValue(TEAM2_FLAGS)+1)
end
function addToBlue()
	return setGlobalStorageValue(TEAM1_FLAGS,getGlobalStorageValue(TEAM1_FLAGS)+1)
end
function getBlueScore()
	return getGlobalStorageValue(TEAM1_FLAGS)
end
function getRedScore()
	return getGlobalStorageValue(TEAM2_FLAGS)
end
function getTheSpeed(level)
	value = (220 +(2 *(level -1)))
	return value
end
 
function resetTheStorage()
	setGlobalStorageValue(Event_Start,-1)
	setGlobalStorageValue(Event_timeend,-1)
	setGlobalStorageValue(TEAM1_FLAGS,0)
	setGlobalStorageValue(FLAG2_INn,-1)
    setGlobalStorageValue(FLAG_IN,-1)
	setGlobalStorageValue(TEAM2_FLAGS,0)
return true
end
function blueStolen()
	return getGlobalStorageValue(FLAG_IN)
end
function redStolen()
	return getGlobalStorageValue(FLAG2_INn)
end
function giveReward(cid)
	local t = math.random(1,100)
	if t <= 10 then
		local rare = rewards_random[10].items[math.random(1,#rewards_random[10].items)]
		doPlayerAddItem(cid,rare,1)
		doPlayerSendTextMessage(cid,25,"Rare rate Reward : you won "..getItemNameById(rare)..".")
 
	elseif t > 10 and t <= 40 then
		local semi = rewards_random[30].items[math.random(1,#rewards_random[30].items)]
		doPlayerAddItem(cid,semi,1)
		doPlayerSendTextMessage(cid,25,"Semi rate Reward : you won "..getItemNameById(semi)..".")
 
 
	elseif t > 40 then
		local aver = rewards_random[60].items[math.random(1,#rewards_random[60].items)]
		doPlayerAddItem(cid,aver,1)
		doPlayerSendTextMessage(cid,25,"Averege rate Reward : you won "..getItemNameById(aver)..".")
	end
	return true
end
]]></lib>
<event type="login" name="Tutorial Login" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
function onLogin(cid)
	if getGlobalStorageValue(Event_Start) < 1 then
		if isTeamOne(cid) or isTeamTwo(cid) then
			resetTheTeams(cid)
		end
	end
	registerCreatureEvent(cid, "Attk")
	registerCreatureEvent(cid, "ctff")
	registerCreatureEvent(cid, "prepare")
return true
end
]]></event>
    <event type="combat" name="Attk" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
 
function onCombat(cid, target)
	if isTeamOne(cid) and isTeamOne(target) then
		return false
    end
    if isTeamTwo(cid) and isTeamTwo(target) then
        return false
    end
	return true
end
]]></event>
 <event type="statschange" name="prepare" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
 
local corpse_ids = {
		[0] = 3065, -- female
        [1] = 3058 -- male
}
function onStatsChange(cid, attacker, type, combat, value)
		if combat == COMBAT_HEALING then
			return true
        end
        if getCreatureHealth(cid) > value then
			return true
        end
		if getGlobalStorageValue(Event_Start) > 0 then
			if flagOwner(cid) then
				if isTeamOne(cid) then
					doItemSetAttribute(doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid)), "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item").."[Flag Holder].") 
					doTeleportThing(cid,Blue_Position,false)
					doSendMagicEffect(Blue_Position,10)
					doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
					doCreatureAddMana(cid,getCreatureMaxMana(cid))
					releaseRF(cid)
							for _,cid in ipairs(getPlayersOnline()) do
								if isTeamOne(cid) or isTeamTwo(cid) then				   
									doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " has died with the "..TEAM2_NAME.." team flag. The flag is returned back to the "..TEAM1_NAME.." team.")
								end
							end
					return false
				elseif isTeamTwo(cid) then
					doItemSetAttribute(doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid)), "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item").."[Flag Holder].") 
					doTeleportThing(cid,Red_Position,false)
					doSendMagicEffect(Red_Position,10)
					doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
					doCreatureAddMana(cid,getCreatureMaxMana(cid))
					releaseBF(cid)
							for _,cid in ipairs(getPlayersOnline()) do
								if isTeamOne(cid) or isTeamTwo(cid) then				   
									doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " has died with the "..TEAM1_NAME.." team flag. The flag is returned back to the "..TEAM1_NAME.." team.")
								end
							end
				return false
				end
 
			else
				if isTeamOne(cid) or isTeamTwo(cid) then
					doItemSetAttribute(doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid)), "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item").."[Normal kill].") 
					doTeleportThing(cid,( isTeamTwo(cid) and Red_Position or Blue_Position ),false)
					doSendMagicEffect(Red_Position,10)
					doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
					doCreatureAddMana(cid,getCreatureMaxMana(cid))
					return false
				end
			end  
 
		end
return true
end
 
]]></event>
<movevent type="StepIn" actionid="6000" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
 
function eventEnds()
	doBroadcastMessage('CTF-Event : The '..TEAM2_NAME..' team won and reciaved their reward.') 
	    for _,cid in ipairs(getPlayersOnline()) do
			if isTeamTwo(cid) then
				doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
				doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
			    doRemoveConditions(cid,false)
			    resetTheTeams(cid)
				doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
				giveReward(cid)
 
			elseif isTeamOne(cid) then
				doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
			    doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
			    doRemoveConditions(cid,false)
			    doPlayerSendTextMessage(cid,22,'Your team have lost.')
				resetTheTeams(cid)
				doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
			end
		end
    addEvent(resetTheStorage,5)
end
function onStepIn(cid, item, position, fromPosition)
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		if isTeamTwo(cid) and redStolen() < 0 then
			if not flagOwner(cid) then
				doTeleportThing(cid, fromPosition,TRUE)
				doSendMagicEffect(getThingPos(cid),2)
				doPlayerSendTextMessage(cid, 27, "This is your team flag, you cant take it!")
			end
		elseif isTeamTwo(cid) and redStolen() > 0 and blueStolen() < 0 then
			doPlayerSendTextMessage(cid, 27, "Your team's Flag has been stolen, go get it back!")
			doTeleportThing(cid, fromPosition,TRUE)
			doSendMagicEffect(getThingPos(cid),2)
		  return true
		end
        if isTeamTwo(cid) and flagOwner(cid) and blueStolen() > 0 and redStolen() < 0 then
			if getRedScore() == FLAG_SCORE -1 then
				addEvent(eventEnds,1000)
				addToRed()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
				releaseBF(cid)
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the last flag and earned match win to the ".. TEAM2_NAME.." team!")
						end
					end
			else
				releaseBF(cid)
				addToRed()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the flag and earned 1 point to the ".. TEAM2_NAME.." team!")
								if Teleport_On_Score == true then
									doTeleportThing(tid,( isTeamTwo(tid) and Red_Position or Blue_Position ), false)
									doSendMagicEffect(getThingPos(tid),10)
								end
						end
					end
			end
		end
		if isTeamOne(cid) then
			if blueStolen() < 0 and redStolen() > 0 then
	            if flagOwner(cid) then
                    doPlayerSendTextMessage(cid, 27, "You already holding the flag!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                elseif (not flagOwner(cid)) then
	                doPlayerSendTextMessage(cid, 27, "Your Team mates already stole the oponent flag, defend him!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                end
			elseif blueStolen() > 0 and redStolen() < 0 then  
	            doPlayerSendTextMessage(cid, 27, "Your team's flag is taken you can't capture or steel a flag!")
		        doTeleportThing(cid, fromPosition,TRUE)
		        doSendMagicEffect(getThingPos(cid),2)
			end
			if redStolen() < 0 and blueStolen() < 0 then
	            setGlobalStorageValue(FLAG2_INn,1)
			    setflagOwner(cid)
                setPlayerStorageValue(cid,103, os.time()+300)
                doTeleportThing(cid, fromPosition,TRUE)
					for _,tid in ipairs(getPlayersOnline()) do
		                if isTeamOne(tid) or isTeamTwo(tid) then				   
                            doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " stolen the "..TEAM2_NAME.." team flag!")
						end
					end
			end
		end
	end
return true
end
]]> </movevent>
<movevent type="StepIn" actionid="3435" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
	if getStorage(Event_Tile_Close) > 0 then
		if getPlayerLevel(cid) < Min_Join_Level then
		   doTeleportThing(cid,fromPosition,false)
			doSendMagicEffect(fromPosition,10)
			doPlayerSendTextMessage(cid,21,"Only players of level "..Min_Join_Level.." are allowed to pass.")
		else
			doTeleportThing(cid,Wait_Place,false)
			doSendMagicEffect(Wait_Place,10)
		end
	else
		doTeleportThing(cid,fromPosition,false)
		doSendMagicEffect(fromPosition,10)
		doPlayerSendTextMessage(cid,21,"Come back later, event is closed now.")
	end
return true
end
 
]]> </movevent>
<movevent type="StepIn" actionid="6001" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
 
function eventEnded()
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		doBroadcastMessage('CTF-Event : The '.. TEAM1_NAME..' team won and reciaved their reward.') 
	        for _,cid in ipairs(getPlayersOnline()) do
			    if isTeamOne(cid) then
				    doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
					doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
					doRemoveConditions(cid,false)
					resetTheTeams(cid)
					doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					giveReward(cid)
				elseif isTeamTwo(cid) then
				    doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
					doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
					doRemoveConditions(cid,false)
			        doPlayerSendTextMessage(cid,22,'Your team have lost.')
					resetTheTeams(cid)
					doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
				end
			end
    end
    addEvent(resetTheStorage,5)
end
function onStepIn(cid, item, position, fromPosition)
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		if isTeamOne(cid) and blueStolen() < 0 then
			if not flagOwner(cid) then
				doTeleportThing(cid, fromPosition,TRUE)
				doSendMagicEffect(getThingPos(cid),2)
				doPlayerSendTextMessage(cid, 27, "This is your team flag, you cant take it!")
			end
		elseif isTeamOne(cid) and blueStolen() > 0 and redStolen() < 0 then
			doPlayerSendTextMessage(cid, 27, "Your team's Flag has been stolen, go get it back!")
			doTeleportThing(cid, fromPosition,TRUE)
			doSendMagicEffect(getThingPos(cid),2)
         return true
		end
		if isTeamOne(cid) and flagOwner(cid) and redStolen() > 0 and blueStolen() < 0 then
			if getBlueScore() == FLAG_SCORE -1 then
				addEvent(eventEnded,1000)
				addToBlue()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
				releaseRF(cid)
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the last flag and earned match win to the ".. TEAM1_NAME.." team!")
						end
					end
			else
				releaseRF(cid)
				addToBlue()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the flag and earned 1 point to the ".. TEAM1_NAME.." team!")
								if Teleport_On_Score == true then
									doTeleportThing(tid,( isTeamTwo(tid) and Red_Position or Blue_Position ), false)
									doSendMagicEffect(getThingPos(tid),10)
								end
						end
					end
			end
		end
		if isTeamTwo(cid) then
			if blueStolen() > 0 and redStolen() < 0 then
			    if flagOwner(cid) then
					doPlayerSendTextMessage(cid, 27, "You already holding the flag!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                elseif (not flagOwner(cid)) then
	                doPlayerSendTextMessage(cid, 27, "Your Team mates already stole the oponent flag, defend him!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                end
			elseif redStolen() > 0 and blueStolen() < 0 then  
				doPlayerSendTextMessage(cid, 27, "Your team's flag is taken you can't capture or steel a flag!")
				doTeleportThing(cid, fromPosition,TRUE)
				doSendMagicEffect(getThingPos(cid),2)
			end
			if blueStolen() < 0 and redStolen() < 0 then
				setGlobalStorageValue(FLAG_IN,1)
			    setflagOwner(cid)
				setPlayerStorageValue(cid,103, os.time()+300)
				doTeleportThing(cid, fromPosition,TRUE)   
                    for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then				   
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " stolen the "..TEAM1_NAME.." team flag!")
						end
					end
			end
		end
	end
return true
end
]]> </movevent>
<globalevent name="ctf" interval="900" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
local players = {}
local bmale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(bmale, {lookType = math.random(128,134), lookHead = 115, lookBody =114, lookLegs = 81, lookFeet = 81, lookTypeEx = 0, lookAddons = 3})
 
	local bfemale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(bfemale, {lookType = math.random(136,142), lookHead = 115, lookBody =114, lookLegs = 81, lookFeet = 81, lookTypeEx = 0, lookAddons = 3})
 
	local rmale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(rmale, {lookType = math.random(128,134), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})
 
	local rfemale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(rfemale, {lookType = math.random(136,142),lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})
	local fight = createConditionObject(CONDITION_INFIGHT)
		setConditionParam(fight, CONDITION_PARAM_TICKS, -1)
function eventEnd()
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		if getRedScore() > getBlueScore() then
	        doBroadcastMessage('CTF-Event : The '.. TEAM2_NAME..' team won and recieved their reward.') 
				for _,cid in ipairs(getPlayersOnline()) do
					if isTeamTwo(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
						giveReward(cid)
					elseif isTeamOne(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						doPlayerSendTextMessage(cid,22,'Your team have lost.')
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					end
				end
 
		elseif getRedScore() < getBlueScore() then
	        doBroadcastMessage('CTF-Event : The '.. TEAM1_NAME..' team won and recieved their reward.') 
				for _,cid in ipairs(getPlayersOnline()) do
					if isTeamOne(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
						giveReward(cid)
					elseif isTeamTwo(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						doPlayerSendTextMessage(cid,22,'Your team have lost.')
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					end
				end
		elseif getRedScore() == getBlueScore() then
	        doBroadcastMessage('CTF-Event : The Event ended with a draw between both teams.') 
				for _,cid in ipairs(getPlayersOnline()) do
					if isTeamTwo(cid) or isTeamOne(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						doPlayerSendTextMessage(cid,22,'It was a draw between both teams.')
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					end
				end
 
		end
		addEvent(resetTheStorage,1000)
	end
end
 
function eventStart()
	doSetStorage(Event_Tile_Close,-1)
	setGlobalStorageValue(Event_timeend,1)
	setGlobalStorageValue(Timer, os.time() + Event_MaxTime*60)
	addEvent(eventEnd,Event_MaxTime*60*1000)
 
 
 
            for v = frompos.x , topos.x do
				for k = frompos.y , topos.y do
					for i = 1, 200 do
						position = {x = v, y = k, z = 7, stackpos = i}
						pid = getThingfromPos(position).uid
							if(pid ~= nil and isPlayer(pid)) then
								table.insert(players, pid)
							end
					end
				end
			end
			if math.mod(#players, 2) ~= 0 then	
				doTeleportThing(players[#players],getTownTemplePosition(getPlayerTown(players[#players])),false)
				doSendMagicEffect(getThingPosition(players[#players]),10)
				doPlayerSendTextMessage(players[#players], 19, "Sorry, you have been kicked from event to balance teams.")					
				table.remove(players)
            end
            if #players < Players_Least_Number then
				doBroadcastMessage("CTF event was cancelled because less than "..Players_Least_Number.." players joined")
				resetTheStorage()
					if #players > 0 then
						for i = 1,#players do
						     doTeleportThing(players[i],getTownTemplePosition(getPlayerTown(players[i])),false) 
				             doSendMagicEffect(getThingPos(players[i]), 10) 
					    end
					end
			else	
					 doBroadcastMessage("CTF started")
						for i = 1, math.floor(#players/2) do
							setFirstTeam(players[i])
						end
						for i = math.floor(#players/2)+1 , #players do
							setSecondTeam(players[i])
						end
						for _,cid in ipairs(getPlayersOnline()) do
							if isTeamOne(cid) then
								if getPlayerSex(cid) == 1 then
									doAddCondition(cid, bmale)
								elseif getPlayerSex(cid) ~= 1 then
									doAddCondition(cid, bfemale)
								end
								doAddCondition(cid, fight)
								doTeleportThing(cid,Blue_Position,false) 
								doSendMagicEffect(Blue_Position, 10) 
								doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid))
							elseif  isTeamTwo(cid) then
								if getPlayerSex(cid) == 1 then
									doAddCondition(cid, rmale)
								elseif getPlayerSex(cid) ~= 1 then
									doAddCondition(cid, rfemale)
								end
								doAddCondition(cid, fight)
								doTeleportThing(cid,Red_Position,false) 
								doSendMagicEffect(Red_Position, 10)
								doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid))					
							end
						end	
						players = {}
 
            end
end
function onThink(interval)
   if getGlobalStorageValue(Event_Start) < 0 then
		setGlobalStorageValue(Event_Start,1)
		doSetStorage(Event_Tile_Close,1)
		doBroadcastMessage("CTF event is opened and teleport is created. It will start in "..Event_WaitTime.." minutes.")
		players = {}
		if getTileItemById(Tp_Place, 1387).uid < 1 then
			doItemSetAttribute(doCreateItem(1387,1, Tp_Place), "aid", 3435)
		end
 
		f= Event_WaitTime - 1
			for i = 1,Event_WaitTime-1 do
				addEvent(doBroadcastMessage,i*60*1000,"CTF event is opened and teleport is created. It will start in "..f.." minutes.")
				f= f-1
			end
		addEvent(eventStart,Event_WaitTime*60*1000)
	end
return true
end
]]></globalevent>
 <event type="think" name="ctff" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
 
local bl = BLUE_FLAG
local re = RED_FLAG
function onThink(interval)
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
        if redStolen() < 0 then
			doSendAnimatedText(re,"FLAG!",TEXTCOLOR_DARKRED)
			doSendMagicEffect(re, CONST_ME_SOUND_RED) 
        end
        if blueStolen() < 0 then
			doSendAnimatedText(bl,"FLAG!",TEXTCOLOR_GREEN)
			doSendMagicEffect(bl, CONST_ME_SOUND_GREEN)
	    end
        for _, cid in ipairs(getPlayersOnline()) do
            if flagOwner(cid) then
				if isTeamOne(cid) or isTeamTwo(cid) then
					if hasCondition(cid,CONDITION_HASTE) then
						doRemoveCondition(cid,CONDITION_HASTE)
					end
				end
				pl = getThingPos(cid) 
					if isTeamTwo(cid) then
						if getPlayerStorageValue(cid,103) < os.time() then
							releaseBF(cid)
								for _,cid in ipairs(getPlayersOnline()) do
									if isTeamOne(cid) or isTeamTwo(cid) then											
										doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " wasted 5 minutes with FLAG."..TEAM2_NAME.." flag is again on spawn!")
									end
								end
						else
							doSendAnimatedText(pl,"FLAG!",TEXTCOLOR_GREEN)
							doSendMagicEffect(pl, CONST_ME_SOUND_GREEN)
						end
					elseif isTeamOne(cid) then
						if getPlayerStorageValue(cid,103) < os.time() then
							releaseRF(cid)
								for _,cid in ipairs(getPlayersOnline()) do
									if isTeamOne(cid) or isTeamTwo(cid) then											
										doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " wasted 5 minutes with FLAG."..TEAM1_NAME.." flag is again on spawn!")
									end
								end
						else
							doSendAnimatedText(pl,"FLAG!",COLOR_RED)
							doSendMagicEffect(pl, CONST_ME_SOUND_RED)
						end
					end
			end
		end
	end
  return true
end
]]></event>
<globalevent name="timer" interval="0.4" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
 
function onThink(interval)
	for _,cid in ipairs(getPlayersOnline()) do
		if isTeamOne(cid) or isTeamTwo(cid) then
			if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
				if getGlobalStorageValue(Timer)- os.time() >= 0 then
					doPlayerSendCancel(cid, "Time -> ".. os.date("%M:%S ",getGlobalStorageValue(Timer)- os.time()) .. "  |  ".. TEAM1_NAME.." Score : "..getBlueScore(cid).."/"..FLAG_SCORE.." captures  |  ".. TEAM2_NAME.." Score : "..getRedScore(cid).."/"..FLAG_SCORE.." captures")
				end
			end
		end
	end
return true
end
]]></globalevent>
<globalevent name="starting" type="startup" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
function onStartup()
	resetTheStorage()
 
 return true
end
]]></globalevent>
</mod>
Try it and rep+ me :p
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="CTF" version="1.0" author="Doggynub" contact="otland.net" enabled="yes">
<config name="toto"><=!=[=C=D=A=T=A=[
 
--[[ Storage Settings]]--
 
 
 Owner = 1900 -- put empty storage
 
 FLAG2_INn = 4000 -- put empty storage
 
 FLAG_IN = 4001 -- put empty storage
 
 TEAM1_FLAGS = 3030 -- put empty storage
 
 TEAM2_FLAGS = 3031 -- put empty storage
 
 Event_Start = 3032 -- put empty storage
 
 Event_timeend = 3033 -- put empty storage
 
 Event_Tile_Close = 3039 -- put empty storage
 
 joined = 2023 --put empty storage
 
 Timer = 1010 --put empty storage
 
--------------------------------------
 
 
--[[ Places setting ]]--
 
 
 BLUE_FLAG = {x=1262,y=1953,z=7} -- Blue flag Place
 
 RED_FLAG = {x=1332,y=2011,z=7} --red flag Place
 
 Tp_Place = {x=1004,y=991,z=6} -- Place where the event teleport will be created.
 
 Wait_Place = {x=1279, y=1975, z=7} -- Positions Players will  be sent when the enter event's teleport
 
 frompos = {x=1277,y=1970,z=7} --start sqm in the waiting room(1 floor)
 
 topos = {x=1281,y=1981,z=7} -- end sqm in the waiting room(1 floor)
 
 Red_Position = {x=1341,y=2018,z=7} -- Red team temple pos
 
 Blue_Position = {x=1271,y=1953,z=7} -- Blue team temple pos
 
 
 
---------------------------------------
 
 
--[[Event setting ]]--
 
 
 Event_WaitTime = 1 -- time for the collection of player then event will start (in minutes)
 
 Event_MaxTime = 7 --- in minutes ( this is the max time for an event to bb running )
 
 Players_Speed = 20000 -- put the level of base speed in event ( like if you want the speed of lvl 300 then wright 300)
 
 TEAM2_NAME = "Red" -- team 2 name
 
 TEAM1_NAME = "Green" -- team 1 name
 
 FLAG_SCORE = 3 -- score when team gets he wins
 
 Teleport_On_Score = true -- this teleport all players to their team main position when some one score a flag , make false to disable.
 
 Players_Least_Number = 2 -- this means if there is less than 2 players joined the event will be cancelled
 
 Min_Join_Level = 1000 -- min lvl for a player to join event
 
 rewards_random = {		
						[60] = { -- Rewards of 60% , if it is then it will randomly give one of the items in the items verible if there you put more than one item there
									items = {6542,2284,2433}
								},
 
						[30] = { -- Rewards of 30% 
									items = {3982,9928,2496}
								},
 
 
						[10] = { -- Rewards of 10% 
									items = {2309,6512,8890}
								}
					}
 
 
]=]=></config>
 <lib name="CTF-lib"><=!=[=C=D=A=T=A=[
function isTeamTwo(cid)
	return (isPlayer(cid) and getPlayerStorageValue(cid,5054) > -1)
end
function isTeamOne(cid)
	return (isPlayer(cid) and getPlayerStorageValue(cid,5055) > -1)
end
function resetTheTeams(cid)
	return (isPlayer(cid) and setPlayerStorageValue(cid,5054,-1) and setPlayerStorageValue(cid,5055,-1))
end
function setflagOwner(cid)
	return setPlayerStorageValue(cid,Owner,1)
end
function flagOwner(cid)
	return (isPlayer(cid) and getPlayerStorageValue(cid,Owner) > 0)
end
function releaseBF(cid)
	setGlobalStorageValue(FLAG_IN,-1)
	setPlayerStorageValue(cid,103, 0)
	setPlayerStorageValue(cid,Owner,-1)
return true
end
function releaseRF(cid)
	setGlobalStorageValue(FLAG2_INn,-1)
	setPlayerStorageValue(cid,103, 0)
	setPlayerStorageValue(cid,Owner,-1)
return true
end
function setFirstTeam(cid)
	return setPlayerStorageValue(cid,5055,1)
end
function setSecondTeam(cid)
	return setPlayerStorageValue(cid,5054,2)
end
function addToRed()
	return setGlobalStorageValue(TEAM2_FLAGS,getGlobalStorageValue(TEAM2_FLAGS)+1)
end
function addToBlue()
	return setGlobalStorageValue(TEAM1_FLAGS,getGlobalStorageValue(TEAM1_FLAGS)+1)
end
function getBlueScore()
	return getGlobalStorageValue(TEAM1_FLAGS)
end
function getRedScore()
	return getGlobalStorageValue(TEAM2_FLAGS)
end
function getTheSpeed(level)
	value = (220 +(2 *(level -1)))
	return value
end
 
function resetTheStorage()
	setGlobalStorageValue(Event_Start,-1)
	setGlobalStorageValue(Event_timeend,-1)
	setGlobalStorageValue(TEAM1_FLAGS,0)
	setGlobalStorageValue(FLAG2_INn,-1)
    setGlobalStorageValue(FLAG_IN,-1)
	setGlobalStorageValue(TEAM2_FLAGS,0)
return true
end
function blueStolen()
	return getGlobalStorageValue(FLAG_IN)
end
function redStolen()
	return getGlobalStorageValue(FLAG2_INn)
end
function giveReward(cid)
	local t = math.random(1,100)
	if t <= 10 then
		local rare = rewards_random[10].items[math.random(1,#rewards_random[10].items)]
		doPlayerAddItem(cid,rare,1)
		doPlayerSendTextMessage(cid,25,"Rare rate Reward : you won "..getItemNameById(rare)..".")
 
	elseif t > 10 and t <= 40 then
		local semi = rewards_random[30].items[math.random(1,#rewards_random[30].items)]
		doPlayerAddItem(cid,semi,1)
		doPlayerSendTextMessage(cid,25,"Semi rate Reward : you won "..getItemNameById(semi)..".")
 
 
	elseif t > 40 then
		local aver = rewards_random[60].items[math.random(1,#rewards_random[60].items)]
		doPlayerAddItem(cid,aver,1)
		doPlayerSendTextMessage(cid,25,"Averege rate Reward : you won "..getItemNameById(aver)..".")
	end
	return true
end
]=]=></lib>
<event type="login" name="Tutorial Login" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
function onLogin(cid)
	if getGlobalStorageValue(Event_Start) < 1 then
		if isTeamOne(cid) or isTeamTwo(cid) then
			resetTheTeams(cid)
		end
	end
	registerCreatureEvent(cid, "Attk")
	registerCreatureEvent(cid, "ctff")
	registerCreatureEvent(cid, "prepare")
return true
end
]=]=></event>
    <event type="combat" name="Attk" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
 
function onCombat(cid, target)
	if isTeamOne(cid) and isTeamOne(target) then
		return false
    end
    if isTeamTwo(cid) and isTeamTwo(target) then
        return false
    end
	return true
end
]=]=></event>
 <event type="statschange" name="prepare" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
 
local corpse_ids = {
		[0] = 3065, -- female
        [1] = 3058 -- male
}
function onStatsChange(cid, attacker, type, combat, value)
		if combat == COMBAT_HEALING then
			return true
        end
        if getCreatureHealth(cid) > value then
			return true
        end
		if getGlobalStorageValue(Event_Start) > 0 then
			if flagOwner(cid) then
				if isTeamOne(cid) then
					doItemSetAttribute(doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid)), "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item").."[Flag Holder].") 
					doTeleportThing(cid,Blue_Position,false)
					doSendMagicEffect(Blue_Position,10)
					doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
					doCreatureAddMana(cid,getCreatureMaxMana(cid))
					releaseRF(cid)
							for _,cid in ipairs(getPlayersOnline()) do
								if isTeamOne(cid) or isTeamTwo(cid) then				   
									doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " has died with the "..TEAM2_NAME.." team flag. The flag is returned back to the "..TEAM1_NAME.." team.")
								end
							end
					return false
				elseif isTeamTwo(cid) then
					doItemSetAttribute(doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid)), "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item").."[Flag Holder].") 
					doTeleportThing(cid,Red_Position,false)
					doSendMagicEffect(Red_Position,10)
					doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
					doCreatureAddMana(cid,getCreatureMaxMana(cid))
					releaseBF(cid)
							for _,cid in ipairs(getPlayersOnline()) do
								if isTeamOne(cid) or isTeamTwo(cid) then				   
									doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " has died with the "..TEAM1_NAME.." team flag. The flag is returned back to the "..TEAM1_NAME.." team.")
								end
							end
				return false
				end
 
			else
				if isTeamOne(cid) or isTeamTwo(cid) then
					doItemSetAttribute(doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid)), "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item").."[Normal kill].") 
					doTeleportThing(cid,( isTeamTwo(cid) and Red_Position or Blue_Position ),false)
					doSendMagicEffect(Red_Position,10)
					doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
					doCreatureAddMana(cid,getCreatureMaxMana(cid))
					return false
				end
			end  
 
		end
return true
end
 
]=]=></event>
<movevent type="StepIn" actionid="6000" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
 
function eventEnds()
	doBroadcastMessage('CTF-Event : The '..TEAM2_NAME..' team won and reciaved their reward.') 
	    for _,cid in ipairs(getPlayersOnline()) do
			if isTeamTwo(cid) then
				doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
				doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
			    doRemoveConditions(cid,false)
			    resetTheTeams(cid)
				doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
				giveReward(cid)
 
			elseif isTeamOne(cid) then
				doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
			    doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
			    doRemoveConditions(cid,false)
			    doPlayerSendTextMessage(cid,22,'Your team have lost.')
				resetTheTeams(cid)
				doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
			end
		end
    addEvent(resetTheStorage,5)
end
function onStepIn(cid, item, position, fromPosition)
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		if isTeamTwo(cid) and redStolen() < 0 then
			if not flagOwner(cid) then
				doTeleportThing(cid, fromPosition,TRUE)
				doSendMagicEffect(getThingPos(cid),2)
				doPlayerSendTextMessage(cid, 27, "This is your team flag, you cant take it!")
			end
		elseif isTeamTwo(cid) and redStolen() > 0 and blueStolen() < 0 then
			doPlayerSendTextMessage(cid, 27, "Your team's Flag has been stolen, go get it back!")
			doTeleportThing(cid, fromPosition,TRUE)
			doSendMagicEffect(getThingPos(cid),2)
		  return true
		end
        if isTeamTwo(cid) and flagOwner(cid) and blueStolen() > 0 and redStolen() < 0 then
			if getRedScore() == FLAG_SCORE -1 then
				addEvent(eventEnds,1000)
				addToRed()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
				releaseBF(cid)
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the last flag and earned match win to the ".. TEAM2_NAME.." team!")
						end
					end
			else
				releaseBF(cid)
				addToRed()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the flag and earned 1 point to the ".. TEAM2_NAME.." team!")
								if Teleport_On_Score == true then
									doTeleportThing(tid,( isTeamTwo(tid) and Red_Position or Blue_Position ), false)
									doSendMagicEffect(getThingPos(tid),10)
								end
						end
					end
			end
		end
		if isTeamOne(cid) then
			if blueStolen() < 0 and redStolen() > 0 then
	            if flagOwner(cid) then
                    doPlayerSendTextMessage(cid, 27, "You already holding the flag!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                elseif (not flagOwner(cid)) then
	                doPlayerSendTextMessage(cid, 27, "Your Team mates already stole the oponent flag, defend him!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                end
			elseif blueStolen() > 0 and redStolen() < 0 then  
	            doPlayerSendTextMessage(cid, 27, "Your team's flag is taken you can't capture or steel a flag!")
		        doTeleportThing(cid, fromPosition,TRUE)
		        doSendMagicEffect(getThingPos(cid),2)
			end
			if redStolen() < 0 and blueStolen() < 0 then
	            setGlobalStorageValue(FLAG2_INn,1)
			    setflagOwner(cid)
                setPlayerStorageValue(cid,103, os.time()+300)
                doTeleportThing(cid, fromPosition,TRUE)
					for _,tid in ipairs(getPlayersOnline()) do
		                if isTeamOne(tid) or isTeamTwo(tid) then				   
                            doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " stolen the "..TEAM2_NAME.." team flag!")
						end
					end
			end
		end
	end
return true
end
]=]=> </movevent>
<movevent type="StepIn" actionid="3435" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
	if getStorage(Event_Tile_Close) > 0 then
		if getPlayerLevel(cid) < Min_Join_Level then
		   doTeleportThing(cid,fromPosition,false)
			doSendMagicEffect(fromPosition,10)
			doPlayerSendTextMessage(cid,21,"Only players of level "..Min_Join_Level.." are allowed to pass.")
		else
			doTeleportThing(cid,Wait_Place,false)
			doSendMagicEffect(Wait_Place,10)
		end
	else
		doTeleportThing(cid,fromPosition,false)
		doSendMagicEffect(fromPosition,10)
		doPlayerSendTextMessage(cid,21,"Come back later, event is closed now.")
	end
return true
end
 
]=]=> </movevent>
<movevent type="StepIn" actionid="6001" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
 
function eventEnded()
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		doBroadcastMessage('CTF-Event : The '.. TEAM1_NAME..' team won and reciaved their reward.') 
	        for _,cid in ipairs(getPlayersOnline()) do
			    if isTeamOne(cid) then
				    doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
					doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
					doRemoveConditions(cid,false)
					resetTheTeams(cid)
					doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					giveReward(cid)
				elseif isTeamTwo(cid) then
				    doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
					doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
					doRemoveConditions(cid,false)
			        doPlayerSendTextMessage(cid,22,'Your team have lost.')
					resetTheTeams(cid)
					doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
				end
			end
    end
    addEvent(resetTheStorage,5)
end
function onStepIn(cid, item, position, fromPosition)
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		if isTeamOne(cid) and blueStolen() < 0 then
			if not flagOwner(cid) then
				doTeleportThing(cid, fromPosition,TRUE)
				doSendMagicEffect(getThingPos(cid),2)
				doPlayerSendTextMessage(cid, 27, "This is your team flag, you cant take it!")
			end
		elseif isTeamOne(cid) and blueStolen() > 0 and redStolen() < 0 then
			doPlayerSendTextMessage(cid, 27, "Your team's Flag has been stolen, go get it back!")
			doTeleportThing(cid, fromPosition,TRUE)
			doSendMagicEffect(getThingPos(cid),2)
         return true
		end
		if isTeamOne(cid) and flagOwner(cid) and redStolen() > 0 and blueStolen() < 0 then
			if getBlueScore() == FLAG_SCORE -1 then
				addEvent(eventEnded,1000)
				addToBlue()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
				releaseRF(cid)
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the last flag and earned match win to the ".. TEAM1_NAME.." team!")
						end
					end
			else
				releaseRF(cid)
				addToBlue()	   
				doTeleportThing(cid, fromPosition,TRUE)
				doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid) )
					for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " have captured the flag and earned 1 point to the ".. TEAM1_NAME.." team!")
								if Teleport_On_Score == true then
									doTeleportThing(tid,( isTeamTwo(tid) and Red_Position or Blue_Position ), false)
									doSendMagicEffect(getThingPos(tid),10)
								end
						end
					end
			end
		end
		if isTeamTwo(cid) then
			if blueStolen() > 0 and redStolen() < 0 then
			    if flagOwner(cid) then
					doPlayerSendTextMessage(cid, 27, "You already holding the flag!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                elseif (not flagOwner(cid)) then
	                doPlayerSendTextMessage(cid, 27, "Your Team mates already stole the oponent flag, defend him!")
	                doTeleportThing(cid, fromPosition,TRUE)
		            doSendMagicEffect(getThingPos(cid),2)
                end
			elseif redStolen() > 0 and blueStolen() < 0 then  
				doPlayerSendTextMessage(cid, 27, "Your team's flag is taken you can't capture or steel a flag!")
				doTeleportThing(cid, fromPosition,TRUE)
				doSendMagicEffect(getThingPos(cid),2)
			end
			if blueStolen() < 0 and redStolen() < 0 then
				setGlobalStorageValue(FLAG_IN,1)
			    setflagOwner(cid)
				setPlayerStorageValue(cid,103, os.time()+300)
				doTeleportThing(cid, fromPosition,TRUE)   
                    for _,tid in ipairs(getPlayersOnline()) do
						if isTeamOne(tid) or isTeamTwo(tid) then				   
							doPlayerSendTextMessage(tid,22,getCreatureName(cid) .. " stolen the "..TEAM1_NAME.." team flag!")
						end
					end
			end
		end
	end
return true
end
]=]=> </movevent>
<globalevent name="ctf" interval="900" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
local players = {}
local bmale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(bmale, {lookType = math.random(128,134), lookHead = 115, lookBody =114, lookLegs = 81, lookFeet = 81, lookTypeEx = 0, lookAddons = 3})
 
	local bfemale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(bfemale, {lookType = math.random(136,142), lookHead = 115, lookBody =114, lookLegs = 81, lookFeet = 81, lookTypeEx = 0, lookAddons = 3})
 
	local rmale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(rmale, {lookType = math.random(128,134), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})
 
	local rfemale = createConditionObject(CONDITION_OUTFIT)
		setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
		addOutfitCondition(rfemale, {lookType = math.random(136,142),lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})
	local fight = createConditionObject(CONDITION_INFIGHT)
		setConditionParam(fight, CONDITION_PARAM_TICKS, -1)
function eventEnd()
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
		if getRedScore() > getBlueScore() then
	        doBroadcastMessage('CTF-Event : The '.. TEAM2_NAME..' team won and recieved their reward.') 
				for _,cid in ipairs(getPlayersOnline()) do
					if isTeamTwo(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
						giveReward(cid)
					elseif isTeamOne(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						doPlayerSendTextMessage(cid,22,'Your team have lost.')
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					end
				end
 
		elseif getRedScore() < getBlueScore() then
	        doBroadcastMessage('CTF-Event : The '.. TEAM1_NAME..' team won and recieved their reward.') 
				for _,cid in ipairs(getPlayersOnline()) do
					if isTeamOne(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
						giveReward(cid)
					elseif isTeamTwo(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						doPlayerSendTextMessage(cid,22,'Your team have lost.')
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					end
				end
		elseif getRedScore() == getBlueScore() then
	        doBroadcastMessage('CTF-Event : The Event ended with a draw between both teams.') 
				for _,cid in ipairs(getPlayersOnline()) do
					if isTeamTwo(cid) or isTeamOne(cid) then
						doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)),false)
						doSendMagicEffect(getTownTemplePosition(getPlayerTown(cid)),10)
						doRemoveConditions(cid,false)
						doPlayerSendTextMessage(cid,22,'It was a draw between both teams.')
						resetTheTeams(cid)
						doChangeSpeed(cid, getTheSpeed(getPlayerLevel(cid)) - getCreatureSpeed(cid))
					end
				end
 
		end
		addEvent(resetTheStorage,1000)
	end
end
 
function eventStart()
	doSetStorage(Event_Tile_Close,-1)
	setGlobalStorageValue(Event_timeend,1)
	setGlobalStorageValue(Timer, os.time() + Event_MaxTime*60)
	addEvent(eventEnd,Event_MaxTime*60*1000)
 
 
 
            for v = frompos.x , topos.x do
				for k = frompos.y , topos.y do
					for i = 1, 200 do
						position = {x = v, y = k, z = 7, stackpos = i}
						pid = getThingfromPos(position).uid
							if(pid ~= nil and isPlayer(pid)) then
								table.insert(players, pid)
							end
					end
				end
			end
			if math.mod(#players, 2) ~= 0 then	
				doTeleportThing(players[#players],getTownTemplePosition(getPlayerTown(players[#players])),false)
				doSendMagicEffect(getThingPosition(players[#players]),10)
				doPlayerSendTextMessage(players[#players], 19, "Sorry, you have been kicked from event to balance teams.")					
				table.remove(players)
            end
            if #players < Players_Least_Number then
				doBroadcastMessage("CTF event was cancelled because less than "..Players_Least_Number.." players joined")
				resetTheStorage()
					if #players > 0 then
						for i = 1,#players do
						     doTeleportThing(players[i],getTownTemplePosition(getPlayerTown(players[i])),false) 
				             doSendMagicEffect(getThingPos(players[i]), 10) 
					    end
					end
			else	
					 doBroadcastMessage("CTF started")
						for i = 1, math.floor(#players/2) do
							setFirstTeam(players[i])
						end
						for i = math.floor(#players/2)+1 , #players do
							setSecondTeam(players[i])
						end
						for _,cid in ipairs(getPlayersOnline()) do
							if isTeamOne(cid) then
								if getPlayerSex(cid) == 1 then
									doAddCondition(cid, bmale)
								elseif getPlayerSex(cid) ~= 1 then
									doAddCondition(cid, bfemale)
								end
								doAddCondition(cid, fight)
								doTeleportThing(cid,Blue_Position,false) 
								doSendMagicEffect(Blue_Position, 10) 
								doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid))
							elseif  isTeamTwo(cid) then
								if getPlayerSex(cid) == 1 then
									doAddCondition(cid, rmale)
								elseif getPlayerSex(cid) ~= 1 then
									doAddCondition(cid, rfemale)
								end
								doAddCondition(cid, fight)
								doTeleportThing(cid,Red_Position,false) 
								doSendMagicEffect(Red_Position, 10)
								doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid))					
							end
						end	
						players = {}
 
            end
end
function onThink(interval)
   if getGlobalStorageValue(Event_Start) < 0 then
		setGlobalStorageValue(Event_Start,1)
		doSetStorage(Event_Tile_Close,1)
		doBroadcastMessage("CTF event is opened and teleport is created. It will start in "..Event_WaitTime.." minutes.")
		players = {}
		if getTileItemById(Tp_Place, 1387).uid < 1 then
			doItemSetAttribute(doCreateItem(1387,1, Tp_Place), "aid", 3435)
		end
 
		f= Event_WaitTime - 1
			for i = 1,Event_WaitTime-1 do
				addEvent(doBroadcastMessage,i*60*1000,"CTF event is opened and teleport is created. It will start in "..f.." minutes.")
				f= f-1
			end
		addEvent(eventStart,Event_WaitTime*60*1000)
	end
return true
end
]=]=></globalevent>
 <event type="think" name="ctff" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
 
local bl = BLUE_FLAG
local re = RED_FLAG
function onThink(interval)
	if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
        if redStolen() < 0 then
			doSendAnimatedText(re,"FLAG!",TEXTCOLOR_DARKRED)
			doSendMagicEffect(re, CONST_ME_SOUND_RED) 
        end
        if blueStolen() < 0 then
			doSendAnimatedText(bl,"FLAG!",TEXTCOLOR_GREEN)
			doSendMagicEffect(bl, CONST_ME_SOUND_GREEN)
	    end
        for _, cid in ipairs(getPlayersOnline()) do
            if flagOwner(cid) then
				if isTeamOne(cid) or isTeamTwo(cid) then
					if hasCondition(cid,CONDITION_HASTE) then
						doRemoveCondition(cid,CONDITION_HASTE)
					end
				end
				pl = getThingPos(cid) 
					if isTeamTwo(cid) then
						if getPlayerStorageValue(cid,103) < os.time() then
							releaseBF(cid)
								for _,cid in ipairs(getPlayersOnline()) do
									if isTeamOne(cid) or isTeamTwo(cid) then											
										doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " wasted 5 minutes with FLAG."..TEAM2_NAME.." flag is again on spawn!")
									end
								end
						else
							doSendAnimatedText(pl,"FLAG!",TEXTCOLOR_GREEN)
							doSendMagicEffect(pl, CONST_ME_SOUND_GREEN)
						end
					elseif isTeamOne(cid) then
						if getPlayerStorageValue(cid,103) < os.time() then
							releaseRF(cid)
								for _,cid in ipairs(getPlayersOnline()) do
									if isTeamOne(cid) or isTeamTwo(cid) then											
										doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " wasted 5 minutes with FLAG."..TEAM1_NAME.." flag is again on spawn!")
									end
								end
						else
							doSendAnimatedText(pl,"FLAG!",COLOR_RED)
							doSendMagicEffect(pl, CONST_ME_SOUND_RED)
						end
					end
			end
		end
	end
  return true
end
]=]=></event>
<globalevent name="timer" interval="0.4" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
 
function onThink(interval)
	for _,cid in ipairs(getPlayersOnline()) do
		if isTeamOne(cid) or isTeamTwo(cid) then
			if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
				if getGlobalStorageValue(Timer)- os.time() >= 0 then
					doPlayerSendCancel(cid, "Time -> ".. os.date("%M:%S ",getGlobalStorageValue(Timer)- os.time()) .. "  |  ".. TEAM1_NAME.." Score : "..getBlueScore(cid).."/"..FLAG_SCORE.." captures  |  ".. TEAM2_NAME.." Score : "..getRedScore(cid).."/"..FLAG_SCORE.." captures")
				end
			end
		end
	end
return true
end
]=]=></globalevent>
<globalevent name="starting" type="startup" event="script"><=!=[=C=D=A=T=A=[
domodlib('toto')
domodlib('CTF-lib')
function onStartup()
	resetTheStorage()
 
 return true
end
]=]=></globalevent>
</mod>
Try it and rep+ me :p

0.3.6?!
 
how do i join it?
please answer asap

EDIT: I meant like can someone edit it so a magicforce field creates when the ctf starts and people walk in it then it tps them to the waiting room. But the magic forcefield shud be created in a certain location like X Y Z and these things.
 
Last edited:
Try it and rep+ me :p

is it yours so he rep you?! also there is a reason why i deleted this script cause it contains some bugs, i donno why you(not specially you) keep posting it.


how do i join it?
please answer fast

EDIT: I meant like can someone edit it so a magicforce field creates when the ctf starts and people walk in it then it tps them to the waiting room. But the magic forcefield shud be created in a certain location like X Y Z and these things.

cant you see it is already like that.. all config are there where tp appear ,, w8 room etc.....
 
where does the tp appear which position? waitingroom pos or redteam pos or what lol

EDIT: i was lookin on the first script, then i checked ahmed's is it workin 100%? did anyone test it?
 
Last edited:
Back
Top