• 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

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Castle System" version="1.1" author="Maniucza i Karpio" contact="" enabled="yes">
<config name="CastleSystem Lib"><![CDATA[
castle = {}
castle.wallid = 7594
castle.wall = {
	{x = 541,y = 865,z = 7, stackpos = 1}, 
	{x = 542,y = 865,z = 7, stackpos = 1}, 
	{x = 543,y = 865,z = 7, stackpos = 1}}
castle.topleft = {x = 445,y = 835,z = 0}
castle.bottomright = {x = 505,y = 930,z = 8}
castle.kick = {x = 170,y = 389,z = 7}
castle.teams = 0
castle.mostdamage = 0
castle.winnerteam = 0
castle.monster = {x = 585, y = 673, z = 7}
castle.guard = true
castle.guardpos = {x = x, y = y, z = z}

		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.topleft.x, castle.bottomright.x do
					for y = castle.topleft.y, castle.bottomright.y do
						for z = castle.topleft.z, castle.bottomright.z do
							local player = getThingFromPos({x=x, y=y, z=z, stackpos = 253})
							if(player.itemid > 0) then
								if(isPlayer(player) == true) then
									doTeleportThing(player, castle.kick)
									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.topleft.x, castle.bottomright.x do
					for y = castle.topleft.y, castle.bottomright.y do
						for z = castle.topleft.z, castle.bottomright.z do
							local player = getThingFromPos({x=x, y=y, z=z, stackpos = 253})
							if(player.itemid > 0) then
								if(isPlayer(player) == true) then
									if(getPlayerGuildId(player) ~= id) then
										doTeleportThing(player, castle.kick)
										return doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Przegral"..(getPlayerSex(player) == 0 and "as" or "es")..".")
									end
                                end
                            end
						end
					end
                end
			end
			return true
		end	
]]></config>
    <event type="kill" name="Castle King Kill" event="script"><![CDATA[
        domodlib("CastleSystem Lib")
        function onKill(cid, target, lastHit)
			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("Guild "..name.." inflicted the greatest injuries to the 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
	]]></event>
    <event type="statschange" name="Hit" event="script"><![CDATA[   
        domodlib("CastleSystem Lib")
        function onStatsChange(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
        end
	]]></event>
    <globalevent name="timer1" time="11:00" event="script"><![CDATA[
        domodlib("CastleSystem Lib")
        function onTimer(interval, lastExecution)
			if(os.date("%A") == "Saturday") then
                setGlobalStorageValue(1, 1)
                setGlobalStorageValue(2, os.time())
                doBroadcastMessage("Attention! Immediately register to Castle Wars. Leaders of the guild can enter your guild command: !castle", MESSAGE_STATUS_WARNING)
				addEvent(secondTimer,5*1000*60) --5mins until start
				addEvent(thirdTimer,15*1000*60) --15mins until end
			end
			return true
		end
		
		function secondTimer()
            setGlobalStorageValue(1, 2)
            if(castle.teams == 0) then
                local result = db.getResult("SELECT * FROM castles WHERE id=1;")
                local winner = result:getDataString("owner")
                result:free()
                doBroadcastMessage("Guilds"..winner.." defended castle. Congratulations!", MESSAGE_STATUS_WARNING)
                setGlobalStorageValue(1, 3)
            end
            doBroadcastMessage("Fight for Castle has begun!", MESSAGE_STATUS_WARNING)
            for i = 1, #castle.wall do
                doRemoveItem(getThingFromPos(castle.wall[i]).uid, 1)
            end
            local mon = doSummonCreature("King", castle.monster)
            registerCreatureEvent(mon, "hit")
			return true
		end
		
		function thirdTimer()
            for i = 1, #castle.wall do
                doCreateItem(castle.wallid, 1, castle.wall[i])
            end
            castle:kickLosers()
            local result = db.getResult("SELECT * FROM castles WHERE id=1;")
            local winner = result:getDataString("owner")
            result:free()
            doBroadcastMessage("The struggle for the castle came to an end. Guilds "..winner.." defended castle. Congratulations!", MESSAGE_STATUS_WARNING)
            setGlobalStorageValue(1, 3)
			return true
		end
	]]></globalevent>
    <talkaction words="!castle" event="buffer"><![CDATA[
        domodlib("CastleSystem Lib")
        function onSay(cid, words, param, channel)
            if(getPlayerGuildLevel(cid) == 3) then
				if(getGlobalStorageValue(1) == 1) then
					local result = db.getResult("SELECT * FROM castles_war WHERE guild_id="..getPlayerGuildId(cid).." AND time="..getGlobalStorageValue(2)..";")
					if(result:getID() ~= -1) then
                        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your guild is already registered to the fight.")
					end
					db.executeQuery("INSERT INTO `castles_war` (`castle_id` ,`guild_id` ,`damage` ,`time`) VALUES ('1', '"..getPlayerGuildId(cid).."', '0', '"..getGlobalStorageValue(2).."');")
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Guild added.")
					for k, v in pairs(getPlayersOnline()) do
                        if(getPlayerGuildId(v) == getPlayerGuildId(cid)) then
                            if lastwinningguild then --fixed me
                                doTeleportThing(v, castle.guardpos)
                                return doPlayerSendTextMessage(v, MESSAGE_INFO_DESCR, "Help your guild to defend the King.")
                            end
							return doPlayerSendTextMessage(v, MESSAGE_INFO_DESCR, "Your guild as joined the fight for Castle.")
                        end
					end
					castle.teams = castle.teams + 1
				else
					return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You cannot sign up at this time.")
				end
			else
				return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You are not a guild leader.")
			end
        end
	]]></talkaction>
</mod>

i tried updating it a bit, the code is 70 lines shorter now. i dont get any errors at all. but !castle doesnt work and it doesnt give any errors. also it never executes the 2nd and 3d timer event. but like i said no errors. i also finished translating it to English and i cleaned up the code a little bit. i hope someone can tell me what is wrong
 
O co chodzi z tymi poss!!
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}
?
 
This script working on TFS 0.4.1 ?
Because I need Castle Mod for TFS 0.4.1 ( tibia 8.60 )
If this scirpt doesn't work anyone give me working castle script for tibia 8.60 ( TFS 0.4.1 )
 
could somebody give link to map castle? :> I never saw the castle and I have no idea how it might look
 
Back
Top