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