Author Topic: [Noob, help needed] ULX God Notify  (Read 4911 times)

0 Members and 1 Guest are viewing this topic.

Offline Fluttershy

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
[Noob, help needed] ULX God Notify
« on: September 13, 2014, 04:05:29 PM »
The situation is, I am an administrator for a server that I am hoping to contribute to for the lack of coders (or active ones). The problem is that due to natural human negligence, some of the admins forget to turn off godmode when they are done using it. So it ends up causing problems when they get back to playing In-Character (Did I mention it was a Roleplay server?). As a result, Godmode has been revoked from all administrators (Including superadmins) and most of the staff have gone into an outrage against this. (They claim sethealth doesn't allow for stealthy administration, and that superadmins should have access to this regardless anyway.) So, To satisfy both ends, I come up with a witty idea. "Why don't we just code something to make a compromise?" Well, I was shot down by the owner in that we don't have many coders/active coders, and that he's going to hold his ground about godmode being disabled UNTIL something like that is coded.

So, I have tasked myself with the honor of being the person that codes this compromise, being the one that came up with the idea. Even if I somehow stopped participating in the server, it is a good opportunity for me to learn more about lua, and I would have a copy of this code anyhow.

To begin: I looked at some Garry's Mod code, and looked at the ULX code, and thought a simple idea. "Why don't I use draw.wordbox with an if statement for when godmode is used, so that when godmode is turned on, it says something like "Godmode is enabled! Turn if off when you're done." so that people won't forget to turn off godmode. When godmode is then disabled, the big giant wordbox will disappear and stop annoying the admin. This will allow the owner to let godmode be able to be used again, and choose how to deal with admins that still "abuse" the godmode feature."

What I have done so far, is that I've looked at This for reference, and found something that might suit my need to put text on the screen (and not the chat) that won't go away.
Now I want to reference the ULX godmode function (Which I found by looking through the files and finding fun.lua) in a way so that I can make an if statement for when godmode is turned on. I think I'm supposed to have a hook to when godmode is enabled.
« Last Edit: September 24, 2014, 09:02:07 PM by Fluttershy »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: [Noob, help needed] ULX God Notify
« Reply #1 on: September 14, 2014, 12:20:54 AM »
To be honest, they should remember to disable it themselves, but I can see why that would be handy.

I have very little experience with visuals in lua, and I probably won't be able to answer most questions regarding drawing.

But I can help in other ways.
As far as I know, there isn't a hook for godmode, so your best bet is to try shoving that into the command itself.
Out of the Garry's Mod business.

Offline Fluttershy

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: [Noob, help needed] ULX God Notify
« Reply #2 on: September 14, 2014, 03:11:35 AM »
All right, well, I'll see to trial and error. Many backups will be made.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: [Noob, help needed] ULX God Notify
« Reply #3 on: September 14, 2014, 03:29:57 AM »
Oh, I forgot, since it's a function for clients, do
Code: [Select]
if CLIENT then

end
Out of the Garry's Mod business.

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: [Noob, help needed] ULX God Notify
« Reply #4 on: September 14, 2014, 07:08:28 AM »
Hello there,
interesting problem you are describing here, I think I have a proper solution to this:

Use the PlayerNoClip hook to grant the admin enabling noclip godmode (serverside), then draw your text box (clientside) when noclip is enabled.

And as Neku told you, there is no hook for GodMode, so I'd go with Noclip instead! - When I find the time to, I will put up some code for you.

Edit: Hopefully you can put it to use, here you go!

Code: [Select]
function GM:PlayerNoClip( ply, on )
if not ply:IsAdmin() then return false end

if on then
ply:GodEnable()
else
ply:GodDisable()
end

return true
end

function PaintGodBox()
if LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then return end
draw.WordBox( 8, 5, ScrH() / 2, "Godmode: ON", "DermaDefault", Color(255,100,100,200), Color(255,255,255,255))
end
hook.Add( "HUDPaint", "GodModeBox", PaintGodBox )

Avoid
« Last Edit: September 14, 2014, 09:01:06 AM by Avoid »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: [Noob, help needed] ULX God Notify
« Reply #5 on: September 14, 2014, 10:23:55 PM »
Can also look for "ulx god" using either of following;
ULibCommandCalled (called on server before any Ulib command actually runs(which ULX uses of course)
ULibPostTranslatedCommand - Server hook - runs after a ulib command call - this one could look for ulx god, then run the additional code you wanted after god.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Fluttershy

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: [Noob, help needed] ULX God Notify
« Reply #6 on: September 23, 2014, 02:21:47 AM »
Hello there,
interesting problem you are describing here, I think I have a proper solution to this:

Use the PlayerNoClip hook to grant the admin enabling noclip godmode (serverside), then draw your text box (clientside) when noclip is enabled.

And as Neku told you, there is no hook for GodMode, so I'd go with Noclip instead! - When I find the time to, I will put up some code for you.

Edit: Hopefully you can put it to use, here you go!

Code: [Select]
function GM:PlayerNoClip( ply, on )
if not ply:IsAdmin() then return false end

if on then
ply:GodEnable()
else
ply:GodDisable()
end

return true
end

function PaintGodBox()
if LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then return end
draw.WordBox( 8, 5, ScrH() / 2, "Godmode: ON", "DermaDefault", Color(255,100,100,200), Color(255,255,255,255))
end
hook.Add( "HUDPaint", "GodModeBox", PaintGodBox )

Avoid
Okay, that makes a lot of sense. If I go into noclip, it will turn on godmode and paint a box saying "Godmode: ON".
I'm kind of having a bit of file troubles with this xD. I had the basic concept of having shared, client, and server, but I don't really know where to put this. I recognize GM in that it is a gamemode hook, since I've seen it when creating basic gamemodes. From observing other files, it goes somewhere...

EDIT: Logic prevails me, and it made sense that since it was a client script and was calling gamemode hooks, that I should put it into cl_init.lua in my gamemode. That actually makes a lot of sense. Although the godmode hook didn't come out too satisfactory, It's better than nothing, especially since people probably shouldn't be running around on the ground with godmode anyway. Thanks a lot guys.

EDIT 2: I actually tested the script and godmode wasn't enabled when I turned on noclip. I didn't get any errors. Will test again. If not will look through Ulib.

EDIT 3: Wait, if Godmode is a variable, then it shouldn't be clientside. So if Godmode and the textbox are both being used in the same code, then it must be shared.lua
Huh. I'm trying that right now.

EDIT 4: Still does not work. The drawing works perfectly fine. It is just the enabling of godmode I am having trouble with.
« Last Edit: September 23, 2014, 03:05:06 AM by Fluttershy »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: [Noob, help needed] ULX God Notify
« Reply #7 on: September 23, 2014, 07:43:38 AM »
Top function is server side.

Bottom is client side.
Out of the Garry's Mod business.

Offline Fluttershy

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: [Noob, help needed] ULX God Notify
« Reply #8 on: September 24, 2014, 03:58:56 PM »
I see, so that should mean that I did not correctly define "if client then" "if server then" for both of them separately? So I am assuming that the code was loaded clientside only because I did not define which parts of the code corresponded to either client or server?
Okay. So the code should look like this. Correct me if I'm wrong.
Code: [Select]
if (SERVER) then
function GM:PlayerNoClip( ply, on )
if not ply:IsAdmin() then return false end

if on then
ply:GodEnable()
else
ply:GodDisable()
end

return true end
end

if (CLIENT) then
function PaintGodBox()
if LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then return end
draw.WordBox( 8, 5, ScrH() / 2, "Godmode: ON", "DermaDefault", Color(255,100,100,200), Color(255,255,255,255)) end
end
hook.Add( "HUDPaint", "GodModeBox", PaintGodBox )

EDIT: The code I have submitted here again works for the box, but not for the actual godmode. I have to figure out whether this problem is in the test environment or the actual code.

  • MOVETYPE_NOCLIP works for ULX noclip, correct?
  • Also ply:IsAdmin applies to SuperAdmins too? Does it specifically have to be written in the server admin textfile as well?
  • Perhaps ply:GodEnable() is using the default implemented godmode that does not work instead of the ULX godmode?


I looked it up and found this. [click] This should be fully functional...

  • This is supposed to be in the shared.lua of a gamemode, right?

EDIT 2:
Code: [Select]
if (SERVER) then
function GM:PlayerNoClip( ply, on )
if not ply:IsAdmin() then return false end

if on then
ply:GodEnable()
else
ply:GodDisable()
end

return true end
end
I am thinking "if not ply:IsAdmin() then return false end" should end with an elseif statement instead of ending. Maybe that is the problem? If this is true, then users should be able to godmode given that they have noclip access... I don't know. Maybe an if ply:isAdmin() should be specified when starting if on then?

EDIT 3:
Code: [Select]
if (SERVER) then
function GM:PlayerNoClip( ply, on )
if not ply:IsAdmin() then return false elseif

on then
ply:GodEnable()
else
ply:GodDisable()
and

return true end
end
Notice the new "elseif" and "and" statements. Well, This failed horribly and also did not work. I am starting to think it may be my testing environment. I really don't know. To verify, maybe someone else can test the original code or notify me of what is wrong with the code? I will be referring back to the original code since I don't think I know what I'm doing at this point.
« Last Edit: September 24, 2014, 06:54:30 PM by Fluttershy »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: [Noob, help needed] ULX God Notify
« Reply #9 on: September 24, 2014, 06:55:28 PM »
Instead of overwriting the gamemode function, try hooking onto it.
Out of the Garry's Mod business.

Offline Fluttershy

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: [Noob, help needed] ULX God Notify
« Reply #10 on: September 24, 2014, 07:16:32 PM »
Instead of overwriting the gamemode function, try hooking onto it.
How would I go about doing that? I found this: [Click me]
Sorry, I did not read it when I asked. ^
So you want me to add to the hooks "hook.Add("PlayerNoClip", "DisableNoclip", DisableNoclip)" ?

Code: [Select]
if (SERVER) then
function GM:PlayerNoClip( ply, on )
if not ply:IsAdmin() then return false end

if on then
ply:GodEnable()
else
ply:GodDisable()
end

return true end
end
hook.Add("PlayerNoClip", "DisableNoclip", DisableNoclip)

if (CLIENT) then
function PaintGodBox()
if LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then return end
draw.WordBox( 8, 5, ScrH() / 2, "Godmode: ON", "DermaDefault", Color(255,100,100,200), Color(255,255,255,255)) end
end
hook.Add( "HUDPaint", "GodModeBox", PaintGodBox )
Tried this, Godmode is still non-functional. Will try removing GM: and see if that will work.

EDIT: Again, it did not work.
I am creating a shared.lua file for my gamemode "since it does not possess one" and adding this code onto it. Under the circumstances, this should work. I do not know why specifically the server function is refusing to work. This makes no sense. the ULX Godmode uses this exact same ply:GodEnable(). I do not understand why I cannot do the same.
« Last Edit: September 24, 2014, 07:52:11 PM by Fluttershy »

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: [Noob, help needed] ULX God Notify
« Reply #11 on: September 24, 2014, 10:18:25 PM »
"hook.Add()" takes three parameters.
One is the hook name, the second is the unique identifier, and the third parameter is the function name the hook should call (although it doesn't have to be a function name and just a function itself, but let's not think about that now).

Now the function name comes after "function". In this case it's "GM:PlayerNoClip". However, in your third "hook.Add()" parameter, it says "DisableNoclip", which means it's trying to call the "DisableNoclip" function which doesn't exist in your current code.

Other than that, you've done it correctly.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Fluttershy

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: [Noob, help needed] ULX God Notify
« Reply #12 on: September 24, 2014, 10:22:06 PM »
"hook.Add()" takes three parameters.
One is the hook name, the second is the unique identifier, and the third parameter is the function name the hook should call (although it doesn't have to be a function name and just a function itself, but let's not think about that now).

Now the function name comes after "function". In this case it's "GM:PlayerNoClip". However, in your third "hook.Add()" parameter, it says "DisableNoclip", which means it's trying to call the "DisableNoclip" function which doesn't exist in your current code.

Other than that, you've done it correctly.
Wait, what are you saying, then? The third parameter must be GM:PlayerNoClip or should DisableNoclip be removed and left at that?

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given