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

[MOD] Castle System

Maniucza

~Lua~ Noob
Joined
Aug 2, 2009
Messages
86
Reaction score
6
Location
Poland / Rzeszów
Hi I have for you a system of locks which consists of:

Created : Maniucza and Karpio

YOUR OTS/MODS/castlesystem.xml added:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Castle System" version="1.0" author="Maniucza i Karpio" contact="http://tibia.net.pl/members/maniucza.html" enabled="yes">
<config name="CastleSystem Lib"><![CDATA[
castle = {}

castle.wallid = 7594
castle.wall = {{x = 587,y = 675,z = 7, stackpos = 1}, {x = 587,y = 676,z = 7, stackpos = 1}, {x = 587,y = 677,z = 7, stackpos = 1}}
castle.fromx = 583
castle.tox = 586
castle.fromy = 675
castle.toy = 677
castle.z = 7
castle.kick = {x = 583,y = 670,z = 7}
castle.teams = 0
castle.pos = {x = 583,y = 670,z = 7}
castle.mostdamage = 0
castle.winnerteam = 0
castle.monster = {x = 585, y = 673, z = 7}
castle.msg = true
castle.gary = true
castle.garypos =
{
	[1] = {x = x, y = y, z = z},
	[2] = {x = x, y = y, z = z},
	[3] = {x = x, y = y, z = z},
	[4] = {x = x, y = y, z = z}

}

function castle:firstTimer()

	if(os.date("%A") == "Thursday") then
		setGlobalStorageValue(1, 1)
		setGlobalStorageValue(2, os.time())
		if(castle.gary) then
			setGlobalStorageValue(1, 1)
		end
		doBroadcastMessage("Attention! Immediately register to Castle Wars. Leaders of the guild can enter your guild command:! Castle", MESSAGE_STATUS_WARNING)
	end
return true
end

function castle:secondTimer()
	
	if(os.date("%A") == "Thursday") then
		if(getGlobalStorageValue(1) == 1) then
			setGlobalStorageValue(1, 2)
		end
		if(castle.teams == 0) then
			local result = db.getResult("SELECT * FROM castles WHERE id=1;")
			local winner = result:getDataString("owner")
			result:free()
			doBroadcastMessage("Gilds"..winner.." defended castle. Congratulations!", MESSAGE_STATUS_WARNING)
			setGlobalStorageValue(1, 3)
		end
		doBroadcastMessage("Fight for Castle has begun!", MESSAGE_STATUS_WARNING)
		for i = 1, #castle.mur do
			doRemoveItem(getThingFromPos(castle.mur[i]).uid, 1)
		end
		local mon = doSummonCreature("King", castle.monster)
		registerCreatureEvent(mon, "hit")
	end
return true
end

function castle:thirdTimer()

	if(os.date("%A") == "Thursday" and getGlobalStorageValue(1) == 2) then
		for i = 1, #castle.mur do
			doCreateItem(castle.murid, 1, castle.mur[i])
		end
		castle:kickLosers()
		local result = db.getResult("SELECT * FROM castles WHERE id=1;")
		local winner = result:getDataString("owner")
		result:free()
		doBroadcastMessage("he struggle for the castle came to an end. Guilds "..winner.." defended castle. Congratulations!", MESSAGE_STATUS_WARNING)
		setGlobalStorageValue(1, 3)
	end
return true
end

function castle:kickLosers(id)

	if(id == nil) then
		local result = db.getResult("SELECT * FROM castles WHERE id=1;")
		id = result:getDataInt("ownerid")
		result:free()
	end
	if(id == "all") then
		for x = castle.fromx, castle.tox do
		for y = castle.fromy, castle.toy do
			local player = getThingFromPos({x=x, y=y, z=castle.z, stackpos = 253})
			if(player.itemid > 0) then
				if(isPlayer(player) == true) then
					doTeleportThing(player, castle.kick)
					if(castle.msg == true) then
						return doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Przegral"..(getPlayerSex(player) == 0 and "as" or "es")..".")
					end
				end
			end
		end
		end
	elseif(isNumber(id) == true) then
		for x = castle.fromx, castle.tox do
		for y = castle.fromy, castle.toy do
			local player = getThingFromPos({x=x, y=y, z=castle.z, stackpos = 253})
			if(player.itemid > 0) then
				if(isPlayer(player) == true) then
					if(getPlayerGuildId(player) ~= id) then
						doTeleportThing(player, castle.kick)
						if(castle.msg == true) then
							return doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Przegral"..(getPlayerSex(player) == 0 and "as" or "es")..".")
						end
					end
				end
			end
		end
		end
	end
	return true
end

function castle:addTeam(cid, gid)

	if(getGlobalStorageValue(1) == 1) then
		local result = db.getResult("SELECT * FROM castles_war WHERE guild_id="..gid.." AND time="..getGlobalStorageValue(2)..";")
		if(result:getID() ~= -1) then
			return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Guild is already written to the fight.")
		end
		db.executeQuery("INSERT INTO `castles_war` (`castle_id` ,`guild_id` ,`damage` ,`time`)VALUES ('1', '"..gid.."', '0', '"..getGlobalStorageValue(2).."');")
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Gilds added.")
		for k, v in pairs(getPlayersOnline()) do
			if(getPlayerGuildId(v) == gid) then
				if(getTilePzInfo(getCreaturePosition(v)) == true) then
					if(castle.gary) then
						doTeleportThing(v, castle.garypos[getGlobalStorageValue(3)])
						if(getGlobalStorageValue(3) < 4) then
							setGlobalStorageValue(3, getGlobalStorageValue(3) + 1)
						end
					else
						doTeleportThing(v, castle.pos)
					end
					if(castle.msg == true) then
						return doPlayerSendTextMessage(v, MESSAGE_INFO_DESCR, "Your guild, she joined the Fight for Castle.")
					end
				end
			end
		end
		castle.teams = castle.teams + 1
	else
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There are currently no records.")
	end
return true
end

function castle:onHit(cid, attacker, type, combat, value)
	
	if(getCreatureName(cid) == "King") then
		if(db.executeQuery("UPDATE `castles_war` SET `damage`=`damage`+"..value.." WHERE `guild_id`="..getPlayerGuildId(attacker).." AND `time`="..getGlobalStorageValue(2)..";") ~= true) then
			return false
		else
			return true
		end
	end
return true
end

function castle:onKill(cid, target)
	if(getCreatureName(target) == "King" and getGlobalStorageValue(1) == 2) then
		local result = db.getResult("SELECT * FROM `castles_war` WHERE `time`="..getGlobalStorageValue(2).." ORDER BY `damage` DESC LIMIT 1;")
		castle.mostdamage = result:getDataInt("damage")
		castle.winnerteam = result:getDataInt("guild_id")
		result:free()
		local result2 = db.getResult("SELECT * FROM guilds WHERE id="..castle.winnerteam..";")
		local name = result2:getDataString("name")
		result2:free()
		setGlobalStorageValue(1, 3)
		doBroadcastMessage("Gilds "..name.." injuries inflicted the greatest king and is the winner. The reward is replaced by the castle.")
		db.executeQuery("UPDATE castles SET ownerid="..castle.winnerteam..", owner=\""..name.."\" WHERE id=1;")
		castle:kickLosers(castle.winnerteam)
	end
	return true
end
]]></config>

	<event type="login" name="Castle King Kill" event="script"><![CDATA[
		domodlib("CastleSystem Lib")
		function onKill(cid, target, lastHit)
			if(getCreatureName(target) == "King") then
				castle:onKill(cid, target)
				return true
			end
		return true
		end]]></event>
		
	<event type="statschange" name="Hit" event="script"><![CDATA[	
		domodlib("CastleSystem Lib")
		function onStatsChange(cid, attacker, type, combat, value)
			castle:onHit(cid, attacker, type, combat, value)
		return true
		end]]></event>
	
	<globalevent name="timer1" time="18:20" event="script"><![CDATA[
		domodlib("CastleSystem Lib")
		function onTimer()
			castle:firstTimer()
		return true
		end]]></globalevent>

	<globalevent name="timer2" time="18:22" event="script"><![CDATA[
		domodlib("CastleSystem Lib")
		function onTimer()
			castle:secondTimer()
		return true
		end]]></globalevent>
	
	<globalevent name="timer3" time="18:24" event="script"><![CDATA[
		domodlib("CastleSystem Lib")
		function onTimer()
			castle:thirdTimer()
		return true
		end]]></globalevent>
	
	<talkaction words="!zamek" event="buffer"><![CDATA[
		domodlib("CastleSystem Lib")
		function onSay(cid, words, param, channel)
			if(getPlayerGuildLevel(cid) == 3) then
				castle:addTeam(cid, getPlayerGuildId(cid))
			return true
			end

			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Nie jestes liderem gildi.")
		return true
		end
]]></talkaction>
</mod>

Phpmyadmin: Added:

PHP:
CREATE TABLE IF NOT EXISTS `castles` (
 `id` int(11) NOT NULL auto_increment,
 `castle_name` varchar(255) NOT NULL,
 `owner_guild` varchar(255) NOT NULL,
 `castle_war` varchar(255) NOT NULL,
 `last_conqueror` varchar(255) NOT NULL,
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1

I think that many a person come in handy ;]

Rep ++ for me ;)

#Edit:
The script converted into English version.
 
Last edited:
sa can sb tell me how to configure it ?
and if walls are blocking player in spawn place or its gate to castle ?
 
Maniucza does not possess to this map because I talked already with him so do not write superfluous fasts..
 
Haha! Karpio, tutaj jest jeszcze opcja for me "gary", "garypos" :D [leniuszek z Ciebie]

Great script! Certainly be useful for everyone!
 
Gratz! I used this in me xXx Evo ots.
PS: Naaby co nie umeija rozszyfrowac czekaja na naaaba ktory wpusci do neta i tutorial opisze ;D.
 
Back
Top