Skip to content

Commit c996f34

Browse files
authored
timed civilize + harden civilize + more replacements (#180)
* timed civilize + harden civilize Redox reccomendation Add ulx timedcivilize command Overrides ulx civilize, players cannot uncivilize themselves if they're timed-civilized Reverse shouldSet logic in code, felt it was weird to negate it at the top Restrict ulx civilize characters to only english keyboard characters * More
1 parent 92e3e73 commit c996f34

2 files changed

Lines changed: 95 additions & 11 deletions

File tree

lua/ulx/modules/sh/cfc_civilize.lua

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,22 @@ local transformations = {
247247
["devotee"] = "individual of devotion",
248248
["ardent"] = "person of thousandfold commitment",
249249
["exalted"] = "transcendent veteran of veneration",
250+
251+
-- Rather degenerate phrases depending on circumstance
252+
["uwu"] = "most certainly",
253+
["owo"] = "indeed",
254+
["nya"] = "quite so",
255+
["nyaa"] = "most assuredly",
256+
[";;w;;"] = "without a doubt",
257+
["^w^"] = "undoubtedly",
258+
["rawr"] = "greetings",
259+
[":3"] = "of course",
260+
["x3"] = "naturally",
261+
["hewo"] = "why, greetings!",
262+
["hewwo"] = "good day",
263+
["meow"] = "a sound of feline origin",
264+
["furry"] = "individual with anthropomorphic affinities",
265+
250266
-- Savage insults and vulgarities
251267
["hell"] = "brimstone",
252268
["balls"] = "round spheroids",
@@ -262,7 +278,6 @@ local transformations = {
262278
["asshole"] = "posterior orifice",
263279
["bald"] = "follicly challenged",
264280
["loser"] = "individual of diminished success",
265-
["furry"] = "individual with anthropomorphic affinities",
266281
["idiot"] = "intellectually challenged individual",
267282
["stupid"] = "lacking in cognitive fortitude",
268283
["dumb"] = "mentally unencumbered",
@@ -314,9 +329,24 @@ local randomPhrases = {
314329
"it seems to be", "quite assuredly", "undoubtably", "yes, of course", "unexpectedly",
315330
}
316331

332+
-- all normal keyboard chars except ~
333+
local validChars = " abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[]{};:,.<>/?`|'\"\\\n"
334+
335+
local function filterInvalidChars( str )
336+
local result = {}
337+
for i = 1, #str do
338+
local sub = str:sub( i, i )
339+
if string.find( validChars, sub, 1, true ) then
340+
result[#result + 1] = sub
341+
end
342+
end
343+
return table.concat( result )
344+
end
345+
317346
local function transform( sentence )
318347
sentence = string.lower( sentence )
319-
sentence = string.Trim( sentence ) -- can bypass with a leading space??? eg, ` i love propspamming`
348+
sentence = string.Trim( sentence ) -- can bypass with a leading space??? eg, ' i love propspamming'
349+
sentence = filterInvalidChars( sentence )
320350

321351
local replaceCount = 0
322352

@@ -328,7 +358,7 @@ local function transform( sentence )
328358
end
329359

330360
local minAddCount = 0
331-
local randomAddChance = 0.05
361+
local randomAddChance = 0.08
332362
if replaceCount <= 1 then -- if no replacements were found, add lots of crap
333363
randomAddChance = 0.5
334364
minAddCount = 1 -- always add ONE thing
@@ -339,7 +369,7 @@ local function transform( sentence )
339369
for word in sentence:gmatch( "%S+" ) do
340370
table.insert( transformedWords, word )
341371

342-
if math.random() < randomAddChance or addCount < minAddCount then
372+
if math.Rand( 0, 1 ) < randomAddChance or addCount < minAddCount then
343373
addCount = addCount + 1
344374
table.insert( transformedWords, randomPhrases[math.random( #randomPhrases )] )
345375
end
@@ -348,23 +378,53 @@ local function transform( sentence )
348378
return table.concat( transformedWords, " " )
349379
end
350380

351-
local targetedPlayers = {}
381+
CFCUlxCommands.civilize = CFCUlxCommands.civilize or {}
382+
local civilizeModule = CFCUlxCommands.civilize
383+
384+
civilizeModule.timedCivilizedPlayers = civilizeModule.timedCivilizedPlayers or {}
385+
local timedCivilizedPlayers = civilizeModule.timedCivilizedPlayers
386+
387+
civilizeModule.targetedPlayers = civilizeModule.targetedPlayers or {}
388+
local targetedPlayers = civilizeModule.targetedPlayers
389+
352390
hook.Add( "PlayerSay", "CFC_PoshSpeech", function( ply, msg )
353391
if not targetedPlayers[ply] then return end
354392
return transform( msg )
355393
end )
356394

395+
function civilizeModule.enable( ply )
396+
targetedPlayers[ply] = true
397+
end
398+
399+
function civilizeModule.disable( ply )
400+
targetedPlayers[ply] = nil
401+
end
402+
357403
local function setPosh( caller, targetPlayers, unSet )
358-
local shouldSet = not unSet
359-
for _, ply in ipairs( targetPlayers ) do
360-
if shouldSet then
361-
targetedPlayers[ply] = true
404+
for i, ply in ipairs( targetPlayers ) do -- don't let ulx uncivilize override timed civilize
405+
if not targetedPlayers[ply] then continue end
406+
if not timedCivilizedPlayers[ply] then continue end
407+
408+
if ply == caller then
409+
ULib.tsayError( caller, "Your civil situation seems to be of a more timed variety!", true )
362410
else
363-
targetedPlayers[ply] = nil
411+
ULib.tsayError( caller, ply:Nick() .. " is timed-civilized!", true )
364412
end
413+
414+
table.remove( targetPlayers, i )
415+
continue
365416
end
417+
for _, ply in ipairs( targetPlayers ) do
418+
if not unSet then
419+
civilizeModule.enable( ply )
420+
elseif unSet then
421+
civilizeModule.disable( ply )
422+
end
423+
end
424+
425+
if #targetPlayers <= 0 then return end
366426

367-
local message = shouldSet and "#A bestowed sophistication upon #T" or "#A returned #T to a more primitive state"
427+
local message = not unSet and "#A bestowed sophistication upon #T" or "#A returned #T to a more primitive state"
368428

369429
ulx.fancyLogAdmin( caller, message, targetPlayers )
370430
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CFCUlxCommands.timecivilize = CFCUlxCommands.timecivilize or {}
2+
local CATEGORY_NAME = "Fun"
3+
local PUNISHMENT = "timedcivilize"
4+
local HELP = "Bestow a period of sophistication upon a player, after which they return to their former, primitive state."
5+
6+
if SERVER then
7+
local civilizeModule = CFCUlxCommands.civilize
8+
9+
local function enable( ply )
10+
civilizeModule.timedCivilizedPlayers[ply] = true
11+
civilizeModule.enable( ply )
12+
end
13+
14+
local function disable( ply )
15+
civilizeModule.timedCivilizedPlayers[ply] = nil
16+
civilizeModule.disable( ply )
17+
end
18+
19+
TimedPunishments.Register( PUNISHMENT, enable, disable )
20+
end
21+
22+
local action = "bestowed a period of sophistication upon ##"
23+
local inverseAction = "returned ## to a more primitive period"
24+
TimedPunishments.MakeULXCommands( PUNISHMENT, action, inverseAction, CATEGORY_NAME, HELP )

0 commit comments

Comments
 (0)