-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsms.lua
More file actions
192 lines (191 loc) · 6.12 KB
/
sms.lua
File metadata and controls
192 lines (191 loc) · 6.12 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
-- Short Message Script
--[[
Inbox message limit: 15
Commands:
!sms - Shows SMS panel
!sms [name] - Shows a popup to type message
!sms [name] message - Sends message to name
!mute [name] - Mutes the player, the player you specified can't send you message
!unmute [name] - Unmutes the player
!fsms [sender] [name] message - Sends fake message
Use or make your own isAdmin and trans functions
]]
langs={
EN={
smsPanel='<R><b><a href="event:close">^</a></b> <J>You have <BL><b>%i</b><G>/<R><b>%i</b> <J>messages in your inbox. <R><a href="event:inbox"><b>[Inbox]</b></a>%s',
smsSuccess='<V>Your message has been sent!',
smsFail='<R>The player could not be found!',
smsFail2="<R>The player's inbox is full!",
smsLimit='<R>Your inbox is full!',
smsMute="<V>%s <J>is ignored!",
smsUnmute='<V>%s <J>is unignored!',
smsFakeMsgOk='<V>Fake message has been sent!',
smsPopup='Message',
smsInbox='<R><b><a href="event:close">^</a></b> <J>Inbox<V>',
smsInboxEmpty='<V>Empty',
smsInfo=[[<R><p align="right"><b><a href="event:close">X</a></b></p><V><b>Sender:</b> <N>%s
<V><b>Date:</b> <N>%s
<V><b>Message</b><J>
%s
<V><p align="center"><b><a href="event:smsr%s">Answer</a></b>]]
},
TR={
smsPanel='<R><b><a href="event:close">^</a></b> <J>Gelen kutunuzda <BL><b>%i</b><G>/<R><b>%i</b> <J>mesajınız bulunmakta. <R><a href="event:inbox"><b>[Gelen Kutusu]</b></a>%s',
smsSuccess='<V>Mesajınız alıcıya teslim edildi!',
smsFail='<R>Oyuncu bulunamadı!',
smsFail2='<R>Oyuncunun gelen kutusu dolu!',
smsLimit='<R>Gelen kutunuz doldu!',
smsMute='<V>%s <J>engellendi!',
smsUnmute='<V>%s <J>engeli kaldırıldı!',
smsFakeMsgOk='<V>Sahte mesaj gönderildi!',
smsPopup='Mesaj',
smsInbox='<R><b><a href="event:close">^</a></b> <J>Gelen Kutusu<V>',
smsInboxEmpty='<V>Boş',
smsInfo=[[<R><p align="right"><b><a href="event:close">X</a></b></p><V><b>Gönderen:</b> <N>%s
<V><b>Tarih:</b> <N>%s
<V><b>Mesaj</b><J>
%s
<V><p align="center"><b><a href="event:smsr%s">Cevapla</a></b>]]
},
}
players={}
function init()
for name in pairs(tfm.get.room.playerList) do
eventNewPlayer(name)
end
for _,c in pairs({'sms','fsms'}) do
system.disableChatCommandDisplay(c, true)
end
end
function eventNewPlayer(name)
if not _get(players, name) then
_set(players, name, {muteList={}, msgs={}, msgc=0})
end
end
function eventChatCommand(name, cmd)
local args = {}
for a in cmd:gmatch('%S+') do args[#args+1] = a end
local pInfo = _get(players,name)
if 'sms' == args[1] then
if args[2] then
local receiver, msg = args[2], cmd:sub(#args[2]+6)
if #msg > 0 then
local rInfo = _get(players, receiver)
if rInfo then
if _get(rInfo.muteList, name) then
updateMsgUI(name, trans('smsFail2',name))
elseif #rInfo.msgs > 14 then
updateMsgUI(name, trans('smsFail2',name))
updateMsgUI(receiver, trans('smsLimit',receiver))
else
table.insert(rInfo.msgs, {time=os.date(), sender=name, msg=isAdmin(name) and msg or smsFilter(msg)})
rInfo.msgc = rInfo.msgc+1
updateMsgUI(name, trans('smsSuccess',name))
updateMsgUI(receiver)
end
else
updateMsgUI(name, trans('smsFail',name))
end
else
pInfo.smsr = receiver
ui.addPopup(8787, 2, trans('smsPopup',name), name, 300, 100, 200, true)
end
else
updateMsgUI(name)
end
elseif 'mute ' == cmd:sub(1,5) then
local who = cmd:sub(6):lower()
pInfo.muteList[who] = 1
updateMsgUI(name, trans('smsMute',name):format(smsFilter(who)))
elseif 'unmute ' == cmd:sub(1,7) then
local who = cmd:sub(8)
_set(pInfo.muteList, who, nil)
updateMsgUI(name, trans('smsUnmute',name):format(smsFilter(who)))
elseif isAdmin(name) then
if 'fsms ' == cmd:sub(1,5) then
local sender,msg = cmd:match('fsms (%S+) (.+)')
if sender and msg then
eventChatCommand(sender, 'sms '..msg)
updateMsgUI(name, trans('smsFakeMsgOk',name))
end
end
end
end
function eventPopupAnswer(ID, name, answer)
if ID == 8787 then
local pInfo = _get(players, name)
if pInfo and pInfo.smsr and #answer > 0 then
eventChatCommand(name, 'sms '..pInfo.smsr..' '..answer)
end
end
end
function eventTextAreaCallback(ID,name,event)
if event == 'close' then
ui.removeTextArea(ID, name)
else
local pInfo = _get(players, name)
if pInfo then
if event == 'inbox' then
ui.addTextArea(8778, '', name, 450, 20, 330, nil, 1, 0, 0.7, true)
updateMsgUI(name)
elseif 'smsd' == event:sub(1,4) then
local smsID = tonumber(event:sub(5))
if pInfo.msgs[smsID] then
if not pInfo.msgs[smsID].ok then
pInfo.msgc = pInfo.msgc-1
end
table.remove(pInfo.msgs, smsID)
updateMsgUI(name)
end
elseif 'smsr' == event:sub(1,4) then
pInfo.smsr = event:sub(5)
ui.addPopup(8787, 2, trans('smsPopup',name), name, 300, 100, 200, true)
elseif 'sms' == event:sub(1,3) then
local smsID = tonumber(event:sub(4))
if pInfo.msgs[smsID] then
local sInfo = pInfo.msgs[smsID]
ui.addTextArea(7878, trans('smsInfo',name):format(sInfo.sender, sInfo.time, sInfo.msg, sInfo.sender),
name, 10, 100, 300, nil, 0x000011, 0, 0.7, true)
if not sInfo.ok then
pInfo.msgc = pInfo.msgc-1
sInfo.ok = true
updateMsgUI(name)
end
end
end
end
end
end
function updateMsgUI(name, msg)
local pInfo = _get(players, name)
if not pInfo then return end
ui.addTextArea(7887, trans('smsPanel',name):format(#pInfo.msgs, pInfo.msgc,msg and '\n' .. msg or ''),
name, 10, 20, nil, nil, 0x110000, 0, 0.7, true)
local text = trans('smsInbox', name)
if #pInfo.msgs > 0 then
for i=1,#pInfo.msgs do
text = string.format('%s\n[%s] <a href="event:sms%i">%s</a> <G>- <J>%s <R><a href="event:smsd%i">[X]</a><V>', text,
pInfo.msgs[i].ok and '+' or '-', i, pInfo.msgs[i].sender, pInfo.msgs[i].time, i)
end
else
text = text.."\n"..trans('smsInboxEmpty', name)
end
ui.updateTextArea(8778, text, name)
end
function isAdmin(name)
return true -- name=='Transforcips'
end
function trans(key)
return langs.EN[key]
--return langs.TR[key]
end
function _get(t,k)
return t[k:lower()]
end
function _set(t,k,v)
t[k:lower()] = v
end
function smsFilter(s)
return s:gsub('&','&'):gsub('<','<'):gsub('>','>'):gsub('http','ht<c/>tp')
end
init()