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

CreatureEvent Darkhaos' Svargrond Arena

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
This is my Svargrond Arena script, this includes a lib files that is very easy to configure, i know this includes 5+ scripts, this can be done in a mod file but i really don't like mods, anyways, i tested it and i didn't find bugs...
In any case, if you find bugs, please post it here.

This Svargrond arena is configured to the map that i'm posting in this post, so if you uses it on another map, you'll probabbly have a lot of bugs. (When i say that it's configured to this map, i mean the positions.). What i say if that you'll have to use this map or copy the svargrond map and paste it on your server, I didn't do it because I haven't installed any map editor and I'm tired ...Problem??

Features
  • Configurable monsters, pits positions, rewards and more
  • It includes timer, like real tibia, you'll be kicked from pit if your time gone (Firefield disappear)
  • There are three levels added (Greenhorn, Scrapper and Warlord). You can add more levels if you want.

Config
http://i55.tinypic.com/33tmcg6.png
http://i55.tinypic.com/2upemc1.png
http://i54.tinypic.com/amts03.jpg
http://i56.tinypic.com/m7rvpt.png
http://i51.tinypic.com/t9z62d.png

We start here...
First, create a lib file on data/lib and paste this inside:
Lua:
timePerPit = 600 --600 seconds = 10 minutes

-- These variables need to be equal to the reward-doors' action id --[[
ACTION_GREENHORNDOOR = 26100 
ACTION_SCRAPPERDOOR = 27100
ACTION_WARLORDDOOR = 28100
--]]

ITEM_FIREFIELD_TIMER = {1500, 1501, 1502}
ITEM_STONEPILLAR = 1354
ITEM_NOTERASABLE = {1500, 1501, 1502, 1354, 1543, 1544, 1545} --Not erasable items when pit is reseted

STORAGE_ARENA = 57209
STORAGE_PIT = 57309

POSITION_REWARD = {x = 1127, y = 1109, z = 6}
POSITION_KICK = {x = 1129, y = 1124, z = 7}

--Just paste here the positions of the first pit and script will configure positions for other pits.
FIRST_PIT =
{
	fromPos = {x = 1110, y = 1123, z = 7}, 
	toPos = {x = 1119, y = 1132, z = 7},
	center = {x = 1114, y = 1128, z = 7},
	pillar = {x = 1109, y = 1127, z = 7},
	summon = {x = 1116, y = 1125, z = 7}
}

PITS =
{
	[1] =
	{
		fromPos = FIRST_PIT.fromPos,
		toPos = FIRST_PIT.toPos,
		center = FIRST_PIT.center,
		pillar = FIRST_PIT.pillar,
		summon = FIRST_PIT.summon
	},
	[2] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 14, y = FIRST_PIT.fromPos.y, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 14, y = FIRST_PIT.toPos.y, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 14, y = FIRST_PIT.center.y, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 14, y = FIRST_PIT.pillar.y, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 14, y = FIRST_PIT.summon.y, z = FIRST_PIT.summon.z}
	},
	[3] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 28, y = FIRST_PIT.fromPos.y, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 28, y = FIRST_PIT.toPos.y, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 28, y = FIRST_PIT.center.y, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 28, y = FIRST_PIT.pillar.y, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 28, y = FIRST_PIT.summon.y, z = FIRST_PIT.summon.z}
	},
	[4] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 42, y = FIRST_PIT.fromPos.y, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 42, y = FIRST_PIT.toPos.y, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 42, y = FIRST_PIT.center.y, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 42, y = FIRST_PIT.pillar.y, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 42, y = FIRST_PIT.summon.y, z = FIRST_PIT.summon.z}
	},
	[5] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 7, y = FIRST_PIT.fromPos.y - 14, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 7, y = FIRST_PIT.toPos.y - 14, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 7, y = FIRST_PIT.center.y - 14, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 7, y = FIRST_PIT.pillar.y - 14, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 7, y = FIRST_PIT.summon.y - 14, z = FIRST_PIT.summon.z}
	},
	[6] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 21, y = FIRST_PIT.fromPos.y - 14, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 21, y = FIRST_PIT.toPos.y - 14, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 21, y = FIRST_PIT.center.y - 14, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 21, y = FIRST_PIT.pillar.y - 14, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 21, y = FIRST_PIT.summon.y - 14, z = FIRST_PIT.summon.z}
	},
	[7] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 35, y = FIRST_PIT.fromPos.y - 14, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 35, y = FIRST_PIT.toPos.y - 14, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 35, y = FIRST_PIT.center.y - 14, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 35, y = FIRST_PIT.pillar.y - 14, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 35, y = FIRST_PIT.summon.y - 14, z = FIRST_PIT.summon.z}
	},
	[8] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 14, y = FIRST_PIT.fromPos.y - 28, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 14, y = FIRST_PIT.toPos.y - 28, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 14, y = FIRST_PIT.center.y - 28, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 14, y = FIRST_PIT.pillar.y - 28, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 14, y = FIRST_PIT.summon.y - 28, z = FIRST_PIT.summon.z}
	},
	[9] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 28, y = FIRST_PIT.fromPos.y - 28, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 28, y = FIRST_PIT.toPos.y - 28, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 28, y = FIRST_PIT.center.y - 28, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 28, y = FIRST_PIT.pillar.y - 28, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 28, y = FIRST_PIT.summon.y - 28, z = FIRST_PIT.summon.z}
	},
	[10] =
	{
		fromPos = {x = FIRST_PIT.fromPos.x - 21, y = FIRST_PIT.fromPos.y - 42, z = FIRST_PIT.fromPos.z},
		toPos = {x = FIRST_PIT.toPos.x - 21, y = FIRST_PIT.toPos.y - 42, z = FIRST_PIT.toPos.z},
		center = {x = FIRST_PIT.center.x - 21, y = FIRST_PIT.center.y - 42, z = FIRST_PIT.center.z},
		pillar = {x = FIRST_PIT.pillar.x - 21, y = FIRST_PIT.pillar.y - 42, z = FIRST_PIT.pillar.z},
		summon = {x = FIRST_PIT.summon.x - 21, y = FIRST_PIT.summon.y - 42, z = FIRST_PIT.summon.z}
	}
}

ARENA =
{
	[1] =
	{
		name = "Greenhorn",
		price = 1000,
		creatures =
		{
			[1] = "frostfur",
			[2] = "bloodpaw",
			[3] = "bovinus",
			[4] = "achad",
			[5] = "colerian the barbarian",
			[6] = "the hairy one",
			[7] = "axeitus headbanger",
			[8] = "rocky",
			[9] = "cursed gladiator",
			[10] = "orcus the cruel"
		},
		reward = 
		{
			storage = 24709,
			trophy = 5807,
			trophyStorage = 25709,
			desc = "A brave warrior that finished the Greenhorn mode. Awarded to %s",
			[26300] =
			{
				container = true,
				id = 1990,
				inside =
				{
					{2114, 1},
					{9570, 1},
					{6574, 1},
					{2688, 10},
					{7372, 1}
				}
			},
			[26400] =
			{
				container = true,
				id = 7342,
				inside =
				{
					{7364, 100},
					{7365, 100}
				},
			},
			[26500] = 
			{
				id = {7406, 1}
			},
			[26600] = 
			{
				id = {7380, 1}
			},
			[26700] = 
			{
				id = {7392, 1}
			}
		}
	},
	[2] =
	{
		name = "Scrapper",
		price = 5000,
		creatures =
		{
			[1] = "avalanche",
			[2] = "kreebosh the exile",
			[3] = "the dark dancer",
			[4] = "the hag",
			[5] = "slim",
			[6] = "grimgor guteater",
			[7] = "drasilla",
			[8] = "spirit of earth",
			[9] = "spirit of water",
			[10] = "spirit of fire"
		},
		reward = 
		{
			storage = 35809,
			trophy = 5806,
			trophyStorage = 25809,
			desc = "A brave warrior that finished the Scrapper mode. Awarded to %s",
			[27300] =
			{
				container = true,
				id = 1990,
				inside =
				{
					{7183, 1},
					{6574, 1},
					{7373, 1},
					{2688, 10}
				}
			},
			[27400] =
			{
				container = true,
				id = 7342,
				inside =
				{
					{2304, 50},
					{2311, 50},
					{2547, 200},
					{7365, 100}
				},
			},
			[27500] = 
			{
				id = {7384, 1}
			},
			[27600] = 
			{
				id = {7389, 1}
			},
			[27700] = 
			{
				id = {7415, 1}
			}
		}
	},
	[3] =
	{
		name = "Warlord",
		price = 10000,
		creatures =
		{
			[1] = "webster",
			[2] = "darakan the executioner",
			[3] = "norgle glacierbeard",
			[4] = "the pit lord",
			[5] = "svoren the mad",
			[6] = "the masked marauder",
			[7] = "gnorre chyllson",
			[8] = "fallen mooh'tah master ghar",
			[9] = "deathbringer",
			[10] = "the obliverator"
		},
		reward = 
		{
			storage = 15909,
			trophy = 5805,
			trophyStorage = 25909,
			desc = "A brave warrior that finished the Warlord mode. Awarded to %s",
			[28300] =
			{
				container = true,
				id = 1990,
				inside =
				{
					{6568, 1},
					{6574, 1},
					{7374, 1},
					{2688, 10}
				}
			},
			[28400] =
			{
				container = true,
				id = 7342,
				inside =
				{
					{6529, 100},
					{7440, 1},
					{7443, 1},
					{2268, 50},
					{2273, 50}
				},
			},
			[28500] = 
			{
				id = {7429, 1}
			},
			[28600] = 
			{
				id = {7434, 1}
			},
			[28700] = 
			{
				id = {7390, 1}
			}
		}
	}
}


function getTopItem(p)
	p.stackpos = 0
	local v = getThingFromPos(p)
	repeat
		p.stackpos = p.stackpos + 1
		v = getThingFromPos(p)
	until v.itemid == 0
	p.stackpos = p.stackpos - 1
	return getThingFromPos(p)
end

function getCreaturesOnPit(pitid)

	local tmp = {}
	local pos
	local thing
	if PITS[pitid] then
		for x = PITS[pitid].fromPos.x, PITS[pitid].toPos.x do
			for y = PITS[pitid].fromPos.y, PITS[pitid].toPos.y do
				for z = PITS[pitid].fromPos.z, PITS[pitid].toPos.z do
					pos = {x = x, y = y, z = z}
					thing = getTopCreature(pos)
					if isCreature(thing.uid) then
						table.insert(tmp, thing.uid)
					end
				end
			end
		end
	end
	return tmp
end

function resetPit(pitid)
	
	if PITS[pitid] then
		for x = PITS[pitid].fromPos.x, PITS[pitid].toPos.x do
			for y = PITS[pitid].fromPos.y, PITS[pitid].toPos.y do
				for z = PITS[pitid].fromPos.z, PITS[pitid].toPos.z do
					local position = {x = x, y = y, z = z}
					local thing = getTopItem(position)
					if thing.itemid > 0 and not isInArray(ITEM_NOTERASABLE, thing.itemid) and not isCreature(thing.uid) and isMoveable(thing.uid) then
						doRemoveItem(thing.uid)
					end
					thing = getTopCreature(position)
					if isMonster(thing.uid) then
						doRemoveCreature(thing.uid)
					end
				end
			end
		end
	end
	return true
end

function startTimer(pitid)
	if not isInArray(ITEM_FIREFIELD_TIMER, getTopItem(PITS[pitid].fromPos).itemid) then
		doCreateItem(ITEM_FIREFIELD_TIMER[1], 1, PITS[pitid].fromPos)
		addEvent(decayTimer, (timePerPit / table.maxn(ITEM_FIREFIELD_TIMER)) * 1000, pitid, PITS[pitid].fromPos)
	end
	return true
end

function decayTimer(pitid)
	local field = getTopItem(PITS[pitid].fromPos)
	if field.itemid == ITEM_FIREFIELD_TIMER[3] then
		doRemoveItem(field.uid)
		local pit = PITS[pitid]
		for x = pit.fromPos.x, pit.toPos.x do
			for y = pit.fromPos.y, pit.toPos.y do
				for z = pit.fromPos.z, pit.toPos.z do
					local position = {x = x, y = y, z = z}
					local thing = getTopCreature(position)
					if isPlayer(thing.uid) then
						doTeleportThing(thing.uid, POSITION_KICK)
						doPlayerSendTextMessage(thing.uid, MESSAGE_INFO_DESCR, "Time out.")
						doCreatureSetStorage(thing.uid, STORAGE_PIT, 0) 
					elseif isMonster(thing.uid) then
						doRemoveCreature(thing.uid)
					end
				end
			end
		end
		return true
	elseif isInArray(ITEM_FIREFIELD_TIMER, field.itemid) then
		doTransformItem(field.uid, (field.itemid == ITEM_FIREFIELD_TIMER[1] and ITEM_FIREFIELD_TIMER[2] or ITEM_FIREFIELD_TIMER[3]))
		addEvent(decayTimer, (timePerPit / table.maxn(ITEM_FIREFIELD_TIMER)) * 1000, pitid, PITS[pitid].fromPos)
	end
	return true
end

Now create a file on data/creaturescripts/scripts called arena_kill.lua and paste this:
Lua:
function onKill(cid, target)

	local pit = getCreatureStorage(cid, STORAGE_PIT)
	local arena = getCreatureStorage(cid, STORAGE_ARENA)
	if isPlayer(target) then return true end
	if pit < 1 or pit > 10 then return true end
	if arena < 1 then return true end

	if isInArray(ARENA[arena].creatures, getCreatureName(target):lower()) then
		local pillar = getTopItem(PITS[pit].pillar)
		if pillar.itemid == ITEM_STONEPILLAR then
			doRemoveItem(pillar.uid)
		else
			print("[Svargrond Arena::CreatureEvent] Cannot remove stone pillar on position X: " .. PITS[pit].pillar.x .. ", Y: " .. PITS[pit].pillar.y .. ", Z: " .. PITS[pit].pillar.z .. ".")
		end
		doCreatureSetStorage(cid, STORAGE_PIT, pit + 1)
		doCreatureSay(cid, "Victory! Head through the new teleporter into the next room.", TALKTYPE_MONSTER)
	end
	return true
end

Create a file on data/movements/scripts called arena_enter.lua and paste:
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
 
	local pit = getCreatureStorage(cid, STORAGE_PIT)
	local arena = getCreatureStorage(cid, STORAGE_ARENA)
 
	if pit < 1 or pit > 10 then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Please talk with the npc first.")
		doTeleportThing(cid, fromPosition)
		return true
	end
 
	if PITS[pit] and ARENA[arena] then
		local thing = getCreaturesOnPit(pit)
		local busy = false
		for _, uid in ipairs(thing) do
			if isPlayer(uid) and uid ~= cid then
				busy = true
				break
			end
		end
		if isPlayer(getTopCreature(PITS[pit].pillar).uid) then
			busy = true
		end
		if busy then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Somebody is fighting in the next pit.")
			doTeleportThing(cid, fromPosition)
			return true
		end
		resetPit(pit)
		doTeleportThing(cid, PITS[pit].center)
		doCreateMonster(ARENA[arena].creatures[pit], PITS[pit].summon)
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
		doCreatureSay(cid, "Fight!", TALKTYPE_MONSTER)
		local pillar = getTopItem(PITS[pit].pillar)
		if(pillar.itemid ~= ITEM_STONEPILLAR) then
			doCreateItem(ITEM_STONEPILLAR, 1, PITS[pit].pillar)
		end
		if isInArray(ITEM_FIREFIELD_TIMER, getTopItem(PITS[pit].fromPos).itemid) then
			doRemoveItem(getTopItem(PITS[pit].fromPos).uid)
		end
		startTimer(pit)
	else
		print("[Svargrond Arena::MoveEvent] >> Wrong configuration\nPlayer: " .. getCreatureName(cid) .. "\nAction: Trying to enter to arena\nStorage " .. STORAGE_ARENA .. " for player is: " .. arena .. "\nStorage " .. STORAGE_PIT .. " for player is " .. pit)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Something is wrong, please contact a gamemaster.")
		doTeleportThing(cid, fromPosition)
	end
	return true
end

Create a file on data/movements/scripts called arena_exit.lua and paste:
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
	doCreatureSetStorage(cid, STORAGE_PIT, 0)
	doSetMonsterOutfit(cid, "Chicken", 120 * 1000)
	doTeleportThing(cid, POSITION_KICK)
	doCreatureSay(cid, "Coward!", TALKTYPE_MONSTER)
	return true
end

Create a file on data/movements/scripts called arena_pit.lua and paste:
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
 
	local oldPit = getCreatureStorage(cid, STORAGE_PIT) - 1
	local newPit = getCreatureStorage(cid, STORAGE_PIT)
 
	local arena = getCreatureStorage(cid, STORAGE_ARENA)
	if newPit < 1 then return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Something is wrong, please contact a gamemaster.") and doTeleportThing(cid, fromPosition) end
	if newPit > 10 then
		doTeleportThing(cid, POSITION_REWARD)
		doSendMagicEffect(getCreaturePosition(cid), (arena == 1 and CONST_ME_FIREWORK_BLUE or arena == 2 and CONST_ME_FIREWORK_YELLOW or CONST_ME_FIREWORK_RED))
		doCreatureSetStorage(cid, STORAGE_PIT, 0)
		doCreatureSetStorage(cid, (arena == 1 and ACTION_GREENHORNDOOR or arena == 2 and ACTION_SCRAPPERDOOR or ACTION_WARLORDDOOR), 1)
		doCreatureSetStorage(cid, STORAGE_ARENA, getCreatureStorage(cid, STORAGE_ARENA) + 1)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Cogratulations! You completed " .. ARENA[arena].name .. " arena, you should take your reward now.")
		doCreatureSay(cid, (arena == 1 and "Welcome back, little hero!" or arena == 2 and "Congratulations, brave warrior!" or "Respect and honour to you, champion!"), TALKTYPE_MONSTER)
		return true
	end
	local thing = getCreaturesOnPit(oldPit)
	for _, uid in ipairs(thing) do
		if getCreatureName(uid):lower() == ARENA[arena].creatures[pit] then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Defeat the monster first.")
			doTeleportThing(cid, fromPosition)
			return true
		end
	end
	thing = getCreaturesOnPit(newPit)
	local busy = false
	for _, uid in ipairs(thing) do
		if isPlayer(uid) and uid ~= cid then
			busy = true
			break
		end
	end
	if isPlayer(getTopCreature(PITS[newPit].pillar).uid) then
		busy = true
	end
	if busy then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Somebody is fighting in the next pit.")
		doTeleportThing(cid, fromPosition)
		return true
	end
	resetPit(newPit)
	doTeleportThing(cid, PITS[newPit].center)
	doCreateMonster(ARENA[arena].creatures[newPit], PITS[newPit].summon)
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
	doCreatureSay(cid, "Fight!", TALKTYPE_MONSTER)
	if(getTopItem(PITS[newPit].pillar).itemid ~= ITEM_STONEPILLAR) then
		doCreateItem(ITEM_STONEPILLAR, 1, PITS[newPit].pillar)
	end
	startTimer(newPit)
	if isInArray(ITEM_FIREFIELD_TIMER, getTopItem(PITS[oldPit].fromPos).itemid) then
		doRemoveItem(getTopItem(PITS[oldPit].fromPos).uid)
	end
	return true
end

Create a file on data/movements/scripts called arena_trophy.lua and paste:
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)

	local arena = getCreatureStorage(cid, STORAGE_ARENA) - 1
	if arena == item.actionid - 23200 then --trophy tile actionid should be 23201 23202 23203
		if getCreatureStorage(cid, ARENA[arena].reward.trophyStorage) < 1 then
			local pos = getCreaturePosition(cid)
			pos.y = pos.y - 1
			local thing = doCreateItem(ARENA[arena].reward.trophy, 1, pos)
			doItemSetAttribute(thing, "description", string.format(ARENA[arena].reward.desc, getCreatureName(cid)))
			doCreatureSetStorage(cid, ARENA[arena].reward.trophyStorage, 1)
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
			return true
		end
	end
	return true
end

Create a file on data/actions/scripts called arena_door.lua and paste:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local toPos = {x = fromPosition.x + 2, y = fromPosition.y, z = fromPosition.z}
	if getCreatureStorage(cid, STORAGE_ARENA) < 1 then
		return false
	end
	if getThingPos(cid).x < getThingPos(item.uid).x then
		toPos.x = getThingPos(cid).x + 2
	elseif getThingPos(cid).x > getThingPos(item.uid).x then
		toPos.x = getThingPos(cid).x - 2
	end
	if isInArray({ACTION_GREENHORNDOOR, ACTION_SCRAPPERDOOR, ACTION_WARLORDDOOR}, item.actionid) then
		if getCreatureStorage(cid, item.actionid) > 0 then
			doTeleportThing(cid, toPos)
			return true
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It's locked.")
		end
	else
		if getCreatureStorage(cid, STORAGE_PIT) == 1 then
			doTeleportThing(cid, toPos)
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Talk with the npc first.")
		end
	end
	return true
end

Create a file on data/actions/scripts called arena_reward.lua and paste:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local arena = getCreatureStorage(cid, STORAGE_ARENA) - 1
	if ARENA[arena].reward[item.actionid] then
		local reward = ARENA[arena].reward[item.actionid]
		if getCreatureStorage(cid, ARENA[arena].reward.storage) > 0 then
			return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It's empty.")
		end

		if reward.container then
			local cont = doPlayerAddItem(cid, reward.id, 1)
			for i = 1, table.maxn(reward.inside) do
				doAddContainerItem(cont, reward.inside[i][1], reward.inside[i][2])
			end
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. getItemArticleById(reward.id) .. " " .. getItemNameById(reward.id) .. ".")
			doCreatureSetStorage(cid, ARENA[arena].reward.storage, 1)
			return true
		else
			doPlayerAddItem(cid, reward.id[1], reward.id[2])
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. (reward.id[2] < 2 and getItemArticleById(reward.id[1]) or "x" .. reward.id[2]) .. " " .. getItemNameById(reward.id[1]) .. ".")
			doCreatureSetStorage(cid, ARENA[arena].reward.storage, 1)
			return true
		end
	end
	return true
end

Now create a file on data/npc called Halvard.xml and paste:
XML:
<?xml version="1.0" encoding="UTF-8"?>
 
<npc name="Halvar" script="data/npc/scripts/svargrond_arena.lua" access="3" walkinterval="2000" lookdir="2">
	<mana now="800" max="800"/>
	<health now="200" max="200"/>
	<look type="143" head="3" body="77" legs="78" feet="116" addons="1"/>

</npc>

Create a file on data/npc/scripts called svargrond_arena.lua and paste:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)                  npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                                      npcHandler:onThink() end

function creatureSayCallback(cid, type, msg)

	local s = getCreatureStorage(cid, STORAGE_ARENA)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	if msgcontains(msg, "fight") then
		if s < 1 then
			doCreatureSetStorage(cid, STORAGE_ARENA, 1)
			s = getCreatureStorage(cid, STORAGE_ARENA)
		end
		if ARENA[s] then
			if getCreatureStorage(cid, STORAGE_PIT) > 0 then
				doCreatureSetStorage(cid, STORAGE_PIT, 0)
			end
			npcHandler:say("Do you want to try the " .. ARENA[s].name .. " mode for the price of " .. ARENA[s].price .. " gold coins?", cid)
			talkState[talkUser] = 1
		elseif getCreatureStorage(cid, STORAGE_ARENA) > 3 then
			npcHandler:say("A brave warrior do not need to test his skills here again...", cid)
			talkState[talkUser] = 0
		else
			print("[Svargrond Arena[NPC]]", "Wrong configuration\nPlayer: " .. getCreatureName(cid) .. "\nAction: Trying to enter to arena\nStorage " .. STORAGE_ARENA .. " for player is: " .. s)
			npcHandler:say("Something is wrong, plase contact a gamemaster.", cid)
			talkState[talkUser] = 0
		end
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
		if ARENA[s] then
			if doPlayerRemoveMoney(cid, ARENA[s].price) then
				doCreatureSetStorage(cid, STORAGE_PIT, 1)
				npcHandler:say("You can pass the door. Good luck!", cid)
				talkState[talkUser] = 0
			else
				npcHandler:say("You do not have enough money.", cid)
				talkState[talkUser] = 0
			end
		else
			print("[Svargrond Arena[NPC]]", "Wrong configuration\nPlayer: " .. getCreatureName(cid) .. "\nAction: Trying to enter to arena\nStorage " .. STORAGE_ARENA .. " for player is: " .. s)
			npcHandler:say("Something is wrong, plase contact a gamemaster.", cid)
			talkState[talkUser] = 0
		end			
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Now paste this at data/creaturescripts/login.lua:
Lua:
registerCreatureEvent(cid, "svargrond_arena")

Paste this at data/creaturescripts/creaturescripts.xml:
XML:
	<event type="kill" name="svargrond_arena" event="script" value="arena_kill.lua"/>

Paste this at data/movements/movements.xml:
XML:
	<movevent type="StepIn" actionid="25100" event="script" value="arena_enter.lua"/>
	<movevent type="StepIn" actionid="25200" event="script" value="arena_pit.lua"/>
	<movevent type="StepIn" actionid="25300" event="script" value="arena_exit.lua"/>

	<movevent type="StepIn" actionid="23201" event="script" value="arena_trophy.lua"/>
	<movevent type="StepIn" actionid="23202" event="script" value="arena_trophy.lua"/>
	<movevent type="StepIn" actionid="23203" event="script" value="arena_trophy.lua"/>

Paste this at data/actions/actions.xml:
XML:
<action actionid="13100;26100;27100;28100" event="script" value="arena_door.lua"/>

	<action actionid="26300;26400;26500;26600;26700;27300;27400;27500;27600;27700;28300;28400;28500;28600;28700" event="script" value="arena_reward.lua"/>

Note that i only uploaded the .otb file of the map, not a .rar file.
Please post all bugs you find here
Enjoy!

Map: Download mapa.otbm from Sendspace.com - send big files the easy way
 
Last edited:
Can you include Achievements?


Go to arena_pit.lua, after:
Lua:
doCreatureSay(cid, "Respect and honour to you, champion!", TALKTYPE_MONSTER)

Add:
Lua:
local ach =
{
-- Arena -- Achievement ID
	[1] = 25,
	[2] = 52,
	[3] = 78
}
doPlayerAddAchievement(cid, ach[getCreatureStorage(cid, STORAGE_ARENA) - 1], true)

Remember, that code is based on my Achievements system
 
orange message & fireworks color is different for each level
 
Are missing the file <movevent type="StepIn" actionid="25100" event="script" value="arena_enter.lua"/> ???
 
Back
Top