Advertisement
Guest User

duel.lua

a guest
Jul 15th, 2013
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. -- FUNÇOES --
  2. function addInvite(cid, player)
  3. local playerinvite = nil
  4.  
  5. for _, func in ipairs(getPlayersOnline()) do
  6. if getCreatureStorage(func, 15215) == getCreatureName(player) then
  7.  
  8. playerinvite = tostring(getCreatureName(func))
  9. end
  10. end
  11.  
  12. if getCreatureStorage(cid, 15215) == getCreatureName(player) then
  13.  
  14. doPlayerSendTextMessage(cid, 27, "Voce ja convidou "..getCreatureName(player).." para duelar, aguarde a resposta.")
  15. return true
  16. end
  17.  
  18. if getDistanceBetween(getPlayerPosition(cid), getPlayerPosition(player)) > 3 then
  19.  
  20. doPlayerSendTextMessage(cid, 27, "Voce precisa chegar perto desse jogador para convida-lo.")
  21. return true
  22. end
  23.  
  24. if playerinvite ~= nil then
  25.  
  26. doPlayerSendTextMessage(cid, 27, "Esse jogador ja foi convidado por outro jogador.")
  27. return true
  28. end
  29.  
  30. if not isCreature(player) then
  31.  
  32. doPlayerSendTextMessage(cid, 27, "Esse jogador nao é valido.")
  33. return true
  34. end
  35.  
  36. if getCreatureStorage(cid, 15215) ~= -1 then
  37.  
  38. doPlayerSendTextMessage(cid, 27, "Voce nao pode convidar outro jogador, voce ja convidou o jogador "..getPlayerStorageValue(cid, 15215))
  39. return true
  40. end
  41.  
  42. if getTilePzInfo(getThingPos(cid)) then
  43.  
  44. doPlayerSendTextMessage(cid, 27, "Voce nao pode convidar outro jogador para o duelo, estando em Protection Zone.")
  45. return true
  46. end
  47.  
  48. setPlayerStorageValue(cid, 15215, getCreatureName(player))
  49. doPlayerSendTextMessage(cid, 27, "Voce está convidando "..getCreatureName(player).." Para duelar.")
  50. doSendAnimatedText(getThingPos(player), "INVITED", 120)
  51. doPlayerSendTextMessage(player, 27, "Voce foi convidado para duelo por "..getCreatureName(cid))
  52. return true
  53. end
  54.  
  55. local tempo = 5
  56.  
  57. function doStartDuel(cid, cid2)
  58. if tempo == 0 then
  59. doCreatureSetSkullType(cid, SKULL_GREEN)
  60. doCreatureSetSkullType(cid2, SKULL_GREEN)
  61. doSendAnimatedText(getThingPos(cid), "BATTLE", 120)
  62. doSendAnimatedText(getThingPos(cid2), "BATTLE", 120)
  63. return true
  64. else
  65.  
  66. doSendAnimatedText(getThingPos(cid), tempo, 120)
  67. doSendAnimatedText(getThingPos(cid2), tempo, 120)
  68. tempo = tempo - 1
  69. return addEvent(doStartDuel, 1000, cid, cid2)
  70. end
  71. return true
  72. end
  73.  
  74. function doSalvePosition(cid)
  75. local p = getThingPos(cid)
  76.  
  77. if isCreature(cid) then
  78.  
  79. setPlayerStorageValue(cid, 18210, p.x)
  80. setPlayerStorageValue(cid, 18211, p.y)
  81. setPlayerStorageValue(cid, 18212, p.z)
  82. end
  83. return true
  84. end
  85.  
  86. function acceptInvite(cid, player)
  87.  
  88. if getCreatureStorage(player, 15215) ~= getCreatureName(cid) then
  89.  
  90. doPlayerSendTextMessage(cid, 27, "Voce nao foi convidado por esse jogador.")
  91. return true
  92. end
  93.  
  94. if getDistanceBetween(getPlayerPosition(cid), getPlayerPosition(player)) > 3 then
  95.  
  96. doPlayerSendTextMessage(cid, 27, "Voce precisa chegar perto desse jogador para aceitar o seu pedido.")
  97. return true
  98. end
  99.  
  100. if getTilePzInfo(getThingPos(cid)) then
  101.  
  102. doPlayerSendTextMessage(cid, 27, "Voce nao pode aceitar o pedido de duelo, estando em Protection Zone.")
  103. return true
  104. end
  105.  
  106. if getPlayerStorageValue(cid, 12577) <= 0 then
  107.  
  108. setPlayerStorageValue(cid, 12577, 0)
  109. end
  110.  
  111. if getPlayerStorageValue(cid, 12578) <= 0 then
  112.  
  113. setPlayerStorageValue(cid, 12578, 0)
  114. end
  115.  
  116. doPlayerSendTextMessage(player, 27, "O Jogador "..getCreatureStorage(player, 15215).." aceitou o seu pedido.")
  117. doSendAnimatedText(getThingPos(cid), "ACCEPTED", 120)
  118. setPlayerStorageValue(cid, 15122, 1)
  119. setPlayerStorageValue(player, 15122, 1)
  120. doSalvePosition(cid)
  121. doSalvePosition(player)
  122. addEvent(doStartDuel,1000,cid, player)
  123. return true
  124. end
  125.  
  126. function recuseInvite(cid, player)
  127. if getCreatureStorage(player, 15215) ~= getCreatureName(cid) then
  128.  
  129. doPlayerSendTextMessage(cid, 27, "Voce nao foi convidado por esse jogador.")
  130. return true
  131. end
  132.  
  133. setPlayerStorageValue(player, 15215, -1)
  134. doPlayerSendTextMessage(player, 27, "O Jogador "..getCreatureName(cid).." Cancelou seu pedido de duelo.")
  135. doPlayerSendTextMessage(cid, 27, "Voce cancelou o pedido do jogador "..getCreatureName(player))
  136. doSendAnimatedText(getThingPos(cid), "RECUSED", 120)
  137. return true
  138. end
  139.  
  140. function cancelInvite(cid)
  141. local player_cancel = nil
  142.  
  143. for _, players in ipairs(getPlayersOnline()) do
  144. if getCreatureStorage(cid, 15215) == getCreatureName(players) then
  145.  
  146. player_cancel = tostring(getCreatureName(players))
  147. end
  148. end
  149.  
  150. if player_cancel == nil then
  151.  
  152. doPlayerSendTextMessage(cid, 27, "Voce nao convidou ninquem, para cancelar.")
  153. return true
  154. end
  155.  
  156. setPlayerStorageValue(cid, 15215, -1)
  157. doPlayerSendTextMessage(cid, 27, "Voce cancelou o seu pedido para "..player_cancel)
  158. doPlayerSendTextMessage(getPlayerByName(player_cancel), 27, "O Jogador "..getCreatureName(cid).." cancelou o seu convite de duelo.")
  159. doSendAnimatedText(getThingPos(cid), "RECUSED", 120)
  160. return true
  161. end
  162.  
  163. function checkMeInvite(cid)
  164. local invites = nil
  165.  
  166. for _, players in ipairs(getPlayersOnline()) do
  167. if getCreatureStorage(players, 15215) == getCreatureName(cid) then
  168.  
  169. invites = tostring(getCreatureName(players))
  170. end
  171. end
  172.  
  173. if invites ~= nil and getCreatureStorage(cid, 15215) == -1 then
  174.  
  175. doPlayerSendTextMessage(cid, 27, "Voce tem invites de "..invites)
  176. elseif getCreatureStorage(cid, 15215) ~= -1 then
  177.  
  178. doPlayerSendTextMessage(cid, 27, "Voce invitou o jogador "..getCreatureStorage(cid, 15215))
  179. else
  180.  
  181. doPlayerSendTextMessage(cid, 27, "Voce nao convidou ninquem , e nem foi convidado.")
  182. end
  183. return true
  184. end
  185.  
  186. function checkStatus(cid, player)
  187. if not isCreature(player) then
  188.  
  189. doPlayerSendCancel(cid, "Creature Not found.")
  190. return true
  191. end
  192.  
  193. doShowTextDialog(cid, 2160, " "..getCreatureName(player).." Status\n\nVitórias : "..getPlayerStorageValue(player, 12578).."\nDerrotas : "..getPlayerStorageValue(player, 12577).."")
  194. return true
  195. end
  196.  
  197. -- FUNÇOES --
  198.  
  199. function onSay(cid, words, param)
  200.  
  201. function showCommands(cid)
  202. if isCreature(cid) then
  203.  
  204. local msg = "Comandos:\n-Invite\n-Accept\n-Recuse\n-Cancel\n-Status\n-Check\n\nModo de Uso:\n"..words.." comando, NomedoJogador"
  205. doShowTextDialog(cid, 2160, msg)
  206. end
  207. return true
  208. end
  209.  
  210. local txt = string.explode(param, ",")
  211. local pid = getPlayerByNameWildcard(txt[2])
  212.  
  213. if txt[1] == "invite" then
  214.  
  215. addInvite(cid, pid)
  216. elseif txt[1] == "accept" then
  217.  
  218. acceptInvite(cid, pid)
  219. elseif txt[1] == "recuse" then
  220.  
  221. recuseInvite(cid, pid)
  222. elseif txt[1] == "commands" then
  223.  
  224. showCommands(cid)
  225. elseif txt[1] == "cancel" then
  226.  
  227. cancelInvite(cid)
  228. elseif txt[1] == "status" then
  229.  
  230. checkStatus(cid, pid)
  231. elseif txt[1] == "check" then
  232.  
  233. checkMeInvite(cid)
  234. else
  235.  
  236. doPlayerSendTextMessage(cid, 27, "Comando nao valido, para saber os comandos use: "..words.." commands")
  237. end
  238. return true
  239. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement