• 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 [Talkactions,Globalevents,Lib,Monsters] Castle War System + Maps!!!

Hi. Sorry for F5, but can anyone tell me, where i can set time for start this event? i select it in globalevents (for ex. time="18:00" ) and it doesn't work (no time yet.).

P.S. Sorry for my bad english <33
 
Hi, I need this script, and i like it, but i see this error:

[26/01/2013 00:32:00] > Broadcasted message: "[ Castle Event Enabled! ]

[26/01/2013 00:32:00] If you're a guild leader and you have at least 1 members you can sign in your guild by saying !castle in default channel.".
[26/01/2013 00:32:20] > Broadcasted message: "[ Castle Event Info ]

[26/01/2013 00:32:20] Guild Test will fight for Castle.
[26/01/2013 00:32:20] Attackers: 1 / 3".
[26/01/2013 00:42:00] > Broadcasted message: "[ Castle Event Fight! ]

[26/01/2013 00:42:00] Event has been started. Kill Tiberia King !!!".

[26/01/2013 00:42:00] [Error - GlobalEvent Interface]
[26/01/2013 00:42:00] In a timer event called from:
[26/01/2013 00:42:00] data/globalevents/scripts/castle.lua:eek:nTimer
[26/01/2013 00:42:00] Description:
[26/01/2013 00:42:00] (luaDoRemoveItem) Item not found

[26/01/2013 00:42:00] [Error - GlobalEvent Interface]
[26/01/2013 00:42:00] In a timer event called from:
[26/01/2013 00:42:00] data/globalevents/scripts/castle.lua:eek:nTimer
[26/01/2013 00:42:00] Description:
[26/01/2013 00:42:00] (luaDoRemoveItem) Item not found

[26/01/2013 00:42:00] [Error - GlobalEvent Interface]
[26/01/2013 00:42:00] In a timer event called from:
[26/01/2013 00:42:00] data/globalevents/scripts/castle.lua:eek:nTimer
[26/01/2013 00:42:00] Description:
[26/01/2013 00:42:00] (luaDoRemoveItem) Item not found

[26/01/2013 00:42:00] [Error - GlobalEvent Interface]
[26/01/2013 00:42:00] In a timer event called from:
[26/01/2013 00:42:00] data/globalevents/scripts/castle.lua:eek:nTimer
[26/01/2013 00:42:00] Description:
[26/01/2013 00:42:00] (luaDoRemoveItem) Item not found

[26/01/2013 00:42:00] [Error - GlobalEvent Interface]
[26/01/2013 00:42:00] In a timer event called from:
[26/01/2013 00:42:00] data/globalevents/scripts/castle.lua:eek:nTimer
[26/01/2013 00:42:00] Description:
[26/01/2013 00:42:01] (luaDoRemoveItem) Item not found

[26/01/2013 00:42:01] [Error - GlobalEvent Interface]
[26/01/2013 00:42:01] In a timer event called from:
[26/01/2013 00:42:01] data/globalevents/scripts/castle.lua:eek:nTimer
[26/01/2013 00:42:01] Description:
[26/01/2013 00:42:01] (luaDoRemoveItem) Item not found

[26/01/2013 00:42:01] [Error - CreatureScript Interface]
[26/01/2013 00:42:01] data/creaturescripts/scripts/castle_kill.lua:eek:nDeath
[26/01/2013 00:42:01] Description:
[26/01/2013 00:42:01] data/lib/102-castle.lua:122: attempt to call global 'getGuildName' (a nil value)
[26/01/2013 00:42:01] stack traceback:
[26/01/2013 00:42:01] data/lib/102-castle.lua:122: in function 'Castle_endEvent'
[26/01/2013 00:42:01] data/creaturescripts/scripts/castle_kill.lua:3: in function <data/creaturescripts/scripts/castle_kill.lua:1>

- - - Updated - - -

ok now all work correctly but when I see it: [26/01/2013 01:49:00] Event has been started. Kill Tiberia King !!!".
I look this error:
[26/01/2013 01:49:00] [Error - CreatureScript Interface]
[26/01/2013 01:49:00] data/creaturescripts/scripts/castle_kill.lua:eek:nDeath
[26/01/2013 01:49:00] Description:
[26/01/2013 01:49:00] data/lib/102-castle.lua:105: attempt to call global 'getGuildName' (a nil value)
[26/01/2013 01:49:00] stack traceback:
[26/01/2013 01:49:01] data/lib/102-castle.lua:105: in function 'Castle_endEvent'
[26/01/2013 01:49:01] data/creaturescripts/scripts/castle_kill.lua:3: in function <data/creaturescripts/scripts/castle_kill.lua:1>
I need this event, please help me. ;]
 
BUMP @up

Running TFS 0.3 - 0.3.7 REV5916 Client: 8.60-win64

The things that (what I've noticed) don't work is:
*You can type !castle several time and fill up all 3 spots by yourself.
*Like the the person above. When you have killed the King the function Castle_endEvent is bugging...

Console error:
Code:
[COLOR="#FF0000"][5/3/2013 13:30:54] [Error - CreatureScript Interface] 
[5/3/2013 13:30:54] data/creaturescripts/scripts/castle_kill.lua:onDeath
[5/3/2013 13:30:54] Description: 
[5/3/2013 13:30:54] data/lib/102-castle.lua:122: attempt to call global 'getGuildName' (a nil value)
[5/3/2013 13:30:54] stack traceback:
[5/3/2013 13:30:54] 	data/lib/102-castle.lua:122: in function 'Castle_endEvent'
[5/3/2013 13:30:54] 	data/creaturescripts/scripts/castle_kill.lua:3: in function <data/creaturescripts/scripts/castle_kill.lua:1>[/COLOR]


Function Castle_getAttackers():
Lua:
function Castle_getAttackers()
	local ret = {}
	local query = string.explode(getGlobalStorageValue(castleConfig.attackersStorage), ",")
	for _,value in ipairs(query) do
		if isNumber(value) then
			table.insert(ret, value)
		end
	end
	return ret
end

Function Castle_endEvent:
Lua:
function Castle_endEvent(killed, damages)
	local playersOnline = getPlayersOnline()
	local dmgCount = 0
	local message = ""
	local winner = 0
	
	if (getGlobalStorageValue(castleConfig.endedStorage) ~= 1) then
		if (killed) then
			for _,value in ipairs(Castle_getAttackers()) do
				message = message.."\n"..getPlayerGuildName(cid)..":"..damages[Castle_getGuildPos(value)].." dmg"
				if damages[Castle_getGuildPos(value)] > dmgCount then
					winner = value
					dmgCount = damages[Castle_getGuildPos(value)]
				end
			end
			doBroadcastMessage("[ Castle Event End! ]\n\n> Statistics " .. message .."\nWINNER:"..getPlayerGuildName(winner), MESSAGE_INFO_DESCR)
			
			local attackers = Castle_getAttackers()
			table.insert(attackers, getGlobalStorageValue(castleConfig.guildOwnStorage))
			for _, pid in ipairs(playersOnline) do
				if ((isInArray(attackers, getPlayerGuildId(pid)) or getGlobalStorageValue(castleConfig.guildOwnStorage) == getPlayerGuildId(pid)) and not(tonumber(getPlayerGuildId(pid)) == tonumber(winner))) then
					doRemoveCondition(pid, CONDITION_INFIGHT)
					doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
				end
			end
			setGlobalStorageValue(castleConfig.guildOwnStorage, winner)
		else
			doBroadcastMessage("[ Castle Event End! ]\n\n> Castle has been saved by owner.", MESSAGE_INFO_DESCR)
		end
		setGlobalStorageValue(castleConfig.endedStorage, 1)
	end
	Castle_cleanUp()
	return true
end

____________________________________________________________________________________________________

(And here's my fixed lib so far:)
Lua:
local castleConfig = {
	days = {2, 5},      -- ???
	time_1 = 2*60*1000, -- time from start event to fight
	time_2 = 10*60*1000, -- time from fight to end event
	guildOwnStorage = 17000, --Storage, fill in empty storage number
	attackersStorage = 17002, --Storage, fill in empty storage number
	enabledStorage = 17006, --Storage, fill in empty storage number
	endedStorage = 17007, --Storage, fill in empty storage number
	leaderLevel = 100, -- Guild leader lvl to enter Castle event
	membersNeeded = 1, -- How many online guild members who is needed to join event
	monster = "King", -- creature name of the boss/king
	monsterSpawn = {x = 2470, y = 2477, z = 3}, -- Where should the boss/king spawn?
	startAttackers = { -- Places where the teams are teleported after join event
		[1] = {x = 2444, y = 2491, z = 6},
		[2] = {x = 2494, y = 2503, z = 6},
		[3] = {x = 2488, y = 2464, z = 6}
	},
	gates = { -- All gates that will be opend when the event starts
		[1] = {pos = {x = 2456, y = 2487, z = 6}, itemid = 9533},
		[2] = {pos = {x = 2456, y = 2488, z = 6}, itemid = 9533},
		
		[3] = {pos = {x = 2486, y = 2498, z = 6}, itemid = 9485},
		[4] = {pos = {x = 2487, y = 2498, z = 6}, itemid = 9485},
		
		[5] = {pos = {x = 2490, y = 2471, z = 6}, itemid = 9486},
		[6] = {pos = {x = 2491, y = 2471, z = 6}, itemid = 9486},
		[7] = {pos = {x = 2492, y = 2471, z = 6}, itemid = 9486},
		
		-- new 
		[8] = {pos = {x = 2452, y = 2480, z = 6}, itemid = 9533},
		[9] = {pos = {x = 2452, y = 2481, z = 6}, itemid = 9533},
		[10] = {pos = {x = 2452, y = 2482, z = 6}, itemid = 9533},
		
		[11] = {pos = {x = 2485, y = 2498, z = 6}, itemid = 9485},	
		
		[12] = {pos = {x = 2498, y = 2502, z = 6}, itemid = 9533},
		[13] = {pos = {x = 2498, y = 2503, z = 6}, itemid = 9533},
		
		[14] = {pos = {x = 2485, y = 2468, z = 6}, itemid = 9486},
		[15] = {pos = {x = 2486, y = 2468, z = 6}, itemid = 9486},
		[16] = {pos = {x = 2487, y = 2468, z = 6}, itemid = 9486},
	

		
	},
}
CASTLE_DAYS = {2,6} -- What days should the event start? 1 = Monday, 2 = Tuesday etc.

function getCastleConfig(value)
	if (value ~= nil) then
		return castleConfig[value] or false 
	else
		return false
	end
end

function removeNotKilledKing(cid)
	if isMonster(cid) and getCreatureName(cid) == castleConfig.monster then
		doRemoveCreature(cid)
	end
	return true
end


-- it sux but don`t have idea how to make it better, attackers Index
function Castle_getGuildPos(guildId)
	local attackers = Castle_getAttackers()
	for i,value in ipairs(attackers) do
		if (tonumber(guildId) == tonumber(value)) then
			ret = i
		end
	end
	return ret
end

function Castle_enableSaving()
	doBroadcastMessage("[ Castle Event Enabled! ]\n\nIf you're a guild leader and you have at least ".. castleConfig.membersNeeded .." members you can sign in your guild by saying !castle in default channel.", MESSAGE_INFO_DESCR)
	setGlobalStorageValue(castleConfig.enabledStorage, 1)
	--setGlobalStorageValue(castleConfig.endedStorage, 0)
	Castle_cleanUp()
	addEvent(Castle_startEvent, castleConfig.time_1)
	return true
end

function Castle_getAttackers()
	local ret = {}
	local query = string.explode(getGlobalStorageValue(castleConfig.attackersStorage), ",")
	for _,value in ipairs(query) do
		if isNumber(value) then
			table.insert(ret, value)
		end
	end
	return ret
end

function Castle_startEvent()
	setGlobalStorageValue(castleConfig.enabledStorage, 0)
	setGlobalStorageValue(castleConfig.endedStorage, 0)
	if(#Castle_getAttackers() == 0) then
		doBroadcastMessage("[ Castle Event Failed! ]\n\nWe have not attackers!", MESSAGE_INFO_DESCR)
		return true
	end
	doBroadcastMessage("[ Castle Event Fight! ]\n\nEvent has been started. Kill Tiberia King !!!", MESSAGE_INFO_DESCR)
	local monster = doSummonCreature(castleConfig.monster, castleConfig.monsterSpawn)
	for _, gate in pairs(castleConfig.gates) do
		doRemoveItem(getTileItemById(gate.pos, gate.itemid).uid)
	end
	addEvent(Castle_endEvent, castleConfig.time_2, false)
	addEvent(removeNotKilledKing, castleConfig.time_2, monster)
	return true
end

function Castle_endEvent(killed, damages)
	local playersOnline = getPlayersOnline()
	local dmgCount = 0
	local message = ""
	local winner = 0
	
	if (getGlobalStorageValue(castleConfig.endedStorage) ~= 1) then
		if (killed) then
			for _,value in ipairs(Castle_getAttackers()) do
				message = message.."\n"..getGuildName(value)..":"..damages[Castle_getGuildPos(value)].." dmg"
				if damages[Castle_getGuildPos(value)] > dmgCount then
					winner = value
					dmgCount = damages[Castle_getGuildPos(value)]
				end
			end
			doBroadcastMessage("[ Castle Event End! ]\n\n> Statistics " .. message .."\nWINNER:"..getGuildName(winner), MESSAGE_INFO_DESCR)
			
			local attackers = Castle_getAttackers()
			table.insert(attackers, getGlobalStorageValue(castleConfig.guildOwnStorage))
			for _, pid in ipairs(playersOnline) do
				if ((isInArray(attackers, getPlayerGuildId(pid)) or getGlobalStorageValue(castleConfig.guildOwnStorage) == getPlayerGuildId(pid)) and not(tonumber(getPlayerGuildId(pid)) == tonumber(winner))) then
					doRemoveCondition(pid, CONDITION_INFIGHT)
					doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
				end
			end
			setGlobalStorageValue(castleConfig.guildOwnStorage, winner)
		else
			doBroadcastMessage("[ Castle Event End! ]\n\n> Castle has been saved by owner.", MESSAGE_INFO_DESCR)
		end
		setGlobalStorageValue(castleConfig.endedStorage, 1)
	end
	Castle_cleanUp()
	return true
end

function Castle_cleanUp()
	setGlobalStorageValue(castleConfig.attackersStorage, ",")
	return true
end

function Castle_getGuildMembers(guildId)
	local playersOnline = getPlayersOnline()
	local members = {}
	for _, pid in ipairs(playersOnline) do
		if (getPlayerGuildId(pid) == guildId) then
			table.insert(members, pid)
		end
	end
	return members
end


function Castle_trySave(cid)
	if not(getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER) then
		doPlayerSendCancel(cid, "Sorry, but you have to be a leader of guild.")
		return true
	end

	if (getGlobalStorageValue(castleConfig.enabledStorage) ~= 1) then
		doPlayerSendCancel(cid, "Sorry, but it's not time yet.")
		return true
	end

	if (getPlayerLevel(cid) < castleConfig.leaderLevel) then
		doPlayerSendCancel(cid, "Sorry, but your level is too low.")
		return true
	end

	local players = Castle_getGuildMembers(getPlayerGuildId(cid))
	if (#players == 1) then
		doPlayerSendCancel(cid, "Sorry, but you haven't any online members in guild.")
		return true
	end

	if (#players < castleConfig.membersNeeded) then
		doPlayerSendCancel(cid, "Sorry, but you need at least ".. castleConfig.membersNeeded .." guild members online.")
		return true
	end
	if (tonumber(getGlobalStorageValue(castleConfig.guildOwnStorage)) == tonumber(getPlayerGuildId(cid))) then
		doPlayerSendCancel(cid, "Your guild should protect Castle, not attack.")
		return true
	end

	if (#Castle_getAttackers() == 3) then
		doPlayerSendCancel(cid, "Sorry, we have already 3 attacking guilds.")
		return true
	end
	if (isInArray(Castle_getAttackers(), getPlayerGuildId(cid))) then
		doPlayerSendCancel(cid, "Be patient, war will start in a few minutes.")
		return true
	end

	setGlobalStorageValue(castleConfig.attackersStorage, getGlobalStorageValue(castleConfig.attackersStorage)..getPlayerGuildId(cid)..",")
	doBroadcastMessage("[ Castle Event Info ]\n\nGuild ".. getPlayerGuildName(cid) .." will fight for Castle.\nAttackers: ".. #Castle_getAttackers() .." / 3", MESSAGE_INFO_DESCR)

	for i, pid in ipairs(getPlayersOnline()) do
		if (isInArray({getPlayerGuildId(cid)}, getPlayerGuildId(pid))) then
			doTeleportThing(pid, castleConfig.startAttackers[#Castle_getAttackers()])
		end
	end
	return true
end
 
Last edited:
Back
Top