Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. print("[ElunaGate]: GM Addon loaded!")
  2.  
  3. local GMAddon = {
  4.     Prefix = "GMAddon"
  5. };
  6.  
  7. -- [[OnChat Trigger]]
  8. function GMAddon.OnChat(Event, Player, Message, Type, Language, Misc)
  9.     if (string.lower(Message) == "gmaddon") then
  10.         if (Player:IsGM()) then
  11.             GMAddon.RenderMainMenu(Player)
  12.         else
  13.             Player:SendBroadcastMessage("You do not have the correct permissions to access this addon!")
  14.         end
  15.     end
  16. end
  17.  
  18. RegisterPlayerEvent(18, GMAddon.OnChat)
  19.  
  20. -- [[ MAIN MENU ]]
  21. function GMAddon.RenderMainMenu(Player)
  22.     GMAddon.MainButtons = {
  23.         "Ports",
  24.         "Tickets",
  25.         "Items",
  26.         "Skills",
  27.         "Spells",
  28.         "GameObjects",
  29.         "NPCs",
  30.         "Players",
  31.         "Pets",
  32.         "Communication",
  33.         "Ban",
  34.         "Server",
  35.         "Overrides",
  36.         "Modify",
  37.     };
  38.  
  39.     local YOffset = 320
  40.     local Frame = CreateFrame(GMAddon.Prefix.."MainFrame")
  41.    
  42.     Frame:SetText("ElunaGate GM")
  43.     Frame:SetCantMove(false)
  44.     Frame:SetHeight(YOffset)
  45.     Frame:SetWidth(150)
  46.    
  47.     for k, v in pairs(GMAddon.MainButtons) do
  48.         local Button = Frame:CreateButton(GMAddon.Prefix..v)
  49.         Button:SetText(v)
  50.         Button:SetHeight(15)           
  51.         Button:SetWidth(130)
  52.         Button:SetYOffset(YOffset-200)
  53.         Button:SetXOffset(2)
  54.        
  55.         Button:SetEvent("OnClick", function(self, event, Player)
  56.                 GMAddon.RenderSubMenu(Player, v)
  57.                 Frame:Hide(Player)
  58.             end
  59.         )
  60.        
  61.         YOffset = YOffset - 20
  62.     end
  63.    
  64.     Frame:Send(Player)
  65. end
  66.  
  67. function GMAddon.RenderSubMenu(Player, Type)
  68.     -- [[ PORTS MENU ]]
  69.     GMAddon.Ports = {
  70.         Height = 320,
  71.         Width = 150,
  72.         Buttons = {
  73.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  74.             {"PortButton", "Port To", 15, 120, 100, 0},
  75.             {"SummonButton", "Summon", 15, 120, 60, 0},
  76.             {"AppearButton", "Appear", 15, 120, 40, 0},
  77.             {"WPPlayerButton", "Port Player", 15, 120, -60, 0},
  78.             {"WPSelfButton", "Port Self", 15, 120, -80, 0},
  79.             {"GetCoordButton", "Get Coords", 15, 120, -100, 0},
  80.             {"BackButton", "Back", 15, 100, -135, 0},
  81.         },
  82.         EditBoxes = {
  83.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  84.             {"PortName", "Input port name here.", 15, 100, 120, 3},
  85.             {"PlayerName", "Input Player name here.", 15, 100, 80, 3},
  86.             {"MapId", "Input Map ID here.", 15, 100, 20, 3},
  87.             {"XCoord", "Input X Coordinate here.", 15, 100, 0, 3},
  88.             {"YCoord", "Input Y Coordinate here.", 15, 100, -20, 3},
  89.             {"ZCoord", "Input Z Coordinate here.", 15, 100, -40, 3},
  90.         },
  91.         TextBoxes = {
  92.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight
  93.         },
  94.         StatusLinks = {
  95.          -- {"EditBoxName", "ButtonName"}
  96.             {"PortName", "PortButton"},
  97.             {"PlayerName", "SummonButton"},
  98.             {"PlayerName", "AppearButton"},
  99.             {"PlayerName", "WPPlayerButton"},
  100.             {"MapId", "WPPlayerButton"},
  101.             {"XCoord", "WPPlayerButton"},
  102.             {"YCoord", "WPPlayerButton"},
  103.             {"ZCoord", "WPPlayerButton"},
  104.             {"MapId", "WPSelfButton"},
  105.             {"XCoord", "WPSelfButton"},
  106.             {"YCoord", "WPSelfButton"},
  107.             {"ZCoord", "WPSelfButton"},
  108.         };
  109.     }
  110.    
  111.     -- [[ TICKETS MENU ]]
  112.     GMAddon.Tickets = {
  113.         Height = 360,
  114.         Width = 360,
  115.         Buttons = {
  116.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  117.             {"BackButton", "Back", 15, 100, -160, 0},
  118.             {"NextPageButton", ">", 25, 25, -130, 75},
  119.             {"PreviousPageButton", "<", 25, 25, -130, -75},
  120.         },
  121.         EditBoxes = {
  122.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  123.         },
  124.         TextBoxes = {
  125.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  126.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  127.             {"NumberTab", "#", 15, 100, 130, -130, 12},
  128.             {"NameTab", "Name", 15, 100, 130, -90, 12},
  129.             {"LocationTab", "Location", 15, 100, 130, 50, 12},
  130.         },
  131.         StatusLinks = {
  132.          -- {"EditBoxName", "ButtonName"}
  133.         };
  134.     }
  135.    
  136.     GMAddon.Items = {
  137.         Height = 320,
  138.         Width = 150,
  139.         Buttons = {
  140.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  141.             {"BackButton", "Back", 15, 100, -135, 0},
  142.         },
  143.         EditBoxes = {
  144.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  145.         },
  146.         TextBoxes = {
  147.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  148.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  149.         },
  150.         StatusLinks = {
  151.          -- {"EditBoxName", "ButtonName"}
  152.         };
  153.     }
  154.    
  155.     GMAddon.Skills = {
  156.         Height = 320,
  157.         Width = 150,
  158.         Buttons = {
  159.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  160.             {"BackButton", "Back", 15, 100, -135, 0},
  161.         },
  162.         EditBoxes = {
  163.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  164.         },
  165.         TextBoxes = {
  166.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  167.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  168.         },
  169.         StatusLinks = {
  170.          -- {"EditBoxName", "ButtonName"}
  171.         };
  172.     }
  173.    
  174.     GMAddon.Spells = {
  175.         Height = 320,
  176.         Width = 150,
  177.         Buttons = {
  178.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  179.             {"BackButton", "Back", 15, 100, -135, 0},
  180.         },
  181.         EditBoxes = {
  182.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  183.         },
  184.         TextBoxes = {
  185.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  186.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  187.         },
  188.         StatusLinks = {
  189.          -- {"EditBoxName", "ButtonName"}
  190.         };
  191.     }
  192.    
  193.     GMAddon.GameObjects = {
  194.         Height = 320,
  195.         Width = 150,
  196.         Buttons = {
  197.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  198.             {"BackButton", "Back", 15, 100, -135, 0},
  199.         },
  200.         EditBoxes = {
  201.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  202.         },
  203.         TextBoxes = {
  204.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  205.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  206.         },
  207.         StatusLinks = {
  208.          -- {"EditBoxName", "ButtonName"}
  209.         };
  210.     }
  211.    
  212.     GMAddon.NPCs = {
  213.         Height = 320,
  214.         Width = 150,
  215.         Buttons = {
  216.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  217.             {"BackButton", "Back", 15, 100, -135, 0},
  218.         },
  219.         EditBoxes = {
  220.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  221.         },
  222.         TextBoxes = {
  223.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  224.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  225.         },
  226.         StatusLinks = {
  227.          -- {"EditBoxName", "ButtonName"}
  228.         };
  229.     }
  230.    
  231.     GMAddon.Players = {
  232.         Height = 320,
  233.         Width = 150,
  234.         Buttons = {
  235.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  236.             {"BackButton", "Back", 15, 100, -135, 0},
  237.         },
  238.         EditBoxes = {
  239.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  240.         },
  241.         TextBoxes = {
  242.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  243.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  244.         },
  245.         StatusLinks = {
  246.          -- {"EditBoxName", "ButtonName"}
  247.         };
  248.     }
  249.    
  250.     GMAddon.Pets = {
  251.         Height = 320,
  252.         Width = 150,
  253.         Buttons = {
  254.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  255.             {"BackButton", "Back", 15, 100, -135, 0},
  256.         },
  257.         EditBoxes = {
  258.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  259.         },
  260.         TextBoxes = {
  261.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  262.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  263.         },
  264.         StatusLinks = {
  265.          -- {"EditBoxName", "ButtonName"}
  266.         };
  267.     }
  268.    
  269.     GMAddon.Communication = {
  270.         Height = 320,
  271.         Width = 150,
  272.         Buttons = {
  273.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  274.             {"BackButton", "Back", 15, 100, -135, 0},
  275.         },
  276.         EditBoxes = {
  277.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  278.         },
  279.         TextBoxes = {
  280.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  281.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  282.         },
  283.         StatusLinks = {
  284.          -- {"EditBoxName", "ButtonName"}
  285.         };
  286.     }
  287.    
  288.     GMAddon.Ban = {
  289.         Height = 320,
  290.         Width = 150,
  291.         Buttons = {
  292.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  293.             {"BackButton", "Back", 15, 100, -135, 0},
  294.         },
  295.         EditBoxes = {
  296.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  297.         },
  298.         TextBoxes = {
  299.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  300.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  301.         },
  302.         StatusLinks = {
  303.          -- {"EditBoxName", "ButtonName"}
  304.         };
  305.     }
  306.    
  307.     GMAddon.Server = {
  308.         Height = 320,
  309.         Width = 150,
  310.         Buttons = {
  311.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  312.             {"BackButton", "Back", 15, 100, -135, 0},
  313.         },
  314.         EditBoxes = {
  315.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  316.         },
  317.         TextBoxes = {
  318.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  319.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  320.         },
  321.         StatusLinks = {
  322.          -- {"EditBoxName", "ButtonName"}
  323.         };
  324.     }
  325.    
  326.     GMAddon.Overrides = {
  327.         Height = 320,
  328.         Width = 150,
  329.         Buttons = {
  330.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  331.             {"BackButton", "Back", 15, 100, -135, 0},
  332.         },
  333.         EditBoxes = {
  334.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  335.         },
  336.         TextBoxes = {
  337.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  338.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  339.         },
  340.         StatusLinks = {
  341.          -- {"EditBoxName", "ButtonName"}
  342.         };
  343.     }
  344.    
  345.     GMAddon.Modify = {
  346.         Height = 320,
  347.         Width = 150,
  348.         Buttons = {
  349.          -- {"ButtonName", "ButtonText", Height, Width, YOffset, XOffset}
  350.             {"BackButton", "Back", 15, 100, -135, 0},
  351.         },
  352.         EditBoxes = {
  353.          -- {"EditBoxName", "HoverText", Height, Width, YOffset, XOffset}
  354.         },
  355.         TextBoxes = {
  356.          -- {"TextBoxName", "Text", Height, Width, YOffset, XOffset, TextHeight}
  357.             {"WIP", "WORK IN PROGRESS!", 15, 200, 0, 0, 12},
  358.         },
  359.         StatusLinks = {
  360.          -- {"EditBoxName", "ButtonName"}
  361.         };
  362.     }
  363.    
  364.     if GMAddon[Type] == nil then
  365.         Player:SendBroadcastMessage("The "..Type.." button has not yet been coded!")
  366.         return
  367.     else
  368.         -- [[ RENDER WINDOW ]]
  369.         local Frame = CreateFrame(GMAddon.Prefix..Type.."SelectFrame")
  370.        
  371.         Frame:SetText(Type)
  372.         Frame:SetCantMove(false)
  373.         Frame:SetHeight(GMAddon[Type]["Height"])
  374.         Frame:SetWidth(GMAddon[Type]["Width"])
  375.        
  376.         -- [[ RENDER BUTTONS ]]
  377.         for k, v in pairs(GMAddon[Type]["Buttons"]) do
  378.             if Button then
  379.                 print("True")
  380.             end
  381.             local Button = Frame:CreateButton(GMAddon.Prefix..Type..v[1])
  382.            
  383.             Button:SetText(v[2])
  384.             Button:SetHeight(v[3])
  385.             Button:SetWidth(v[4])
  386.             Button:SetYOffset(v[5])
  387.             Button:SetXOffset(v[6])
  388.            
  389.             -- [[ HANDLE ONCLICK EVENT ]]
  390.             Button:SetEvent("OnClick", function(self, event, Player, Cache)
  391.                 GMAddon.HandleOnClick(Player, Type, Frame, v[1], Cache, Button)
  392.             end)
  393.         end
  394.        
  395.         -- [[ RENDER TEXT BOXES ]]
  396.         for k, v in pairs(GMAddon[Type]["TextBoxes"]) do
  397.             local TextBox = Frame:CreateTextBox(GMAddon.Prefix..Type..v[1])
  398.            
  399.             TextBox:SetText(v[2])
  400.             TextBox:SetHeight(v[3])
  401.             TextBox:SetWidth(v[4])
  402.             TextBox:SetYOffset(v[5])
  403.             TextBox:SetXOffset(v[6])
  404.             TextBox:SetTextHeight(v[7])
  405.         end
  406.        
  407.         -- [[ RENDER EDIT BOXES ]]
  408.         for k, v in pairs(GMAddon[Type]["EditBoxes"]) do
  409.             local EditBox = Frame:CreateEditBox(GMAddon.Prefix..Type..v[1])
  410.            
  411.             EditBox:SetTooltip(v[2])
  412.             EditBox:SetHeight(v[3])
  413.             EditBox:SetWidth(v[4])
  414.             EditBox:SetYOffset(v[5])
  415.             EditBox:SetXOffset(v[6])
  416.        
  417.             -- [[ CREATE STATUSLINK ]]
  418.             for key, link in pairs(GMAddon[Type]["StatusLinks"]) do
  419.                 if(v[1] == link[1]) then
  420.                     EditBox:SetStatusLink(GMAddon.Prefix..Type..link[2])
  421.                 end
  422.             end
  423.         end
  424.        
  425.         Frame:Send(Player)
  426.     end
  427. end
  428.  
  429. function GMAddon.HandleOnClick(Player, Type, Frame, Button, Cache)
  430.     if(Type == "Ports") then
  431.         if(Button == "PortButton") then
  432.             -- TODO: Implement tele to name
  433.             Player:SendBroadcastMessage("This feature is currently not coded.")
  434.         elseif(Button == "SummonButton" or Button == "AppearButton") then
  435.             local PlayerNameBox = Cache[3]
  436.            
  437.             if(PlayerNameBox == nil) then
  438.                 Player:SendBroadcastMessage("Please enter a player name to use this feature.")
  439.                 return;
  440.             end
  441.            
  442.             local SelectedPlayer = GetPlayerByName(PlayerNameBox)
  443.            
  444.             if not SelectedPlayer then
  445.                 Player:SendBroadcastMessage(PlayerNameBox.." is currently not in game.")
  446.                 return;
  447.             end
  448.            
  449.             if(Button == "SummonButton") then
  450.                 -- [[ HANDLE SUMMON CODE ]]
  451.                 SelectedPlayer:Teleport(Player:GetMapId(), Player:GetX(), Player:GetY(), Player:GetZ(), Player:GetO())
  452.                 Player:SendBroadcastMessage("Summoning "..PlayerNameBox..".")
  453.             else
  454.                 -- [[ HANDLE APPEAR CODE ]]
  455.                 Player:Teleport(SelectedPlayer:GetMapId(), SelectedPlayer:GetX(), SelectedPlayer:GetY(), SelectedPlayer:GetZ(), SelectedPlayer:GetO())
  456.                 Player:SendBroadcastMessage("Appearing to "..PlayerNameBox..".")
  457.             end
  458.         elseif(Button == "WPPlayerButton") then
  459.             GMAddon.Temp = {};
  460.            
  461.             -- Handle stupid dynamic cache table...
  462.             for k, v in pairs(Cache) do
  463.                 if v == "GMAddonPortsMapId" then
  464.                     GMAddon.Temp["MapId"] = tonumber(Cache[k+1])
  465.                 elseif v == "GMAddonPortsXCoord" then
  466.                     GMAddon.Temp["X"] = tonumber(Cache[k+1])
  467.                 elseif v == "GMAddonPortsYCoord" then
  468.                     GMAddon.Temp["Y"] = tonumber(Cache[k+1])
  469.                 elseif v == "GMAddonPortsZCoord" then
  470.                     GMAddon.Temp["Z"] = tonumber(Cache[k+1])
  471.                 elseif v == "GMAddonPortsPlayerName" then
  472.                     GMAddon.Temp["PlayerName"] = Cache[k+1]
  473.                 end
  474.             end
  475.            
  476.             local Map, X, Y, Z = GMAddon.Temp["MapId"], GMAddon.Temp["X"], GMAddon.Temp["Y"], GMAddon.Temp["Z"]
  477.            
  478.             if(#Cache < 11) then
  479.                 Player:SendBroadcastMessage("All fields (Player name and coordinates) must be filled out to teleport a player!")
  480.             else
  481.                 local SelectedPlayer = GetPlayerByName(GMAddon.Temp["PlayerName"])
  482.                
  483.                 if not SelectedPlayer or SelectedPlayer == nil then
  484.                     Player:SendBroadcastMessage(GMAddon.Temp["PlayerName"].." is currently not in game.")
  485.                 elseif Map == nil or X == nil or Y == nil or Z == nil then
  486.                     Player:SendBroadcastMessage("Your coordinates are incorrect values.")
  487.                 else
  488.                     SelectedPlayer:Teleport(Map, X, Y, Z, 0)
  489.                     Player:SendBroadcastMessage("Teleporting "..GMAddon.Temp["PlayerName"].." to coordinates: "..Map.." "..X.." "..Y.." "..Z..".")
  490.                 end
  491.             end
  492.            
  493.             GMAddon.Temp = nil;
  494.         elseif(Button == "WPSelfButton") then
  495.             GMAddon.Temp = {};
  496.            
  497.             -- Handle stupid dynamic cache table...
  498.             for k, v in pairs(Cache) do
  499.                 if v == "GMAddonPortsMapId" then
  500.                     GMAddon.Temp["MapId"] = tonumber(Cache[k+1])
  501.                 elseif v == "GMAddonPortsXCoord" then
  502.                     GMAddon.Temp["X"] = tonumber(Cache[k+1])
  503.                 elseif v == "GMAddonPortsYCoord" then
  504.                     GMAddon.Temp["Y"] = tonumber(Cache[k+1])
  505.                 elseif v == "GMAddonPortsZCoord" then
  506.                     GMAddon.Temp["Z"] = tonumber(Cache[k+1])
  507.                 end
  508.             end
  509.            
  510.             local Map, X, Y, Z = GMAddon.Temp["MapId"], GMAddon.Temp["X"], GMAddon.Temp["Y"], GMAddon.Temp["Z"]
  511.            
  512.             if(#Cache < 9) then
  513.                 Player:SendBroadcastMessage("All coordinate fields must be filled out to teleport!")
  514.             else
  515.                 if Map == nil or X == nil or Y == nil or Z == nil then
  516.                     Player:SendBroadcastMessage("Your coordinates are incorrect values.")
  517.                 else
  518.                     Player:Teleport(Map, X, Y, Z, 0)
  519.                     Player:SendBroadcastMessage("Teleporting to coordinates: "..Map.." "..X.." "..Y.." "..Z..".")
  520.                 end
  521.             end
  522.            
  523.             GMAddon.Temp = nil;
  524.         elseif(Button == "GetCoordButton") then
  525.             Player:SendBroadcastMessage("Map: "..Player:GetMapId().." X Coord: "..Player:GetX().." Y Coord: "..Player:GetY().." Z Coord: "..Player:GetZ().." Orientation: "..Player:GetO())
  526.         end
  527.     end
  528.    
  529.     if(Button == "BackButton") then
  530.         GMAddon.RenderMainMenu(Player)
  531.         Frame:Hide(Player)
  532.     end
  533. end