Advertisement
Mordred

challenge instance spawn system

Jul 6th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.41 KB | None | 0 0
  1. -- v2.3 -
  2.  
  3. IS = {InstanceIDs = {44},  -- Maintable
  4.             InstanceActivated = {},
  5.             Spawned = {},
  6.             PlayerCount = {},
  7.             pCheck = {},
  8.             CountD = {}}
  9.  
  10. function IS.EnterInstance(_,Player)
  11.     Player:RegisterLuaEvent(function() -- whole script timed for error elimination (Player is not in world until teleportet?)
  12.    
  13.     local AreaTriggerID = Player:GetMapId()
  14.     local AreaCheck = 0
  15.     local iID = Player:GetInstanceID()
  16.     for nr,inID in pairs(IS.InstanceIDs) do -- check if mapid is in IS.InstanceIDs
  17.         if AreaTriggerID==inID then
  18.             AreaCheck = 1
  19.             if iID and IS.InstanceActivated[iID] and IS.Spawned[iID] then -- health correction
  20.                 if IS.PlayerCount[iID] then
  21.                     local plrCount = GetInstancePlayerCount(AreaTriggerID, iID)
  22.                     if IS.PlayerCount[iID] ~= plrCount and plrCount >=1 then
  23.                         for uNr, unt in pairs(IS.Spawned[iID]) do
  24.                             if type(unt)=="table" then
  25.                                 unt[1]:SetMaxHealth( unt[1]:GetMaxHealth() * plrCount )
  26.                             end
  27.                         end
  28.                         IS.PlayerCount[iID] = plrCount
  29.                     end
  30.                 else
  31.                     IS.PlayerCount[iID] = GetInstancePlayerCount(AreaTriggerID, iID)
  32.                     if IS.PlayerCount[iID] > 1 then
  33.                         for uNr, unt in pairs(IS.Spawned[iID]) do
  34.                             if type(unt)=="table" then
  35.                                 unt[1]:SetMaxHealth( unt[1]:GetMaxHealth() * IS.PlayerCount[iID] )
  36.                             end
  37.                         end
  38.                     end
  39.                 end
  40.             end
  41.         end
  42.     end
  43.     if AreaCheck==0 then return; end -- if mapid is not in it, cancel further actions
  44.    
  45.     local pGUID = tostring(Player:GetGUID())
  46.     if not IS.InstanceActivated[iID] then
  47.         Player:RegisterLuaEvent(function() Player:CastSpell(59123) end, 200,1)
  48.        
  49.         IS.Info = CreateFrame("Information")
  50.             IS.IB = IS.Info:CreateTextBox("InfoBox")
  51.         -------------------------
  52.         IS.Info:SetHeight(75)
  53.         IS.Info:SetYOffset(0)
  54.         IS.Info:SetWidth(300)
  55.         IS.Info:SetCantMove(true)
  56.         IS.Info:SetCantClose(true)
  57.         -------------------------
  58.         IS.IB:SetYOffset(-20)
  59.         IS.IB:SetWidth(300)
  60.         IS.IB:SetHeight(300)
  61.         IS.IB:SetText("")
  62.         -------------------------
  63.         IS.Info:Send(Player)
  64.        
  65.         --------------------------------------------------
  66.         --------------------------------------------------
  67.        
  68.         IS.Diff = CreateFrame("Difficulty")
  69.             IS.Stat = IS.Diff:CreateStatusBar("Countdown")
  70.             IS.Easy = IS.Diff:CreateButton("Easy")
  71.                 IS.Ie = IS.Diff:CreateButton("InfoEasy")
  72.             IS.Medium = IS.Diff:CreateButton("Medium")
  73.                 IS.Im = IS.Diff:CreateButton("InfoMedium")
  74.             IS.Hard = IS.Diff:CreateButton("Hard")
  75.                 IS.Ih = IS.Diff:CreateButton("InfoHard")
  76.         -------------------------
  77.         IS.Stat:SetWidth(250)
  78.         IS.Stat:SetHeight(5)
  79.         IS.Stat:SetYOffset(25)
  80.         IS.Stat:SetXOffset(-10)
  81.         IS.Stat:SetCountdown(38)
  82.         -------------------------
  83.         IS.Diff:SetHeight(75)
  84.         IS.Diff:SetWidth(300)
  85.         IS.Diff:SetCantMove(true)
  86.         IS.Diff:SetCantClose(true)
  87.         -------------------------
  88.         IS.Easy:SetText("Easy")
  89.         IS.Easy:SetXOffset(-100)
  90.         IS.Easy:SetYOffset(5)
  91.         IS.Easy:SetWidth(80)
  92.         IS.Easy:SetHeight(35)
  93.         IS.Easy:SetEvent("OnClick", function(self, event, player,_)
  94.                                         IS.Diff:Hide(player)
  95.                                         IS.Info:Hide(player)
  96.                                         player:RemoveAura(59123)
  97.                                         player:RemoveLuaEvent(IS.Countdowner)
  98.                                         IS.StartSpawning(player,AreaTriggerID,1)
  99.                                     end)
  100.         -------------------------
  101.         IS.Medium:SetText("Medium")
  102.         IS.Medium:SetXOffset(-10)
  103.         IS.Medium:SetYOffset(5)
  104.         IS.Medium:SetWidth(80)
  105.         IS.Medium:SetHeight(35)
  106.         IS.Medium:SetEvent("OnClick", function(self, event, player,_)
  107.                                         IS.Diff:Hide(player)
  108.                                         IS.Info:Hide(player)
  109.                                         player:RemoveAura(59123)
  110.                                         player:RemoveLuaEvent(IS.Countdowner)
  111.                                         IS.StartSpawning(player,AreaTriggerID,2)
  112.                                     end)
  113.         -------------------------
  114.         IS.Hard:SetText("Hard")
  115.         IS.Hard:SetXOffset(80)
  116.         IS.Hard:SetYOffset(5)
  117.         IS.Hard:SetWidth(80)
  118.         IS.Hard:SetHeight(35)
  119.         IS.Hard:SetEvent("OnClick", function(self, event, player,_)
  120.                                         IS.Diff:Hide(player)
  121.                                         IS.Info:Hide(player)
  122.                                         player:RemoveAura(59123)
  123.                                         player:RemoveLuaEvent(IS.Countdowner)
  124.                                         IS.StartSpawning(player,AreaTriggerID,4)
  125.                                     end)
  126.         -------------------------
  127.         -------------------------
  128.         IS.pCheck[pGUID] = {0,0,0}
  129.        
  130.         IS.Ie:SetText("\\/")
  131.         IS.Ie:SetXOffset(-100)
  132.         IS.Ie:SetYOffset(-17)
  133.         IS.Ie:SetWidth(20)
  134.         IS.Ie:SetHeight(20)
  135.         IS.Ie:SetEvent("OnClick", function(self, event, player,_)
  136.                                         IS.Info:Hide(player)
  137.                                         player:RemoveLuaEvent(IS.Countdowner)
  138.                                         IS.CountD[pGUID] = 30
  139.                                         LCF:RegisterLuaEvent(tostring(player),IS.Countdowner,1000,30, player,IS.Diff,IS.Info)
  140.                                         if IS.pCheck[pGUID][1]==0 then
  141.                                             IS.Ie:SetText("/\\")
  142.                                             IS.Im:SetText("\\/")
  143.                                             IS.Ih:SetText("\\/")
  144.                                             IS.Info:SetHeight(300)
  145.                                             IS.Info:SetYOffset(-113)
  146.                                             IS.IB:SetText("|cFF58FF0A--EASY--|r\n\n\nIf you choose the difficulty\nLevel 'Easy' you will get this:\n\n|cFF58FF0A1xBoss-Loot|r")
  147.                                             IS.pCheck[pGUID][1] = 1
  148.                                             IS.pCheck[pGUID][2] = 0
  149.                                             IS.pCheck[pGUID][3] = 0
  150.                                         else
  151.                                             IS.Ie:SetText("\\/")
  152.                                             IS.IB:SetText("")
  153.                                             IS.Info:SetHeight(75)
  154.                                             IS.Info:SetYOffset(0)
  155.                                             IS.pCheck[pGUID][1] = 0
  156.                                         end
  157.                                         IS.Info:Send(Player)
  158.                                         IS.Diff:Send(Player)
  159.                                     end)
  160.         -------------------------
  161.         IS.Im:SetText("\\/")
  162.         IS.Im:SetXOffset(-10)
  163.         IS.Im:SetYOffset(-17)
  164.         IS.Im:SetWidth(20)
  165.         IS.Im:SetHeight(20)
  166.         IS.Im:SetEvent("OnClick", function(self, event, player,_)
  167.                                         IS.Info:Hide(player)
  168.                                         player:RemoveLuaEvent(IS.Countdowner)
  169.                                         IS.CountD[pGUID] = 30
  170.                                         LCF:RegisterLuaEvent(tostring(player),IS.Countdowner,1000,30, player,IS.Diff,IS.Info)
  171.                                         if IS.pCheck[pGUID][2]==0 then
  172.                                             IS.Ie:SetText("\\/")
  173.                                             IS.Im:SetText("/\\")
  174.                                             IS.Ih:SetText("\\/")
  175.                                             IS.Info:SetHeight(300)
  176.                                             IS.Info:SetYOffset(-113)
  177.                                             IS.IB:SetText("|cFFFF8D0A--MEDIUM--|r\n\n\nIf you choose the difficulty\nLevel 'Medium' you will get this:\n\n|cFFFF8D0A2xBoss-Loot\n1xRandom-Enchantment|r")
  178.                                             IS.pCheck[pGUID][1] = 0
  179.                                             IS.pCheck[pGUID][2] = 1
  180.                                             IS.pCheck[pGUID][3] = 0
  181.                                         else
  182.                                             IS.Im:SetText("\\/")
  183.                                             IS.IB:SetText("")
  184.                                             IS.Info:SetHeight(75)
  185.                                             IS.Info:SetYOffset(0)
  186.                                             IS.pCheck[pGUID][2] = 0
  187.                                         end
  188.                                         IS.Info:Send(Player)
  189.                                         IS.Diff:Send(Player)
  190.                                     end)
  191.         -------------------------
  192.         IS.Ih:SetText("\\/")
  193.         IS.Ih:SetXOffset(80)
  194.         IS.Ih:SetYOffset(-17)
  195.         IS.Ih:SetWidth(20)
  196.         IS.Ih:SetHeight(20)
  197.         IS.Ih:SetEvent("OnClick", function(self, event, player,_)
  198.                                         IS.Info:Hide(player)
  199.                                         player:RemoveLuaEvent(IS.Countdowner)
  200.                                         IS.CountD[pGUID] = 30
  201.                                         LCF:RegisterLuaEvent(tostring(player),IS.Countdowner,1000,30, player,IS.Diff,IS.Info)
  202.                                         if IS.pCheck[pGUID][3]==0 then
  203.                                             IS.Ie:SetText("\\/")
  204.                                             IS.Im:SetText("\\/")
  205.                                             IS.Ih:SetText("/\\")
  206.                                             IS.Info:SetHeight(300)
  207.                                             IS.Info:SetYOffset(-113)
  208.                                             IS.IB:SetText("|cFFFF0000--HARD--|r\n\n\nIf you choose the difficulty\nLevel 'Hard' you will get this:\n\n|cFFFF8D0A2xBoss-Loot\n1xRandom-Enchantment|r\n|cFFFF00001xSecret-Boss|r")
  209.                                             IS.pCheck[pGUID][1] = 0
  210.                                             IS.pCheck[pGUID][2] = 0
  211.                                             IS.pCheck[pGUID][3] = 1
  212.                                         else
  213.                                             IS.Ih:SetText("\\/")
  214.                                             IS.IB:SetText("")
  215.                                             IS.Info:SetHeight(75)
  216.                                             IS.Info:SetYOffset(0)
  217.                                             IS.pCheck[pGUID][3] = 0
  218.                                         end
  219.                                         IS.Info:Send(Player)
  220.                                         IS.Diff:Send(Player)
  221.                                     end)
  222.         -------------------------
  223.         IS.Diff:Send(Player)
  224.         IS.CountD[pGUID] = 30
  225.         LCF:RegisterLuaEvent(tostring(Player),IS.Countdowner,30000,1, Player,IS.Diff,IS.Info)
  226.     end end, 100, 1)
  227. end
  228. function IS.Countdowner(Plr,Diff,Info)
  229.     local pGUID = tostring(Plr:GetGUID())
  230.     IS.CountD[pGUID] = IS.CountD[pGUID]-1
  231.     if IS.CountD[pGUID]==0 then
  232.         for nr,inID in pairs(IS.InstanceIDs) do
  233.             if Plr:GetMapId()==inID then
  234.                 Plr:RemoveAura(59123)
  235.                 Plr:Teleport(-7553.146,-1203.9,478.05,5.317)
  236.                 Diff:Hide(Plr)
  237.                 Info:Hide(Plr)
  238.             end
  239.         end
  240.     end
  241. end
  242.  
  243. RegisterServerHook(4, IS.EnterInstance)
  244.  
  245. for iniint,iniid in pairs(IS.InstanceIDs) do
  246.     RegisterInstanceEvent(iniid, 6, function(InstanceID) IS.InstanceActivated[InstanceID] = true; end)
  247. end
  248.  
  249.  
  250.  
  251.  
  252. function IS.StartSpawning(Player,AreaTriggerID,Difficulty)
  253.     local iID = Player:GetInstanceID()
  254.     IS.Spawned[iID] = {Difficulty}
  255.     local NPC_EASY = nil; local NPC_MEDI = nil; local NPC_HARD = nil; local NPC_DEBUG = nil;
  256.     if Difficulty==1 then
  257.         NPC_EASY = WorldDBQuery("SELECT * FROM instance_spawns WHERE mapid = "..AreaTriggerID.." AND difficulty = 1 OR difficulty = 3 OR difficulty = 5 OR difficulty = 7;")
  258.     elseif Difficulty==2 then
  259.         NPC_MEDI = WorldDBQuery("SELECT * FROM instance_spawns WHERE mapid = "..AreaTriggerID.." AND difficulty = 2 OR difficulty = 3 OR difficulty = 6 OR difficulty = 7;")
  260.     elseif Difficulty==4 then
  261.         NPC_HARD = WorldDBQuery("SELECT * FROM instance_spawns WHERE mapid = "..AreaTriggerID.." AND difficulty = 4 OR difficulty = 5 OR difficulty = 6 OR difficulty = 7;")
  262.     end
  263.     if NPC_EASY and Difficulty==1 then
  264.         IS.Spawning(Player, NPC_EASY, iID)
  265.     elseif NPC_MEDI and Difficulty==2 then
  266.         IS.Spawning(Player, NPC_MEDI, iID)
  267.     elseif NPC_HARD and Difficulty==4 then
  268.         IS.Spawning(Player, NPC_HARD, iID)
  269.     end
  270. end
  271.  
  272. function IS.Spawning(Player, SQL, iID)
  273.     local Group_Version = {}
  274.     repeat
  275.         local grpid = SQL:GetColumn(8):GetULong()
  276.         if Group_Version[grpid]==nil then
  277.             local GVer = WorldDBQuery("SELECT versionid FROM instance_spawns WHERE groupid = "..grpid..";")
  278.             local maxVersion = nil
  279.             repeat
  280.                 local GVnum = GVer:GetColumn(0):GetULong()
  281.                 if maxVersion then
  282.                     if maxVersion<GVnum then
  283.                         maxVersion = GVnum
  284.                     end
  285.                 else
  286.                     maxVersion = GVnum
  287.                 end
  288.             until GVer:NextRow()~=true
  289.             Group_Version[grpid] = math.random(1, maxVersion)
  290.         end
  291.         if Group_Version[grpid]==SQL:GetColumn(9):GetULong() then
  292.             local spwn = Player:SpawnCreature(SQL:GetColumn(1):GetULong(), SQL:GetColumn(3):GetFloat(), SQL:GetColumn(4):GetFloat(), SQL:GetColumn(5):GetFloat(), SQL:GetColumn(6):GetFloat(), SQL:GetColumn(7):GetULong(),0, SQL:GetColumn(10):GetULong(), SQL:GetColumn(11):GetULong(), SQL:GetColumn(12):GetULong(),_,_)
  293.             table.insert(IS.Spawned[iID], {spwn,grpid})
  294.         end
  295.     until SQL:NextRow()~=true
  296. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement