Hello,
I have some idea about creating a LUA script but I'm a beginner in this domain and I have no idea how to start.
To summarize, I want a script running when the player die, playing sound and displaying a post processing effect. If you can give me an example or even a tutorial of this kind of script it would be helpful.
Thanks for advance.
Hooks are used to run functions when certain events happen in the game. In your case, you can use the [url=http://wiki.garrysmod.com/page/GM/PlayerDeath]PlayerDeath[/url] hook to do what you want whenever a player dies.
[lua]hook.Add( "PlayerDeath", "RandomNameYouGiveToYourHook", function( victim, weapon, killer )
// code
end )[/lua]
This hook returns three arguments, seen in the function, the person receiving the damage (i.e. the victim), the entity used to deal the damage (i.e. the weapon) and the owner of said weapon ( i.e. the killer ).
[url=http://wiki.garrysmod.com/page/Entity/EmitSound]EmitSound[/url] is the function to emit a sound from the given the player's current location.
[lua] LocalPlayer():EmitSound( "sound.wav" ) [/lua]
This will play the sound locally, so only the player from which this code was run will hear it.
If you're running this serverside, which you will need to do for the hook to be able to be used, you'll have to supply the player, and LocalPlayer() can't be used. If the code is run server-side, you can also make the sound be heard by other players withing a certain range of the player the sound was emitted from, check the link for more info.
The issue with that, is that PlayerDeath is a SERVER-side hook.
Here's what I do to draw death effects on the client
[lua]//
//
//
function GM:RenderDeathEffects( )
if ( !LocalPlayer( ):Alive( ) ) then
DrawSobel( 0.0001 )
DrawMotionBlur( 0.1, 0.79, 0.05)
local tab = {}
tab[ "$pp_colour_addr" ] = 0
tab[ "$pp_colour_addg" ] = 0
tab[ "$pp_colour_addb" ] = 0
tab[ "$pp_colour_brightness" ] = 0
tab[ "$pp_colour_colour" ] = 0
tab[ "$pp_colour_contrast" ] = 1
tab[ "$pp_colour_mulr" ] = 0
tab[ "$pp_colour_mulg" ] = 0
tab[ "$pp_colour_mulb" ] = 0
DrawColorModify( tab )
-- local tab = {}
-- tab[ "$darken" ] = 1
-- tab[ "$multiply" ] = 0
-- DrawDownSample( tab )
end
end
hook.Add( "RenderScreenspaceEffects", "RenderDeathEffects", GM.RenderDeathEffects )[/lua]
As for optimizing this so it's not always detecting if the player is !Alive, you could use PlayerDeath, network some code to the client to start the hook, start playing sound, etc. And then it can monitor until the player is alive, when the player is alive, remove the hook and the sound!
I want to get an flash effect with the bloom (start the darken amount from 1.00 and finish to 0.00) and the screen fade to black.
I'm also trying to put "game.ConsoleCommand("host_timescale 0.35\n")" but it says "attempt to call field 'ConsoleCommand' (a nil value)"