Advertisement
Guest User

lua script

a guest
Sep 27th, 2019
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.54 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. local MyTeleport = "myteleport"-- .myteleport
  15.  
  16. --Getting position
  17. local function getMapDetails(player)
  18.     return player:GetLocation();
  19. end
  20. local function getZoneId(player)
  21.     return player:GetZoneId();
  22. end
  23. local function getMapId(player)
  24.     return player:GetMapId();
  25. end
  26.  
  27. --Checking if player and target are in the same group
  28. --Returns true if they are false otherwise.
  29. local function checkForGroup(player,target)
  30.     if(player:IsInGroup()) then
  31.             local group = player:GetGroup();
  32.             local tarGUID = target:GetGUID();
  33.         if  (group:IsMember(tarGUID)) then
  34.             return true;
  35.         else
  36.             return false;
  37.         end
  38.     else
  39.         return false;
  40.     end
  41. end
  42.  
  43. --Handle .gappear command
  44. local function CmdAppear(player, target)
  45.     if (target:IsAlive()) then
  46.         local x, y, z, o = getMapDetails(target);
  47.         player:Teleport(getMapId(target), x, y, z, o);
  48.         player:SendBroadcastMessage("Appearing at "..target:GetName().."'s location.");
  49.     else
  50.         player:SendBroadcastMessage("Your target must be alive to appear them");
  51.     end
  52. end
  53.  
  54. --Handle .gsummon command
  55. local function CmdSummon(player, target)
  56.     local x, y, z, o = getMapDetails(player);
  57.     player:SummonPlayer(target, getMapId(player), x, y, z, getZoneId(player));
  58.     player:SendBroadcastMessage("Summoning "..target:GetName().." to your location.");
  59. end
  60.  
  61. --Handle .gsummon all command
  62. local function CmdSummon_all(player)
  63.     if(player:IsInGroup()) then
  64.         --Get map details for the summoning player
  65.         local x, y, z, o = getMapDetails(player);
  66.         local plrMapId = getMapId(player);
  67.         local plrZoneId = getZoneId(player);
  68.         --Get the group & each member in group of the player
  69.         local playerGroup = player:GetGroup();
  70.         local groupPlayers = playerGroup:GetMembers();
  71.         player:SendBroadcastMessage("Summoning group to your location");
  72.         for i,v in ipairs(groupPlayers) do
  73.             if(v ~= player) then
  74.                 player:SummonPlayer(v, plrMapId, x, y, z, plrZoneId);
  75.             end
  76.         end
  77.     else
  78.         player:SendBroadcastMessage("You must be in a group.");
  79.     end
  80. end
  81. --Handle #help command
  82. local function CmdHelp(player)
  83.     player:SendBroadcastMessage("The following commands are available to you when you're in a group : ");
  84.     player:SendBroadcastMessage(".gappear ~ Syntax : .gappear [Player Name] ~ appear at target location");
  85.     player:SendBroadcastMessage(".gsummon ~ Syntax : .gsummon [Player Name] ~ summon target to your location");
  86.     player:SendBroadcastMessage(".gsummon all ~ Will summon all group members to your location.");
  87.     player:SendBroadcastMessage(".ghelp ~ Show this help text");
  88. end
  89.  
  90. --Gets the player's target: Either their selection or through text.
  91. --Selection has priority over text.
  92. local function GetTarget(player, msg, lang)
  93.     if (player:GetSelection() ~= nil) then
  94.         local target = player:GetSelection();
  95.         return target;
  96.     elseif (string.len(msg) > 8) then
  97.         local playerName = string.match(msg,"%s(.-)%s*$"); --Match with any text after fisrt space, and trim first space.
  98.         if (playerName == "all") then
  99.             return playerName
  100.         else   
  101.             local target = GetPlayerByName(playerName);
  102.             --print(playerName); Used for Debug
  103.             --print(target);
  104.             return target;
  105.         end
  106.     else
  107.         player:SendBroadcastMessage("You must have a target");
  108.         --print("Fail"); --Debug
  109.         return nil;
  110.     end
  111. end
  112.  
  113. --Handles player event.
  114. local function CmdAction(event, player, msg, lang)
  115.     if  (msg:find(GroupSummon) == 1) then --If typed .gsummon
  116.         local target = GetTarget(player, msg, lang); --Returns Player Obj or string "all"
  117.         if(target == "all") then
  118.             CmdSummon_all(player);
  119.             return false;
  120.         else   
  121.             if(target ~= nil) then --Check for target
  122.                 if (checkForGroup(player, target)) then --Check for group
  123.                     CmdSummon(player, target);
  124.                     return false;
  125.                 else
  126.                     player:SendBroadcastMessage("The target must be in your group!");
  127.                     return false;
  128.                 end
  129.             else
  130.                 return false;
  131.             end
  132.         end
  133.     elseif(msg:find(GroupAppear) == 1) then --If typed .gappear
  134.         local target = GetTarget(player, msg, lang); --Returns Player Obj
  135.         if(target ~= nil) then --Check for target
  136.             if (checkForGroup(player, target)) then
  137.                 CmdAppear(player, target);
  138.                 return false;
  139.             else
  140.                 player:SendBroadcastMessage("The target must be in your group!");
  141.                 return false;
  142.             end
  143.         else
  144.             return false;
  145.         end
  146.     elseif(msg:find(GroupHelp) == 1) then
  147.         CmdHelp(player);
  148.         return false;
  149.     elseif(msg:find(MyTeleport)== 1) then
  150.         player:SendBroadcastMessage("Got Message MyTeleport");
  151.         local x, y, z, o = getMapDetails(player);
  152.         local plrMapId = getMapId(player);
  153.         local plrZoneId = getZoneId(player);
  154.         local player_location = string.format("X:%d,y:%d,z:%d,o:%d,MapID:%d,ZoneID:%d",x,y,z,o,plrMapId,plrZoneId)
  155.         player:SendBroadcastMessage("Player location: " .. player_location);
  156.         local msg_copy = msg       
  157.         local str = string.format("[MyTeleport] Got Message: %s",msg)
  158.         player:SendBroadcastMessage(str);
  159.         local input_x,input_y,map_id = string.match(msg_copy,"myteleport%s(%d+)%s(%d+)%s(%d+)")
  160.         local str2 = string.format( "X:%d,Y:%d,MapID:%d",input_x,input_y,map_id )
  161.         player:SendBroadcastMessage(str2);
  162.         -- player:Teleport(getMapId(target), x, y, z, o);
  163.  
  164.     end    
  165.  
  166. end
  167.  
  168. RegisterPlayerEvent(42, CmdAction) --Upon player use command check for prefix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement