ULX

Author Topic: Just a general lua problem.  (Read 2535 times)

0 Members and 3 Guests are viewing this topic.

Offline blackfire88

  • Jr. Member
  • **
  • Posts: 56
  • Karma: 0
Just a general lua problem.
« on: August 08, 2012, 07:02:46 PM »
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: [Select]
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

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

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Just a general lua problem.
« Reply #1 on: August 08, 2012, 07:45:19 PM »
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.

Offline blackfire88

  • Jr. Member
  • **
  • Posts: 56
  • Karma: 0
Re: Just a general lua problem.
« Reply #2 on: August 08, 2012, 08:15:44 PM »
Thanks for the help :)
It works now.

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

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Just a general lua problem.
« Reply #3 on: August 08, 2012, 08:27:12 PM »
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.