• Fire code on a player on respawn?
    6 replies, posted
How do i do this?
If you're wanting to run code on the player's first spawn then use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html]Gamemode.PlayerInitialSpawn[/url] but if you just want it to run every spawn then use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index249d.html]Gamemode.PlayerSpawn[/url]. Both are serverside so you'll need it in the init.lua
[QUOTE=Adzter;44486718]If you're wanting to run code on the player's first spawn then use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html]Gamemode.PlayerInitialSpawn[/url] but if you just want it to run every spawn then use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index249d.html]Gamemode.PlayerSpawn[/url]. Both are serverside so you'll need it in the init.lua[/QUOTE] So [code] function GM:PlayerSpawn( ply ) ply:SetModel( "models/player/breen.mdl" ); end [/code] would work?
That should work just make sure it is serverside [QUOTE=OldGoldie;44486757]So [code] function GM:PlayerSpawn( ply ) ply:SetModel( "models/player/breen.mdl" ); end [/code] would work?[/QUOTE]
[QUOTE=vrej;44486835]That should work just make sure it is serverside[/QUOTE] How do i make sure it's serverside? I put it in lua\autorun\server and it says GM is a nil value
[QUOTE=OldGoldie;44486901]How do i make sure it's serverside? I put it in lua\autorun\server and it says GM is a nil value[/QUOTE] If the code isn't in a gamemode folder, you have to use hook.Add. [lua] hook.Add("PlayerSpawn", "UniqueNameForThisHook", function(ply) ply:SetModel("models/player/breen.mdl") end)[/lua]
I'd recommend using the proper hook for setting the player-model which is: PlayerSetModel with a ply argument.
Sorry, you need to Log In to post a reply to this thread.