· 9 years ago · Dec 19, 2016, 04:18 PM
1--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2-- GlobalChat MTA:DayZ v1
3-- Creado por: Ghost
4-- Não Remova OS Créditos
5--///////////////////////////////////
6
7
8--Add the resource as addon to DayZ
9
10
11--------------------------------------------------------------------
12--Your Code
13
14--Please edit the settings in the meta.xml or admin panel instead of changing those
15colorCodesDefault = { }
16colorCodesDefault.colorcode1 = "#FFFFFF"
17colorCodesDefault.colorcode3 = "#FFFFFF"
18colorCodesDefault.colorcode2 = "#FFFFFF"
19
20colorCodes = { }
21colorCodes.colorcode1 = get ( "colorcode1" ) or colorCodesDefault.colorcode1
22colorCodes.colorcode2 = get ( "colorcode2" ) or colorCodesDefault.colorcode2
23colorCodes.colorcode3 = get ( "colorcode3" ) or colorCodesDefault.colorcode3
24
25--Check color code on start
26for i, v in pairs ( colorCodes ) do
27 if not getColorFromString ( v ) then
28 colorCodes[i] = colorCodesDefault[i] --if the admin fails to enter a valid hex color code
29 outputChatBox ( "Bad " .. i .. " specified at GlobalChat addon (format: #FFFFFF)", root, 255, 0, 0, false)
30 outputDebugString ( "Bad " .. i .. " specified at GlobalChat addon (format: #FFFFFF)", 2 )
31 end
32end
33
34outputLimit = 128 --character limit for chatbox outputs (do not change this)
35
36
37messagePrefix = "#FFFF00[WorldDayZ]" --prefix for the outputs
38
39
40
41onlyLatinCharacters = get ( "latinchars" ) == "true" and true or false
42
43timeBetweenMessages = tonumber ( get ( "messagedelay" ) ) or 1000 --time to wait between chat messages
44playerTickTable = { } --create a table with tick counts of the most recent chat message
45
46--The message output
47function playeGlobalChat ( playersource, cmd, ... )
48local accountname = getAccountName(getPlayerAccount(playersource))
49messagePrefix = "#FFFF00[WorldDayZ]" --prefix for the outputs
50if isObjectInACLGroup("user." .. accountname, aclGetGroup("Moderator")) then
51messagePrefix = "#003300[Moderator]" --prefix for the outputs
52elseif isObjectInACLGroup("user." .. accountname, aclGetGroup("Admin")) then
53messagePrefix = "#660000[Admin]" --prefix for the outputs
54elseif isObjectInACLGroup("user." .. accountname, aclGetGroup("SuperModerador")) then
55messagePrefix = "#FF0000[jAdmin]" --prefix for the outputs
56end
57 if cmd == "Globalchat" then
58 --Check whether the player is muted first
59 if isPlayerMuted ( playersource ) then
60 outputChatBox ("You are mutated by flood!", playersource, 255, 128, 22, true)
61 return
62 end
63
64 local msg = table.concat ( {...} , " " ) --concat the arguments from table to a string seperated by spaces
65 local msg = string.gsub ( msg, '#%x%x%x%x%x%x', '' ) --remove color-codes
66
67 --Anti-spam checks
68 local onlyLettersMsg = string.gsub ( msg , "%A", "" ) --extract letters only
69 if onlyLettersMsg == string.upper ( onlyLettersMsg ) and #onlyLettersMsg > 6 then --check if there are more than 6 uppercase letters without any lowercase letters
70 outputChatBox ( "Turn off your capslock!", playersource, 255, 0, 0 )
71 return
72 end
73
74 if string.find ( msg, "mtasa://" ) then --disallow links
75 outputChatBox ( "No Hagas SPAM de IP ", playersource, 255, 0, 0 )
76 return
77 end
78
79 if string.find ( msg, "porno" ) then --disallow links
80 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
81 return
82 end
83
84 if string.find ( msg, "www" ) then --disallow links
85 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
86 return
87 end
88
89 if string.find ( msg, "Proyecto Z" ) then --disallow links
90 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
91 return
92 end
93
94 if string.find ( msg, "Blood X" ) then --disallow links
95 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
96 return
97 end
98
99 if string.find ( msg, "Proyecto" ) then --disallow links
100 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
101 return
102 end
103
104 if string.find ( msg, "ProChile" ) then --disallow links
105 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
106 return
107 end
108
109 if string.find ( msg, "prochile" ) then --disallow links
110 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
111 return
112 end
113
114 if string.find ( msg, "Chilez" ) then --disallow links
115 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
116 return
117 end
118
119 if string.find ( msg, "PZ" ) then --disallow links
120 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
121 return
122 end
123
124 if string.find ( msg, "Pz" ) then --disallow links
125 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
126 return
127 end
128
129 if string.find ( msg, "TOPGTA" ) then --disallow links
130 outputChatBox ( "Por Favor No haga SPAM IP!", playersource, 255, 0, 0 )
131 return
132 end
133
134 if onlyLatinCharacters then
135 local noSpacesMsg = string.gsub ( msg, " ", "" )
136 local onlySpecCharMsg = string.gsub( noSpacesMsg, "[%a%d]", "") --extract special chars only
137 if #onlySpecCharMsg > 10 then --check if there are more than 10 non-latin characters used (including russian, chinese, etc. characters)
138 outputChatBox ( "Do not spam the chat with special (language) characters!", playersource, 255, 0, 0 )
139 return
140 end
141 end
142
143 local var, spacesCount = string.gsub( msg, " ", "") --get the count of spaces
144 if ( #msg / spacesCount ) > 20 and #msg > 20 then --check if there is at least one space per 20 or less characters
145 outputChatBox ( "Do not spam the chat with long words!", playersource, 255, 0, 0 )
146 return
147 end
148
149 if playerTickTable[playersource] then --check if a table entry for the player exists
150 local tick = getTickCount ( ) --get the current tick count in ms
151 local timePassed = tick - playerTickTable[playersource] --calculate the time that passed between two messages
152 if timePassed <= timeBetweenMessages then
153 outputChatBox ( "Please refrain from chat spam!", playersource, 255, 0, 0 )
154 return
155 end
156 else
157 playerTickTable[playersource] = getTickCount ( )
158 end
159 --End of anti-spam checks
160
161 --Chat loggings
162
163
164 outputServerLog ( messagePrefix .. getPlayerName ( playersource ) .. " : " .. msg )
165
166 local message = messagePrefix .. colorCodes.colorcode2 .. string.gsub ( ( getPlayerName ( playersource ) .. " : " ), '#%x%x%x%x%x%x', '' ) .. colorCodes.colorcode3 .. msg --precreate the message string
167 local message = string.sub ( message, 1, outputLimit ) --since the chatbox won't display messages with more than 128 characters we just drop the ones at the end
168 local r, g, b = getColorFromString ( colorCodes.colorcode1 )
169 outputChatBox ( message, root, r, g, b, true )
170
171 playerTickTable[playersource] = getTickCount ( )
172 end
173end
174addCommandHandler ( "Globalchat", playeGlobalChat )
175
176--Admin panel resource settings checks
177addEventHandler ( "onSettingChange", root,
178 function ( setting, oldValue, newValue )
179 local setting = gettok ( setting, 2, string.byte ( "." ) )
180 if setting == "colorcode1" or setting == "colorcode2" or setting == "colorcode3" then
181 if getColorFromString ( fromJSON( newValue ) ) then --if the admin fails to enter a valid hex color code
182 colorCodes[setting] = fromJSON( newValue )
183 else
184 colorCodes[setting] = colorCodesDefault[setting]
185 outputChatBox ( "Bad " .. setting .. " specified at GlobalChat addon (format: #FFFFFF)", root, 255, 0, 0, false)
186 outputDebugString ( "Bad " .. setting .. " specified at GlobalChat addon (format: #FFFFFF)", 2 )
187 end
188 end
189 if setting == "messagedelay" then --update message delay when changed
190 if tonumber ( fromJSON( newValue ) ) then
191 timeBetweenMessages = tonumber ( fromJSON( newValue ) ) or 1000 --maximum securtiy is usually best
192 end
193 end
194 if setting == "prefix" then --update message prefix when changed
195 if fromJSON( newValue ) then
196 messagePrefix = fromJSON ( newValue ) or "[WorldDayZ]" --maximum securtiy is usually best
197 end
198 end
199 if setting == "latinchars" then --update onlyLatinCharacters setting when changed
200 onlyLatinCharacters = fromJSON ( newValue ) == "true" and true or false
201 end
202 end
203)
204
205addEventHandler ( "onPlayerQuit", root,
206 function ( )
207 playerTickTable[source] = nil --remove a leaving player from our cached table
208 end
209)