• Prevent players from clipping walls with noclip
    10 replies, posted
Like the title says, I'd like to allow players to use noclip and fly around, but prevent them from being able to fly through props and world geometry.
[url]http://wiki.garrysmod.com/page/Enums/MOVETYPE[/url] Gonna wanna use the fly movetype without gravity, I believe. [sp] Never done that before, but this looks pretty legit. Apologies if that doesn't work[/sp]
there is an addon called uclip, its by the ulyssess team. you should find it in their ulyssess-master.
The fly movetype seems interesting. I tried implementing it in this function; [code] local function noclip(ply, state) result = not (state and not ply.god) if not result then ply:PrintMessage(3, "You may not use noclip while PvP is active; use !god.") ply:SetMovetype(MOVETYPE_WALK) else ply:SetMovetype(MOVETYPE_FLY) end return result end hook.Add("PlayerNoClip", "PlayerNoClip_", noclip)[/code] But it doesn't work properly, and it also prevents players in god mode from leaving noclip.
[QUOTE=Maurdekye;47277374]The fly movetype seems interesting. I tried implementing it in this function; [code] local function noclip(ply, state) result = not (state and not ply.god) if not result then ply:PrintMessage(3, "You may not use noclip while PvP is active; use !god.") ply:SetMovetype(MOVETYPE_WALK) else ply:SetMovetype(MOVETYPE_FLY) end return result end hook.Add("PlayerNoClip", "PlayerNoClip_", noclip)[/code] But it doesn't work properly, and it also prevents players in god mode from leaving noclip.[/QUOTE] Put return false at the bottom instead of result. Is ply.god defined?
Yes, ply.god is defined. It's a part of the rest of my script, and is a boolean value. Also, I put return false at the bottom and now players in god mode are stuck in fly mode.
[QUOTE=Maurdekye;47277527]Yes, ply.god is defined. It's a part of the rest of my script, and is a boolean value. Also, I put return false at the bottom and now players in god mode are stuck in fly mode.[/QUOTE] The logic in your code is wrong. [code] local function noclip(ply, _) if !ply.state && ply.god then ply:SetMovetype(MOVETYPE_FLY) ply.state = true return false end if !ply.state && !ply.god then ply:PrintMessage(3, "You may not use noclip while PvP is active; use !god.") ply:SetMovetype(MOVETYPE_WALK) ply.state = false return false end if ply.state then ply:SetMovetype(MOVETYPE_WALK) ply.state = false end return false end hook.Add("PlayerNoClip", "PlayerNoClip_", noclip) [/code] Something like that I'm assuming that's what you are aiming for.
Thanks, I was just coming back to this thread to mention that I might need to add a new value to the player's metatable. I ended up using this code below, and it works pretty well; [code]local function noclip(ply, _) checkValues(ply) if not ply.state then if ply.god then ply:SetMoveType(MOVETYPE_FLY) ply.state = true else ply:PrintMessage(3, "You may not use noclip while PvP is active; use !god.") ply:SetMoveType(MOVETYPE_WALK) ply.state = false end else ply:SetMoveType(MOVETYPE_WALK) ply.state = false end return false end hook.Add("PlayerNoClip", "PlayerNoClip_", noclip)[/code] But the flying movetype doesn't work very well, and is kind of buggy. I think i'll just stick with my old noclip version since there doesn't seem to be an easy alternative.
Here's what I did for mine: [code]// // Enable / Disable noclip or fly-modes - Josh 'Acecool' Moser // function GM:PlayerNoClip( _p ) // Level database local _level, _leveldb = _p:GetAccessLevel( ); if ( _p:IsAdmin( ) ) then if ( _leveldb.noclip == PERMISSIONS_CAN_FLY ) then if ( _p:GetMoveType( ) == MOVETYPE_FLY ) then _p:SetMoveType( MOVETYPE_WALK ); _p:SetFlag( "player_noclipping", false ); else _p:SetMoveType( MOVETYPE_FLY ); _p:SetFlag( "player_noclipping", true ); end return false; elseif ( _leveldb.noclip == PERMISSIONS_CAN_NOCLIP ) then if ( SERVER ) then _p:SetFlag( "player_noclipping", !( _p:GetMoveType( ) == MOVETYPE_NOCLIP || _p:GetMoveType( ) == MOVETYPE_FLY ) ); end return true; end end return false; end // // // function GM:SetupMove( _p, _move, _cmd ) // GM Fly Mod if ( _p:GetMoveType( ) == MOVETYPE_FLY ) then // || _p.__MOVEZ ) then -- print( "fly" ) local speed = 1000; if ( _p:KeyDown(IN_SPEED) ) then speed = 2000; end local pav = _p:GetAi_moveector( ) local _pos = _p:GetPos( ) local notFlying = true; // Not working as designed. if ( _p:KeyDown( IN_FORWARD ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then notFlying = false; pav = pav + ( pav * speed ) if ( _p:KeyDown( IN_MOVELEFT ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then pav = pav + ( pav:Angle( ):Right( ) * -speed ) elseif ( _p:KeyDown( IN_MOVERIGHT ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then pav = pav + ( pav:Angle( ):Right( ) * speed ) end elseif ( _p:KeyDown( IN_BACK ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then notFlying = false; pav = pav + ( pav * -speed ) if ( _p:KeyDown( IN_MOVELEFT ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then pav = pav - ( pav:Angle( ):Right( ) * -speed ) elseif ( _p:KeyDown( IN_MOVERIGHT ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then pav = pav - ( pav:Angle( ):Right( ) * speed ) end elseif ( _p:KeyDown( IN_MOVELEFT ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then notFlying = false; pav = pav + ( pav:Angle( ):Right( ) * -speed ) elseif ( _p:KeyDown( IN_MOVERIGHT ) ) then // _p:KeyDown(IN_WALK) ) then // and _p:IsAdmin( ) ) then notFlying = false; pav = pav + ( pav:Angle( ):Right( ) * speed ) end if ( notFlying ) then _move:SetVelocity( pav * 0 ) else // Player won't unstick?? _move:SetVelocity( pav ) end end end[/code] It's old code and I am going to re-code it for my admin system that'll be released soon. It works, but the one issue is if you are on the ground you need to look up while in fly-mode or jump prior to going into fly-mode because otherwise you're magnetized to the ground.
That's interesting, but as far as I can tell it does pretty much exactly the same thing as mine does, but just with more checks and flags that i'm assuming play into the rest of the script that you ripped that from. I'm not going to use the fly movetype, because it's buggy, slow, and difficult to use.
You may be able to use the drive library... If not, it wouldn't be difficult to change the fly system to work better.. Take a look at this ( a newer movement system ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player_movement/2d.5_movement.lua.html[/url] - Remove .html to view / copy .Lua ... That'd be how I'd set it up now...
Sorry, you need to Log In to post a reply to this thread.