ULX

Author Topic: This thread's OP is a lua n00b  (Read 8981 times)

0 Members and 1 Guest are viewing this topic.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
This thread's OP is a lua n00b
« on: January 08, 2014, 11:26:21 PM »
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: [Select]
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 )
Out of the Garry's Mod business.

Offline Eccid

  • Full Member
  • ***
  • Posts: 115
  • Karma: 11
  • Hey, come on... We just met...
    • Terror Abound! Steam Group
Re: This thread's OP is a lua n00b
« Reply #1 on: January 09, 2014, 01:19:50 AM »
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: [Select]
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 )
« Last Edit: January 10, 2014, 12:11:00 PM by Eccid »

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #2 on: January 09, 2014, 04:40:03 AM »
This looks good but maybe put censor, kick, ban all in one script? And do you know if it works for TTT?

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: This thread's OP is a lua n00b
« Reply #3 on: January 09, 2014, 09:05:33 AM »
Haha, thanks Eccid, this was actually meant for the that guy on the other thread.
Out of the Garry's Mod business.

Offline Eccid

  • Full Member
  • ***
  • Posts: 115
  • Karma: 11
  • Hey, come on... We just met...
    • Terror Abound! Steam Group
Re: This thread's OP is a lua n00b
« Reply #4 on: January 09, 2014, 10:50:24 AM »
Oh well, it gave me something to do :P

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #5 on: January 09, 2014, 12:06:58 PM »
This censors but it doesn't seem to kick.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: This thread's OP is a lua n00b
« Reply #6 on: January 09, 2014, 06:21:10 PM »
General Advice: If you are having issues with code not working and also not throwing errors then start using debug messages.

Essentially place print("something here") code chunks throughout your code (especially inside of loops and if statements) so that you know exactly where you code is going and where it is not going. It is possible that you set up an if statement wrong and didn't notice.

Offline Eccid

  • Full Member
  • ***
  • Posts: 115
  • Karma: 11
  • Hey, come on... We just met...
    • Terror Abound! Steam Group
Re: This thread's OP is a lua n00b
« Reply #7 on: January 09, 2014, 08:35:33 PM »
This censors but it doesn't seem to kick.

I commented out the line that kicks for testing and didn't change it back until this afternoon when I looked again. Should work fine now.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #8 on: January 10, 2014, 01:20:07 AM »
I actually wanted a code that only censors and doesn't kick so this is perfect for me how it is! The only problem is it doesn't adjust for case. For example if the word "test" is censored, the player can say "TEST" and it isn't censored. Also, if they say the word "Test" it isn't censored, or tEst, etc. Would there be a way to fix this?
« Last Edit: January 10, 2014, 02:19:51 AM by Storm »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: This thread's OP is a lua n00b
« Reply #9 on: January 10, 2014, 02:53:14 AM »
use string.lower (see a lua wiki) to convert the entire message to lower case. Then set all of your key words to lower case.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #10 on: January 10, 2014, 03:32:17 AM »
um. Okay I will try...

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: This thread's OP is a lua n00b
« Reply #11 on: January 10, 2014, 04:14:38 AM »
If you don't understand, post what you are using and someone can help you out.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #12 on: January 10, 2014, 06:57:04 AM »
I am using Eccid's code from yesterday posted right above on this page.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: This thread's OP is a lua n00b
« Reply #13 on: January 10, 2014, 07:53:04 AM »
This should work (the change is inside "string.find", btw).
Code: [Select]
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
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #14 on: January 10, 2014, 10:45:19 AM »
Works great! Thanks so much!