General > Developers Corner

This thread's OP is a lua n00b

(1/8) > >>

Neku:
Could someone point out what I'm doing wrong here?

When I run it in-game, it gives me no lua errors, so it's difficult to pinpoint what the issue is.

Don't question my naming.


--- Code: ---local adminexception = false -- Will admins still be kicked for using a blocked string?
local sadminexception = false -- Will superadmins still be kicked for using a blocked string?
local noadmincensor = false -- Will admins still be censored? (Neku: Bad idea imo, nya-nya.)
local nosadmincensor = false -- Will superadmins still be censored? (Neku: Still a bad idea, meow.)

local youmeanie = {
"lolipop", -- Remember to place a comma after strings.
"damndude",
"corecheng",
"prinnies" -- Always leave the last string without a comma.
} -- Having many strings blocked will delay chat for everyone and possibly lag the server. They are also not case sensitive.

for k,v in pairs( youmeanie ) do
table.insert( youmeanie, v:upper( ) )
end

local function GetOuttaHere(ply)
RunConsoleCommand("ulx kick" .. ply .. "")
end

local function Riplash( ply, text, public )
local kickpls = nil
local forcetext = nil
local riplash = text
for i = 1, #youmeanie do
local v = youmeanie[ i ]
if ply:IsAdmin() then
if noadmincensor then
forcetext = true
end
elseif ply:IsSuperAdmin() then
if nosadmincensor then
forcetext = true
end
end
if string.find( riplash, v ) and forcetext == nil then
riplash = string.gsub( riplash, v, string.rep( "*", string.len( v ) ) )
kickpls = true
end
end
if forcetext then
return text
else
return riplash
end
if kickpls then
if ply:IsAdmin() then
if adminexception then
else
ply:GetOuttaHere()
end
elseif ply:IsSuperAdmin() then
if ply:IsSuperAdmin() then
else
ply:GetOuttaHere()
end
else
ply:GetOuttaHere()
end
end
end

hook.Add( "PlayerSay", "Meaniecake", Riplash )

--- End code ---

Eccid:
I'm kinda falling asleep atm, so It's bed time. Here's what I have for you, a modification of what I posted before on another thread. I made censorship into one variable, if you want to change that tell me and I'll look at it in the morning. Everything else is straightforward.
lua\autorun\server


--- Code: ---KickWords = KickWords or {}
KickWords.words = {
"lolipop",
"damndude",
"corecheng",
"prinnies"
}
KickWords.admins = false   --Kick Admins?
KickWords.sadmins = false  --Kick Superadmins?
KickWords.censor = true    --Censor words?

hook.Add( "PlayerSay", "Meanie Head", function(ply, text)
local oldtext = text --Remember what they said, for admins sake
for a,b in pairs(KickWords.words) do
if string.find(string.lower(text), b, 1, true) then --Is a word being used?
if KickWords.censor then text = "I said a bad word...." end --What to print if censored.
if (ply:IsAdmin() and not KickWords.admins) or (ply:IsSuperAdmin() and not KickWords.sadmins) then return text end--Tie it all into one line
RunConsoleCommand("ulx", "kick", ply:Nick(), "You Meanie!") --If yes, kick them
ulx.fancyLogAdmin( ply, true, "#A was kicked for saying the following: #s", oldtext or text) --Tell admins they were kicked and what they said.
return text --Return nothing so everyone can't read what was said.
end
end
end )
--- End code ---

Storm:
This looks good but maybe put censor, kick, ban all in one script? And do you know if it works for TTT?

Neku:
Haha, thanks Eccid, this was actually meant for the that guy on the other thread.

Eccid:
Oh well, it gave me something to do :P

Navigation

[0] Message Index

[#] Next page

Go to full version