Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.67 KB | None | 0 0
  1. local MAXIMUM_RESERVE_TIME = 60 --minutes
  2. local keywordHandler = KeywordHandler:new()
  3. local npcHandler = NpcHandler:new(keywordHandler)
  4. npcHandler:setMessage(MESSAGE_GREET, "Greetings, |PLAYERNAME|. I am here to offer the opportunity to enage in an {instanced war}. Maybe you have received an {invitation}? Or do you want to {enter} an ongoing war?")
  5. NpcSystem.parseParameters(npcHandler)
  6.  
  7. local arenas = {}
  8. local selected_arena = {}
  9. local time = {}
  10. local wartype = {}
  11. local playerLimit = {}
  12. local challengedguild = {}
  13. local guild1 = {}
  14. local guild2 = {}
  15. local challengedArena = {}
  16. local challengedDuration = {}
  17. local challengedGuild1 = {}
  18. local enemyGuild = {}
  19. local disablePotions = {}
  20. local numberOfArenas = {}
  21. local talkState = {}
  22.  
  23. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  24. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  25. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  26. function onThink() npcHandler:onThink() end
  27.  
  28. local function greetCallback(cid)
  29. --local player = Player(cid)
  30. --if(player:getGuild() == 0 or player:getGuild() == nil) then
  31. --selfSay("Hmpf.", cid)
  32. --return false
  33. --end
  34.  
  35.  
  36. --local guildLevel = player:getGuildLevel()
  37. --if guildLevel ~= 3 then
  38. --selfSay("Hmpf. Only guild leaders can speak to me.", cid)
  39. --return false
  40. --end
  41. talkState[cid] = 0
  42. return true
  43. end
  44.  
  45. local function creatureSayCallback(cid, type, msg)
  46. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  47.  
  48. if not npcHandler:isFocused(cid) then
  49. return false
  50. end
  51.  
  52. if talkState[talkUser] == 0 then
  53. --Find the player guild
  54. local playerGuild = getPlayerGuildId(cid)
  55.  
  56. --Find the guild name
  57. local playerGuildName = getPlayerGuildName(cid)
  58. -------------------------------------------------------------------------------------------------
  59. ---------------------------------------------hi--------------------------------------------------
  60. ---------------------------------------------war-------------------------------------------------
  61. if msg == "instanced war" or msgcontains(msg, "war") then
  62. if getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER then
  63. selfSay("What is the name of the {enemy guild}?", cid)
  64. talkState[talkUser] = 1
  65. else
  66. selfSay("You are not the leader of your guild.", cid)
  67. talkState[talkUser] = 0
  68. end
  69. ---------------------------------------------enter-----------------------------------------------
  70. elseif(msgcontains(msg, "enter")) then
  71. if (isInWar(getPlayerGuildId(cid))) then
  72. --There is a war going on
  73. --Check for arena reservations
  74. local warArenaPos = getWarArena(cid)
  75.  
  76. if(warArenaPos == nil) then
  77. selfSay("The limit of players on the arena has been reached.", cid)
  78. return false
  79. end
  80. query = "SELECT * FROM `guildwar_arenas` WHERE `inuse` = 1 and `guild2` = " .. getPlayerGuildId(cid) .. " or `guild1` = " .. getPlayerGuildId(cid)
  81. queryResult = db.storeQuery(query)
  82. local wartype = result.getDataString(queryResult, "type")
  83.  
  84. result.free(queryResult)
  85. if(warArenaPos == false) then
  86. selfSay("No arena was reserved for your war.", cid)
  87. return false
  88. else
  89. doPlayerSendTextMessage(cid, 22, "You have been teleported to the arena.")
  90. setPlayerStorageValue(cid, 18774, 1)
  91. if wartype == 0 then
  92. setPlayerStorageValue(cid, 18775, 0)
  93. elseif wartype == 1 then
  94. setPlayerStorageValue(cid, 18775, 1)
  95. elseif wartype == 2 then
  96. setPlayerStorageValue(cid, 18775, 2)
  97. end
  98. doTeleportThing(cid, warArenaPos, false)
  99. end
  100. else
  101. selfSay("Your guild is not in a war.", cid)
  102. return false
  103. end
  104. return false
  105. ---------------------------------------------invitation------------------------------------------
  106. elseif(msgcontains(msg, "invitation")) then
  107. if(msg == playerGuildName) then
  108. selfSay("The only battlefield one can fight oneself is in one's mind.",cid)
  109. talkState[talkUser] = 0
  110. return false
  111. end
  112.  
  113. query = "SELECT * FROM `guildwar_arenas` WHERE `pending` = 1 and `guild2` = " .. getPlayerGuildId(cid) .. " or `guild1` = " .. getPlayerGuildId(cid)
  114. queryResult = db.storeQuery(query)
  115. local pending = result.getDataInt(queryResult, "pending")
  116. if(pending == 0) then
  117. selfSay("There are no pending war invitations for your guild,", cid)
  118. result.free(queryResult)
  119. return false
  120. end
  121.  
  122. --See if it was found
  123. if(queryResult == false) then
  124. selfSay("There are no pending war invitations for your guild,", cid)
  125. result.free(queryResult)
  126. return false
  127. else
  128. local guild1 = result.getDataInt(queryResult, "guild1")
  129. local guild2 = result.getDataInt(queryResult, "guild2")
  130. local arena = result.getDataString(queryResult, "name")
  131. local wartype = result.getDataString(queryResult, "type")
  132. local duration = result.getDataString(queryResult, "duration")
  133. local potionDisabled = result.getDataInt(queryResult, "disablePotions")
  134. local limitOfPlayers= result.getDataInt(queryResult, "maxplayers")
  135. local potionstring = "{with all potions}"
  136. challengedArena[cid] = arena
  137. challengedDuration[cid] = duration
  138. challengedGuild1[cid] = guild1
  139. if(wartype == "0") then
  140. warstring = "{default}"
  141. elseif(wartype == "1") then
  142. warstring = "{no UE}"
  143. elseif(wartype == "2") then
  144. warstring = "{SD only}"
  145. end
  146. if(potionDisabled == 1) then
  147. potionstring = "{without ultimate potions}"
  148. end
  149. if getPlayerGuildId(cid) == guild1 then
  150. query = "SELECT `name` FROM `guilds` WHERE `id` = " .. guild1
  151. else
  152. query = "SELECT `name` FROM `guilds` WHERE `id` = " .. guild2
  153. end
  154.  
  155. queryResult = db.storeQuery(query)
  156. selfSay("You have been invited to a " .. warstring .. " war " .. potionstring .. " by {" .. result.getDataString(queryResult, "name") .. ",} the arena chosen is {" .. arena .. "}, the duration is set to {" .. duration .. " minutes} and the limit of players is {" .. limitOfPlayers .. "} on each side. Do you want to {accept}?", cid)
  157. talkState[talkUser] = 12
  158. result.free(queryResult)
  159. return false
  160. end
  161. end
  162. ---------------------------------------------war-----------------------------------------------
  163. ---------------------------------------------enemy guild name----------------------------------
  164. elseif talkState[talkUser] == 1 then
  165. --Find the player guild
  166. local playerGuild = getPlayerGuildId(cid)
  167.  
  168. --Find the guild name
  169. local playerGuildName = getPlayerGuildName(cid)
  170. if(msg == playerGuildName) then
  171. selfSay("The only battlefield one can fight oneself is in one's mind.",cid)
  172. talkState[talkUser] = 1
  173. return false
  174. end
  175.  
  176. --Prepare a db query
  177. --local query = "SELECT * FROM `guild_wars` WHERE `guild_id` = " .. getPlayerGuildId(cid) .. " or `enemy_id` = " .. getPlayerGuildId(cid)
  178. local query = "SELECT * FROM `guild_wars` WHERE NOT `status` = 5 and `guild_id` = " .. getPlayerGuildId(cid) .. " OR `enemy_id` = " .. getPlayerGuildId(cid) .. " AND NOT `status` =5"
  179.  
  180. --Use it
  181. local queryResult = db.storeQuery(query)
  182.  
  183. local temporaryStatus = false
  184. while (queryResult ~= false and temporaryStatus == false) do
  185. guild1[cid] = result.getDataInt(queryResult, "guild_id")
  186. guild2[cid] = result.getDataInt(queryResult, "enemy_id")
  187. local status = result.getDataInt(queryResult, "status")
  188. if status == 1 and (getGuildId(msg) == guild1[cid] or getGuildId(msg) == guild2[cid]) then
  189. temporaryStatus = true
  190. else
  191. result.next(queryResult)
  192. end
  193. end
  194. result.free(queryResult)
  195.  
  196. --Find out if the guild is in war
  197. if(temporaryStatus == false) then
  198. print("Erro aqui!! UM")
  199. selfSay("Your guild is not in a war with ".. msg .. ".",cid)
  200. talkState[talkUser] = 0
  201. return false
  202. end
  203.  
  204.  
  205. challengedguild[cid] = msg
  206. free_arenas_string = getFreeArenas(cid)
  207. if(free_arenas_string == nil or free_arenas_string == "" or free_arenas_string == false or free_arenas_string == true) then
  208. selfSay("Unfortunately there are no free arenas. I'm sorry.", cid)
  209. talkState[talkUser] = 0
  210. result.free(queryResult)
  211. else
  212. selfSay("The free arenas are " .. free_arenas_string .. " Which one do you want?", cid)
  213. talkState[talkUser] = 2
  214. result.free(queryResult)
  215. end
  216. ---------------------------------------------war-----------------------------------------------
  217. ---------------------------------------------enemy guild name----------------------------------
  218. ---------------------------------------------selected arena------------------------------------
  219. elseif talkState[talkUser] == 2 then
  220. local isValid = false
  221. local arena = 0
  222. print("free arenas:")
  223. --for k,v in pairs(arenas[cid]) do print(k, v) end
  224. print("number of free arenas: " .. #arenas[cid] )
  225. for arena = 0, #arenas[cid], 1 do
  226. if(arenas[cid][arena] ~= nil) then
  227. if(msgcontains(msg,arenas[cid][arena])) then
  228. selected_arena[cid] = arenas[cid][arena]
  229. isValid = true
  230. selfSay(selected_arena[cid] .. ", very well. For how much time, in {minutes}, do you want to fight?", cid)
  231. talkState[talkUser] = 3
  232. return false
  233. end
  234. end
  235. end
  236. if(not isValid) then
  237. selfSay("What? There was no option with that name.", cid)
  238. return false
  239. end
  240. ---------------------------------------------war-----------------------------------------------
  241. ---------------------------------------------enemy guild name----------------------------------
  242. ---------------------------------------------selected arena------------------------------------
  243. ---------------------------------------------selected time-------------------------------------
  244. elseif talkState[talkUser] == 3 then
  245. time[cid] = tonumber(msg)
  246. if(time[cid] > MAXIMUM_RESERVE_TIME) then
  247. time[cid] = 0
  248. selfSay("The limit is 60 minutes, unfortunately.", cid)
  249. return false
  250. end
  251. selfSay("Perfect, do you want a {default} war, {no UE} war or {SD only} war?", cid)
  252. talkState[talkUser] = 4
  253. ---------------------------------------------war-----------------------------------------------
  254. ---------------------------------------------enemy guild name----------------------------------
  255. ---------------------------------------------selected arena------------------------------------
  256. ---------------------------------------------selected time-------------------------------------
  257. ---------------------------------------------selected type-------------------------------------
  258. elseif talkState[talkUser] == 4 then
  259. if(msgcontains(msg, "default")) then
  260. wartype[cid] = 0
  261. elseif(msgcontains(msg, "UE") or msgcontains(msg, "ue")) then
  262. wartype[cid] = 1
  263. elseif(msgcontains(msg, "SD") or msgcontains(msg, "sd")) then
  264. wartype[cid] = 2
  265. else
  266. selfSay("What? There was no option with that name.", cid)
  267. return false
  268. end
  269. talkState[talkUser] = 6
  270. disablePotions[cid] = 0
  271. selfSay("Lastly, would you like to limit the number of players? If yes, say the {number} of players allowed. If not, say {no}.", cid)
  272. return false
  273. ---------------------------------------------war-----------------------------------------------
  274. ---------------------------------------------enemy guild name----------------------------------
  275. ---------------------------------------------selected arena------------------------------------
  276. ---------------------------------------------selected time-------------------------------------
  277. ---------------------------------------------selected type-------------------------------------
  278. ---------------------------------------------potions-------------------------------------------
  279. elseif talkState[talkUser] == 5 then
  280. if(msgcontains(msg, "disable") or msgcontains(msg, "yes")) then
  281. disablePotions[cid] = 1
  282. elseif(msgcontains(msg,"no")) then
  283. disablePotions[cid] = 0
  284. else
  285. selfSay("Would you like to disable the supreme potions potions? {Yes} or {no}.", cid)
  286. talkState[talkUser] = 5
  287. return false
  288. end
  289. selfSay("Lastly, would you like to limit the number of players? If yes, say the {number} of players allowed. If not, say {no}.", cid)
  290. talkState[talkUser] = 6
  291. return false
  292. ---------------------------------------------war-----------------------------------------------
  293. ---------------------------------------------enemy guild name----------------------------------
  294. ---------------------------------------------selected arena------------------------------------
  295. ---------------------------------------------selected time-------------------------------------
  296. ---------------------------------------------selected type-------------------------------------
  297. ---------------------------------------------potions-------------------------------------------
  298. ---------------------------------------------player limit--------------------------------------
  299. elseif talkState[talkUser] == 6 then
  300. if(msgcontains(msg,"no")) then
  301. playerLimit[cid] = 1000
  302. else
  303. if(tonumber(msg) == nil) then
  304. playerLimit[cid] = 1000
  305. else
  306. playerLimit[cid] = tonumber(msg)
  307. end
  308. end
  309. selfSay("The war invitation is open now. The leader of the enemy guild must accept the invitation. The invitation expires in {one minute}. Good luck, " .. getPlayerName(cid) .. ".", cid)
  310. registerWarInvitation(selected_arena[cid], guild1[cid], guild2[cid], time[cid], wartype[cid], cid, disablePotions[cid], playerLimit[cid])
  311. broadcastMessage("Leader of guild " .. getPlayerGuildName(cid) .. " " .. getPlayerName(cid) .. " has challenged guild " .. challengedguild[cid] .. " to an instanced war on " .. selected_arena[cid] .. " with a duration of " .. time[cid] .. " minutes. The challenge will expire in 60 seconds.")
  312. talkState[talkUser] = 0
  313. ---------------------------------------------invitation-----------------------------------------------
  314. elseif talkState[talkUser] == 12 then
  315. if(msgcontains(msg,"yes") or msgcontains(msg,"accept")) then
  316. query = "UPDATE `guildwar_arenas` SET `playersOnTeamA`=0, `playersOnTeamB`=0, `start` = " .. os.time() .. ", `pending` = 0, `inuse` = 1 WHERE `name` = \"" .. challengedArena[cid] .. "\""
  317. db.query(query)
  318. selfSay("The arena is now open. Say {enter} to enter.", cid)
  319. addEvent(freeArena, 10 + 60*challengedDuration[cid]*1000, challengedArena[cid])
  320. talkState[talkUser] = 0
  321. broadcastMessage("Leader of guild " .. getPlayerGuildName(cid) .. " " .. getPlayerName(cid) .. " has accepted the challenge.")
  322. return false
  323. elseif(msgcontains(msg,"no")) then
  324. query = "UPDATE `guildwar_arenas` SET `end` = " .. os.time() .. ", `inuse` = 0, `guild1` = 0, `guild2` = 0 WHERE `name` = \"" .. challengedArena[cid] .. "\""
  325. db.query(query)
  326. selfSay("Alright, alright. The invitation was {refused}.", cid)
  327. talkState[talkUser] = 0
  328. end
  329. end
  330. return true
  331. end
  332.  
  333. --local function onAddFocus(cid)
  334. --time[cid] = 0
  335. --time[cid] = 0
  336. --wartype[cid] = 0
  337. --selected_arena[cid] = 0
  338. --end
  339.  
  340. --local function onReleaseFocus(cid)
  341. --time[cid] = nil
  342. --wartype[cid] = nil
  343. --selected_arena[cid] = nil
  344. --end
  345.  
  346. --npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
  347. --npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
  348.  
  349. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  350. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  351. npcHandler:addModule(FocusModule:new())
  352.  
  353.  
  354. ---------------------------------------------------------------------
  355. -----LIB FOR WAR SYSTEM----------------------------------------------
  356. ---------------------------------------------------------------------
  357.  
  358.  
  359. function registerWarInvitation(arena, guild1, guild2, duration, wartype, cid, disablePotions, playerLimit)
  360. local invitationQuery = "UPDATE `guildwar_arenas` SET `challenger` = " .. getPlayerGuildId(cid) .. ", `maxplayers`= ".. playerLimit .. ", `disablePotions`= ".. disablePotions .. ", `type`= " .. wartype .. ", `duration` = " .. duration .. " ,`start` = " .. os.time() .. ", `end` = 0, `inuse` = 0, `pending` = 1, `guild1` = " .. guild1 .. ", `guild2` = " .. guild2 .. " WHERE `name` = \"" .. arena .. "\""
  361. db.query(invitationQuery)
  362. addEvent(revokeWarInvitation, 60*1000, arena)
  363. return true
  364. end
  365.  
  366. function revokeWarInvitation(arena)
  367. --print("The invitation has expired.")
  368. query = "UPDATE `guildwar_arenas` SET `pending` = 0 WHERE `name` = \"" .. arena .. "\""
  369. db.query(query)
  370. end
  371.  
  372. function freeArena(arenaName)
  373. print("Reserve time is over, freeing arena " .. arenaName .. ".")
  374. local query = "SELECT * FROM `guildwar_arenas` WHERE `name` = \"" .. arenaName .. "\""
  375. local queryResult = db.storeQuery(query)
  376. if(query == false) then
  377. print("[Warning] Could not free arena: arena not found on table.")
  378. return false
  379. end
  380.  
  381. local guild1 = result.getDataInt(queryResult, "guild1")
  382. local guild2 = result.getDataInt(queryResult, "guild2")
  383.  
  384. print("Guilds involved: " .. guild1 .. " and " .. guild2)
  385.  
  386. local inuse = result.getDataInt(queryResult, "inuse")
  387. if(inuse == 0) then
  388. print("[Warning] Could not free arena: arena was already free.")
  389. return false
  390. end
  391. query = "UPDATE `guildwar_arenas` SET `end` = " .. os.time() .. ", `inuse` = 0, `guild1` = 0, `guild2` = 0 WHERE `name` = \"" .. arenaName .. "\""
  392. db.query(query)
  393. print (arenaName .. " is now free to be used again.")
  394. local onlinePlayers = getPlayersOnline()
  395. for unused, targetPlayer in ipairs(onlinePlayers) do
  396. if(getPlayerStorageValue(targetPlayer, STORAGE_PLAYER_IN_ARENA) == 1) then
  397. print(getPlayerName(targetPlayer) .. " was inside the arena;")
  398. print(getPlayerName(targetPlayer) .. " is a member of guild " .. getPlayerGuildId(targetPlayer))
  399. if((getPlayerGuildId(targetPlayer) == guild1 or getPlayerGuildId(targetPlayer) == guild2)) then
  400. doTeleportThing(targetPlayer, getTownTemplePosition(getPlayerTown(targetPlayer)), false)
  401. setPlayerStorageValue(targetPlayer, STORAGE_PLAYER_IN_ARENA, 0)
  402. setPlayerStorageValue(targetPlayer, STORAGE_PLAYER_WAR_TYPE, 0)
  403. setPlayerStorageValue(targetPlayer, STORAGE_PLAYER_DISABLED_POTIONS, 0)
  404. print(getPlayerName(targetPlayer) .. " has been sent back to temple.")
  405. end
  406. end
  407. end
  408.  
  409. result.free(queryResult)
  410. end
  411.  
  412. function getFreeArenas(cid)
  413. local listOfFreeArenas = {}
  414. local arena_names = ""
  415. --Find available arenas
  416. --See if it was found
  417. query = "SELECT * FROM `guildwar_arenas` WHERE `inuse` = 0"
  418. --print("Running query " .. query)
  419. queryResult = db.storeQuery(query)
  420. if(queryResult == false) then
  421. return false
  422. end
  423. arenas[cid] = {}
  424. while queryResult ~= false do
  425. local currentArenaName = result.getDataString(queryResult, "name")
  426. if(currentArenaName == nil) then print ("nil") end
  427. table.insert(arenas[cid], currentArenaName)
  428. print("inserted " .. currentArenaName)
  429. arena_names = arena_names .. "{" .. currentArenaName .. "}, "
  430. if (not result.next(queryResult)) then
  431. break
  432. end
  433. end
  434. numberOfArenas[cid] = #arenas[cid]
  435. --arenas[cid] = listOfFreeArenas
  436. result.free(queryResult)
  437. return arena_names
  438. end
  439.  
  440. function isInWar(playerGuildId)
  441. --Prepare a db query
  442. local query = "SELECT * FROM `guild_wars` WHERE `guild_id` = " .. playerGuildId .. " or `enemy_id` = " .. playerGuildId
  443.  
  444. --Use it
  445. local queryResult = db.storeQuery(query)
  446.  
  447. --Find out if the guild is in war
  448. if(queryResult == false) then
  449. return false
  450. end
  451.  
  452. --Extract the results
  453. local guild1 = result.getDataInt(queryResult, "guild_id")
  454. local guild2 = result.getDataInt(queryResult, "enemy_id")
  455. local status = result.getDataInt(queryResult, "status")
  456.  
  457. --Free result
  458. result.free(queryResult)
  459.  
  460. if(status == 0) then
  461. return false
  462. else
  463. return true
  464. end
  465. end
  466.  
  467. function getWarArena(cid)
  468. local playerGuildId = getPlayerGuildId(cid)
  469. print("[DEBUG] Guild Id = " .. tostring(playerGuildId))
  470. --Check for arena reservations
  471. query = "SELECT * FROM `guildwar_arenas` WHERE `guild1` = " .. playerGuildId .. " or `guild2` = " .. playerGuildId .." and `inuse`=1"
  472. queryResult = db.storeQuery(query)
  473.  
  474. if(queryResult == false) then
  475. result.free(queryResult)
  476. return false
  477. end
  478.  
  479. --Extract query results
  480. local arena_mapname = result.getDataString(queryResult, "name")
  481. local arena_inuse = result.getDataInt(queryResult, "inuse")
  482. local numberOfPlayersOnTeamA = result.getDataInt(queryResult, "playersOnTeamA")
  483. local numberOfPlayersOnTeamB = result.getDataInt(queryResult, "playersOnTeamB")
  484. local maxPlayers = result.getDataInt(queryResult, "maxplayers")
  485.  
  486.  
  487. if(arena_inuse == 0) then
  488. result.free(queryResult)
  489. return false
  490. end
  491.  
  492. local guild1 = result.getDataInt(queryResult, "guild1")
  493. local guild2 = result.getDataInt(queryResult, "guild2")
  494. local arena_team_a_pos = {x = result.getDataInt(queryResult, "team_a_posx"), y = result.getDataInt(queryResult, "team_a_posy"), z = result.getDataInt(queryResult, "team_a_posz")}
  495. local arena_team_b_pos = {x = result.getDataInt(queryResult, "team_b_posx"), y = result.getDataInt(queryResult, "team_b_posy"), z = result.getDataInt(queryResult, "team_b_posz")}
  496. local war_type = result.getDataInt(queryResult, "type")
  497. local disabledPotions = result.getDataInt(queryResult,"disablePotions")
  498. local limitOfPlayers = result.getDataInt(queryResult,"maxplayers")
  499.  
  500. --Player on the guild1 will be sent to arena pos A
  501. --Players on the guild2 will be sent to arena pos B
  502. if(playerGuildId == guild1) then
  503. if(numberOfPlayersOnTeamA == maxPlayers) then
  504. return nil
  505. end
  506. result.free(queryResult)
  507. local updatequery = "UPDATE `guildwar_arenas` SET `playersOnTeamA` = " .. tostring(numberOfPlayersOnTeamA+1) .. " WHERE `name` = \"" .. arena_mapname .. "\""
  508. setPlayerStorageValue(cid, STORAGE_PLAYER_IN_ARENA, 1)
  509. setPlayerStorageValue(cid, STORAGE_PLAYER_TEAM, 1)
  510. setPlayerStorageValue(cid, STORAGE_PLAYER_WAR_TYPE, war_type)
  511. setPlayerStorageValue(cid, STORAGE_PLAYER_DISABLED_POTIONS, disabledPotions)
  512. db.query(updatequery)
  513. result.free(queryResult)
  514. return arena_team_a_pos
  515. elseif(playerGuildId == guild2) then
  516. if(numberOfPlayersOnTeamB == maxPlayers) then
  517. return nil
  518. end
  519. result.free(queryResult)
  520. setPlayerStorageValue(cid, STORAGE_PLAYER_IN_ARENA, 1)
  521. setPlayerStorageValue(cid, STORAGE_PLAYER_TEAM, 2)
  522. setPlayerStorageValue(cid, STORAGE_PLAYER_WAR_TYPE, war_type)
  523. setPlayerStorageValue(cid, STORAGE_PLAYER_DISABLED_POTIONS, disabledPotions)
  524. local updatequery = "UPDATE `guildwar_arenas` SET `playersOnTeamB` = " .. tostring(numberOfPlayersOnTeamB+1) .. " WHERE `name` = \"" .. arena_mapname .. "\""
  525. db.query(updatequery)
  526. result.free(queryResult)
  527. return arena_team_b_pos
  528. else
  529. print("Warning: Error on enter war script.")
  530. print("Player guild id: " .. playerGuildId)
  531. print("Guild1 id: " .. guild1)
  532. print("Guild2 id: " .. guild2)
  533. result.free(queryResult)
  534. return false
  535. end
  536. result.free(queryResult)
  537. return false
  538. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement