I was over at Facepunch
asking for a script to only allow admins to noclip but let everyone else fly, and someone posted this code:
http://xanthite.com/scripts/Scripts/Server%20Side/fly.lua// ##################################################
// Fly Mode
// By RabidToaster
// ##################################################
// #########################
// Settings!
// #########################
local Speed = 60 // Speed of flight.
// #########################
// Don't change down here!
// #########################
// Called when the player tries to noclip.
local function PlayerNoClip( pPlayer )
// If the player isn't an admin...
if ( !pPlayer:IsAdmin() ) then
// Make sure the variable is there to be toggled, and toggle it.
pPlayer.Flying = pPlayer.Flying or false
pPlayer.Flying = not pPlayer.Flying
// If they're flying, set their gravity very low to stop them sinking down, otherwise put normal.
local iGravity = 1
if ( pPlayer.Flying ) then iGravity = 0.00001 end
pPlayer:SetGravity( iGravity )
// Stop them from noclipping.
return false
end
end
hook.Add( "PlayerNoClip", "Fly.PlayerNoClip", PlayerNoClip )
// Called before the engine processes movements.
local function SetupMove( pPlayer, mdData )
// If the player is flying...
if ( pPlayer.Flying ) then
// Get their velocity, and slow them a little, and get their aim vector.
local vlPlayer = mdData:GetVelocity() * 0.9
local aPlayer = pPlayer:GetAimVector():Angle()
// Add appropriate velocity for key presses.
if ( pPlayer:KeyDown( IN_FORWARD ) ) then
vlPlayer = vlPlayer + ( aPlayer:Forward() * Speed )
elseif ( pPlayer:KeyDown( IN_BACK ) ) then
vlPlayer = vlPlayer + ( aPlayer:Forward() * -Speed )
end
if ( pPlayer:KeyDown( IN_MOVERIGHT ) ) then
vlPlayer = vlPlayer + ( aPlayer:Right() * Speed )
elseif ( pPlayer:KeyDown( IN_MOVELEFT ) ) then
vlPlayer = vlPlayer + ( aPlayer:Right() * -Speed )
end
// Set their new velocity.
mdData:SetVelocity( vlPlayer )
end
end
hook.Add( "SetupMove", "Fly.SetupMove", SetupMove )
Now I noticed earlier in the Facepunch thread, Megiddo said code that interacts with PlayerNoClip may conflict with scripts like ULX. Anywho I installed this code and it works fine for admins but for other users it doesn't do anything. Is this a problem with that script/code or is it conflicting with ULX somehow? If the latter, any idea how to get it to un-conflict? Thanks so much.