Announcement: The amount of coins earned has been increased, visit the F.A.Q Section for more information!
Register and start earning coins for adding servers, creating threads, posting and much more!


[0.4] Team Death Match Event Watch Thread

Extrodus
Administrator

Posts: 112
Tested by Extrodus on 0.4

Info: Team Death Match Event with constant Displaying White Text during event showing score/time left.

<?xml version="1.0" encoding="UTF-8"?>
<mod name="Team Deathmatch" version="1.0" author="Ancores" contact="otland.net" enabled="yes">
	<config name="teamdeathmatch_config"><![CDATA[
		-- USE PZ IN WAITING ROOM!
		-- USE PVP ZONE AND NON LOGOUT ZONE IN THE EVENT!
		
		config = {
			fragsToWin = 30,                                               -- Stop event when a team has this many frags
			timeLimit = 10,                                                -- When 15 minutes have passed, stop event
			minPlayers = 4,                                                -- Minimum players needed to start event
			maxPlayers = 20,                                               -- Maximum players allowed to join
			levelReq = 100,                                                -- Minimum level required to join
			startTime = "18:00 GMT",                                       -- Time to start the event (this is just for the message, change time below the config if you want to change it)
			teamColor = {114, 0},                                          -- Team colors (Team 1, Team 2) (0 = black, 114 = white, 101 = green, 94 = red, 68 = blue)
			teamStorage = 52000,                                           -- Storage value that stores which team the player is in
			fragsTeam1 = 52001,                                            -- Team 1 frag storage
			fragsTeam2 = 52002,                                            -- Team 2 frag storage
			active = 52000,                                                -- Global Storage Value to know if the event is on or off
			startPos = {{x=31623, y=32191, z=7}, {x=31642, y=32166, z=7}},     -- Start position of team 1 and team 2
			waitRoomPos = {x=31623, y=32189, z=5},                           -- Position to get teleported to in the waiting room
			expReward = 75000,                                             -- Amount of experience given to the winning team
			itemReward = true,                                             -- Use item rewards?
			itemRewards = {{2160, 5}, {2195, 1}}                          -- Items given to the winning team ({ID, Amount}, {ID, Amount}, etc)
		}		
	]]></config>
	
	<globalevent name="TeamDeathMatch" interval="7200000" event="script"><![CDATA[
	function onThink()
		domodlib('teamdeathmatch_config')
		setGlobalStorageValue(config.active, 1)
		doBroadcastMessage("Team Death Match event has been opened, the portal is located in the event room!", MESSAGE_STATUS_CONSOLE_BLUE)
	return true
	end
	]]></globalevent>

	<event type="preparedeath" name="TeamDeathmatchDeath" event="script"><![CDATA[
	function onPrepareDeath(cid)
		domodlib('teamdeathmatch_config')
		if(isPlayer(cid)) then
			if(getPlayerStorageValue(cid, config.teamStorage) > 0) then
				if(getPlayerStorageValue(cid, config.teamStorage) == 1) then
					setGlobalStorageValue(config.fragsTeam2, getGlobalStorageValue(config.fragsTeam2) + 1)
				elseif(getPlayerStorageValue(cid, config.teamStorage) == 2) then
					setGlobalStorageValue(config.fragsTeam1, getGlobalStorageValue(config.fragsTeam1) + 1)
				end
				addEvent(doTeleportThing, 50, cid, config.startPos)
				doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
				for _, pid in ipairs(getPlayersOnline()) do
					if(getPlayerStorageValue(pid, config.teamStorage) > 0) then
						if(getPlayerStorageValue(pid, config.teamStorage) > 0) then
							doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "Black = " .. getGlobalStorageValue(config.fragsTeam1) .. "\nWhite = " .. getGlobalStorageValue(config.fragsTeam2))
						end
						if(getGlobalStorageValue(config.fragsTeam1) >= config.fragsToWin or getGlobalStorageValue(config.fragsTeam2) >= config.fragsToWin) then
							if(getGlobalStorageValue(config.fragsTeam1) >= config.fragsToWin) then
								if(getPlayerStorageValue(pid, config.teamStorage) == 1) then
									doPlayerAddExperience(pid, config.expReward)
									if(config.itemReward == true) then
										for k = 1, #config.itemRewards do
											doPlayerAddItem(pid, config.itemRewards, config.itemRewards)
										end
									end
								end
								doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "The black team won Team Deathmatch!")
							elseif(getGlobalStorageValue(config.fragsTeam2) >= config.fragsToWin) then
								if(getPlayerStorageValue(pid, config.teamStorage) == 2) then
									doPlayerAddExperience(pid, config.expReward)
									if(config.itemReward == true) then
										for k = 1, #config.itemRewards do
											doPlayerAddItem(pid, config.itemRewards, config.itemRewards)
										end
									end
								end
								doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "The white team won Team Deathmatch!")
							end
							addEvent(doTeleportThing, 100, pid, getTownTemplePosition(getPlayerTown(cid)))
							setPlayerStorageValue(pid, config.teamStorage, 0)
							doRemoveCondition(pid, CONDITION_OUTFIT)
							doRemoveCondition(pid, CONDITION_INFIGHT)
						end
					end
				end
			end
		end
	return true
	end
	]]></event>

	<event type="combat" name="TeamDeathmatchCombat" event="script"><![CDATA[
	function onCombat(cid, target)
		domodlib('teamdeathmatch_config')
		if(isPlayer(cid) and isPlayer(target)) then
			if(getPlayerStorageValue(cid, config.teamStorage) > 0 and getPlayerStorageValue(target, config.teamStorage) > 0) then
				if(getPlayerStorageValue(cid, config.teamStorage) == getPlayerStorageValue(target, config.teamStorage)) then
					return false
				end
			end
		end
	return true
	end
	]]></event>

	<event type="login" name="TeamDeathmatchLogin" event="script"><![CDATA[
	function onLogin(cid)
		domodlib('teamdeathmatch_config')
		registerCreatureEvent(cid, "TeamDeathmatchDeath")
		registerCreatureEvent(cid, "TeamDeathmatchCombat")
		if(getPlayerStorageValue(cid, config.teamStorage) > 0) then
			doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
			setPlayerStorageValue(cid, config.teamStorage, 0)
		end
	return true
	end
	]]></event>
	
	<movevent type="StepIn" actionid="52000" event="script"><![CDATA[
	local function stopEvent(timeLeft)
		timeLeft = timeLeft - 1
		if(timeLeft > 0) then
			for _, pid in ipairs(getPlayersOnline()) do
				if(getPlayerStorageValue(pid, config.teamStorage) > 0) then
					doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, timeLeft .. " minutes remaining.")
					doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, timeLeft .. " minutes remaining.")
				end
			end
			addEvent(stopEvent, 1 * 60 * 1000, timeLeft)
		else
			for _, pid in ipairs(getPlayersOnline()) do
				if(getPlayerStorageValue(pid, config.teamStorage) > 0) then
					if(getGlobalStorageValue(config.fragsTeam1) > getGlobalStorageValue(config.fragsTeam2)) then
						if(getPlayerStorageValue(pid, config.teamStorage) == 1) then
							doPlayerAddExperience(pid, config.expReward)
							if(config.itemReward == true) then
								for k = 1, #config.itemRewards do
									doPlayerAddItem(pid, config.itemRewards, config.itemRewards)
								end
							end
						end
						doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "The red team won Team Deathmatch!")
					elseif(getGlobalStorageValue(config.fragsTeam2) > getGlobalStorageValue(config.fragsTeam1)) then
						if(getPlayerStorageValue(pid, config.teamStorage) == 2) then
							doPlayerAddExperience(pid, config.expReward)
							if(config.itemReward == true) then
								for k = 1, #config.itemRewards do
									doPlayerAddItem(pid, config.itemRewards, config.itemRewards)
								end
							end
						end
						doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "The blue team won Team Deathmatch!")
					elseif(getGlobalStorageValue(config.fragsTeam2) == getGlobalStorageValue(config.fragsTeam1)) then
						doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "Team Deathmatch was a draw!")
					end			
					doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
					setPlayerStorageValue(pid, config.teamStorage, 0)
					doRemoveCondition(pid, CONDITION_OUTFIT)
					doRemoveCondition(pid, CONDITION_INFIGHT)
				end
			end
		end
	return true
	end	
	
	local function startEvent()
		local players = {}
		for _, pid in ipairs(getPlayersOnline()) do
			if(getPlayerStorageValue(pid, config.teamStorage) > 0) then
				table.insert(players, pid)
			end
		end
		
		for _, pid in ipairs(players) do
			if(#players < config.minPlayers) then
				doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
				doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, "Team Deathmatch has insufficient players and has been revoked.")
				doRemoveCondition(pid, CONDITION_OUTFIT)
				doRemoveCondition(pid, CONDITION_INFIGHT)
				setPlayerStorageValue(pid, config.teamStorage, 0)
			else
				doTeleportThing(pid, config.startPos)
				doSendMagicEffect(getThingPos(pid), CONST_ME_TELEPORT)
			end
		end
		
		local timeLeft = config.timeLimit
		addEvent(stopEvent, 1 * 60 * 1000, timeLeft)
		
		setGlobalStorageValue(config.active, 0)
		setGlobalStorageValue(config.fragsTeam1, 0)
		setGlobalStorageValue(config.fragsTeam2, 0)
	return true
	end
	
	function onStepIn(cid, item, position, fromPosition)
		domodlib('teamdeathmatch_config')
		
		if(getGlobalStorageValue(config.active) <= 0) then
			doTeleportThing(cid, fromPosition)
			doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Team Death Match event is closed, the teleporter will open in another 2 hours.")
			return
		end
		
		if(getPlayerLevel(cid) < config.levelReq) then
			doTeleportThing(cid, fromPosition)
			doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your level is too low to join Team Deathmatch, try again when you have reached level " .. config.levelReq .. ".")
			return
		end
		
		local players = {}
		for _, pid in ipairs(getPlayersOnline()) do
			if(getPlayerStorageValue(pid, config.teamStorage) > 0) then
				table.insert(players, pid)
			end
		end
		
		if(#players >= config.maxPlayers) then
			doTeleportThing(cid, fromPosition)
			doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Team Deathmatch has reached the maximum player limit.")
			return
		end
		
		local team1 = 0
		local team2 = 0
		for _, pid in ipairs(players) do
			if(getPlayerStorageValue(pid, config.teamStorage) == 1) then
				team1 = team1 + getPlayerLevel(pid)
			elseif(getPlayerStorageValue(pid, config.teamStorage) == 2) then
				team2 = team2 + getPlayerLevel(pid)
			end
		end
		
		setPlayerStorageValue(cid, config.teamStorage, team1 < team2 and 1 or 2)
		local voc = getPlayerVocation(cid)
		local color = config.teamColor
		doSetCreatureOutfit(cid, {lookType = (voc == 1 and 130 or voc == 2 and 144 or voc == 3 and 129 or voc == 4 and 131 or voc == 5 and 130 or voc == 6 and 144 or voc == 7 and 129 or voc == 8 and 131), lookHead = color, lookAddons = 3, lookLegs = color, lookBody = color, lookFeet = color})
	
		if(#players <= 0) then
			doBroadcastMessage("Team Death Match starting in 3 minutes!", MESSAGE_STATUS_CONSOLE_BLUE)
			addEvent(doBroadcastMessage, 1 * 60 * 1000, "Team Death Match starting in 2 minutes!", MESSAGE_STATUS_CONSOLE_BLUE)
			addEvent(doBroadcastMessage, 2 * 60 * 1000, "Team Death Match starting in 1 minute!", MESSAGE_STATUS_CONSOLE_BLUE)
			addEvent(startEvent, 3 * 60 * 1000)
		end
		
		doTeleportThing(cid, config.waitRoomPos)
		doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
	return true
	end
	]]></movevent>
</mod>

Created 21 December 2013 01:29:55#post-17
dzynks

Posts: 66
Thanks, it is great!
Created 12 March 2016 09:50:31#post-532
Who is viewing this thread?
nobody
Copyright OTList.net Follow us on Facebook