Advertisement
XtremeGX

GrpCmds

Aug 14th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.72 KB | None | 0 0
  1. --[[
  2. Author : Jafferwaffer
  3. Core : Trinity Core with Eluna 3.3.5a (Latest Rev)
  4. Script name : GroupCmds
  5. Huge thanks to the Emu Devs, especially Rochet2 for great support!
  6. Please ask if you wish to repost by PM on emudevs.com
  7. Also PM with any bugs.
  8. Thank you, enjoy!
  9. ]]
  10.  
  11. local GroupSummon = "gsummon" -- .gsummon
  12. local GroupAppear = "gappear" -- .gappear
  13. local GroupHelp = "ghelp" -- .ghelp
  14.  
  15. --Getting position
  16. local function getMapDetails(player)
  17.     return player:GetLocation();
  18. end
  19. local function getZoneId(player)
  20.     return player:GetZoneId();
  21. end
  22. local function getMapId(player)
  23.     return player:GetMapId();
  24. end
  25.  
  26. --Checking if player and target are in the same group
  27. --Returns true if they are false otherwise.
  28. local function checkForGroup(player,target)
  29.     if(player:IsInGroup()) then
  30.             local group = player:GetGroup();
  31.             local tarGUID = target:GetGUID();
  32.         if  (group:IsMember(tarGUID)) then
  33.             return true;
  34.         else
  35.             return false;
  36.         end
  37.     else
  38.         return false;
  39.     end
  40. end
  41.  
  42. --Handle .gappear command
  43. local function CmdAppear(player, target)
  44.     if (target:IsAlive()) then
  45.         local x, y, z, o = getMapDetails(target);
  46.         player:Teleport(getMapId(target), x, y, z, o);
  47.         player:SendBroadcastMessage("Appearing at "..target:GetName().."'s location.");
  48.     else
  49.         player:SendBroadcastMessage("Your target must be alive to appear them");
  50.     end
  51. end
  52.  
  53. --Handle .gsummon command
  54. local function CmdSummon(player, target)
  55.     local x, y, z, o = getMapDetails(player);
  56.     player:SummonPlayer(target, getMapId(player), x, y, z, getZoneId(player));
  57.     player:SendBroadcastMessage("Summoning "..target:GetName().." to your location.");
  58. end
  59.  
  60. --Handle .gsummon all command
  61. local function CmdSummon_all(player)
  62.     if(player:IsInGroup()) then
  63.         --Get map details for the summoning player
  64.         local x, y, z, o = getMapDetails(player);
  65.         local plrMapId = getMapId(player);
  66.         local plrZoneId = getZoneId(player);
  67.         --Get the group & each member in group of the player
  68.         local playerGroup = player:GetGroup();
  69.         local groupPlayers = playerGroup:GetMembers();
  70.         player:SendBroadcastMessage("Summoning group to your location");
  71.         for i,v in ipairs(groupPlayers) do
  72.             if(v ~= player) then
  73.                 player:SummonPlayer(v, plrMapId, x, y, z, plrZoneId);
  74.             end
  75.         end
  76.     else
  77.         player:SendBroadcastMessage("You must be in a group.");
  78.     end
  79. end
  80. --Handle #help command
  81. local function CmdHelp(player)
  82.     player:SendBroadcastMessage("The following commands are available to you when you're in a group : ");
  83.     player:SendBroadcastMessage(".gappear ~ Syntax : .gappear [Player Name] ~ appear at target location");
  84.     player:SendBroadcastMessage(".gsummon ~ Syntax : .gsummon [Player Name] ~ summon target to your location");
  85.     player:SendBroadcastMessage(".gsummon all ~ Will summon all group members to your location.");
  86.     player:SendBroadcastMessage(".ghelp ~ Show this help text");
  87. end
  88.  
  89. --Gets the player's target: Either their selection or through text.
  90. --Selection has priority over text.
  91. local function GetTarget(player, msg, lang)
  92.     if (player:GetSelection() ~= nil) then
  93.         local target = player:GetSelection();
  94.         return target;
  95.     elseif (string.len(msg) > 8) then
  96.         local playerName = string.match(msg,"%s(.-)%s*$"); --Match with any text after fisrt space, and trim first space.
  97.         if (playerName == "all") then
  98.             return playerName
  99.         else   
  100.             local target = GetPlayerByName(playerName);
  101.             --print(playerName); Used for Debug
  102.             --print(target);
  103.             return target;
  104.         end
  105.     else
  106.         player:SendBroadcastMessage("You must have a target");
  107.         --print("Fail"); --Debug
  108.         return nil;
  109.     end
  110. end
  111.  
  112. --Handles player event.
  113. local function CmdAction(event, player, msg, lang)
  114.     if  (msg:find(GroupSummon) == 1) then --If typed .gsummon
  115.         local target = GetTarget(player, msg, lang); --Returns Player Obj or string "all"
  116.         if(target == "all") then
  117.             CmdSummon_all(player);
  118.             return false;
  119.         else   
  120.             if(target ~= nil) then --Check for target
  121.                 if (checkForGroup(player, target)) then --Check for group
  122.                     CmdSummon(player, target);
  123.                     return false;
  124.                 else
  125.                     player:SendBroadcastMessage("The target must be in your group!");
  126.                     return false;
  127.                 end
  128.             else
  129.                 return false;
  130.             end
  131.         end
  132.     elseif(msg:find(GroupAppear) == 1) then --If typed .gappear
  133.         local target = GetTarget(player, msg, lang); --Returns Player Obj
  134.         if(target ~= nil) then --Check for target
  135.             if (checkForGroup(player, target)) then
  136.                 CmdAppear(player, target);
  137.                 return false;
  138.             else
  139.                 player:SendBroadcastMessage("The target must be in your group!");
  140.                 return false;
  141.             end
  142.         else
  143.             return false;
  144.         end
  145.     elseif(msg:find(GroupHelp) == 1) then
  146.         CmdHelp(player);
  147.         return false;
  148.     end    
  149.  
  150. end
  151.  
  152. RegisterPlayerEvent(42, CmdAction) --Upon player use command check for prefix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement