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

0 Members and 4 Guests are viewing this topic.

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 #15 on: January 10, 2014, 12:10:37 PM »
I forgot the string.lower, sorry. Thanks decius.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: This thread's OP is a lua n00b
« Reply #16 on: January 10, 2014, 02:15:26 PM »
Works great! Thanks so much!
No problem!

I forgot the string.lower, sorry. Thanks decius.
It's alright. Got it in the end.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: This thread's OP is a lua n00b
« Reply #17 on: January 10, 2014, 05:40:00 PM »
Do you see what he did with string.lower?

Try and learn these little things as you go. Being able to customize (if not write your own) lua scripts will set your server apart from all of the many others out there.


Just a protip from someone who's been doing this a very long time.. :)

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: This thread's OP is a lua n00b
« Reply #18 on: January 10, 2014, 06:52:14 PM »
I hope you guys have read the first sentence of my post.

I didn't exactly want someone to right it for me.
Just wanted to know what I did wrong.
Out of the Garry's Mod business.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: This thread's OP is a lua n00b
« Reply #19 on: January 10, 2014, 08:33:29 PM »
And from your code, it only seems to work with the first word.

:/
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 #20 on: January 10, 2014, 11:33:08 PM »
And from your code, it only seems to work with the first word.

:/

I just retested it, it works no matter where I put the word, even sandwiched between other words without spaces. Did you change anything?

I hope you guys have read the first sentence of my post.

I didn't exactly want someone to right it for me.
Just wanted to know what I did wrong.

It wasn't exactly my intention to rewrite it for you, it's just hard to discuss back and forth on a forum. I've been learning lua by reading other peoples codes, so I normally just write my own to show other people as help.
« Last Edit: January 10, 2014, 11:39:09 PM by Eccid »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: This thread's OP is a lua n00b
« Reply #21 on: January 10, 2014, 11:57:58 PM »
I changed it so it doesn't display a set message upon trying to use a banned word.

Mine actually censors it.
I did base it off of your's though, so I'm not sure what the issue is.

I don't believe I touched anything related to the array.
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 #22 on: January 11, 2014, 01:36:28 AM »
If you wanna post what I you, I can take a look, and see if I can figure out the problem

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #23 on: January 11, 2014, 03:52:35 AM »
This will greatly reduce my bans. So I can stop people from posting links, I added "www.", "http", etc. Problem is that I need mods and admins to be able to post the steam link for our group page. Even I can't do it as owner. Is there a way to disable the censor for mods. admins?

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: This thread's OP is a lua n00b
« Reply #24 on: January 11, 2014, 10:22:02 AM »
This will greatly reduce my bans. So I can stop people from posting links, I added "www.", "http", etc. Problem is that I need mods and admins to be able to post the steam link for our group page. Even I can't do it as owner. Is there a way to disable the censor for mods. admins?

I'll see what I can do. As soon as I can fix my version.
Out of the Garry's Mod business.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: This thread's OP is a lua n00b
« Reply #25 on: January 11, 2014, 03:17:45 PM »
If you wanna post what I you, I can take a look, and see if I can figure out the problem

Code: [Select]
CenKik = CenKik or {} --Do not edit or remove this line.

CenKik.words = {
"lolipop",
"damndude",
"corecheng",
"prinnies" --Always leave the last one without a comma.
}

CenKik.kik = false --Enable kicking?
CenKik.kikadmin = true --Kick Admins?
CenKik.kiksadmin = false --Kick SuperAdmins?
CenKik.censor = true --Enable censoring?
CenKik.cenadmin = true --Censor Admins? (Neku: Bad idea to not censor.)
CenKik.censadmin = true --Censor SuperAdmins? (Neku: Still a bad idea to not censor.)

local function GetOuttaHere(meanie)
RunConsoleCommand("ulx", "kick", meanie:Nick(), "Attempting to use a blocked word.")
--[[ ulx.fancyLogAdmin( ply, true, "#A got kicked for saying: #s", text ) --It doesn't work. ]]--
end

--[[ local function NoCase( s )
s = string.gsub( s, "%a", function (c)
return string.format( "[%s%s]", string.lower( c ),
       string.upper( c ) )
end )
return s
end ]]--

local function Riplash( ply, text )
local filter = text
local forcetext = nil
CenKik.kikpls = nil
local replace = nil
for k,v in pairs(CenKik.words) do
if string.find( string.lower(filter), v, 1, true ) then --Is a word being used?
if CenKik.censor then
replace = string.rep( "*", string.len( v ) )
filter = string.gsub( string.lower(filter), v, replace )
CenKik.kikpls = true
end
end

if (ply:IsAdmin() and not CenKik.cenadmin) or (ply:IsSuperAdmin() and not CenKik.censadmin) then
forcetext = true
end

if (ply:IsAdmin() and not CenKik.kikadmin) or (ply:IsSuperAdmin() and not CenKik.kiksadmin) then
-- Something goes here. lol
else
if CenKik.kik and CenKik.kikpls then
GetOuttaHere(ply)
end
end

if forcetext or not CenKik.censor then
return text
else
return filter
end
end
end

hook.Add( "PlayerSay", "CenKik", 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 #26 on: January 11, 2014, 04:43:36 PM »
This will greatly reduce my bans. So I can stop people from posting links, I added "www.", "http", etc. Problem is that I need mods and admins to be able to post the steam link for our group page. Even I can't do it as owner. Is there a way to disable the censor for mods. admins?

do you want mods to bypass all censors, or just be able to post web links?


Ok, Ven. I made some modifications using only the code you had there, nothing of my own. I'll walk you through what I did. "function GetOuttaHere" is really un-needed. You can set up what you want to do when the person is decidedly kicked in the same function that checks for the words, so I got rid of that function. Using "return" ends the fuction with the specified results. So, in a script like this, order is everything. It starts off like it did before, except all the local variables except one was removed. You only need to predefine a variable if there's a chance it is called before it's set, which isn't what's happening here. So on line 20, replace is defined as a local variable. Otherwise the censoring code was solid.

After filter has been set as a censored word, we can move on with how to handle censoring and kicking. First it checks if you're an admin or sadmin, and if you're able to be kicked. If you can't be kicked, it then checks if you're censored. If not it returns the text (which finishes the function), else it returns the filter. If you can be kicked, it skips the admin only filter, and treats you like a regular user. Next is where it kicks you, if kick is enabled, you're kicked; all one line. Finally, it checks if the censor is turned on, and if it is it returns the filer, else it returns the real text.

The most important thing to do is make sure what order to check things, and to try and be as little complicated as possible. I try to tie as many things into a single if statement that can be checked together. Here's my edited code below. Tell me if you need to explain anything else I did. I did test this as a user, admin, and superadmin, and it works fine for me.

Code: [Select]
CenKik = CenKik or {}
CenKik.words = {
"lolipop",
"damndude",
"corecheng",
"prinnies" --Always leave the last one without a comma.
}
CenKik.kik = false --Enable kicking?
CenKik.kikadmin = false --Kick Admins?
CenKik.kiksadmin = false --Kick SuperAdmins?
CenKik.censor = true --Enable censoring?
CenKik.cenadmin = true --Censor Admins? (Neku: Bad idea to not censor.)
CenKik.censadmin = false --Censor SuperAdmins? (Neku: Still a bad idea to not censor.)

local function Riplash( ply, text )
local filter = text
for k,v in pairs(CenKik.words) do
if string.find( string.lower(filter), v, 1, true ) then
if CenKik.censor then
local replace = string.rep( "*", string.len( v ) )
filter = string.gsub( string.lower(filter), v, replace )
end
end
end

if (ply:IsAdmin() and not CenKik.kikadmin) or (ply:IsSuperAdmin() and not CenKik.kiksadmin) then
if (ply:IsAdmin() and not CenKik.cenadmin) or (ply:IsSuperAdmin() and not CenKik.censadmin) then
return text
else
return filter
end
end

if CenKik.kik then RunConsoleCommand("ulx", "kick", meanie:Nick(), "Attempting to use a blocked word.") end

if CenKik.censor then
return filter
else
return text
end
end

hook.Add( "PlayerSay", "CenKik", Riplash )
« Last Edit: January 11, 2014, 05:20:27 PM by Eccid »

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #27 on: January 12, 2014, 01:36:45 AM »
Yes I wanted to make the groups moderator, admin, superadmin, owner completely immune, I can just add these other groups consistent with the ULX group names?

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: This thread's OP is a lua n00b
« Reply #28 on: January 12, 2014, 02:11:09 AM »
Do you know lua, Storm?

If so, use
Code: [Select]
if ply:IsUserGroup() == "moderator" then
Out of the Garry's Mod business.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: This thread's OP is a lua n00b
« Reply #29 on: January 12, 2014, 03:53:00 AM »
No, Ven, I am afraid I don't know lua but I am trying to pick things up from you guys on this thread and the other thread. I am using Eccid's code but commenting out the kick part, like he did originally. What I want is to just censor all players except mod, admin, sadmin, owner. No kicks or bans for anyone. So all I have to fix is how Eccid's code currently censors those groups.
« Last Edit: January 12, 2014, 04:21:52 AM by Storm »