Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------
- -- RunTo
- -- Allows you to send slash commands to other players to be run.
- -- http://www.wowinterface.com/forums/showthread.php?t=48372
- -- Usage examples:
- -- /runto Player-Server print("Hello world!")
- -- /runto Player-Server /dance
- ----------------------------------------------------------------------------
- -- START OF CONFIGURATION
- -- Set this to "false" to see only error messages,
- -- or leave it set to "true" to see all notifications.
- local SHOW_NOTIFICATIONS = true
- -- Add players here in the "Name-Server" format:
- local TRUSTED_SENDERS = {
- ["Somename-Theserver"] = true,
- ["Anothername-Otherserver"] = true,
- }
- -- END OF CONFIGURATION
- ----------------------------------------------------------------------------
- RegisterAddonMessagePrefix("RUN")
- local COLOR_GREEN = "|cff7fff7f"
- local COLOR_RED = "|cffff7f7f"
- local REALM_SUFFIX = "-" .. gsub(GetRealmName(), "%s", "")
- local PLAYER_NAME = UnitName("player") .. REALM_SUFFIX
- local frame = CreateFrame("Frame", "RunTo", UIParent)
- frame:RegisterEvent("CHAT_MSG_ADDON")
- frame:SetScript("OnEvent", function(self, event, prefix, command, _, sender)
- if sender == PLAYER_NAME or prefix ~= "RUN" then return end
- if not strfind(sender, "%-") then
- -- Not actually sure if same-server senders
- -- are shown as just "Name" or not. If they are,
- -- then this line is necessary. If they aren't, then
- -- this line won't hurt anything.
- sender = sender .. REALM_SUFFIX
- end
- -- print(strjoin(" / ", event, prefix, sender, command)) -- #DEBUG
- if not TRUSTED_SENDERS[sender] then
- -- print("Sender not trusted!") -- #DEBUG
- return
- end
- if SHOW_NOTIFICATIONS then
- print(format("Running command %s%s|r from user %s%s|r", COLOR_GREEN, command, COLOR_RED, sender))
- end
- if strsub(command, 1, 1) == "/" then
- ChatFrame1EditBox:SetText(command)
- ChatEdit_SendText(ChatFrame1EditBox)
- return
- end
- local func, err = loadstring(command)
- if err then
- print("Error running command:", err)
- return
- end
- -- print("Running securecall...") -- #DEBUG
- securecall(func)
- end)
- SLASH_RUNTO1 = "/runto"
- SlashCmdList.RUNTO = function(msg)
- local target, command = strsplit(" ", strtrim(msg), 2)
- -- print(strjoin(" / ", "/runto", target or "NO TARGET", command or "NO COMMAND")) -- #DEBUG
- if target and command then
- if SHOW_NOTIFICATIONS then
- print(format("Sending command %s%s|r to user %s%s|r", COLOR_RED, command, COLOR_GREEN, sender))
- end
- if not strfind(target, "%-") then
- target = target .. REALM_SUFFIX
- end
- SendAddonMessage("RUN", command, "WHISPER", target)
- -- print(strjoin(" / ", "SendAddonMessage", "RUN", command, "WHISPER", target)) -- #DEBUG
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement