Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.96 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. if getGuild(msg) == nil then
  177. selfSay("The guild ".. msg .. " does not exist.",cid)
  178. talkState[talkUser] = 1
  179. return false
  180. end
  181.  
  182. --Prepare a db query
  183. --local query = "SELECT * FROM `guild_wars` WHERE `guild_id` = " .. getPlayerGuildId(cid) .. " or `enemy_id` = " .. getPlayerGuildId(cid)
  184. local query = "SELECT * FROM `guild_wars` WHERE NOT `status` = 5 and `guild_id` = " .. getPlayerGuildId(cid) .. " OR `enemy_id` = " .. getPlayerGuildId(cid) .. " AND NOT `status` =5"
  185.  
  186. --Use it
  187. local queryResult = db.storeQuery(query)
  188.  
  189. if (queryResult == false) then
  190. selfSay("Your guild is not in a war with ".. msg .. ".",cid)
  191. talkState[talkUser] = 0
  192. return false
  193. end
  194.  
  195. local temporaryStatus = false
  196. while (queryResult ~= false and temporaryStatus == false) do
  197. guild1[cid] = result.getDataInt(queryResult, "guild_id")
  198. guild2[cid] = result.getDataInt(queryResult, "enemy_id")
  199. local status = result.getDataInt(queryResult, "status")
  200. if status == 1 and (getGuildId(msg) == guild1[cid] or getGuildId(msg) == guild2[cid]) then
  201. temporaryStatus = true
  202. else
  203. result.next(queryResult)
  204. end
  205. end
  206. result.free(queryResult)
  207.  
  208. --Find out if the guild is in war
  209. if(temporaryStatus == false) then
  210. print("Erro aqui!! UM")
  211. selfSay("Your guild is not in a war with ".. msg .. ".",cid)
  212. talkState[talkUser] = 0
  213. return false
  214. end
  215.  
  216.  
  217. challengedguild[cid] = msg
  218. free_arenas_string = getFreeArenas(cid)
  219. if(free_arenas_string == nil or free_arenas_string == "" or free_arenas_string == false or free_arenas_string == true) then
  220. selfSay("Unfortunately there are no free arenas. I'm sorry.", cid)
  221. talkState[talkUser] = 0
  222. result.free(queryResult)
  223. else
  224. selfSay("The free arenas are " .. free_arenas_string .. " Which one do you want?", cid)
  225. talkState[talkUser] = 2
  226. result.free(queryResult)
  227. end
  228. ---------------------------------------------war-----------------------------------------------
  229. ---------------------------------------------enemy guild name----------------------------------
  230. ---------------------------------------------selected arena------------------------------------
  231. elseif talkState[talkUser] == 2 then
  232. local isValid = false
  233. local arena = 0
  234. print("free arenas:")
  235. --for k,v in pairs(arenas[cid]) do print(k, v) end
  236. print("number of free arenas: " .. #arenas[cid] )
  237. for arena = 0, #arenas[cid], 1 do
  238. if(arenas[cid][arena] ~= nil) then
  239. if(msgcontains(msg,arenas[cid][arena])) then
  240. selected_arena[cid] = arenas[cid][arena]
  241. isValid = true
  242. selfSay(selected_arena[cid] .. ", very well. For how much time, in {minutes}, do you want to fight?", cid)
  243. talkState[talkUser] = 3
  244. return false
  245. end
  246. end
  247. end
  248. if(not isValid) then
  249. selfSay("What? There was no option with that name.", cid)
  250. return false
  251. end
  252. ---------------------------------------------war-----------------------------------------------
  253. ---------------------------------------------enemy guild name----------------------------------
  254. ---------------------------------------------selected arena------------------------------------
  255. ---------------------------------------------selected time-------------------------------------
  256. elseif talkState[talkUser] == 3 then
  257. time[cid] = tonumber(msg)
  258. if(time[cid] > MAXIMUM_RESERVE_TIME) then
  259. time[cid] = 0
  260. selfSay("The limit is 60 minutes, unfortunately.", cid)
  261. return false
  262. end
  263. selfSay("Perfect, do you want a {default} war, {no UE} war or {SD only} war?", cid)
  264. talkState[talkUser] = 4
  265. ---------------------------------------------war-----------------------------------------------
  266. ---------------------------------------------enemy guild name----------------------------------
  267. ---------------------------------------------selected arena------------------------------------
  268. ---------------------------------------------selected time-------------------------------------
  269. ---------------------------------------------selected type-------------------------------------
  270. elseif talkState[talkUser] == 4 then
  271. if(msgcontains(msg, "default")) then
  272. wartype[cid] = 0
  273. elseif(msgcontains(msg, "UE") or msgcontains(msg, "ue")) then
  274. wartype[cid] = 1
  275. elseif(msgcontains(msg, "SD") or msgcontains(msg, "sd")) then
  276. wartype[cid] = 2
  277. else
  278. selfSay("What? There was no option with that name.", cid)
  279. return false
  280. end
  281. talkState[talkUser] = 6
  282. disablePotions[cid] = 0
  283. selfSay("Lastly, would you like to limit the number of players? If yes, say the {number} of players allowed. If not, say {no}.", cid)
  284. return false
  285. ---------------------------------------------war-----------------------------------------------
  286. ---------------------------------------------enemy guild name----------------------------------
  287. ---------------------------------------------selected arena------------------------------------
  288. ---------------------------------------------selected time-------------------------------------
  289. ---------------------------------------------selected type-------------------------------------
  290. ---------------------------------------------potions-------------------------------------------
  291. elseif talkState[talkUser] == 5 then
  292. if(msgcontains(msg, "disable") or msgcontains(msg, "yes")) then
  293. disablePotions[cid] = 1
  294. elseif(msgcontains(msg,"no")) then
  295. disablePotions[cid] = 0
  296. else
  297. selfSay("Would you like to disable the supreme potions potions? {Yes} or {no}.", cid)
  298. talkState[talkUser] = 5
  299. return false
  300. end
  301. selfSay("Lastly, would you like to limit the number of players? If yes, say the {number} of players allowed. If not, say {no}.", cid)
  302. talkState[talkUser] = 6
  303. return false
  304. ---------------------------------------------war-----------------------------------------------
  305. ---------------------------------------------enemy guild name----------------------------------
  306. ---------------------------------------------selected arena------------------------------------
  307. ---------------------------------------------selected time-------------------------------------
  308. ---------------------------------------------selected type-------------------------------------
  309. ---------------------------------------------potions-------------------------------------------
  310. ---------------------------------------------player limit--------------------------------------
  311. elseif talkState[talkUser] == 6 then
  312. if(msgcontains(msg,"no")) then
  313. playerLimit[cid] = 1000
  314. else
  315. if(tonumber(msg) == nil) then
  316. playerLimit[cid] = 1000
  317. else
  318. playerLimit[cid] = tonumber(msg)
  319. end
  320. end
  321. 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)
  322. registerWarInvitation(selected_arena[cid], guild1[cid], guild2[cid], time[cid], wartype[cid], cid, disablePotions[cid], playerLimit[cid])
  323. 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.")
  324. talkState[talkUser] = 0
  325. ---------------------------------------------invitation-----------------------------------------------
  326. elseif talkState[talkUser] == 12 then
  327. if(msgcontains(msg,"yes") or msgcontains(msg,"accept")) then
  328. query = "UPDATE `guildwar_arenas` SET `playersOnTeamA`=0, `playersOnTeamB`=0, `start` = " .. os.time() .. ", `pending` = 0, `inuse` = 1 WHERE `name` = \"" .. challengedArena[cid] .. "\""
  329. db.query(query)
  330. selfSay("The arena is now open. Say {enter} to enter.", cid)
  331. addEvent(freeArena, 10 + 60*challengedDuration[cid]*1000, challengedArena[cid])
  332. talkState[talkUser] = 0
  333. broadcastMessage("Leader of guild " .. getPlayerGuildName(cid) .. " " .. getPlayerName(cid) .. " has accepted the challenge.")
  334. return false
  335. elseif(msgcontains(msg,"no")) then
  336. query = "UPDATE `guildwar_arenas` SET `end` = " .. os.time() .. ", `inuse` = 0, `guild1` = 0, `guild2` = 0 WHERE `name` = \"" .. challengedArena[cid] .. "\""
  337. db.query(query)
  338. selfSay("Alright, alright. The invitation was {refused}.", cid)
  339. talkState[talkUser] = 0
  340. end
  341. end
  342. return true
  343. end
  344.  
  345. --local function onAddFocus(cid)
  346. --time[cid] = 0
  347. --time[cid] = 0
  348. --wartype[cid] = 0
  349. --selected_arena[cid] = 0
  350. --end
  351.  
  352. --local function onReleaseFocus(cid)
  353. --time[cid] = nil
  354. --wartype[cid] = nil
  355. --selected_arena[cid] = nil
  356. --end
  357.  
  358. --npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
  359. --npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
  360.  
  361. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  362. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  363. npcHandler:addModule(FocusModule:new())
  364.  
  365.  
  366. ---------------------------------------------------------------------
  367. -----LIB FOR WAR SYSTEM----------------------------------------------
  368. ---------------------------------------------------------------------
  369.  
  370.  
  371. function registerWarInvitation(arena, guild1, guild2, duration, wartype, cid, disablePotions, playerLimit)
  372. 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 .. "\""
  373. db.query(invitationQuery)
  374. addEvent(revokeWarInvitation, 60*1000, arena)
  375. return true
  376. end
  377.  
  378. function revokeWarInvitation(arena)
  379. --print("The invitation has expired.")
  380. query = "UPDATE `guildwar_arenas` SET `pending` = 0 WHERE `name` = \"" .. arena .. "\""
  381. db.query(query)
  382. end
  383.  
  384. function freeArena(arenaName)
  385. print("Reserve time is over, freeing arena " .. arenaName .. ".")
  386. local query = "SELECT * FROM `guildwar_arenas` WHERE `name` = \"" .. arenaName .. "\""
  387. local queryResult = db.storeQuery(query)
  388. if(query == false) then
  389. print("[Warning] Could not free arena: arena not found on table.")
  390. return false
  391. end
  392.  
  393. local guild1 = result.getDataInt(queryResult, "guild1")
  394. local guild2 = result.getDataInt(queryResult, "guild2")
  395.  
  396. print("Guilds involved: " .. guild1 .. " and " .. guild2)
  397.  
  398. local inuse = result.getDataInt(queryResult, "inuse")
  399. if(inuse == 0) then
  400. print("[Warning] Could not free arena: arena was already free.")
  401. return false
  402. end
  403. query = "UPDATE `guildwar_arenas` SET `end` = " .. os.time() .. ", `inuse` = 0, `guild1` = 0, `guild2` = 0 WHERE `name` = \"" .. arenaName .. "\""
  404. db.query(query)
  405. print (arenaName .. " is now free to be used again.")
  406. local onlinePlayers = getPlayersOnline()
  407. for unused, targetPlayer in ipairs(onlinePlayers) do
  408. if(getPlayerStorageValue(targetPlayer, STORAGE_PLAYER_IN_ARENA) == 1) then
  409. print(getPlayerName(targetPlayer) .. " was inside the arena;")
  410. print(getPlayerName(targetPlayer) .. " is a member of guild " .. getPlayerGuildId(targetPlayer))
  411. if((getPlayerGuildId(targetPlayer) == guild1 or getPlayerGuildId(targetPlayer) == guild2)) then
  412. doTeleportThing(targetPlayer, getTownTemplePosition(getPlayerTown(targetPlayer)), false)
  413. setPlayerStorageValue(targetPlayer, STORAGE_PLAYER_IN_ARENA, 0)
  414. setPlayerStorageValue(targetPlayer, STORAGE_PLAYER_WAR_TYPE, 0)
  415. setPlayerStorageValue(targetPlayer, STORAGE_PLAYER_DISABLED_POTIONS, 0)
  416. print(getPlayerName(targetPlayer) .. " has been sent back to temple.")
  417. end
  418. end
  419. end
  420.  
  421. result.free(queryResult)
  422. end
  423.  
  424. function getFreeArenas(cid)
  425. local listOfFreeArenas = {}
  426. local arena_names = ""
  427. --Find available arenas
  428. --See if it was found
  429. query = "SELECT * FROM `guildwar_arenas` WHERE `inuse` = 0"
  430. --print("Running query " .. query)
  431. queryResult = db.storeQuery(query)
  432. if(queryResult == false) then
  433. return false
  434. end
  435. arenas[cid] = {}
  436. while queryResult ~= false do
  437. local currentArenaName = result.getDataString(queryResult, "name")
  438. if(currentArenaName == nil) then print ("nil") end
  439. table.insert(arenas[cid], currentArenaName)
  440. print("inserted " .. currentArenaName)
  441. arena_names = arena_names .. "{" .. currentArenaName .. "}, "
  442. if (not result.next(queryResult)) then
  443. break
  444. end
  445. end
  446. numberOfArenas[cid] = #arenas[cid]
  447. --arenas[cid] = listOfFreeArenas
  448. result.free(queryResult)
  449. return arena_names
  450. end
  451.  
  452. function isInWar(playerGuildId)
  453. --Prepare a db query
  454. local query = "SELECT * FROM `guild_wars` WHERE `guild_id` = " .. playerGuildId .. " or `enemy_id` = " .. playerGuildId
  455.  
  456. --Use it
  457. local queryResult = db.storeQuery(query)
  458.  
  459. --Find out if the guild is in war
  460. if(queryResult == false) then
  461. return false
  462. end
  463.  
  464. --Extract the results
  465. local guild1 = result.getDataInt(queryResult, "guild_id")
  466. local guild2 = result.getDataInt(queryResult, "enemy_id")
  467. local status = result.getDataInt(queryResult, "status")
  468.  
  469. --Free result
  470. result.free(queryResult)
  471.  
  472. if(status == 0) then
  473. return false
  474. else
  475. return true
  476. end
  477. end
  478.  
  479. function getWarArena(cid)
  480. local playerGuildId = getPlayerGuildId(cid)
  481. print("[DEBUG] Guild Id = " .. tostring(playerGuildId))
  482. --Check for arena reservations
  483. query = "SELECT * FROM `guildwar_arenas` WHERE `guild1` = " .. playerGuildId .. " or `guild2` = " .. playerGuildId .." and `inuse`=1"
  484. queryResult = db.storeQuery(query)
  485.  
  486. if(queryResult == false) then
  487. result.free(queryResult)
  488. return false
  489. end
  490.  
  491. --Extract query results
  492. local arena_mapname = result.getDataString(queryResult, "name")
  493. local arena_inuse = result.getDataInt(queryResult, "inuse")
  494. local numberOfPlayersOnTeamA = result.getDataInt(queryResult, "playersOnTeamA")
  495. local numberOfPlayersOnTeamB = result.getDataInt(queryResult, "playersOnTeamB")
  496. local maxPlayers = result.getDataInt(queryResult, "maxplayers")
  497.  
  498.  
  499. if(arena_inuse == 0) then
  500. result.free(queryResult)
  501. return false
  502. end
  503.  
  504. local guild1 = result.getDataInt(queryResult, "guild1")
  505. local guild2 = result.getDataInt(queryResult, "guild2")
  506. 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")}
  507. 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")}
  508. local war_type = result.getDataInt(queryResult, "type")
  509. local disabledPotions = result.getDataInt(queryResult,"disablePotions")
  510. local limitOfPlayers = result.getDataInt(queryResult,"maxplayers")
  511.  
  512. --Player on the guild1 will be sent to arena pos A
  513. --Players on the guild2 will be sent to arena pos B
  514. if(playerGuildId == guild1) then
  515. if(numberOfPlayersOnTeamA == maxPlayers) then
  516. return nil
  517. end
  518. result.free(queryResult)
  519. local updatequery = "UPDATE `guildwar_arenas` SET `playersOnTeamA` = " .. tostring(numberOfPlayersOnTeamA+1) .. " WHERE `name` = \"" .. arena_mapname .. "\""
  520. setPlayerStorageValue(cid, STORAGE_PLAYER_IN_ARENA, 1)
  521. setPlayerStorageValue(cid, STORAGE_PLAYER_TEAM, 1)
  522. setPlayerStorageValue(cid, STORAGE_PLAYER_WAR_TYPE, war_type)
  523. setPlayerStorageValue(cid, STORAGE_PLAYER_DISABLED_POTIONS, disabledPotions)
  524. db.query(updatequery)
  525. result.free(queryResult)
  526. return arena_team_a_pos
  527. elseif(playerGuildId == guild2) then
  528. if(numberOfPlayersOnTeamB == maxPlayers) then
  529. return nil
  530. end
  531. result.free(queryResult)
  532. setPlayerStorageValue(cid, STORAGE_PLAYER_IN_ARENA, 1)
  533. setPlayerStorageValue(cid, STORAGE_PLAYER_TEAM, 2)
  534. setPlayerStorageValue(cid, STORAGE_PLAYER_WAR_TYPE, war_type)
  535. setPlayerStorageValue(cid, STORAGE_PLAYER_DISABLED_POTIONS, disabledPotions)
  536. local updatequery = "UPDATE `guildwar_arenas` SET `playersOnTeamB` = " .. tostring(numberOfPlayersOnTeamB+1) .. " WHERE `name` = \"" .. arena_mapname .. "\""
  537. db.query(updatequery)
  538. result.free(queryResult)
  539. return arena_team_b_pos
  540. else
  541. print("Warning: Error on enter war script.")
  542. print("Player guild id: " .. playerGuildId)
  543. print("Guild1 id: " .. guild1)
  544. print("Guild2 id: " .. guild2)
  545. result.free(queryResult)
  546. return false
  547. end
  548. result.free(queryResult)
  549. return false
  550. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement