• 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

if I'm not mistaken this is the MOD so I do not need to add entries to talkactions because they are already included in the xml file
 
if I'm not mistaken this is the MOD so I do not need to add entries to talkactions because they are already included in the xml file


Then can someone write a base map or something so ppl can know how to make it work. Im using tfs 0.3.6pl1
 
Hi I have an error

Code:
04/06/2010 08:53:00] [Error - GlobalEvent Interface] 
[04/06/2010 08:53:00] buffer:onTimer
[04/06/2010 08:53:00] Description: 
[04/06/2010 08:53:00] data/lib/database.lua:76: [Result:getDataString] Result not set!
[04/06/2010 08:53:00] stack traceback:
[04/06/2010 08:53:00] 	[C]: in function 'error'
[04/06/2010 08:53:00] 	data/lib/database.lua:76: in function 'getDataString'
[04/06/2010 08:53:00] 	[string "castle = {}..."]:48: in function 'secondTimer'
[04/06/2010 08:53:00] 	[string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>
[04/06/2010 08:53:00] [Error - GlobalEvents::timer] Couldn't execute event: timer2


and this

Code:
[04/06/2010 08:55:00] [Error - GlobalEvent Interface] 
[04/06/2010 08:55:00] buffer:onTimer
[04/06/2010 08:55:00] Description: 
[04/06/2010 08:55:00] data/lib/database.lua:60: [Result:getDataInt] Result not set!
[04/06/2010 08:55:00] stack traceback:
[04/06/2010 08:55:00] 	[C]: in function 'error'
[04/06/2010 08:55:00] 	data/lib/database.lua:60: in function 'getDataInt'
[04/06/2010 08:55:00] 	[string "castle = {}..."]:83: in function 'kickLosers'
[04/06/2010 08:55:00] 	[string "castle = {}..."]:69: in function 'thirdTimer'
[04/06/2010 08:55:00] 	[string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>
[04/06/2010 08:55:00] [Error - GlobalEvents::timer] Couldn't execute event: timer3

please help

I use the engine TFS 0.3.6.pl1
 
I change onTimer to onTime
PHP:
<globalevent name="timer1" time="12:04" event="script"><![CDATA[
                domodlib("CastleSystem Lib")
                function onTime()
                        castle:firstTimer()
                return true
                end]]></globalevent>


PHP:
[06/06/2010 12:04:00] [Error - GlobalEvents::timer] Couldn't execute event: timer1
[06/06/2010 12:05:00] [Error - GlobalEvents::timer] Couldn't execute event: timer2
[06/06/2010 12:06:00] [Error - GlobalEvents::timer] Couldnt execute event: timer3
 
Maniucza You don't have full script. You should also to add this to database:
PHP:
CREATE TABLE IF NOT EXISTS `castles_war` (
  `castle_id` int(5) NOT NULL,
  `guild_id` int(5) NOT NULL,
  `damage` int(20) NOT NULL,
  `time` int(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
not fully translated look at this:
return doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Przegral"..(getPlayerSex(player) == 0 and "as" or "es")..".")
<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.")
maybe !zamek means !castle
im right?
when i put it, i cant log in.. im using TFS 0.3.6
thanks nice script!
 
Last edited:
Probably many of you were waiting for the update script, so you can share improved 1.1 version:

Lua:
<?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 = 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="kill" 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, "There are a guild leader.")
					return true
                end
]]></talkaction>
</mod>

MySql 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

And:
PHP:
CREATE TABLE IF NOT EXISTS `castles_war` (
  `castle_id` int(5) NOT NULL,
  `guild_id` int(5) NOT NULL,
  `damage` int(20) NOT NULL,
  `time` int(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Have fun!

Btw. Description of the script is not compatible with the script.
 
Last edited:
In 1.1 version zero reaction of the console nothing is happening and in version 1.0 first timer is acting and second and third:
Code:
[30/07/2010 08:30:00] > Broadcasted message: "Attention! Immediately register to Castle Wars. Leaders of the guild can enter your guild command:! Castle".

[30/07/2010 08:32:00] [Error - GlobalEvent Interface] 
[30/07/2010 08:32:00] buffer:onTimer
[30/07/2010 08:32:00] Description: 
[30/07/2010 08:32:00] data/lib/004-database.lua:76: [Result:getDataString] Result not set!
[30/07/2010 08:32:00] stack traceback:
[30/07/2010 08:32:00] 	[C]: in function 'error'
[30/07/2010 08:32:00] 	data/lib/004-database.lua:76: in function 'getDataString'
[30/07/2010 08:32:00] 	[string "castle = {}..."]:48: in function 'secondTimer'
[30/07/2010 08:32:00] 	[string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>
[30/07/2010 08:32:00] [Error - GlobalEvents::timer] Couldn't execute event: timer2

[30/07/2010 08:34:00] [Error - GlobalEvent Interface] 
[30/07/2010 08:34:00] buffer:onTimer
[30/07/2010 08:34:00] Description: 
[30/07/2010 08:34:00] [string "castle = {}..."]:66: attempt to get length of field 'mur' (a nil value)
[30/07/2010 08:34:00] stack traceback:
[30/07/2010 08:34:00] 	[string "castle = {}..."]:66: in function 'thirdTimer'
[30/07/2010 08:34:00] 	[string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>
[30/07/2010 08:34:00] [Error - GlobalEvents::timer] Couldn't execute event: timer3
 
Great release, hopefully you didn't release someone's work that they were trying to sell.
I also moved this threads to the Mods board.

Red
 
Back
Top