Advertisement
Guest User

RunTo v3

a guest
Nov 5th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. ----------------------------------------------------------------------------
  2. -- RunTo
  3. -- Allows you to send slash commands to other players to be run.
  4. -- http://www.wowinterface.com/forums/showthread.php?t=48372
  5. -- Usage examples:
  6. --    /runto Player-Server print("Hello world!")
  7. --    /runto Player-Server /dance
  8. ----------------------------------------------------------------------------
  9. -- START OF CONFIGURATION
  10.  
  11. -- Set this to "false" to see only error messages,
  12. -- or leave it set to "true" to see all notifications.
  13.  
  14. local SHOW_NOTIFICATIONS = true
  15.  
  16. -- Add players here in the "Name-Server" format:
  17.  
  18. local TRUSTED_SENDERS = {
  19.     ["Somename-Theserver"] = true,
  20.     ["Anothername-Otherserver"] = true,
  21. }
  22.  
  23. -- END OF CONFIGURATION
  24. ----------------------------------------------------------------------------
  25.  
  26. RegisterAddonMessagePrefix("RUN")
  27.  
  28. local COLOR_GREEN = "|cff7fff7f"
  29. local COLOR_RED   = "|cffff7f7f"
  30.  
  31. local REALM_SUFFIX = "-" .. gsub(GetRealmName(), "%s", "")
  32. local PLAYER_NAME = UnitName("player") .. REALM_SUFFIX
  33.  
  34. local frame = CreateFrame("Frame", "RunTo", UIParent)
  35. frame:RegisterEvent("CHAT_MSG_ADDON")
  36. frame:SetScript("OnEvent", function(self, event, prefix, command, _, sender)
  37.     if sender == PLAYER_NAME or prefix ~= "RUN" then return end
  38.     if not strfind(sender, "%-") then
  39.         -- Not actually sure if same-server senders
  40.         -- are shown as just "Name" or not. If they are,
  41.         -- then this line is necessary. If they aren't, then
  42.         -- this line won't hurt anything.
  43.         sender = sender .. REALM_SUFFIX
  44.     end
  45.     -- print(strjoin(" / ", event, prefix, sender, command)) -- #DEBUG
  46.     if not TRUSTED_SENDERS[sender] then
  47.         -- print("Sender not trusted!") -- #DEBUG
  48.         return
  49.     end
  50.     if SHOW_NOTIFICATIONS then
  51.         print(format("Running command %s%s|r from user %s%s|r", COLOR_GREEN, command, COLOR_RED, sender))
  52.     end
  53.     if strsub(command, 1, 1) == "/" then
  54.         ChatFrame1EditBox:SetText(command)
  55.         ChatEdit_SendText(ChatFrame1EditBox)
  56.         return
  57.     end
  58.     local func, err = loadstring(command)
  59.     if err then
  60.         print("Error running command:", err)
  61.         return
  62.     end
  63.     -- print("Running securecall...") -- #DEBUG
  64.     securecall(func)
  65. end)
  66.  
  67. SLASH_RUNTO1 = "/runto"
  68. SlashCmdList.RUNTO = function(msg)
  69.     local target, command = strsplit(" ", strtrim(msg), 2)
  70.     -- print(strjoin(" / ", "/runto", target or "NO TARGET", command or "NO COMMAND")) -- #DEBUG
  71.     if target and command then
  72.         if SHOW_NOTIFICATIONS then
  73.             print(format("Sending command %s%s|r to user %s%s|r", COLOR_RED, command, COLOR_GREEN, sender))
  74.         end
  75.         if not strfind(target, "%-") then
  76.             target = target .. REALM_SUFFIX
  77.         end
  78.         SendAddonMessage("RUN", command, "WHISPER", target)
  79.         -- print(strjoin(" / ", "SendAddonMessage", "RUN", command, "WHISPER", target)) -- #DEBUG
  80.     end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement