Advertisement
Guest User

Untitled

a guest
Feb 9th, 2012
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 71.35 KB | None | 0 0
  1. Data provided by Pastebin.com - Download Raw - See Original
  2. --[[
  3. ##################################
  4. #                                #
  5. #        Made by Laurea          #
  6. #                                #
  7. #        Special thanks:         #
  8. # Sympathy at wow-v for teaching #
  9. #    me how to use metatables.   #
  10. #                                #
  11. ##################################
  12. ]]
  13.  
  14. local WorldDB = "world" --Name of your world db
  15. local MasterID = 70003 --Id of npc you choose path at (warrior or mage)
  16.  
  17. --Duel ranks and ranked wins needed to get them.
  18. --If you are going to edit these, only edit the rank names and wins needed.
  19. CustomDuel = {
  20.         ranks = {
  21.                 warrior = {
  22.                         [1] = "Novice",
  23.                         [2] = "Squire",
  24.                         [3] = "Scout",
  25.                         [4] = "Footman",
  26.                         [5] = "Knight",
  27.                         [6] = "Blademaster",
  28.                         [7] = "Warlord",
  29.                 },
  30.                 mage = {
  31.                         [1] = "Apprentice",
  32.                         [2] = "Initiate",
  33.                         [3] = "Disciple",
  34.                         [4] = "Adept",
  35.                         [5] = "Master",
  36.                         [6] = "Oracle",
  37.                         [7] = "Arch Mage",
  38.                 },
  39.                 both = {
  40.                         [8] = "Demigod",
  41.                         [9] = "God",
  42.                         [10] = "Titan",
  43.                         [11] = "Infinity",
  44.                         [12] = "Chaos",
  45.                 },
  46.                 ranked_wins ={
  47.                         [1] = 0,
  48.                         [2] = 5,
  49.                         [3] = 20,
  50.                         [4] = 60,
  51.                         [5] = 150,
  52.                         [6] = 300,
  53.                         [7] = 600,
  54.                         [8] = 1200,
  55.                         [9] = 1800,
  56.                         [10] = 2700,
  57.                         [11] = 4050,
  58.                         [12] = 6075,
  59.                         [13] = 9999999, --Do not edit, its for debugging
  60.                 },
  61.         },
  62. --DO NOT EDIT ANYTHING BEYOND THIS POINT
  63.         champions = {
  64.                 [1] = {
  65.                         health = 90,
  66.                         mindamage = 16,
  67.                         maxdamage = 24,
  68.                         defense = 12,
  69.                         power = 6,
  70.                         crit = 1,
  71.                         dodge = 1,
  72.                 },
  73.                 [2] = {
  74.                         health = 180,
  75.                         mindamage = 32,
  76.                         maxdamage = 48,
  77.                         defense = 24,
  78.                         power = 12,
  79.                         crit = 1,
  80.                         dodge = 1,
  81.                 },
  82.                 [3] = {
  83.                         health = 360,
  84.                         mindamage = 64,
  85.                         maxdamage = 96,
  86.                         defense = 48,
  87.                         power = 24,
  88.                         crit = 5,
  89.                         dodge = 1,
  90.                 },
  91.                 [4] = {
  92.                         health = 720,
  93.                         mindamage = 128,
  94.                         maxdamage = 192,
  95.                         defense = 96,
  96.                         power = 48,
  97.                         crit = 10,
  98.                         dodge = 4,
  99.                 },
  100.                 [5] = {
  101.                         health = 1440,
  102.                         mindamage = 256,
  103.                         maxdamage = 384,
  104.                         defense = 192,
  105.                         power = 96,
  106.                         crit = 15,
  107.                         dodge = 8,
  108.                 },
  109.                 [6] = {
  110.                         health = 2880,
  111.                         mindamage = 512,
  112.                         maxdamage = 768,
  113.                         defense = 384,
  114.                         power = 192,
  115.                         crit = 20,
  116.                         dodge = 12,
  117.                 },
  118.                 [7] = {
  119.                         health = 5760,
  120.                         mindamage = 1024,
  121.                         maxdamage = 1536,
  122.                         defense = 768,
  123.                         power = 384,
  124.                         crit = 25,
  125.                         dodge = 16,
  126.                 },
  127.                 [8] = {
  128.                         health = 11520,
  129.                         mindamage = 2048,
  130.                         maxdamage = 3072,
  131.                         defense = 1536,
  132.                         power = 768,
  133.                         crit = 30,
  134.                         dodge = 20,
  135.                 },
  136.         },
  137.         stats = {},
  138.         queries = {},
  139.         functions = {},
  140.         __index = function(_, key)
  141.                 return CustomDuel.functions[key]
  142.         end
  143. }
  144. local duel = {}
  145. local reset = {}
  146. setmetatable (duel, CustomDuel)
  147.  
  148. function CustomDuel.OnChat(event, player, message, type, language)
  149.         if message == "#duel" then
  150.                 player:SendBroadcastMessage("|cff0088FF#duel start|r Starts a duel with targeted player.")
  151.                 player:SendBroadcastMessage("|cff0088FF#duel stats|r Shows your duel stats.")
  152.                 player:SendBroadcastMessage("|cff0088FF#duel tstats|r Shows the duel stats of targeted player.")
  153.                 player:SendBroadcastMessage("|cff0088FF#duel cstats|r Compares yours and targeted players duel stats.")
  154.                 player:SendBroadcastMessage("|cff0088FF#duel setup|r Sets your starting duel stats.")
  155.                 player:SendBroadcastMessage("|cff0088FF#duel reset|r Resets your duel stats.")
  156.                 player:SendBroadcastMessage("|cff0088FF#duel info|r Shows info about dueling.")
  157.                 player:SendBroadcastMessage("|cff0088FF#duel faq|r shows some common questions and their answers.")
  158.         elseif message == "#duel info" then
  159.                 player:SendBroadcastMessage("1. |cff0088FFOnly you can see your own duels, not anyone else.")
  160.                 player:SendBroadcastMessage("2. |cff0088FFDuels \"tick\" every 5 seconds, they are not finished instantly.")
  161.                 player:SendBroadcastMessage("3. |cff0088FFIf you win or loose to someone they do not get a win/loose in their stats, only you do.")
  162.                 player:SendBroadcastMessage("4. |cff0088FFEvery time you win a duel you get 1 statpoint.")
  163.                 player:SendBroadcastMessage("5. |cff0088FFWhen you win or loose to a player you get locked, this means you cannot gain a ranked win from the player. Locks last for 5 minutes and you can still duel anyone else to get a ranked win.")
  164.                 player:SendBroadcastMessage("6. |cff0088FFYou do not get rewarded for winning over someone 2 ranks or more below your own and if you win over someone 1 rank or more above your own you get 1 extra statpoint.")
  165.         elseif message == "#duel faq" then
  166.                 player:SendBroadcastMessage("Q: |cff0088FFI only get a message saying i have no duel stats when i try to duel someone, check my stats or compare my stats!")
  167.                 player:SendBroadcastMessage("A: |cff00FF00Write \"#duel setup\" without the quotes.")
  168.                 player:SendBroadcastMessage("Q: |cff0088FFWhen i try to use #duel tstats or #duel cstats it says my target does not have any duel stats!")
  169.                 player:SendBroadcastMessage("A: |cff00FF00This means your target does not have any duel stats.")
  170.                 player:SendBroadcastMessage("Q: |cff0088FFI reseted my duel stats but changed my mind, how can i get them back?")
  171.                 player:SendBroadcastMessage("A: |cff00FF00You cant, thats why you had to confirm the reset.")
  172.         elseif message == "#duel stats" then
  173.                 if duel:GetQuery(player) == false or duel:GetStats(player) == false then
  174.                         player:SendBroadcastMessage("You do not have any duel stats.")
  175.                 elseif duel:GetBusy(player) == 1 then
  176.                         player:SendBroadcastMessage("You cannot check your duel stats while dueling.")
  177.                 else
  178.                         local query = duel:GetQuery(player)
  179.                         local stats = duel:GetStats(player)
  180.                         local class = duel:GetClass(player)
  181.                         local fornext = CustomDuel.ranks.ranked_wins[query.rank+1] - query.ranked_wins
  182.                         player:SendBroadcastMessage("Class: |cff0088FF"..class)
  183.                         player:SendBroadcastMessage("Rank: |cff0088FF"..query.rank_name)
  184.                         player:SendBroadcastMessage("Ranked wins: |cff0088FF"..query.ranked_wins)
  185.                         player:SendBroadcastMessage("Ranked wins for next rank: |cff0088FF"..fornext)
  186.                         player:SendBroadcastMessage("Health: |cff0088FF"..stats.health)
  187.                         player:SendBroadcastMessage("Min Damage: |cff0088FF"..stats.mindamage)
  188.                         player:SendBroadcastMessage("Max damage: |cff0088FF"..stats.maxdamage)
  189.                         if class == "Warrior" then
  190.                                 player:SendBroadcastMessage("Attackpower: |cff0088FF"..stats.power)
  191.                         else
  192.                                 player:SendBroadcastMessage("Spellpower: |cff0088FF"..stats.power)
  193.                         end
  194.                         player:SendBroadcastMessage("Defense: |cff0088FF"..stats.defense)
  195.                         player:SendBroadcastMessage("Crit: |cff0088FF"..stats.crit)
  196.                         player:SendBroadcastMessage("Dodge: |cff0088FF"..stats.dodge)
  197.                         player:SendBroadcastMessage("Statpoints: |cff0088FF"..query.statpoints)
  198.                         player:SendBroadcastMessage("Duels won: |cff0088FF"..query.won)
  199.                         player:SendBroadcastMessage("Duels lost: |cff0088FF"..query.lost)
  200.                         player:SendBroadcastMessage("Ties: |cff0088FF"..query.ties)
  201.                 end
  202.         elseif message == "#duel tstats" then
  203.                 local target = player:GetSelection()
  204.                 if target == nil then
  205.                         player:SendBroadcastMessage("You do not have any target.")
  206.                 elseif target:IsPlayer() == false then
  207.                         player:SendBroadcastMessage("You can only use this command on players.")
  208.                 elseif duel:GetQuery(target) == false or duel:GetStats(target) == false or duel:GetBusy(target) == false then
  209.                         player:SendBroadcastMessage(target:GetName().." does not have any duel stats.")
  210.                 elseif duel:GetBusy(player) == 1 then
  211.                         player:SendBroadcastMessage("You cannot check others duel stats while dueling.")
  212.                 else
  213.                         local query = duel:GetQuery(target)
  214.                         local stats = duel:GetStats(target)
  215.                         local class = duel:GetClass(target)
  216.                         player:SendBroadcastMessage("Name: |cff0088FF"..target:GetName())
  217.                         player:SendBroadcastMessage("Class: |cff0088FF"..class)
  218.                         player:SendBroadcastMessage("Rank: |cff0088FF"..query.rank_name)
  219.                         player:SendBroadcastMessage("Health: |cff0088FF"..stats.health)
  220.                         player:SendBroadcastMessage("Min Damage: |cff0088FF"..stats.mindamage)
  221.                         player:SendBroadcastMessage("Max damage: |cff0088FF"..stats.maxdamage)
  222.                         if class == "Warrior" then
  223.                                 player:SendBroadcastMessage("Attackpower: |cff0088FF"..stats.power)
  224.                         else
  225.                                 player:SendBroadcastMessage("Spellpower: |cff0088FF"..stats.power)
  226.                         end
  227.                         player:SendBroadcastMessage("Defense: |cff0088FF"..stats.defense)
  228.                         player:SendBroadcastMessage("Crit: |cff0088FF"..stats.crit)
  229.                         player:SendBroadcastMessage("Dodge: |cff0088FF"..stats.dodge)
  230.                         player:SendBroadcastMessage("Duels won: |cff0088FF"..query.won)
  231.                         player:SendBroadcastMessage("Duels lost: |cff0088FF"..query.lost)
  232.                         player:SendBroadcastMessage("Ties: |cff0088FF"..query.ties)
  233.                 end
  234.         elseif message == "#duel cstats" then
  235.                 local target = player:GetSelection()
  236.                 if duel:GetQuery(player) == false then
  237.                         player:SendBroadcastMessage("You do not have any duel stats.")
  238.                 elseif target == nil then
  239.                         player:SendBroadcastMessage("You do not have any target.")
  240.                 elseif target:IsPlayer() == false then
  241.                         player:SendBroadcastMessage("You can only use this command on players.")
  242.                 elseif duel:GetQuery(target) == false or duel:GetStats(target) == false or duel:GetBusy(target) == false then
  243.                         player:SendBroadcastMessage(target:GetName().." does not have any duel stats.")
  244.                 elseif duel:GetBusy(player) == 1 then
  245.                         player:SendBroadcastMessage("You cannot compare duel stats while dueling.")
  246.                 else
  247.                         local query = duel:GetQuery(player)
  248.                         local stats = duel:GetStats(player)
  249.                         local class = duel:GetClass(player)
  250.                         local tquery = duel:GetQuery(target)
  251.                         local tstats = duel:GetStats(target)
  252.                         local tclass = duel:GetClass(target)
  253.                         player:SendBroadcastMessage(string.format("Class: |cff0088FF%s %s", class, tclass))
  254.                         if query.rank > tquery.rank then
  255.                                 player:SendBroadcastMessage(string.format("Rank: |cff00FF00%s|r |cffFF0000%s", query.rank_name, tquery.rank_name))
  256.                         elseif query.rank < tquery.rank then
  257.                                 player:SendBroadcastMessage(string.format("Rank: |cffFF0000%s|r |cff00FF00%s", query.rank_name, tquery.rank_name))
  258.                         elseif query.rank == tquery.rank then
  259.                                 player:SendBroadcastMessage(string.format("Rank: |cff0088FF%s|r |cff0088FF%s", query.rank_name, tquery.rank_name))
  260.                         end
  261.                         if stats.health > tstats.health then
  262.                                 player:SendBroadcastMessage(string.format("Health: |cff00FF00%d|r |cffFF0000%d", stats.health, tstats.health))
  263.                         elseif stats.health < tstats.health then
  264.                                 player:SendBroadcastMessage(string.format("Health: |cffFF0000%d|r |cff00FF00%d", stats.health, tstats.health))
  265.                         elseif stats.health == tstats.health then
  266.                                 player:SendBroadcastMessage(string.format("Health: |cff0088FF%d", stats.health))
  267.                         end
  268.                         if stats.mindamage > tstats.mindamage then
  269.                                 player:SendBroadcastMessage(string.format("Min Damage: |cff00FF00%d|r |cffFF0000%d", stats.mindamage, tstats.mindamage))
  270.                         elseif stats.mindamage < tstats.mindamage then
  271.                                 player:SendBroadcastMessage(string.format("Min Damage: |cffFF0000%d|r |cff00FF00%d", stats.mindamage, tstats.mindamage))
  272.                         elseif stats.mindamage == tstats.mindamage then
  273.                                 player:SendBroadcastMessage(string.format("Min Damage: |cff0088FF%d", stats.mindamage))
  274.                         end
  275.                         if stats.maxdamage > tstats.maxdamage then
  276.                                 player:SendBroadcastMessage(string.format("Max Damage: |cff00FF00%d|r |cffFF0000%d", stats.maxdamage, tstats.maxdamage))
  277.                         elseif stats.maxdamage < tstats.maxdamage then
  278.                                 player:SendBroadcastMessage(string.format("Max Damage: |cffFF0000%d|r |cff00FF00%d", stats.maxdamage, tstats.maxdamage))
  279.                         elseif stats.maxdamage == tstats.maxdamage then
  280.                                 player:SendBroadcastMessage(string.format("Max Damage: |cff0088FF%d", stats.maxdamage))
  281.                         end
  282.                         if stats.power > tstats.power then
  283.                                 player:SendBroadcastMessage(string.format("Power: |cff00FF00%d|r |cffFF0000%d", stats.power, tstats.power))
  284.                         elseif stats.power < tstats.power then
  285.                                 player:SendBroadcastMessage(string.format("Power: |cffFF0000%d|r |cff00FF00%d", stats.power, tstats.power))
  286.                         elseif stats.power == tstats.power then
  287.                                 player:SendBroadcastMessage(string.format("Power: |cff0088FF%d", stats.power))
  288.                         end
  289.                         if stats.defense > tstats.defense then
  290.                                 player:SendBroadcastMessage(string.format("Defense: |cff00FF00%d|r |cffFF0000%d", stats.defense, tstats.defense))
  291.                         elseif stats.defense < tstats.defense then
  292.                                 player:SendBroadcastMessage(string.format("Defense: |cffFF0000%d|r |cff00FF00%d", stats.defense, tstats.defense))
  293.                         elseif stats.defense == tstats.defense then
  294.                                 player:SendBroadcastMessage(string.format("Defense: |cff0088FF%d", stats.defense))
  295.                         end
  296.                         if stats.crit > tstats.crit then
  297.                                 player:SendBroadcastMessage(string.format("Crit chance: |cff00FF00%d|r |cffFF0000%d", stats.crit, tstats.crit))
  298.                         elseif stats.crit < tstats.crit then
  299.                                 player:SendBroadcastMessage(string.format("Crit chance: |cffFF0000%d|r |cff00FF00%d", stats.crit, tstats.crit))
  300.                         elseif stats.crit == tstats.crit then
  301.                                 player:SendBroadcastMessage(string.format("Crit chance: |cff0088FF%d", stats.crit))
  302.                         end
  303.                         if stats.dodge > tstats.dodge then
  304.                                 player:SendBroadcastMessage(string.format("Dodge chance: |cff00FF00%d|r |cffFF0000%d", stats.dodge, tstats.dodge))
  305.                         elseif stats.dodge < tstats.dodge then
  306.                                 player:SendBroadcastMessage(string.format("Dodge chance: |cffFF0000%d|r |cff00FF00%d", stats.dodge, tstats.dodge))
  307.                         elseif stats.dodge == tstats.dodge then
  308.                                 player:SendBroadcastMessage(string.format("Dodge chance: |cff0088FF%d", stats.dodge))
  309.                         end
  310.                         if query.won > tquery.won then
  311.                                 player:SendBroadcastMessage(string.format("Duels won: |cff00FF00%d|r |cffFF0000%d", query.won, tquery.won))
  312.                         elseif query.won < tquery.won then
  313.                                 player:SendBroadcastMessage(string.format("Duels won: |cffFF0000%d|r |cff00FF00%d", query.won, tquery.won))
  314.                         elseif query.won == tquery.won then
  315.                                 player:SendBroadcastMessage(string.format("Duels won: |cff0088FF%d", query.won))
  316.                         end
  317.                         if query.lost > tquery.lost then
  318.                                 player:SendBroadcastMessage(string.format("Duels lost: |cff00FF00%d|r |cffFF0000%d", query.lost, tquery.lost))
  319.                         elseif query.lost < tquery.lost then
  320.                                 player:SendBroadcastMessage(string.format("Duels lost: |cffFF0000%d|r |cff00FF00%d", query.lost, tquery.lost))
  321.                         elseif query.lost == tquery.lost then
  322.                                 player:SendBroadcastMessage(string.format("Duels lost: |cff0088FF%d", query.lost))
  323.                         end
  324.                         if query.ties > tquery.ties then
  325.                                 player:SendBroadcastMessage(string.format("Ties: |cff00FF00%d|r |cffFF0000%d", query.ties, tquery.ties))
  326.                         elseif query.ties < tquery.ties then
  327.                                 player:SendBroadcastMessage(string.format("Ties: |cffFF0000%d|r |cff00FF00%d", query.ties, tquery.ties))
  328.                         elseif query.ties == tquery.ties then
  329.                                 player:SendBroadcastMessage(string.format("Ties: |cff0088FF%d", query.ties))
  330.                         end
  331.                 end
  332.         elseif message == "#duel setup" then
  333.                 if duel:GetQuery(player) ~= nil then
  334.                         player:SendBroadcastMessage("You already have duel stats. If you want to reset them use #duel reset instead.")
  335.                 else
  336.                         player:SendBroadcastMessage("Disabled as of v4.0. Please go to a Duel Master instead.")
  337.                 end
  338.         elseif message == "#duel reset" then
  339.                 if duel:GetQuery(player) == nil or duel:GetStats(player) == nil then
  340.                         player:SendBroadcastMessage("You do not have any duel stats.")
  341.                 elseif duel:GetBusy(player) == 1 then
  342.                         player:SendBroadcastMessage("You cannot reset your duel stats while dueling.")
  343.                 elseif reset[player:GetName()] == 1 then
  344.                         player:SendBroadcastMessage("You already have an active duel stat reset request.")
  345.                 else
  346.                         player:SendBroadcastMessage("|cffFF0000WARNING: If you reset your duel stats there is no way to get them back!|r Type #confirm to confirm the duel stat reset.")
  347.                         reset[player:GetName()] = {
  348.                                 expire = os.time()+10,
  349.                                 check = 1,
  350.                         }
  351.                 end
  352.         elseif message == "#duel start" then
  353.                 local target = player:GetSelection()
  354.                 if target == nil then
  355.                         player:SendBroadcastMessage("You do not have any target.")
  356.                 elseif target:IsPlayer() == false and duel:Champion(target) == false then
  357.                         player:SendBroadcastMessage("You can only duel players and champions.")
  358.                 elseif target:GetName() == player:GetName() then
  359.                         player:SendBroadcastMessage("You cannot duel yourself.")
  360.                 elseif duel:GetQuery(player) == false or duel:GetStats(player) == false then
  361.                         player:SendBroadcastMessage("You do not have any duel stats.")
  362.                 elseif duel:Champion(target) == false and (duel:GetQuery(target) == false or duel:GetStats(target) == false) then
  363.                         player:SendBroadcastMessage(target:GetName().." does not have any duel stats.")
  364.                 elseif duel:GetBusy(player) == 1 then
  365.                         player:SendBroadcastMessage("You are already in a duel.")
  366.                 elseif duel:Champion(target) ~= false then
  367.                         local diff = duel:Champion(target)
  368.                         local name = target:GetName()
  369.                         name = (name:gsub("'", "\\'"))
  370.                         WorldDBQuery("INSERT INTO `custom_duel_duels` (`player`, `enemy`, `player_hp`, `enemy_hp`, `player_status`, `enemy_status`, `champion`) VALUES ('"..player:GetName().."', '"..name.."', "..duel:GetStats(player).health..", "..CustomDuel.champions[diff].health..", 0, 0, "..diff..")")
  371.                         WorldDBQuery("UPDATE `custom_duel_players` SET `busy`=1 WHERE `name`='"..player:GetName().."'")
  372.                 else
  373.                         WorldDBQuery("INSERT INTO `custom_duel_duels` (`player`, `enemy`, `player_hp`, `enemy_hp`, `player_status`, `enemy_status`, `champion`) VALUES ('"..player:GetName().."', '"..target:GetName().."', "..duel:GetStats(player).health..", "..duel:GetStats(target).health..", 0, 0, 0)")
  374.                         WorldDBQuery("UPDATE `custom_duel_players` SET `busy`=1 WHERE `name`='"..player:GetName().."'")
  375.                 end
  376.         end
  377.         if message:find("#duel") then
  378.                 return 0
  379.         end
  380. end
  381.  
  382. function CustomDuel.OnFirstEnter(event, player)
  383.         if duel:GetQuery(player) ~= false then
  384.                 WorldDBQuery("DELETE FROM `custom_duel_players` WHERE (`name`='"..player:GetName().."')")
  385.         end
  386. end
  387.  
  388. function CustomDuel.Tick()
  389.         local query = WorldDBQuery("SELECT `player`, `enemy`, `player_hp`, `enemy_hp`, `player_status`, `enemy_status`, `champion` FROM `"..WorldDB.."`.`custom_duel_duels`")
  390.         if query ~= nil then
  391.                 local rows = query:GetRowCount()
  392.                 for i=1, rows do
  393.                         local player = query:GetColumn(0):GetString()
  394.                         local enemy = query:GetColumn(1):GetString()
  395.                         local player_hp = query:GetColumn(2):GetString()
  396.                         local enemy_hp = query:GetColumn(3):GetString()
  397.                         local player_status = query:GetColumn(4):GetString()
  398.                         local enemy_status = query:GetColumn(5):GetString()
  399.                         local stats = CustomDuel.stats[player]
  400.                         local estats
  401.                         if query:GetColumn(6):GetFloat() == 0 then
  402.                                 estats = CustomDuel.stats[enemy]
  403.                         else
  404.                                 local diff = query:GetColumn(6):GetFloat()
  405.                                 estats = CustomDuel.champions[diff]
  406.                         end
  407.                         local plr = GetPlayer(player)
  408.                         local damage = math.random(stats.mindamage, stats.maxdamage)
  409.                         local edamage = math.random(estats.mindamage, estats.maxdamage)
  410.                         if query:GetColumn(6):GetFloat() == 0 and stats.class ~= estats.class then
  411.                                 damage = damage*2
  412.                                 edamage = edamage*2
  413.                         end
  414.                         local def = stats.defense - estats.power
  415.                         local edef = estats.defense - stats.power
  416.                         if def < 0 then
  417.                                 def = 0
  418.                         end
  419.                         if edef < 0 then
  420.                                 edef = 0
  421.                         end
  422.                         damage = damage - edef
  423.                         edamage = edamage - def
  424.                         local crit = math.random(1, 100)
  425.                         local ecrit = math.random(1, 100)
  426.                         if crit <= stats.crit then
  427.                                 damage = damage*2
  428.                                 crit = true
  429.                         else
  430.                                 crit = false
  431.                         end
  432.                         if ecrit <= estats.crit then
  433.                                 edamage = edamage*2
  434.                                 ecrit = true
  435.                         else
  436.                                 ecrit = false
  437.                         end
  438.                         if damage <= 0 then
  439.                                 damage = 1
  440.                         end
  441.                         if edamage <= 0 then
  442.                                 edamage = 1
  443.                         end
  444.                         local dodge = math.random(1, 100)
  445.                         local edodge = math.random(1, 100)
  446.                         if dodge <= stats.dodge then
  447.                                 edamage = 0
  448.                                 dodge = true
  449.                         else
  450.                                 dodge = false
  451.                         end
  452.                         if edodge <= estats.dodge then
  453.                                 damage = 0
  454.                                 edodge = true
  455.                         else
  456.                                 edodge = false
  457.                         end
  458.                         player_hp = player_hp - edamage
  459.                         enemy_hp = enemy_hp - damage
  460.                         WorldDBQuery("UPDATE `custom_duel_duels` SET `player_hp`="..player_hp..", `enemy_hp`="..enemy_hp.." WHERE `player`='"..player.."'")
  461.                         if dodge == true then
  462.                                 plr:SendAreaTriggerMessage(string.format("You dodge %s's attack.", enemy))
  463.                         elseif ecrit == true and dodge == false then
  464.                                 plr:SendAreaTriggerMessage(string.format("%s criticaly hits you for %d damage. You have %d hp left.", enemy, edamage, player_hp))
  465.                         elseif ecrit == false and dodge == false then
  466.                                 plr:SendAreaTriggerMessage(string.format("%s hits you for %d damage. You have %d hp left.", enemy, edamage, player_hp))
  467.                         end
  468.                         if edodge == true then
  469.                                 plr:SendAreaTriggerMessage(string.format("%s dodges your attack.", enemy))
  470.                         elseif crit == true and edodge == false then
  471.                                 plr:SendAreaTriggerMessage(string.format("You criticaly hit %s for %d damage. %s has %d hp left", enemy, damage, enemy, enemy_hp))
  472.                         elseif crit == false and edodge == false then
  473.                                 plr:SendAreaTriggerMessage(string.format("You hit %s for %d damage. %s has %d hp left", enemy, damage, enemy, enemy_hp))
  474.                         end
  475.                         if player_hp > 0 and enemy_hp <= 0 then
  476.                                 local pquery = duel:GetQuery(player)
  477.                                 local diff = query:GetColumn(6):GetFloat()
  478.                                 if diff == 0 then
  479.                                         local equery = duel:GetQuery(enemy)
  480.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  481.                                         if lock == nil then
  482.                                                 if pquery.rank == equery.rank then
  483.                                                         local statpoints = pquery.statpoints + 1
  484.                                                         local ranked = pquery.ranked_wins + 1
  485.                                                         WorldDBQuery("UPDATE `custom_duel_players` SET `ranked_wins`="..ranked..", `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  486.                                                         plr:SendBroadcastMessage("You have won the duel against "..enemy.."! As your ranks were the same you gain 1 ranked win and 1 statpoint.")
  487.                                                 elseif pquery.rank-equery-rank < 0 then
  488.                                                         local statpoints = pquery.statpoints + 2
  489.                                                         local ranked = pquery.ranked_wins + 1
  490.                                                         WorldDBQuery("UPDATE `custom_duel_players` SET `ranked_wins`="..ranked..", `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  491.                                                         plr:SendBroadcastMessage("You have won the duel against "..enemy.."! As your rank is atleast 1 or more below your opponents you gain 1 ranked win and 2 statpoints.")
  492.                                                 elseif equery.rank-pquery.rank > 1 then
  493.                                                         plr:SendBroadcastMessage("You have won the duel against "..enemy.."! As your rank is atleast 2 or more above your opponents you gain nothing.")
  494.                                                 end
  495.                                         else
  496.                                                 if pquery.rank == equery.rank then
  497.                                                         local statpoints = pquery.statpoints + 1
  498.                                                         WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  499.                                                         plr:SendBroadcastMessage("You have won the duel against "..enemy.."! As your ranks were the same you gain 1 statpoint.")
  500.                                                 elseif pquery.rank-equery.rank < 0 then
  501.                                                         local statpoints = pquery.statpoints + 2
  502.                                                         WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  503.                                                         plr:SendBroadcastMessage("You have won the duel against "..enemy.."! As your rank is atleast 1 or more below your opponents you gain 2 statpoints.")
  504.                                                 elseif equery.rank-pquery.rank > 1 then
  505.                                                         plr:SendBroadcastMessage("You have won the duel against "..enemy.."! As your rank is atleast 2 or more above your opponents you gain nothing.")
  506.                                                 end
  507.                                         end
  508.                                         if pquery.rank < 12 and duel:GetQuery(player).ranked_wins >= CustomDuel.ranks.ranked_wins[pquery.rank+1] then
  509.                                                 local newrank = pquery.rank+1
  510.                                                 if newrank <= 7 and pquery.class == "Warrior" then
  511.                                                         WorldDBQuery("UPDATE `custom_duel_players` SET `rank_name`='"..CustomDuel.ranks.warrior[newrank].."', `rank`="..newrank.." WHERE `name`='"..player.."'")
  512.                                                 elseif newrank <= 7 and pquery.class == "Mage" then
  513.                                                         WorldDBQuery("UPDATE `custom_duel_players` SET `rank_name`='"..CustomDuel.ranks.mage[newrank].."', `rank`="..newrank.." WHERE `name`='"..player.."'")
  514.                                                 elseif newrank >= 8 then
  515.                                                         WorldDBQuery("UPDATE `custom_duel_players` SET `rank_name`='"..CustomDuel.ranks.both[newrank].."', `rank`="..newrank.." WHERE `name`='"..player.."'")
  516.                                                 end
  517.                                         end
  518.                                         local won = pquery.won+1
  519.                                         if lock == nil then
  520.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()+300)..")")
  521.                                         end
  522.                                 elseif diff == 1 then
  523.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  524.                                         if lock == nil then
  525.                                                 local won = pquery.won+1
  526.                                                 local ep = 5
  527.                                                 local statpoints = pquery.statpoints + ep
  528.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  529.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  530.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  531.                                         else
  532.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  533.                                         end
  534.                                 elseif diff == 2 then
  535.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  536.                                         if lock == nil then
  537.                                                 local won = pquery.won+1
  538.                                                 local ep = 10
  539.                                                 local statpoints = pquery.statpoints + ep
  540.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  541.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  542.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  543.                                         else
  544.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  545.                                         end
  546.                                 elseif diff == 3 then
  547.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  548.                                         if lock == nil then
  549.                                                 local won = pquery.won+1
  550.                                                 local ep = 20
  551.                                                 local statpoints = pquery.statpoints + ep
  552.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  553.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  554.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  555.                                         else
  556.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  557.                                         end
  558.                                 elseif diff == 4 then
  559.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  560.                                         if lock == nil then
  561.                                                 local won = pquery.won+1
  562.                                                 local ep = 40
  563.                                                 local statpoints = pquery.statpoints + ep
  564.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  565.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  566.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  567.                                         else
  568.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  569.                                         end
  570.                                 elseif diff == 5 then
  571.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  572.                                         if lock == nil then
  573.                                                 local won = pquery.won+1
  574.                                                 local ep = 80
  575.                                                 local statpoints = pquery.statpoints + ep
  576.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  577.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  578.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  579.                                         else
  580.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  581.                                         end
  582.                                 elseif diff == 6 then
  583.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  584.                                         if lock == nil then
  585.                                                 local won = pquery.won+1
  586.                                                 local ep = 160
  587.                                                 local statpoints = pquery.statpoints + ep
  588.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  589.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  590.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  591.                                         else
  592.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  593.                                         end
  594.                                 elseif diff == 7 then
  595.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  596.                                         if lock == nil then
  597.                                                 local won = pquery.won+1
  598.                                                 local ep = 320
  599.                                                 local statpoints = pquery.statpoints + ep
  600.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  601.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  602.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  603.                                         else
  604.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  605.                                         end
  606.                                 elseif diff == 8 then
  607.                                         local lock = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks` WHERE `player`='"..player.."' AND `enemy`='"..enemy.."'")
  608.                                         if lock == nil then
  609.                                                 local won = pquery.won+1
  610.                                                 local ep = 640
  611.                                                 local statpoints = pquery.statpoints + ep
  612.                                                 WorldDBQuery("UPDATE `custom_duel_players` SET `statpoints`="..statpoints.." WHERE `name`='"..player.."'")
  613.                                                 plr:SendBroadcastMessage("You have successfully defeated the champion "..enemy.."! You are rewarded with "..ep.." statpoints!")
  614.                                                 WorldDBQuery("INSERT INTO `custom_duel_locks` (`player`, `enemy`, `expire`) VALUES ('"..player.."', '"..enemy.."', "..(os.time()*5)..")")
  615.                                         else
  616.                                                 plr:SendBroadcastMessage("You have already defeated this champion once, you do not get any reward.")
  617.                                         end
  618.                                 end
  619.                                 duel:Setup(player)
  620.                                 WorldDBQuery("UPDATE `custom_duel_players` SET `busy`=0 WHERE `name`='"..player.."'")
  621.                                 WorldDBQuery("DELETE FROM `custom_duel_duels` WHERE (`player`='"..player.."')")
  622.                         elseif player_hp <= 0 and enemy_hp > 0 then
  623.                                 local pquery = duel:GetQuery(player)
  624.                                 local equery = duel:GetQuery(enemy)
  625.                                 plr:SendBroadcastMessage("You have lost the duel against "..enemy..".")
  626.                                 local lost = pquery.lost+1
  627.                                 WorldDBQuery("UPDATE `custom_duel_players` SET `busy`=0, `lost`="..lost.." WHERE `name`='"..player.."'")
  628.                                 WorldDBQuery("DELETE FROM `custom_duel_duels` WHERE (`player`='"..player.."')")
  629.                                 duel:Setup(player)
  630.                         elseif player_hp <= 0 and enemy_hp <= 0 then
  631.                                 local pquery = duel:GetQuery(player)
  632.                                 local equery = duel:GetQuery(enemy)
  633.                                 plr:SendBroadcastMessage("Both you and your opponent are dead, its a tie.")
  634.                                 local ties = pquery.ties+1
  635.                                 WorldDBQuery("UPDATE `custom_duel_players` SET `busy`=0, `ties`="..ties.." WHERE `name`='"..player.."'")
  636.                                 WorldDBQuery("DELETE FROM `custom_duel_duels` WHERE (`player`='"..player.."')")
  637.                                 duel:Setup(player)
  638.                         end
  639.                 end
  640.         end
  641. end
  642.  
  643. function CustomDuel.ClearLocks()
  644.         local query = WorldDBQuery("SELECT `player`, `enemy`, `expire` FROM `"..WorldDB.."`.`custom_duel_locks`")
  645.         if query ~= nil then
  646.                 local rows = query:GetRowCount()
  647.                 for i=1, rows do
  648.                         local expire = query:GetColumn(2):GetFloat()
  649.                         if os.time() >= expire then
  650.                                 WorldDBQuery("DELETE FROM `custom_duel_locks` WHERE (`player`='"..query:GetColumn(0):GetString().."' AND `enemy`='"..query:GetColumn(1):GetString().."')")
  651.                         end
  652.                         query:NextRow()
  653.                 end
  654.         end
  655. end
  656.  
  657. function CustomDuel.ExpireReset()
  658.         for k, v in pairs (reset) do
  659.                 if os.time() >= reset[k].expire then
  660.                         expire = 0
  661.                         check = 0
  662.                 end
  663.         end
  664. end
  665.  
  666. function CustomDuel.Confirm(event, player, message, type, language)
  667.         if message == "#confirm" and reset[player:GetName()].check == 1 then
  668.                 player:SendBroadcastMessage("Your duel stats are now reseted.")
  669.                 if duel:GetClass(player) == "Warrior" then
  670.                         WorldDBQuery("UPDATE `custom_duel_players` SET `rank_name`='"..CustomDuel.ranks.warrior[1].."', `rank`=1, `ranked_wins`=0, `strength`=10, `agility`=7, `intellect`=10, `spirit`=7, `stamina`=9, `defense`=4, `power`=1, `crit`=3, `dodge`=5, `busy`=0, `statpoints`=0, `won`=0, `lost`=0, `ties`=0 WHERE `name`='"..player:GetName().."'")
  671.                 else
  672.                         WorldDBQuery("UPDATE `custom_duel_players` SET `rank_name`='"..CustomDuel.ranks.mage[1].."', `rank`=1, `ranked_wins`=0, `strength`=10, `agility`=7, `intellect`=10, `spirit`=7, `stamina`=9, `defense`=4, `power`=1, `crit`=3, `dodge`=5, `busy`=0, `statpoints`=0, `won`=0, `lost`=0, `ties`=0 WHERE `name`='"..player:GetName().."'")
  673.                 end
  674.                 duel:Setup(player)
  675.                 reset[player:GetName()].expire = 0
  676.                 reset[player:GetName()].check = 0
  677.                 return 0
  678.         end
  679. end
  680.  
  681. function CustomDuel.MasterGossip(pUnit, event, player)
  682.         if duel:GetQuery(player) == false then
  683.                 pUnit:GossipCreateMenu(100, player, 0)
  684.                 pUnit:GossipMenuAddItem(0, "Do you want to get your duel stats "..player:GetName().."?", 1, 0)
  685.                 pUnit:GossipSendMenu(player)
  686.         elseif duel:GetStatpoints(player) == false or duel:GetStatpoints(player) == 0 then
  687.                 player:SendBroadcastMessage("You do not have any statpoints.")
  688.                 player:GossipComplete()
  689.         else
  690.                 pUnit:GossipCreateMenu(100, player, 0)
  691.                 if duel:GetClass(player) == "Warrior" then
  692.                         pUnit:GossipMenuAddItem(0, "Buy Strength", 2, 3)
  693.                         pUnit:GossipMenuAddItem(0, "Buy Agility", 3, 3)
  694.                 elseif duel:GetClass(player) == "Mage" then
  695.                         pUnit:GossipMenuAddItem(0, "Buy Intellect", 4, 3)
  696.                         pUnit:GossipMenuAddItem(0, "Buy Spirit", 5, 3)
  697.                 end
  698.                 pUnit:GossipMenuAddItem(0, "Buy Stamina", 6, 3)
  699.                 pUnit:GossipSendMenu(player)
  700.         end
  701. end
  702.  
  703. function CustomDuel.MasterSelect(pUnit, event, player, id, intid, code)
  704.         local code = tonumber(code)
  705.         if (intid == 1) then
  706.                 pUnit:GossipCreateMenu(100, player, 0)
  707.                 pUnit:GossipMenuAddItem(0, "Warrior", 11, 0)
  708.                 pUnit:GossipMenuAddItem(0, "Mage", 12, 0)
  709.                 pUnit:GossipSendMenu(player)
  710.         elseif (intid == 11) then
  711.                 local class = "Warrior"
  712.                 local rank = CustomDuel.ranks.warrior[1]
  713.                 duel:Setup(player, class, rank)
  714.                 player:GossipComplete()
  715.         elseif (intid == 12) then
  716.                 local class = "Mage"
  717.                 local rank = CustomDuel.ranks.mage[1]
  718.                 duel:Setup(player, class, rank)
  719.                 player:GossipComplete()
  720.         elseif (intid == 2) then
  721.                 check = {}
  722.                 string.gsub(code, "([^%d]+)", function(c) table.insert(check, c) end)
  723.                 if check[1] ~= nil then
  724.                         player:SendBroadcastMessage("Please only use numbers next time.")
  725.                         player:GossipComplete()
  726.                         check = nil
  727.                 elseif duel:GetStatpoints(player) < code then
  728.                         player:SendBroadcastMessage("You do not have "..code.." statpoints.")
  729.                         player:GossipComplete()
  730.                 else
  731.                         local stats = duel:GetQuery(player).strength + code
  732.                         local statpoints = duel:GetStatpoints(player) - code
  733.                         player:SendBroadcastMessage("You have bought "..code.." strength.")
  734.                         WorldDBQuery("UPDATE `custom_duel_players` SET `strength`="..stats..", `statpoints`="..statpoints.." WHERE `name`='"..player:GetName().."'")
  735.                         duel:Setup(player)
  736.                         player:GossipComplete()
  737.                 end
  738.         elseif (intid == 3) then
  739.                 check = {}
  740.                 string.gsub(code, "([^%d]+)", function(c) table.insert(check, c) end)
  741.                 if check[1] ~= nil then
  742.                         player:SendBroadcastMessage("Please only use numbers next time.")
  743.                         player:GossipComplete()
  744.                         check = nil
  745.                 elseif duel:GetStatpoints(player) < code then
  746.                         player:SendBroadcastMessage("You do not have "..code.." statpoints.")
  747.                         player:GossipComplete()
  748.                 else
  749.                         local stats = duel:GetQuery(player).agility + code
  750.                         local statpoints = duel:GetStatpoints(player) - code
  751.                         player:SendBroadcastMessage("You have bought "..code.." agility.")
  752.                         WorldDBQuery("UPDATE `custom_duel_players` SET `agility`="..stats..", `statpoints`="..statpoints.." WHERE `name`='"..player:GetName().."'")
  753.                         duel:Setup(player)
  754.                         player:GossipComplete()
  755.                 end
  756.         elseif (intid == 4) then
  757.                 check = {}
  758.                 string.gsub(code, "([^%d]+)", function(c) table.insert(check, c) end)
  759.                 if check[1] ~= nil then
  760.                         player:SendBroadcastMessage("Please only use numbers next time.")
  761.                         player:GossipComplete()
  762.                         check = nil
  763.                 elseif duel:GetStatpoints(player) < code then
  764.                         player:SendBroadcastMessage("You do not have "..code.." statpoints.")
  765.                         player:GossipComplete()
  766.                 else
  767.                         local stats = duel:GetQuery(player).intellect + code
  768.                         local statpoints = duel:GetStatpoints(player) - code
  769.                         player:SendBroadcastMessage("You have bought "..code.." intellect.")
  770.                         WorldDBQuery("UPDATE `custom_duel_players` SET `intellect`="..stats..", `statpoints`="..statpoints.." WHERE `name`='"..player:GetName().."'")
  771.                         duel:Setup(player)
  772.                         player:GossipComplete()
  773.                 end
  774.         elseif (intid == 5) then
  775.                 check = {}
  776.                 string.gsub(code, "([^%d]+)", function(c) table.insert(check, c) end)
  777.                 if check[1] ~= nil then
  778.                         player:SendBroadcastMessage("Please only use numbers next time.")
  779.                         player:GossipComplete()
  780.                         check = nil
  781.                 elseif duel:GetStatpoints(player) < code then
  782.                         player:SendBroadcastMessage("You do not have "..code.." statpoints.")
  783.                         player:GossipComplete()
  784.                 else
  785.                         local stats = duel:GetQuery(player).spirit + code
  786.                         local statpoints = duel:GetStatpoints(player) - code
  787.                         player:SendBroadcastMessage("You have bought "..code.." spirit.")
  788.                         WorldDBQuery("UPDATE `custom_duel_players` SET `spirit`="..stats..", `statpoints`="..statpoints.." WHERE `name`='"..player:GetName().."'")
  789.                         duel:Setup(player)
  790.                         player:GossipComplete()
  791.                 end
  792.         elseif (intid == 6) then
  793.                 check = {}
  794.                 string.gsub(code, "([^%d]+)", function(c) table.insert(check, c) end)
  795.                 if check[1] ~= nil then
  796.                         player:SendBroadcastMessage("Please only use numbers next time.")
  797.                         player:GossipComplete()
  798.                         check = nil
  799.                 elseif duel:GetStatpoints(player) < code then
  800.                         player:SendBroadcastMessage("You do not have "..code.." statpoints.")
  801.                         player:GossipComplete()
  802.                 else
  803.                         local stats = duel:GetQuery(player).stamina + code
  804.                         local statpoints = duel:GetStatpoints(player) - code
  805.                         player:SendBroadcastMessage("You have bought "..code.." stamina.")
  806.                         WorldDBQuery("UPDATE `custom_duel_players` SET `stamina`="..stats..", `statpoints`="..statpoints.." WHERE `name`='"..player:GetName().."'")
  807.                         duel:Setup(player)
  808.                         player:GossipComplete()
  809.                 end
  810.         end
  811. end
  812.  
  813. function CustomDuel.StopDuel(event, player)
  814.         if duel:GetQuery(player) ~= false and duel:GetBusy(player) == 1 then
  815.                 WorldDBQuery("DELETE FROM `custom_duel_duels` WHERE (`player`='"..player:GetName().."')")
  816.                 local add1 = 5
  817.                 local add2 = math.random(duel:GetQuery(player).lost/20, duel:GetQuery(player).lost/20)
  818.                 local add
  819.                 if add1 > add2 then
  820.                         add = duel:GetQuery(player).lost + add1
  821.                 else
  822.                         add = duel:GetQuery(player).lost + add2
  823.                 end
  824.                 WorldDBQuery("UPDATE `custom_duel_players` SET `lost`="..add..", `busy`=0 WHERE `name`='"..player:GetName().."'")
  825.         end
  826. end
  827.  
  828. --Custom functions
  829. function CustomDuel.functions:GetClass(player)
  830.         assert(type(player) == "userdata", "Bad argument #1 to `GetClass` (Expected userdata, got "..type(player)..").")
  831.         if CustomDuel.stats[player:GetName()] ~= nil then
  832.                 return CustomDuel.stats[player:GetName()].class
  833.         else
  834.                 return false
  835.         end
  836. end
  837. function CustomDuel.functions:GetStats(player)
  838.         assert(type(player) == "userdata", "Bad argument #1 to `GetStats` (Expected userdata, got "..type(player)..").")
  839.         if CustomDuel.stats[player:GetName()] ~= nil then
  840.                 return CustomDuel.stats[player:GetName()]
  841.         else
  842.                 return false
  843.         end
  844. end
  845. function CustomDuel.functions:GetQuery(player)
  846.         assert(type(player) == "userdata" or "string", "Bad argument #1 to `GetQuery` (Expected userdata or string, got "..type(player)..").")
  847.         if type(player) == "userdata" then
  848.                 if WorldDBQuery("SELECT `name` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player:GetName().."'") ~= nil then
  849.                         local query = WorldDBQuery("SELECT `name`, `class`, `rank_name`, `rank`, `ranked_wins`, `strength`, `agility`, `intellect`, `spirit`, `stamina`, `defense`, `power`, `crit`, `dodge`, `busy`, `statpoints`, `won`, `lost`, `ties` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player:GetName().."'")
  850.                         CustomDuel.queries[player:GetName()] = {
  851.                                 name = query:GetColumn(0):GetString(),
  852.                                 class = query:GetColumn(1):GetString(),
  853.                                 rank_name = query:GetColumn(2):GetString(),
  854.                                 rank = query:GetColumn(3):GetFloat(),
  855.                                 ranked_wins = query:GetColumn(4):GetFloat(),
  856.                                 strength = query:GetColumn(5):GetFloat(),
  857.                                 agility = query:GetColumn(6):GetFloat(),
  858.                                 intellect = query:GetColumn(7):GetFloat(),
  859.                                 spirit = query:GetColumn(8):GetFloat(),
  860.                                 stamina = query:GetColumn(9):GetFloat(),
  861.                                 defense = query:GetColumn(10):GetFloat(),
  862.                                 power = query:GetColumn(11):GetFloat(),
  863.                                 crit = query:GetColumn(12):GetFloat(),
  864.                                 dodge = query:GetColumn(13):GetFloat(),
  865.                                 busy = query:GetColumn(14):GetFloat(),
  866.                                 statpoints = query:GetColumn(15):GetFloat(),
  867.                                 won = query:GetColumn(16):GetFloat(),
  868.                                 lost = query:GetColumn(17):GetFloat(),
  869.                                 ties = query:GetColumn(18):GetFloat(),
  870.                         }
  871.                         return CustomDuel.queries[player:GetName()]
  872.                 else
  873.                         return false
  874.                 end
  875.         elseif type(player) == "string" then
  876.                 if WorldDBQuery("SELECT `name` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player.."'") ~= nil then
  877.                         local query = WorldDBQuery("SELECT `name`, `class`, `rank_name`, `rank`, `ranked_wins`, `strength`, `agility`, `intellect`, `spirit`, `stamina`, `defense`, `power`, `crit`, `dodge`, `busy`, `statpoints`, `won`, `lost`, `ties` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player.."'")
  878.                         CustomDuel.queries[player] = {
  879.                                 name = query:GetColumn(0):GetString(),
  880.                                 class = query:GetColumn(1):GetString(),
  881.                                 rank_name = query:GetColumn(2):GetString(),
  882.                                 rank = query:GetColumn(3):GetFloat(),
  883.                                 ranked_wins = query:GetColumn(4):GetFloat(),
  884.                                 strength = query:GetColumn(5):GetFloat(),
  885.                                 agility = query:GetColumn(6):GetFloat(),
  886.                                 intellect = query:GetColumn(7):GetFloat(),
  887.                                 spirit = query:GetColumn(8):GetFloat(),
  888.                                 stamina = query:GetColumn(9):GetFloat(),
  889.                                 defense = query:GetColumn(10):GetFloat(),
  890.                                 power = query:GetColumn(11):GetFloat(),
  891.                                 crit = query:GetColumn(12):GetFloat(),
  892.                                 dodge = query:GetColumn(13):GetFloat(),
  893.                                 busy = query:GetColumn(14):GetFloat(),
  894.                                 statpoints = query:GetColumn(15):GetFloat(),
  895.                                 won = query:GetColumn(16):GetFloat(),
  896.                                 lost = query:GetColumn(17):GetFloat(),
  897.                                 ties = query:GetColumn(18):GetFloat(),
  898.                         }
  899.                         return CustomDuel.queries[player]
  900.                 else
  901.                         return false
  902.                 end
  903.         end
  904. end
  905. function CustomDuel.functions:GetBusy(player)
  906.         assert(type(player) == "userdata", "Bad argument #1 to `GetBusy` (Expected userdata, got "..type(player)..").")
  907.         if WorldDBQuery("SELECT `name` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player:GetName().."'") ~= nil then
  908.                 return WorldDBQuery("SELECT `busy` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player:GetName().."'"):GetColumn(0):GetFloat()
  909.         else
  910.                 return false
  911.         end
  912. end
  913. function CustomDuel.functions:Setup(player, ...)
  914.         local class, rank = ...
  915.         assert(type(player) == "userdata" or "string", "Bad argument #1 to `Setup` (Expected userdata or string, got "..type(player)..").")
  916.         local name
  917.         if type(player) == "userdata" then
  918.                 name = player:GetName()
  919.         elseif type(player) == "string" then
  920.                 name = player
  921.         end
  922.         if duel:GetQuery(player) == false then
  923.                 WorldDBQuery("INSERT INTO `custom_duel_players` (`name`, `class`, `rank_name`, `rank`, `ranked_wins`, `strength`, `agility`, `intellect`, `spirit`, `stamina`, `defense`, `power`, `crit`, `dodge`, `busy`, `statpoints`, `won`, `lost`, `ties`) VALUES ('"..name.."', '"..class.."', '"..rank.."', 1, 0, 10, 7, 10, 7, 9, 1, 4, 1, 3, 5, 0, 0, 0, 0, 0, 0)")
  924.         end
  925.         local query = duel:GetQuery(player)
  926.         if query.class == "Warrior" then
  927.                 CustomDuel.stats[name] = {
  928.                         class = query.class,
  929.                         health = query.stamina*5,
  930.                         mindamage = math.random(query.strength*0.8, query.strength*0.8),
  931.                         maxdamage = math.random(query.strength*1.2, query.strength*1.2),
  932.                         defense = math.random(query.defense+(query.agility*0.35), query.defense+(query.agility*0.35)),
  933.                         power = math.random(query.power+((query.strength*0.10)+(query.agility*0.10)), query.power+((query.strength*0.10)+(query.agility*0.10))),
  934.                         crit = math.random(query.crit+(query.agility*0.05), query.crit+(query.agility*0.05)),
  935.                         dodge = math.random(query.dodge+(query.agility*0.01), query.dodge+(query.agility*0.01)),
  936.                 }
  937.         else
  938.                 CustomDuel.stats[name] = {
  939.                         class = query.class,
  940.                         health = query.stamina*5,
  941.                         mindamage = math.random(query.intellect*0.8, query.intellect*0.8),
  942.                         maxdamage = math.random(query.intellect*1.2, query.intellect*1.2),
  943.                         defense = math.random(query.defense+(query.spirit*0.35), query.defense+(query.spirit*0.35)),
  944.                         power = math.random(query.power+((query.intellect*0.10)+(query.spirit*0.10)), query.power+((query.intellect*0.10)+(query.spirit*0.10))),
  945.                         crit = math.random(query.crit+(query.spirit*0.05), query.crit+(query.spirit*0.05)),
  946.                         dodge = math.random(query.dodge+(query.spirit*0.01), query.dodge+(query.spirit*0.01)),
  947.                 }
  948.         end
  949.         if CustomDuel.stats[name].crit > 30 then
  950.                 CustomDuel.stats[name].crit = 30
  951.         end
  952.         if CustomDuel.stats[name].dodge > 20 then
  953.                 CustomDuel.stats[name].dodge = 20
  954.         end
  955. end
  956. function CustomDuel.functions:GetStatpoints(player)
  957.         assert(type(player) == "userdata", "Bad argument #1 to `GetBusy` (Expected userdata, got "..type(player)..").")
  958.         if WorldDBQuery("SELECT `name` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player:GetName().."'") ~= nil then
  959.                 return WorldDBQuery("SELECT `statpoints` FROM `"..WorldDB.."`.`custom_duel_players` WHERE `name`='"..player:GetName().."'"):GetColumn(0):GetFloat()
  960.         else
  961.                 return false
  962.         end
  963. end
  964. function CustomDuel.functions:Champion(pUnit)
  965.         assert(type(pUnit) == "userdata", "Bad argument #1 to `Champion` (Expected userdata, got "..type(pUnit)..").")
  966.         if pUnit:GetObjectType() == "Unit" then
  967.                 local id = pUnit:GetEntry()
  968.                 if WorldDBQuery("SELECT `champion`, `difficulty` FROM `"..WorldDB.."`.`custom_duel_champions` WHERE `champion`="..id) ~= nil then
  969.                         return WorldDBQuery("SELECT `champion`, `difficulty` FROM `"..WorldDB.."`.`custom_duel_champions` WHERE `champion`="..id):GetColumn(1):GetFloat()
  970.                 else
  971.                         return false
  972.                 end
  973.         else
  974.                 return false
  975.         end
  976. end
  977.  
  978. --Startup events
  979. if GetLuaEngine() == "LuaHypArc" then
  980.         RegisterServerHook(16, CustomDuel.OnChat)
  981.         RegisterServerHook(3, CustomDuel.OnFirstEnter)
  982.         RegisterServerHook(16, CustomDuel.Confirm)
  983.         RegisterServerHook(13, CustomDuel.StopDuel)
  984.         RegisterTimedEvent("CustomDuel.Tick", 5000, 0)
  985.         RegisterTimedEvent("CustomDuel.ClearLocks", 10000, 0)
  986.         RegisterTimedEvent("CustomDuel.ExpireReset", 1000, 0)
  987.         RegisterUnitGossipEvent(MasterID, 1, "CustomDuel.MasterGossip")
  988.         RegisterUnitGossipEvent(MasterID, 2, "CustomDuel.MasterSelect")
  989.         RegisterTimedEvent("CustomDuel.Setup", 2000, 1)
  990.         local start = os.time()
  991.         local players = 0
  992.         local query = WorldDBQuery("SELECT `name` FROM `"..WorldDB.."`.`custom_duel_players`")
  993.         if query ~= nil then
  994.                 local rows = query:GetRowCount()
  995.                 for i=1, rows do
  996.                         players = players+1
  997.                 end
  998.         end
  999.         logcol(3)
  1000.         print ("\n\n[Custom Duel System]: Loading...")
  1001.         print (string.format("[Custom Duel System]: Loaded %d player(s).", players))
  1002.         print (string.format("[Custom Duel System]: Loaded in %f seconds.", os.time() - start))
  1003.         print ("[Custom Duel System]: Version 4.1 (Made by Laurea)\n\n")
  1004.         logcol(15)
  1005. else
  1006.         logcol(4)
  1007.         print ("\n\n[Custom Duel System]: Failed to load - Server does not have LuaHypArc.\n\n")
  1008.         logcol(15)
  1009. end
  1010. function CustomDuel.Setup()
  1011.         local query = WorldDBQuery("SELECT `name`, `class`, `rank_name`, `rank`, `ranked_wins`, `strength`, `agility`, `intellect`, `spirit`, `stamina`, `defense`, `power`, `crit`, `dodge`, `busy`, `statpoints`, `won`, `lost`, `ties` FROM `"..WorldDB.."`.`custom_duel_players`")
  1012.         if query ~= nil then
  1013.                 local rows = query:GetRowCount()
  1014.                 for i=1, rows do
  1015.                         local name = query:GetColumn(0):GetString()
  1016.                         local class = query:GetColumn(1):GetString()
  1017.                         local strength = query:GetColumn(5):GetFloat()
  1018.                         local agility = query:GetColumn(6):GetFloat()
  1019.                         local intellect = query:GetColumn(7):GetFloat()
  1020.                         local spirit = query:GetColumn(8):GetFloat()
  1021.                         local stamina = query:GetColumn(9):GetFloat()
  1022.                         local defense = query:GetColumn(10):GetFloat()
  1023.                         local power = query:GetColumn(11):GetFloat()
  1024.                         local crit = query:GetColumn(12):GetFloat()
  1025.                         local dodge = query:GetColumn(13):GetFloat()
  1026.                         if class == "Warrior" then
  1027.                                 CustomDuel.stats[name] = {
  1028.                                         name = name,
  1029.                                         class = class,
  1030.                                         health = stamina*5,
  1031.                                         mindamage = math.random(strength*0.8, strength*0.8),
  1032.                                         maxdamage = math.random(strength*1.2, strength*1.2),
  1033.                                         defense = math.random(defense+(agility*0.35), defense+(agility*0.35)),
  1034.                                         power = math.random(power+((strength*0.10)+(agility*0.10)), power+((strength*0.10)+(agility*0.10))),
  1035.                                         crit = math.random(crit+(agility*0.05), crit+(agility*0.05)),
  1036.                                         dodge = math.random(dodge+(agility*0.01), dodge+(agility*0.01)),
  1037.                                 }
  1038.                         else
  1039.                                 CustomDuel.stats[name] = {
  1040.                                         name = name,
  1041.                                         class = class,
  1042.                                         health = stamina*5,
  1043.                                         mindamage = math.random(intellect*0.8, intellect*0.8),
  1044.                                         maxdamage = math.random(intellect*1.2, intellect*1.2),
  1045.                                         defense = math.random(defense+(spirit*0.35), defense+(spirit*0.35)),
  1046.                                         power = math.random(power+((intellect*0.10)+(spirit*0.10)), power+((intellect*0.10)+(spirit*0.10))),
  1047.                                         crit = math.random(crit+(spirit*0.05), crit+(spirit*0.05)),
  1048.                                         dodge = math.random(dodge+(spirit*0.01), dodge+(spirit*0.01)),
  1049.                                 }
  1050.                         end
  1051.                         if CustomDuel.stats[name].crit > 30 then
  1052.                                 CustomDuel.stats[name].crit = 30
  1053.                         end
  1054.                         if CustomDuel.stats[name].dodge > 20 then
  1055.                                 CustomDuel.stats[name].dodge = 20
  1056.                         end
  1057.                         query:NextRow()
  1058.                 end
  1059.         end
  1060. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement