General > Developers Corner

Help build a game mode!

<< < (5/7) > >>

Megiddo:
Sorry, not hook.Register... hook.Add. It's as you had it in the post above, if it's not working there's probably a bug in the code..

JamminR:
You mentioned you didn't understand hooks...well, for a game mode, you better learn! :)
In simplest terms I can think of;

Garry wrote hooks into Gmod.
Those hooks watch for specific events (Spawn,Death, TakeDamage, Suicide, ... ) within the game, no matter what type of game mode.
Adding a hook watcher (hook.add) makes your code look for any of those events, and if they occur, do something.
See also http://wiki.garrysmod.com/?title=Hook

LuaTenshi:
I was reading the posts carefully and I found that Megiddo said that the code I had from before should work, now I feel stupid for posting script veriations  :-[

I will check to see if I get any other problems, also just woundering if any one else is working, or thinking about working on some thing for this game-mode.

I have decided to keep this closer to ULX and stay farther away from Facepunch because I was told and have also seen that facepunch is not a place for development.

(Why am I up at 5:30 AM you ask thats because I was haunted with thoughts about the game-mode...)

LuaTenshi:
I am adding this into "...\lua\autorun\"


--- Code: ---function GAMEMODE:EntityTakeDamage( ent )
 
if ent:IsPlayer() then
Hp = ent:Health()
if(Hp <= 41) then
hook.Call( "RenderScreenspaceEffects", RenderEFunc, ent, Hp )
end
end
end

local function RenderEFunc( ent, Hp )

local tab = {}
tab[ "$pp_colour_addr" ] = 5
tab[ "$pp_colour_addg" ] = 0
tab[ "$pp_colour_addb" ] = 0
tab[ "$pp_colour_brightness" ] = 0
tab[ "$pp_colour_contrast" ] = 1
tab[ "$pp_colour_colour" ] = 1
tab[ "$pp_colour_mulr" ] = Hp * 2
tab[ "$pp_colour_mulg" ] = 1
tab[ "$pp_colour_mulb" ] = 1

DrawColorModify( tab )
DrawMotionBlur( 0.5, 0.5, 0.1)
DrawBloom( 1, Hp/100, 3, 9, 9, 1, 255, 0, 0 )

end

hook.Add( "RenderScreenspaceEffects", "RenderEFunc", RenderEFunc )

--- End code ---

I get the following error when my health reaches 41...


--- Code: ---ERROR: Hook 'RenderEFunc' Failed: [lua\autorun\sh_damageeffect.lua:24] attempt to call method 'DrawColorModify' (a nil value)
Removing Hook 'RenderEFunc'

--- End code ---

I have tried sending the entity over to my hook with no results. I have also tried separating it and putting the hook into the client folder but I got the same error...


--- Code: ---ERROR: Hook 'RenderEFunc' Failed: [lua\autorun\client\cl_damageeffect.lua:14] attempt to call global 'DrawColorModify' (a nil value)
Removing Hook 'RenderEFunc'

--- End code ---

Any ideas on how I can fix this?

Edit: I need help before my head explodes!!! Because I looked in the script of weather mod and it looks like he is doing that the same way I am...

Aaron113:
I think your problem is you're running it shared.  Try making a client folder inside the autorun folder and place the file in there.  It's just a guess.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version