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

GlobalEvent Capture the flag :d

bump ..

- - - Updated - - -

ok, heres the working one, its a mod and easy setup:
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"><=!=[=C=D=A=T=A=[
		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"><=!=[=C=D=A=T=A=[
		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"><=!=[=C=D=A=T=A=[
		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"><=!=[=C=D=A=T=A=[
		registerCreatureEvent(cid, "ctf_stats")
		return registerCreatureEvent(cid, "ctf_target")
	]=]=></event>
	<event type="statschange" name="ctf_stats" event="script"><=!=[=C=D=A=T=A=[
		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"><=!=[=C=D=A=T=A=[
		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"><=!=[=C=D=A=T=A=[
		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>
read the description, map:
map rar
0.4_DEV

I have some questions to this script,

Redpos, bluepos are the position where they will get teleported if they die right ?
--
Next question: in map i have to add any flag ?
--
next one: in waiting room i have to do 2 teleports one to red team carpet, and blue team carpet ?
--
Thanks !

- - - Updated - - -

bump
 
is there anyway i can add a script to give the winning team a reward>?
 
So :
Tile Action ID
= 6000 Will Red Team flag (pick up position)
=6001 Will Blue team flag (pick up position)
=6002 will be capture point for both teams
=8412 will be your the square on your temple


This works for 8.6 [0.4.0 too]


Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="ctf" 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 = 16781,y = 16573,z = 5},
			toPos = {x = 16791, y = 16577, z = 5}
		}
		redPlayers = 1200
		bluePlayers = 2200

		redGoal = 3200
		blueGoal = 4200

		redFlag = 5200
		blueFlag = 5520

		ctf = {
			redPos = {x=16762,y=16575,z=7},
			bluePos = {x=16812,y=16575,z=7}
		}

		temple = {x = 32345, y = 32220, 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="6000000" event="script"><![CDATA[
		domodlib("ctf_config")
		setGlobalStorageValue(3200, 0)
		setGlobalStorageValue(4200, 0)
		setGlobalStorageValue(5200, -1)
		setGlobalStorageValue(5520, -1)
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 5200 .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 5520 .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key`= " .. 1200 .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 2200 .. ";")
	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])
		elseif #t == 5 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
			table.insert(red, t[3])
			table.insert(blue, t[4])
			table.insert(red, t[5])	
		elseif #t == 6 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
			table.insert(red, t[3])
			table.insert(blue, t[4])
			table.insert(red, t[5])
			table.insert(blue, t[6])	
		elseif #t == 7 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
			table.insert(red, t[3])
			table.insert(blue, t[4])
			table.insert(red, t[5])
			table.insert(blue, t[6])
			table.insert(red, t[7])			
		elseif #t == 8 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
			table.insert(red, t[3])
			table.insert(blue, t[4])
			table.insert(red, t[5])
			table.insert(blue, t[6])
			table.insert(red, t[7])	
			table.insert(blue, t[8])			
		elseif #t == 9 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
			table.insert(red, t[3])
			table.insert(blue, t[4])
			table.insert(red, t[5])
			table.insert(blue, t[6])
			table.insert(red, t[7])	
			table.insert(blue, t[8])
			table.insert(red, t[9])				
		elseif #t == 10 then
			table.insert(red, t[1])
			table.insert(blue, t[2])
			table.insert(red, t[3])
			table.insert(blue, t[4])	
			table.insert(red, t[5])
			table.insert(blue, t[6])
			table.insert(red, t[7])	
			table.insert(blue, t[8])
			table.insert(red, t[9])	
			table.insert(blue, t[10])			
		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 5 minutes.")
		addEvent(doBroadcastMessage, 60 * 1 * 1000, "Capture The Flag will begin in 4 minutes.")
		addEvent(doBroadcastMessage, 60 * 2 * 1000, "Capture The Flag will begin in 3 minutes.")
		addEvent(doBroadcastMessage, 60 * 3 * 1000, "Capture The Flag will begin in 2 minutes.")		
		addEvent(doBroadcastMessage, 60 * 4 * 1000, "Capture The Flag will begin in 1 minute.")
		addEvent(doBroadcastMessage, 57 * 5 * 1000, "Capture The Flag will begin in 15 seconds.")
		addEvent(finishThis, 5 * 60 * 1000)
	end
	function onThink(interval)
		return teleport()
	end
	]]></globalevent>

	<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 == 6001 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 == 6000 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, 9971, math.random(3, 7))
						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, 9971, math.random(3, 7))
						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>



Set this Action ID as your temple position squares (only way i could get it to work on my server)


In movements.xml
Code:
<movement type="StepIn" actionid="8412" event="script" value="ctfdeath.lua"/>


In movements->scripts->ctfdeath


Code:
function onStepIn(cid, item, position, fromPosition)
	if item.actionid == 8412 then

	if getPlayerStorageValue(cid, 2200) == 1 then 
	doTeleportThing(cid, {x = 16814, y = 16581, z = 7}) --this will be blue team respawn point


	elseif getPlayerStorageValue(cid, 1200) == 1 then
	doTeleportThing(cid, {x = 16760, y = 16568, z = 7}) --this will be red team respawn point


return end
end
end





+rep if it worked!

edit : heres my map and a pic!

View attachment ctf.rar


(note my map has some action ids already set)
ctf2.jpg
 
Last edited:
I'm gonna check it out later, I can't read everything and fix everything right now so I'll be back soon and tell you if it works. Thanks.
 
its been running for months on my server, i know it works, its a matter of configurating it
 
So why does it say "The flag is not home right now". And when I try to get the blue team's flag, it says "Can't pickup your own team's flag", does that mean I'm in the blue team?
How can I make for example if I put this event in my server, that 3 ppl goes red team and 3 ppl goes blue team by using a lever/switch?

Rep+ anyone who can help.

Edit: Oh and I'm a bit slow in scripting so... explain as much as you can, I'd appreciate it, thanks in advance.
 
okay, one sec, let me give you my debug script for when errors occur, this is what i use


in talkactions.xml
Code:
		<talkaction log="yes" words="/ctfdebug" access="5" event="script" value="ctfdebug.lua"/>

in talkactions->scripts->ctfdebug.lua

Code:
function onSay(cid, words, param)
if getPlayerMoney(cid) >= 10000 then
		setGlobalStorageValue(3200, 0)
		setGlobalStorageValue(4200, 0)
		setGlobalStorageValue(5200, -1)
		setGlobalStorageValue(5520, -1)
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 5200 .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 5520 .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key`= " .. 1200 .. ";")
		db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 2200 .. ";")
doSendMagicEffect(getPlayerPosition(cid),12)
doPlayerSendTextMessage(cid,22,"You have debugged the event.")
else
doPlayerSendCancel(cid,"You don't have enough money! You need 10000gps")
doSendMagicEffect(getPlayerPosition(cid),2)
end
return true
end


this is my debug script ; its a talkaction.

it just requires you to have 1cc in your inventory (to see if its working, it wont remove the cc)


and your error is, you arent turning in the flag in the right spot!


6002 is the AID of the spot where you should turn in BOTH your flags! (i.e. in my example map, its in the center, because this makes the most sense!)

- - - Updated - - -

So why does it say "The flag is not home right now". And when I try to get the blue team's flag, it says "Can't pickup your own team's flag", does that mean I'm in the blue team?
How can I make for example if I put this event in my server, that 3 ppl goes red team and 3 ppl goes blue team by using a lever/switch?

Rep+ anyone who can help.

Edit: Oh and I'm a bit slow in scripting so... explain as much as you can, I'd appreciate it, thanks in advance.

here we are!

omfg i forgot to upload a script, thx for pointing it out! will be here in 1 sec

- - - Updated - - -

in Movements.xml]
Code:
<movevent type="StepIn" actionid="6002" event="script" value="test.lua"/>

In Movements->scripts->test.xml
Code:
local t = {
	redStorage = 1200,
	blueStorage = 2200,
	redFlag = 5200,
	blueFlag = 5520,
	redGoal = 3200,
	blueGoal = 4200,
	fromPos = {x = 16760, y = 16561, z = 7},
	toPos = {x = 16818, y = 16584, z = 7}
}
local function getPlayers()
	local thisTable = {}
	for x = t.fromPos.x, t.toPos.x do
		for y = t.fromPos.y, t.toPos.y do
			for z = t.fromPos.z, t.toPos.z do
				local myPos = {x = x, y = y, z = z}
				local player = getTopCreature(myPos).uid
				if player > 0 then table.insert(thisTable, player) else table.remove(thisTable, player) end
			end
		end
	end
	return {thisTable = thisTable}
end
local function repeatFlagOnPlayer(cid)
	local k = getThingPos(cid)
	local r = {
		{pos = {x = k.x + 2, y = k.y - 2, z = k.z}, delay = 500},
		{pos = {x = k.x + 2, y = k.y + 2, z = k.z}, delay = 500},
		{pos = {x = k.x - 2, y = k.y + 2, z = k.z}, delay = 500},
		{pos = {x = k.x - 2, y = k.y, z = k.z}, delay = 500},
		{pos = {x = k.x - 2, y = k.y - 2, z = k.z}, delay = 500},
		{pos = {x = k.x, y = k.y - 2, z = k.z}, delay = 500}
	}
	local effects = {27, 28, 29, 30}
	if isPlayer(cid) then
		if getPlayerStorageValue(cid, t.blueStorage) == 1 and getPlayerStorageValue(cid, t.redFlag) == 1 and getGlobalStorageValue(t.redFlag) == 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(repeatFlagOnPlayer, 1000, cid)
		elseif getPlayerStorageValue(cid, t.redStorage) == 1 and getPlayerStorageValue(cid, t.blueFlag) == 1 and getGlobalStorageValue(t.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(repeatFlagOnPlayer, 1000, cid)
		else
			return false
		end
	else
		return false
	end
end
function onStepIn(cid, item, position, fromPosition, toPosition, lastPosition, actor)
	if isPlayer(cid) then
		if item.actionid == 6000 then
			if getPlayerStorageValue(cid, t.redStorage) == 1 then
				if getPlayerStorageValue(cid, t.blueFlag) == -1 and getGlobalStorageValue(t.blueFlag) == -1 then
					setPlayerStorageValue(cid, t.blueFlag, 1)
					setGlobalStorageValue(t.blueFlag, 1)
					repeatFlagOnPlayer(cid)
					doBroadcastMessage(getCreatureName(cid) .. " has stolen the Blue Flag!")
				else
					doCreatureSay(cid, "The flag is not at home.", 19)
					doTeleportThing(cid, fromPosition, false)
				end
			else
				doCreatureSay(cid, "You may only pick up the opposite team flag.", 19)
				doTeleportThing(cid, fromPosition, false)
			end
		elseif item.actionid == 6001 then
			if getPlayerStorageValue(cid, t.blueStorage) == 1 then
				if getPlayerStorageValue(cid, t.redFlag) == -1 and getGlobalStorageValue(t.redFlag) == -1 then
					setPlayerStorageValue(cid, t.redFlag, 1)
					setGlobalStorageValue(t.redFlag, 1)
					repeatFlagOnPlayer(cid)
					doBroadcastMessage(getCreatureName(cid) .. " has stolen the Red flag!")
				else
					doCreatureSay(cid, "The flag is not at home.", 19)
					doTeleportThing(cid, fromPosition, false)
				end
			else
				doCreatureSay(cid, "The flag is not at home.", 19)
				doTeleportThing(cid, fromPosition, false)
			end
		end
		if item.actionid == 6002 then
			if getPlayerStorageValue(cid, t.redStorage) == 1 then
				if getPlayerStorageValue(cid, t.blueFlag) == 1 and getGlobalStorageValue(t.blueFlag) == 1 then
					setGlobalStorageValue(t.blueFlag, -1)
					setPlayerStorageValue(cid, t.blueFlag, -1)
					setGlobalStorageValue(t.redGoal, getGlobalStorageValue(t.redGoal)+1)
					doBroadcastMessage("Current CTF Game Score:\nRed Team: " .. getGlobalStorageValue(t.redGoal) .. "\nBlue Team: " .. getGlobalStorageValue(t.blueGoal) .. "\nTen Scores to win!", 20)
					doBroadcastMessage(getCreatureName(cid) .. " has scored 1 point for the Red Team!")
				else
					doCreatureSay(cid, "You dont have the flag.", 19)
					doTeleportThing(cid, fromPosition, false)
				end
			elseif getPlayerStorageValue(cid, t.blueStorage) == 1 then
				if getPlayerStorageValue(cid, t.redFlag) == 1 and getGlobalStorageValue(t.redFlag) == 1 then
					setGlobalStorageValue(t.redFlag, -1)
					setPlayerStorageValue(cid, t.redFlag, -1)
					setGlobalStorageValue(t.blueGoal, getGlobalStorageValue(t.blueGoal)+1)
					doBroadcastMessage("Current CTF Game Score:\nRed Team: " .. getGlobalStorageValue(t.redGoal) .. "\nBlue Team: " .. getGlobalStorageValue(t.blueGoal) .. "\nTen Scores to win!", 20)
					doBroadcastMessage(getCreatureName(cid) .. " has scored 1 point for the Blue Team!")
				else
					doCreatureSay(cid, "You dont have the flag.", 19)
					doTeleportThing(cid, fromPosition, false)
				end
			end
			if getGlobalStorageValue(t.blueGoal) == 10 and getGlobalStorageValue(t.redGoal) < 10 then
				for _, cid in ipairs(getPlayersOnline()) do
					if getPlayerStorageValue(cid, t.blueStorage) == 1 then
						setPlayerStorageValue(cid, t.blueStorage, -1)
						doPlayerAddItem(cid, 9971, math.random(1, 6))
					elseif getPlayerStorageValue(cid, t.redStorage) == 1 then
						setPlayerStorageValue(cid, t.redStorage, -1)
					end
					doRemoveCondition(cid, CONDITION_OUTFIT)
					setGlobalStorageValue(t.redGoal, 0)
					setGlobalStorageValue(t.blueGoal, 0)
				end
				local FF = getPlayers().thisTable
				if #FF > 1 then
					for _, hh in ipairs(FF) do
						doTeleportThing(hh, getTownTemplePosition(getPlayerTown(hh)), true)
					end
				end
			elseif getGlobalStorageValue(t.redGoal) == 10 and getGlobalStorageValue(t.blueGoal) < 10 then
				for _, cid in ipairs(getPlayersOnline()) do
					if getPlayerStorageValue(cid, t.redStorage) == 1 then
						setPlayerStorageValue(cid, t.redStorage, -1)
						doPlayerAddItem(cid, 9971, math.random(1, 6))
					elseif getPlayerStorageValue(cid, t.blueStorage) == 1 then
						setPlayerStorageValue(cid, t.blueStorage, -1)
					end
					doRemoveCondition(cid, CONDITION_OUTFIT)
					setGlobalStorageValue(t.redGoal, 0)
					setGlobalStorageValue(t.blueGoal, 0)
				end
				local F = getPlayers().thisTable
				if #F > 1 then
					for _, h in ipairs(F) do
						doTeleportThing(h, getTownTemplePosition(getPlayerTown(h)), true)
					end
				end
			end
		end
	else
		doRemoveCreature(cid)
	end
	return true
end
 
K man I don't understand anything you just said... how did that even help me? What's the debug for and what's the movement things for? Could you explain with more sentences because I said I'm a noob.

If I want to have red team and blue team, 4 ppl stand on 4 tiles, and 4 other people stand on 4 other tiles, then poff they get teleported to ctf arena in red, and blue team, how do I do that? Because the ctf event isn't working for me, maybe I should remove it and don't use it...
 
Sorry guy, im not writting you a whole brand new script from scratch lol, that would take hours. I sent you mine, be happy! I even wrote nice directions on how to set it up...

- - - Updated - - -

I mean, if you wanna know what the code does exactly, its best to read it yourself. You're going to have to learn to code yourself too! I came here similar skills to yours now, but after 3-4 months of ATLEAST TRYING you can pick up on it! its so simple. just time consuming. but with globalstorage values + playerstorage values you can do anything.
 
Yeah man thanks for everything... But I mean, I already have all scripts inserted in my server, so what do I have to do on my map for entering the event? I mean, I can't just make a teleport into the event; then what team would people be in? I was thinking like in RL Annihlator, 4 spots and pull a switch to get into blue team, and to get into red team. But how do I do that exactly?
 
Okay, how it works, is a waiting room, just make a 4 by 4 square box room, with a TP out of it. thats what i have, and when the event starts, all players in the waiting room will be teleported it. And the TP in the waiting room, will be for players to cancel, or leave the waiting room while the event isnt ready. Does that make sense? If you want to hop on my server, I can show you what mine is like!

- - - Updated - - -

forgot to mention : and the portal TO the waiting room will ALWAYS be open, because if it isnt ready, they can just take the exit portal out from inside the waiting room!
 
Oh ok, but should there be any special action scripts on tiles? Or just a simple room? Rep+ man I appreciate ur help u deserve it. Thanks
 
Nope, just a simple room! Can easily be made in rme in under 5 mins. if your still not getting it, please get on my server, its easiest to explain it there! and i can show you mine!
 
Nope, just a simple room! Can easily be made in rme in under 5 mins. if your still not getting it, please get on my server, its easiest to explain it there! and i can show you mine!

Ok I'll join your server tomorrow. I'm gonna PM you so you can give me Server info/IP etc then I'll join and check it out mate.
Goodnight, cya tomorrow.

P.S Sry for OffTopic.
 
people die during the event? or when died what occurs? tried to find on the creaturescripts but nothing. thanks.
 
Back
Top