I wonder what exactly determines the alive state of a player. I have tried to place a player in the TEAM_SPECTATOR, and set it to a spectator mode. However when checking the alive state with one of the example functions, the player is still considered alive. Only after the kill command the player is dead, until respawning.
I need to figure out how to place any new connected player in the spectating team and have him "dead". For that I need to know what exactly makes the player dead. I mean I could "kill" the player when connected, but is not there a more elegant way?
Also what controls the automatic respawning of players? I did not find anything useful in the functions.
[url]http://wiki.garrysmod.com/?title=Player.KillSilent[/url]
[url]http://wiki.garrysmod.com/?title=Gamemode.PlayerDeathThink[/url] - Is where the respawning magic happens
I use this to place the player in the spectator team:
-------When joining spectators, kill the player and assign to team3-----------
function JoinSpectators ( ply )
ply:KillSilent( )
ply:SetTeam( 3 )
ply:Spectate( OBS_MODE_ROAMING )
ply:PrintMessage( HUD_PRINTTALK, "[DEV]Joining Spectators, " .. ply:Nick() )
end
-------Call Joinspectators() on first spawn-----------
function FirstSpawn( ply )
ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!")
ply:JoinSpectators()
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
Calling JoinSpectators() from a console command works, however calling it from this hook gives an error:
Hook 'playerInitialSpawn' Failed: sniperambush/gamemode/init.lua:121: attempt to call method 'JoinSpectators' (a nil value)
Did I screw up the syntax somewhere?
[QUOTE=alleycat;18833273]I use this to place the player in the spectator team:
-------When joining spectators, kill the player and assign to team3-----------
function JoinSpectators ( ply )
ply:KillSilent( )
ply:SetTeam( 3 )
ply:Spectate( OBS_MODE_ROAMING )
ply:PrintMessage( HUD_PRINTTALK, "[DEV]Joining Spectators, " .. ply:Nick() )
end
-------Call Joinspectators() on first spawn-----------
function FirstSpawn( ply )
ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!")
ply:JoinSpectators()
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
Calling JoinSpectators() from a console command works, however calling it from this hook gives an error:
Hook 'playerInitialSpawn' Failed: sniperambush/gamemode/init.lua:121: attempt to call method 'JoinSpectators' (a nil value)
Did I screw up the syntax somewhere?[/QUOTE]
Yes, you registered your function as a global and are calling it as a method.
Because JoinSpectators isn't a member function of the player object. You'd called it like:
JoinSpectators( ply )
instead of
ply:JoinSpectators()
I found this in the base gamemode player.lua:
/*---------------------------------------------------------
Name: gamemode:PlayerDeathThink( player )
Desc: Called when the player is waiting to respawn
---------------------------------------------------------*/
function GM:PlayerDeathThink( pl )
if ( pl.NextSpawnTime && pl.NextSpawnTime > CurTime() ) then return end
if ( pl:KeyPressed( IN_ATTACK ) || pl:KeyPressed( IN_ATTACK2 ) || pl:KeyPressed( IN_JUMP ) ) then
pl:Spawn()
end
end
----------------------------------
This is the code, which control when to respawn the player. How do I override this whole thing with my own function? Since it is somewhere deeper
in the base game and not in my gamemode code I am not sure how to replace this. I mean it will be executed anyway?
Wtf is up with not using lua tags?
Yeah, you can overwrite it. However, be sure to copy some of that code or the player won't be able to respawn.
But how exactly do I replaced that code so that anything inside this function will not be used. I assume if my function function GM:PlayerDeathThink( pl ) appaers in my gamemode folder, it will skip this base one completely?
I copied the complete DeathThink from the base gamemode over to my gamemode, and it appears to replace the default base gamemode code if this function is present in the new gamemode. But I got a question about what hooks are.
Example:
[lua]
/*---------------------------------------------------------
Name: gamemode:PlayerDeathThink( player )
Desc: Called when the player is waiting to respawn
---------------------------------------------------------*/
function GM:PlayerDeathThink( pl )
if ( pl.NextSpawnTime && pl.NextSpawnTime > CurTime() ) then return end
if ( pl:KeyPressed( IN_ATTACK ) || pl:KeyPressed( IN_ATTACK2 ) || pl:KeyPressed( IN_JUMP ) ) then
pl:Spawn()
end
end
[/lua]
This is the default code for Deaththink. What is the difference between:
1) Copying the complete function into my gamemode and placing new functions inside of it
2) Using hooks, which from what I can see basically "inject" functions into the base gamemode function.
Why use hooks at all if I can copy the complete function from base into my gamemode and add functions in it?
Sorry, you need to Log In to post a reply to this thread.