This repository was archived by the owner on Apr 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmsg.lua
More file actions
66 lines (54 loc) · 2.1 KB
/
msg.lua
File metadata and controls
66 lines (54 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local lastMessaged = {} -- Store the last person messaged for /r (using UUIDs)
-- Function to send a private message
local function sendPrivateMessage(sender, target, message)
-- Check if the target player is online
local targetPlayer = script.getServer():getPlayer(target)
if targetPlayer then
-- Send the message to the target
targetPlayer:sendRichMessage("<gray>[From " .. sender:getName() .. "]: <reset>" .. message)
sender:sendRichMessage("<gray>[To " .. targetPlayer:getName() .. "]: <reset>" .. message)
-- Update last messaged players for both sender and target (using UUIDs)
lastMessaged[sender:getUniqueId()] = targetPlayer:getUniqueId()
lastMessaged[targetPlayer:getUniqueId()] = sender:getUniqueId()
else
sender:sendRichMessage("<red>Player not found or is not online: " .. tostring(target))
end
end
-- Register the /msg command
script.registerSimpleCommand(function(sender, args)
if #args < 2 then
sender:sendRichMessage("<red>Usage: /msg <player> <message>")
return
end
local target = args[1]
table.remove(args, 1) -- Remove the target from the args
local message = table.concat(args, " ")
sendPrivateMessage(sender, target, message)
end, {
name = "msg",
description = "Send a private message to a player",
usage = "/msg <player> <message>"
})
-- Register the /r command
script.registerSimpleCommand(function(sender, args)
local lastTargetUUID = lastMessaged[sender:getUniqueId()]
if not lastTargetUUID then
sender:sendRichMessage("<red>No player to reply to.")
return
end
local lastTarget = script.getServer():getPlayer(lastTargetUUID)
if not lastTarget then
sender:sendRichMessage("<red>Player not found.")
return
end
if #args < 1 then
sender:sendRichMessage("<red>Usage: /r <message>")
return
end
local message = table.concat(args, " ")
sendPrivateMessage(sender, lastTarget:getName(), message)
end, {
name = "r",
description = "Reply to the last player messaged",
usage = "/r <message>"
})