Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile "cl_init.lua"
- AddCSLuaFile "shared.lua"
- include "shared.lua"
- util.AddNetworkString( "netKCSMenu" )
- util.AddNetworkString( "netKCSpawn" )
- util.AddNetworkString( "netKeycardHackSpawn" )
- net.Receive( "netKCSpawn", function( len, ply )
- local ent = net.ReadEntity()
- if not IsValid( ply ) or not IsValid( ent ) then return end
- if ent:GetStatus() ~= ent.Status_None then return end
- timer.Simple( 2, function()
- if not IsValid( ent ) or not IsValid( keycard ) then return end
- keycard:Remove()
- end )
- ScanCard( ply, ent )
- end )
- net.Receive( "netKeycardHackSpawn", function( len, ply )
- local ent = net.ReadEntity()
- if not IsValid( ply ) or not IsValid( ent ) then return end
- if ent:GetStatus() ~= ent.Status_None then return end
- local keycard = ents.Create( "ent_keycardh" )
- keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) )
- keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) )
- keycard:SetParent( ent )
- keycard:Spawn()
- ply:StripWeapon( "weapon_keycardh" )
- ent:EmitSound( "buttons/button18.wav" )
- ent:SetStatus( ent.Status_Hacking )
- timer.Create( "KS_Beep", 1, 0, function()
- if not IsValid( ent ) or not IsValid( keycard ) then
- if IsValid( ent ) then ent:SetStatus( ent.Status_None ) end
- if IsValid( ply ) then
- ply:Give( "weapon_keycardh" )
- end
- return
- end
- ent:EmitSound( "buttons/button17.wav" )
- end )
- timer.Create( "KS_Beep2", 1.5, 0, function()
- if not IsValid( ent ) or not IsValid( keycard ) then return end
- ent:EmitSound( "buttons/button17.wav" )
- end )
- timer.Simple( 60, function()
- if not IsValid( ent ) or not IsValid( keycard ) then return end
- ply:Give( "weapon_keycardh" )
- timer.Destroy( "KS_Beep" )
- timer.Destroy( "KS_Beep2" )
- ent:SetStatus( ent.Status_None )
- keycard:Remove()
- ent:Access( true )
- end )
- end )
- function ScanCard( ply, ent )
- if not IsValid( ply ) or not IsValid( ent ) then return end
- if ent:GetStatus() ~= ent.Status_None then return end
- if ply:EyePos():Distance( ent:GetPos() ) >= 120 then return end
- ply:StripWeapon( "weapon_keycard" )
- ent:EmitSound( "buttons/button14.wav" )
- ent:SetStatus( ent.Status_Scanning )
- timer.Simple( 2, function()
- if not IsValid( ent ) then return end
- local AllowedUsers = ent.KCSData.AllowedUsers or {}
- if ply == ent.KCSData.Owner or table.HasValue( AllowedUsers, ply ) then ent:Access( true ) else ent:Access( false ) end
- end )
- timer.Simple( 2, function() ply:Give( "weapon_keycard" ) end )
- end
- function ENT:Initialize()
- self.Outputs = WireLib.CreateOutputs(self, {"Access Granted", "Access Denied"})
- self:SetModel( "models/card/keycard_scanner.mdl" )
- self:PhysicsInit( SOLID_VPHYSICS )
- self:SetMoveType( MOVETYPE_VPHYSICS )
- self:SetSolid( SOLID_VPHYSICS )
- self:SetUseType( SIMPLE_USE )
- local phys = self:GetPhysicsObject()
- if phys:IsValid() then phys:Wake() end
- end
- function ENT:Access( granted )
- local length, initdelay, delay, owner, key
- if granted then
- self:SetStatus( self.Status_Granted )
- length = self.KCSData.LengthGranted
- initdelay = self.KCSData.InitDelayGranted
- delay = self.KCSData.DelayGranted
- owner = self.KCSData.Owner
- key = tonumber( self.KCSData.KeyGranted ) or 0
- else
- self:SetStatus( self.Status_Denied )
- length = self.KCSData.LengthDenied
- initdelay = self.KCSData.InitDelayDenied
- delay = self.KCSData.DelayDenied
- owner = self.KCSData.Owner
- key = tonumber( self.KCSData.KeyDenied ) or 0
- end
- timer.Simple( math.max(initdelay + length + delay * 0.25, 2), function()
- if IsValid( self ) then
- self:Reset()
- end
- end )
- timer.Simple(initdelay, function()
- if(IsValid(self)) then
- for i = 0, repeats do
- timer.Simple(length * i + delay * i, function()
- if(IsValid(self) and IsValid(owner)) then
- numpad.Activate(owner, key, true)
- end
- end)
- timer.Simple(length * (i + 1) + delay * i, function()
- if(IsValid(self) and IsValid(owner)) then
- numpad.Deactivate(owner, key, true)
- end
- end)
- end
- end
- end)
- if granted then
- self:EmitSound( "buttons/button9.wav" )
- WireLib.TriggerOutput(self,"Access Granted",accessGrantedValue)
- else
- self:EmitSound( "buttons/button11.wav" )
- WireLib.TriggerOutput(self,"Access Denied",accessDeniedValue)
- end
- end
- function ENT:SetData( data )
- self.KCSData = data
- self:Reset()
- end
- function ENT:GetData()
- return self.KCSData
- end
- function ENT:Reset()
- self:SetStatus( self.Status_None )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement