ULX

Author Topic: Group Restrict Autorun script  (Read 2698 times)

0 Members and 1 Guest are viewing this topic.

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Group Restrict Autorun script
« on: February 04, 2011, 01:09:09 PM »
Ok so I asked for help restricting an addon [PAC] in facepunch, and the author gave me this script to place in PAC's lua/autorun folder, and it works great.

Code: [Select]
hook.Add("PrePACConfigApply", "pac_regulars_only", function(ply, config)
    if not (ply:IsUserGroup("local") or ply:IsUserGroup("thief") or ply:IsAdmin() or ply:IsSuperAdmin()) then
        return false, "Only regulars and up can use pac!"
    end
end)

Now I would like to take this idea and apply it to other addons, like Ragmorph.
Can someone please explain what exactly is going on here?
Is "PrePACConfigApply" something that PAC already has or is that something that is being created with this script here?
Can I just change that string(?) to PreRagmorphConfigApply, and drop it is ragmorph's autorun folder expecting it to work?

Thank you
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Group Restrict Autorun script
« Reply #1 on: February 04, 2011, 02:56:19 PM »
Just from a quick look, I'd educated guestimate that Pre blah blah is a PAC bit of code that this overwrites.
Have your OS "text scan utility" of choice search the text of your lua files in /addons/PAC and see.

EDIT-
And to answer your actual questions..
Pac already has (95% sure), No, No, No
« Last Edit: February 04, 2011, 02:59:17 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Group Restrict Autorun script
« Reply #2 on: February 04, 2011, 04:47:41 PM »
LOL thanks for the quick reply, and little lesson.
Sounds like its over my head, then  ::) hahaha

I AM, however, pretty proud of some lua hackage I did at work today, I successfully sized down a "pixel" size, and enlarged a painting canvas for a dead addon called gm_paint, then added 10 new colors *pats self on the the back*   ;D
« Last Edit: February 04, 2011, 06:10:36 PM by krooks »
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Group Restrict Autorun script
« Reply #3 on: February 04, 2011, 05:50:35 PM »
Pat so hard had to say it twice?
:P
Anyway, Ragmorph, if it already has an admin check of some sort (most do), shouldn't be hard to find that code, add additional checks like you did for pac, and edit.
However, The way the code you got from the original post is nicest way.
You'll most likely not have to re-hack if PAC updates. Only if the hook PAC uses changes names.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Group Restrict Autorun script
« Reply #4 on: February 04, 2011, 06:11:38 PM »
I was trying to edit but I quoted and edited the quote hahahaha!

I'll look into it, thanks again
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Group Restrict Autorun script
« Reply #5 on: February 04, 2011, 08:13:16 PM »
Whenever looking through G-lua files/addons/whatever you're trying to edit for further checks, use text searches for the following three most common.
(You may already know all three, but just in case)
Player.IsSuperAdmin
Player.IsAdmin
Player.IsUserGroup

According to the wiki article for IsAdmin, it will return 'true' if the player is a SuperAdmin, so, the code given to you for PAC in your original post shouldn't need the ending IsSuperAdmin check to work. (Optimization of code. .000001ms faster execution perhaps :D)
When searching files for adding additional group checks, I'd stick to IsAdmin.

Edit - BTW, don't actually search for the word 'player'. Use 'IsAdmin'. Player will usually be a variable.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming