• Problem with ply:Spectate
    4 replies, posted
Hello, I have a problem with ply:Spectate( 6 ). When a player joins the server he gets the roaming spectator mode, so he has god mode and is flying. Now when he spawns I wrote this code: [CODE]ply:Spectate( 0 ) ply:UnSpectate()[/CODE] It is all okay and he can move correctly, but he is invisible (the other players can only see the weapon) and has still god mode. Also there is no HUD. Can you help me? Maksimo007
You don't have to set the spectate mode before unspectate. I'm not sure if this is the cause (since they would be called in the same frame). If that doesn't help, there might be an addon confliction or some part of the gamemode doesn't get triggered correctly when the player is removed from spectating. Don't use the actual values for the modes, they are [url=http://wiki.garrysmod.com/page/Enums/OBS_MODE]Enums[/url]. [url]http://en.wikipedia.org/wiki/Enumerated_type[/url]
Hmm, it does not work... Here is a part of my whole code: [CODE] function GM:PlayerSpawn( ply ) if ply:Team() == 1 then if #player.GetAll() > 1 then if round.Active == false or round.Prepare == true then ply:UnSpectate() ply:Freeze(false) ply:GodDisable() ply:SetMaxHealth( 100, true ) pang = ply:GetAngles() ply:SetAngles(Angle(0, pang.y, 0)) GAMEMODE:PlayerLoadout( ply ) GAMEMODE:PlayerSetModel( ply ) GAMEMODE:SetPlayerSpeed( ply, 250, 300 ) end end elseif ply:Team() == 3 then ply:Spectate( OBS_MODE_ROAMING ) end end function GM:PlayerSetModel( ply ) ply:SetModel( "models/player/leet.mdl" ) end --Give weapons function GM:PlayerLoadout( ply ) ply:Give("weapon_push") end function GM:PlayerInitialSpawn( ply ) ply:SetTeam( 3 ) if #player.GetAll() > 1 then if round.Active == false then if round.Prepare == false then print("Spawning...") round.Preparing() else GAMEMODE:PlayerSpawn( ply ) end end else print("Nicht genuegend Spieler zum Starten!") end --print(round.Prepare) end function round.Broadcast(Text) for k, v in pairs(player.GetAll()) do v:ChatPrint(Text) end end function round.Preparing() round.Prepare = true round.Active = false print("Preparing...") for k, v in pairs(player.GetAll()) do if v:Team() == 3 or v:Team() == 2 then v:SetTeam( 1 ) GAMEMODE:PlayerSpawn( v ) end end round.Broadcast("Preparing! 20 Seconds!") timer.Simple(round.PrepareTime, round.Begin) end[/CODE] So my problem is that I spawn with Godmode, so I have no HUD.
There's quite a bit wrong... Change GAMEMODE:... calls to hook.Call( "....", GAMEMODE, args ); so hooks can modify behavior. Don't use PlayerSpawn to spawn players, use v:Spawn( ); in round.Preparing and remove PlayerSpawn from PlayerInitialSpawn ( because PlayerSpawn is always called, even if InitialSpawn is also called the first time the player joins / spawns ). Example of limiting player spawning when they join the server: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/spectating_players_system.lua.html[/url] Method for creating spawn-points system: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/playerselectspawn_system.lua.html[/url] Hopefully those provide some insight.
Ah thank you very much! I will try it. ;)
Sorry, you need to Log In to post a reply to this thread.