General > Developers Corner

Just a general lua problem.

(1/1)

blackfire88:
Hey there,
I am coding a gamemode, and i kinda need some help regarding spectating.
I have two problems.
1. When I use ply:Spectate( OBS_MODE_ROAMING ) or OBS_MODE_CHASE it still just spawns them as a normal player.
2. When I use ply:SetColor(Color(255,255,255,0) it doesnt make them invisible.
Here is my code:

--- Code: ---function GM:PlayerInitialSpawn( ply )
ply:SetTeam( TEAM_SPEC )
ply:Spectate( OBS_MODE_CHASE )
timer.Create("Timer.Initspawn."..ply:SteamID(), 1, 1, function()
ply:SetMoveType( MOVETYPE_NOCLIP )
ply:SetColor(Color(255,255,255,0))
end)
ply:Respawn()
end

--- End code ---

EDIT: The movetype_noclip movetype is my terrible fix for the spectating.

MrPresident:
When you use player:Spectate(mode) you have to set an entity for the player to spectate.

player:SpectateEntity(ent)

Try that.

*edit* Also, try without the Respawn code too. i think that runs the GAMEMODE:PlayerSpawn() hook which will spawn the players entity at a spawn point which I don't think you want. You'll need to call that later when you want the player to stop spectating.

blackfire88:
Thanks for the help :)
It works now.

Do you by any chance know how to disable team damage (friendly fire)?

MrPresident:
use the PlayerShouldTakeDamage gamemode hook..
http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index148c.html

One of the examples on the wiki addresses exactly what you want.

Navigation

[0] Message Index

Go to full version