General > Developers Corner

[Noob, help needed] ULX God Notify

<< < (2/3) > >>

JamminR:
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.

Fluttershy:

--- Quote from: Avoid 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: ---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 )

--- End code ---

Avoid

--- End quote ---
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.

Neku:
Top function is server side.

Bottom is client side.

Fluttershy:
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: ---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 )
--- End code ---

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: ---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
--- End code ---
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: ---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
--- End code ---
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.

Neku:
Instead of overwriting the gamemode function, try hooking onto it.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version