januszek89
Scripter
I have found script http://tibiaplanet.pl/category/creaturescripts with castle system and I have one problem with it. I'm using TFS 0.3.6pl1.
This is script:
And when I put it to myots/mods/castlesystem.xml and if I add this into database:
Then I can't login my character into server and in the TFS appears this error :
I'm searching someone who want to help me and convert this script for TFS 0.3.6.
Thanks so much for help :thumbup: and I sorry for not too good English
This is script:
Code:
<?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") == "Sunday") then
setGlobalStorageValue(1, 1)
setGlobalStorageValue(2, os.time())
if(castle.gary) then
setGlobalStorageValue(1, 1)
end
doBroadcastMessage("Uwaga! Rozpoczynaja sie zapisy do Wojny o Zamek. Liderzy gildii moga wpisac swoja gildie komenda: !zamek", MESSAGE_STATUS_WARNING)
end
return true
end
function castle:secondTimer()
if(os.date("%A") == "Sunday") 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("Gildia "..winner.." obronila zamek. Gratulujemy!", MESSAGE_STATUS_WARNING)
setGlobalStorageValue(1, 3)
end
doBroadcastMessage("Walka o Zamek rozpoczeta!", 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") == "Sunday" 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("Walka o Zamek dobiegla konca. Gildia "..winner.." obronila zamek. Gratulujemy!", 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, "Gildia jest juz zapisana do walki.")
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, "Gildia dodana.")
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, "Twoja gildia zapisala sie do Walki o Zamek.")
end
end
end
end
castle.teams = castle.teams + 1
else
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Obecnie nie ma zapisow.")
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("Gildia "..name.." zadala najwieksze obrazenia Krolowi i zostaje zwyciezca. W nagrode otrzymuje zamek.")
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="17:00" event="script"><![CDATA[
domodlib("CastleSystem Lib")
function onTimer()
castle:firstTimer()
return true
end]]></globalevent>
<globalevent name="timer2" time="17:01" event="script"><![CDATA[
domodlib("CastleSystem Lib")
function onTimer()
castle:secondTimer()
return true
end]]></globalevent>
<globalevent name="timer3" time="17:02" 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>
And when I put it to myots/mods/castlesystem.xml and if I add this into database:
Code:
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
Then I can't login my character into server and in the TFS appears this error :
Code:
[16/05/2010 17:01:00] [Error - GlobalEvent Interface]
[16/05/2010 17:01:00] buffer:onTimer
[16/05/2010 17:01:00] Description:
[16/05/2010 17:01:00] data/lib/004-database.lua:76: [Result:getDataString] Result not set!
[16/05/2010 17:01:00] stack traceback:
[16/05/2010 17:01:00] [C]: in function 'error'
[16/05/2010 17:01:00] data/lib/004-database.lua:76: in function 'getDataString'
[16/05/2010 17:01:00] [string "castle = {}..."]:48: in function 'secondTimer'
[16/05/2010 17:01:00] [string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>
[16/05/2010 17:01:00] [Error - GlobalEvents::timer] Couldn't execute event: timer2
[16/05/2010 17:02:00] [Error - GlobalEvent Interface]
[16/05/2010 17:02:00] buffer:onTimer
[16/05/2010 17:02:00] Description:
[16/05/2010 17:02:00] [string "castle = {}..."]:66: attempt to get length of field 'mur' (a nil value)
[16/05/2010 17:02:00] stack traceback:
[16/05/2010 17:02:00] [string "castle = {}..."]:66: in function 'thirdTimer'
[16/05/2010 17:02:00] [string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>
[16/05/2010 17:02:00] [Error - GlobalEvents::timer] Couldn't execute event: timer3
Thanks so much for help :thumbup: and I sorry for not too good English
Last edited: