Advertisement
Guest User

Untitled

a guest
Apr 10th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.46 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mod name="Castle System" version="1.1" author="Maniucza i Karpio" contact="" enabled="yes">
  3. <config name="CastleSystem Lib"><![CDATA[
  4. castle = {}
  5. castle.wallid = 7594
  6. 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}}
  7. castle.fromx = 583
  8. castle.tox = 586
  9. castle.fromy = 675
  10. castle.toy = 677
  11. castle.z = 7
  12. castle.kick = {x = 583,y = 670,z = 7}
  13. castle.teams = 0
  14. castle.pos = {x = 583,y = 670,z = 7}
  15. castle.mostdamage = 0
  16. castle.winnerteam = 0
  17. castle.monster = {x = 585, y = 673, z = 7}
  18. castle.msg = true
  19. castle.gary = true
  20. castle.garypos =
  21. {
  22. [1] = {x = x, y = y, z = z},
  23. [2] = {x = x, y = y, z = z},
  24. [3] = {x = x, y = y, z = z},
  25. [4] = {x = x, y = y, z = z}
  26. }
  27. function castle:firstTimer()
  28. if(os.date("%A") == "Thursday") then
  29. setGlobalStorageValue(1, 1)
  30. setGlobalStorageValue(2, os.time())
  31. if(castle.gary) then
  32. setGlobalStorageValue(1, 1)
  33. end
  34. doBroadcastMessage("Attention! Immediately register to Castle Wars. Leaders of the guild can enter your guild command:! Castle", MESSAGE_STATUS_WARNING)
  35. end
  36. return true
  37. end
  38. function castle:secondTimer()
  39. if(os.date("%A") == "Thursday") then
  40. if(getGlobalStorageValue(1) == 1) then
  41. setGlobalStorageValue(1, 2)
  42. end
  43. if(castle.teams == 0) then
  44. local result = db.getResult("SELECT * FROM castles WHERE id=1;")
  45. local winner = result:getDataString("owner")
  46. result:free()
  47. doBroadcastMessage("Gilds"..winner.." defended castle. Congratulations!", MESSAGE_STATUS_WARNING)
  48. setGlobalStorageValue(1, 3)
  49. end
  50. doBroadcastMessage("Fight for Castle has begun!", MESSAGE_STATUS_WARNING)
  51. for i = 1, #castle.mur do
  52. doRemoveItem(getThingFromPos(castle.mur[i]).uid, 1)
  53. end
  54. local mon = doSummonCreature("King", castle.monster)
  55. registerCreatureEvent(mon, "hit")
  56. end
  57. return true
  58. end
  59. function castle:thirdTimer()
  60. if(os.date("%A") == "Thursday" and getGlobalStorageValue(1) == 2) then
  61. for i = 1, #castle.mur do
  62. doCreateItem(castle.murid, 1, castle.mur[i])
  63. end
  64. castle:kickLosers()
  65. local result = db.getResult("SELECT * FROM castles WHERE id=1;")
  66. local winner = result:getDataString("owner")
  67. result:free()
  68. doBroadcastMessage("he struggle for the castle came to an end. Guilds "..winner.." defended castle. Congratulations!", MESSAGE_STATUS_WARNING)
  69. setGlobalStorageValue(1, 3)
  70. end
  71. return true
  72. end
  73. function castle:kickLosers(id)
  74. if(id == nil) then
  75. local result = db.getResult("SELECT * FROM castles WHERE id=1;")
  76. id = result:getDataInt("ownerid")
  77. result:free()
  78. end
  79. if(id == "all") then
  80. for x = castle.fromx, castle.tox do
  81. for y = castle.fromy, castle.toy do
  82. local player = getThingFromPos({x=x, y=y, z=castle.z, stackpos = 253})
  83. if(player.itemid > 0) then
  84. if(isPlayer(player) == true) then
  85. doTeleportThing(player, castle.kick)
  86. if(castle.msg == true) then
  87. return doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Przegral"..(getPlayerSex(player) == 0 and "as" or "es")..".")
  88. end
  89. end
  90. end
  91. end
  92. end
  93. elseif(isNumber(id) == true) then
  94. for x = castle.fromx, castle.tox do
  95. for y = castle.fromy, castle.toy do
  96. local player = getThingFromPos({x=x, y=y, z=castle.z, stackpos = 253})
  97. if(player.itemid > 0) then
  98. if(isPlayer(player) == true) then
  99. if(getPlayerGuildId(player) ~= id) then
  100. doTeleportThing(player, castle.kick)
  101. if(castle.msg == true) then
  102. return doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Przegral"..(getPlayerSex(player) == 0 and "as" or "es")..".")
  103. end
  104. end
  105. end
  106. end
  107. end
  108. end
  109. end
  110. return true
  111. end
  112. function castle:addTeam(cid, gid)
  113. if(getGlobalStorageValue(1) == 1) then
  114. local result = db.getResult("SELECT * FROM castles_war WHERE guild_id="..gid.." AND time="..getGlobalStorageValue(2)..";")
  115. if(result:getID() ~= -1) then
  116. return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Guild is already written to the fight.")
  117. end
  118. db.executeQuery("INSERT INTO `castles_war` (`castle_id` ,`guild_id` ,`damage` ,`time`)VALUES ('1', '"..gid.."', '0', '"..getGlobalStorageValue(2).."');")
  119. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Gilds added.")
  120. for k, v in pairs(getPlayersOnline()) do
  121. if(getPlayerGuildId(v) == gid) then
  122. if(getTilePzInfo(getCreaturePosition(v)) == true) then
  123. if(castle.gary) then
  124. doTeleportThing(v, castle.garypos[getGlobalStorageValue(3)])
  125. if(getGlobalStorageValue(3) < 4) then
  126. setGlobalStorageValue(3, getGlobalStorageValue(3) + 1)
  127. end
  128. else
  129. doTeleportThing(v, castle.pos)
  130. end
  131. if(castle.msg == true) then
  132. return doPlayerSendTextMessage(v, MESSAGE_INFO_DESCR, "Your guild, she joined the Fight for Castle.")
  133. end
  134. end
  135. end
  136. end
  137. castle.teams = castle.teams + 1
  138. else
  139. return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There are currently no records.")
  140. end
  141. return true
  142. end
  143. function castle:onHit(cid, attacker, type, combat, value)
  144. if(getCreatureName(cid) == "King") then
  145. if(db.executeQuery("UPDATE `castles_war` SET `damage`=`damage`+"..value.." WHERE `guild_id`="..getPlayerGuildId(attacker).." AND `time`="..getGlobalStorageValue(2)..";") ~= true) then
  146. return false
  147. else
  148. return true
  149. end
  150. end
  151. return true
  152. end
  153. function castle:onKill(cid, target)
  154. if(getCreatureName(target) == "King" and getGlobalStorageValue(1) == 2) then
  155. local result = db.getResult("SELECT * FROM `castles_war` WHERE `time`="..getGlobalStorageValue(2).." ORDER BY `damage` DESC LIMIT 1;")
  156. castle.mostdamage = result:getDataInt("damage")
  157. castle.winnerteam = result:getDataInt("guild_id")
  158. result:free()
  159. local result2 = db.getResult("SELECT * FROM guilds WHERE id="..castle.winnerteam..";")
  160. local name = result2:getDataString("name")
  161. result2:free()
  162. setGlobalStorageValue(1, 3)
  163. doBroadcastMessage("Gilds "..name.." injuries inflicted the greatest king and is the winner. The reward is replaced by the castle.")
  164. db.executeQuery("UPDATE castles SET ownerid="..castle.winnerteam..", owner=\""..name.."\" WHERE id=1;")
  165. castle:kickLosers(castle.winnerteam)
  166. end
  167. return true
  168. end
  169. ]]></config>
  170. <event type="kill" name="Castle King Kill" event="script"><![CDATA[
  171. domodlib("CastleSystem Lib")
  172. function onKill(cid, target, lastHit)
  173. if(getCreatureName(target) == "King") then
  174. castle:onKill(cid, target)
  175. return true
  176. end
  177. return true
  178. end]]></event>
  179. <event type="statschange" name="Hit" event="script"><![CDATA[
  180. domodlib("CastleSystem Lib")
  181. function onStatsChange(cid, attacker, type, combat, value)
  182. castle:onHit(cid, attacker, type, combat, value)
  183. return true
  184. end]]></event>
  185. <globalevent name="timer1" time="18:20" event="script"><![CDATA[
  186. domodlib("CastleSystem Lib")
  187. function onTimer()
  188. castle:firstTimer()
  189. return true
  190. end]]></globalevent>
  191. <globalevent name="timer2" time="18:22" event="script"><![CDATA[
  192. domodlib("CastleSystem Lib")
  193. function onTimer()
  194. castle:secondTimer()
  195. return true
  196. end]]></globalevent>
  197. <globalevent name="timer3" time="18:24" event="script"><![CDATA[
  198. domodlib("CastleSystem Lib")
  199. function onTimer()
  200. castle:thirdTimer()
  201. return true
  202. end]]></globalevent>
  203. <talkaction words="!zamek" event="buffer"><![CDATA[
  204. domodlib("CastleSystem Lib")
  205. function onSay(cid, words, param, channel)
  206. if(getPlayerGuildLevel(cid) == 3) then
  207. castle:addTeam(cid, getPlayerGuildId(cid))
  208. return true
  209. end
  210. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There are a guild leader.")
  211. return true
  212. end
  213. ]]></talkaction>
  214. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement