-
-
Save samisalreadytaken/dbb6d96ac97c5ef24a123b14f96fb84e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// github.com/samisalreadytaken | |
local World = Entities.First() | |
if ( IsServer() ) | |
{ | |
World.PrecacheSoundScript("ambient/machines/keyboard1_clicks.wav") | |
World.PrecacheSoundScript("ambient/machines/keyboard2_clicks.wav") | |
World.PrecacheSoundScript("ambient/machines/keyboard3_clicks.wav") | |
World.PrecacheSoundScript("ambient/machines/keyboard4_clicks.wav") | |
World.PrecacheSoundScript("ambient/machines/keyboard5_clicks.wav") | |
World.PrecacheSoundScript("ambient/machines/keyboard6_clicks.wav") | |
local SoundThink = function(self) | |
{ | |
if ( m_bUseDown && m_hEntLocked ) | |
{ | |
self.EmitSound("k_lab.typing_short_random") | |
return 0.25 | |
} | |
return -1 | |
} | |
// cache every string | |
local m_barstring = array(25) | |
m_barstring[0] = "|" | |
for ( local i = 0; i < 24; ++i ) | |
m_barstring[i+1] = m_barstring[i] + "|" | |
local m_pcstring = array(25) | |
for ( local i = 0; i < 25; ++i ) | |
m_pcstring[i] = (i*4) + "%%" | |
m_nCurIndex <- 0 | |
m_bUseDown <- false | |
m_bUseComplete <- false | |
function UseBarThink(self) | |
{ | |
if ( m_bUseDown ) | |
{ | |
if ( m_hEntLocked ) | |
{ | |
if ( m_nCurIndex == 24 ) | |
{ | |
debugoverlay.ScreenText( 0.43, 0.65, m_barstring[m_nCurIndex], 0,255,0,255, 2.5 ) | |
debugoverlay.ScreenText( 0.43, 0.67, "100%%\tCOMPLETE", 0,255,0,255, 2.5 ) | |
m_bUseComplete = true; | |
return -1 | |
} | |
++m_nCurIndex | |
} | |
else | |
{ | |
m_nCurIndex = 0 | |
} | |
debugoverlay.ScreenText( 0.43, 0.65, m_barstring[m_nCurIndex], 0,255,0,255, 0.2 ) | |
debugoverlay.ScreenText( 0.43, 0.67, m_pcstring[m_nCurIndex], 0,255,0,255, 0.2 ) | |
return 0.15 | |
} | |
else | |
{ | |
if ( m_nCurIndex != 0 ) | |
--m_nCurIndex | |
debugoverlay.ScreenText( 0.43, 0.65, m_barstring[m_nCurIndex], 0,255,0,255, 0.075 ) | |
debugoverlay.ScreenText( 0.43, 0.67, m_pcstring[m_nCurIndex], 0,255,0,255, 0.075 ) | |
return 0.045 | |
} | |
} | |
local IN_Use = function(...) | |
{ | |
// down | |
if ( vargv[0][0] == '+' ) | |
{ | |
m_bUseDown = true; | |
} | |
// up | |
else | |
{ | |
m_bUseDown = false; | |
} | |
} | |
function RegisterUse() | |
{ | |
m_bUseComplete = false | |
m_bUseDown = false | |
m_nCurIndex = 0 | |
player.SetContextThink( "UseBar", UseBarThink, 0.0 ) | |
Convars.RegisterCommand( "+use", IN_Use, "", FCVAR_NONE ) | |
Convars.RegisterCommand( "-use", IN_Use, "", FCVAR_NONE ) | |
} | |
local entlist = [] | |
function DoAction(ent) | |
{ | |
local pos = ent.GetOrigin() | |
ent.Destroy() | |
NetMsg.Start("Explosion") | |
NetMsg.WriteVec3Coord( pos ) | |
NetMsg.Send( player, true ) | |
local hull = Vector(256,256,256) | |
local mins = pos - hull | |
local maxs = pos + hull | |
EntitiesInBox( entlist, 256, mins, maxs, 0 ) | |
foreach( v in entlist ) | |
{ | |
if ( v.GetPhysicsObject() ) | |
{ | |
local dir = v.GetCenter().Subtract(pos) | |
local dist = 1000.0 / dir.Norm() | |
dir.z += 0.25 | |
dir.Multiply( 0.4 * dist * v.GetMass() ) | |
v.ApplyAbsVelocityImpulse( dir ) | |
} | |
} | |
entlist.clear() | |
m_hEntLocked = null | |
player.SetContextThink( "Unfreeze", Unfreeze, 2.0 ) | |
} | |
function Unfreeze(self) | |
{ | |
RegisterUse() | |
player.SetContextThink( "MainThink", MainThink, 0.0 ) | |
} | |
m_flOffset <- 16.0 | |
m_flLerpFrac <- 0.0 | |
m_bLerpDir <- false | |
// oscillate between 16 - 24 | |
// values can be cached | |
local CalcOffset = function() | |
{ | |
local dt = 0.11 | |
if ( !m_bLerpDir ) | |
{ | |
if ( m_flLerpFrac < 1.0 ) | |
{ | |
m_flLerpFrac = SimpleSpline( m_flLerpFrac ) | |
m_flLerpFrac += dt | |
m_flOffset = Lerp( m_flLerpFrac, m_flOffset, 24.0 ) | |
} | |
else | |
{ | |
m_bLerpDir = true | |
} | |
} | |
else | |
{ | |
if ( m_flLerpFrac > 0.0 ) | |
{ | |
m_flLerpFrac = SimpleSpline( m_flLerpFrac ) | |
m_flLerpFrac -= dt | |
m_flOffset = Lerp( m_flLerpFrac, 16.0, m_flOffset ) | |
} | |
else | |
{ | |
m_bLerpDir = false | |
} | |
} | |
} | |
m_hEntLocked <- null | |
function MainThink(self) | |
{ | |
local vecEye = self.EyePosition() | |
local ent | |
if ( !m_hEntLocked || (m_hEntLocked && !m_hEntLocked.IsValid()) ) | |
{ | |
ent = Entities.FindByClassNearestFacing( vecEye, self.GetEyeForward(), 0.9, "*" ) | |
} | |
else | |
{ | |
ent = m_hEntLocked | |
} | |
if ( !ent ) | |
return 0.1 | |
if ( m_bUseComplete ) | |
{ | |
DoAction(ent) | |
m_bUseComplete = false | |
return -1 | |
} | |
local r,g,b | |
if ( m_bUseDown ) | |
{ | |
r = 250 | |
g = 50 | |
b = 50 | |
if ( !m_hEntLocked ) | |
{ | |
m_hEntLocked = ent | |
player.EmitSound("HL2Player.Use") | |
player.SetContextThink( "SoundThink", SoundThink, 0.0 ) | |
} | |
} | |
else | |
{ | |
r = 50 | |
g = 250 | |
b = 50 | |
if ( m_hEntLocked ) | |
m_hEntLocked = null | |
} | |
CalcOffset() | |
local vecOrigin = ent.GetCenter() | |
local dir = vecEye - vecOrigin | |
dir.Norm() | |
local ang = VectorAngles( dir ) | |
debugoverlay.CircleOriented( vecOrigin, ang, 4.0, r,g,b,8, true, 0.15 ) | |
vecOrigin.z += m_flOffset | |
local vecStart = Vector().Set( vecOrigin ) | |
vecStart.z += 16.0 | |
debugoverlay.VertArrow( vecStart, vecOrigin, 2.5, r,255,b,127, true, 0.05 ) | |
NetMsg.Start( "DlightThink" ) | |
NetMsg.WriteVec3Coord( vecOrigin ) | |
NetMsg.WriteByte( r ) | |
NetMsg.WriteByte( g ) | |
NetMsg.WriteByte( b ) | |
NetMsg.Send( player, true ) | |
return 0.01 | |
} | |
NetMsg.Recieve( "NotifyFileLoaded", function(ply) | |
{ | |
RegisterUse() | |
player.SetContextThink( "MainThink", MainThink, 0.0 ) | |
} ) | |
SendToConsole("script_execute_client " + __FILE__) | |
} | |
if ( IsClient() ) | |
{ | |
NetMsg.Recieve( "DlightThink", function() | |
{ | |
local pos = NetMsg.ReadVec3Coord() | |
local r = NetMsg.ReadByte() | |
local g = NetMsg.ReadByte() | |
local b = NetMsg.ReadByte() | |
effects.DynamicLight( 0x10000000, pos, r,g,b,3, 64.0, 0.1, 0.0, 0, 0x0 ) | |
} ) | |
NetMsg.Recieve( "Explosion", function() | |
{ | |
local pos = NetMsg.ReadVec3Coord() | |
effects.Explosion( pos, 16.0, 64, 8, 0 ) | |
effects.Sparks( pos, 8, 2, Vector(0,0,1) ) | |
effects.DynamicLight( 0x10000000, pos, 255,120,0,2, 256.0, 0.25, 256.0/0.25, 0, 0x0 ) | |
local dist = player.GetOrigin().DistTo(pos) | |
local scale = 1.0 - ( dist/256.0 ) | |
NetMsg.Reset() | |
NetMsg.WriteByte( 0 ) | |
NetMsg.WriteFloat( 32.0 * scale ) // magnitude | |
NetMsg.WriteFloat( 2.0 * scale ) // freq | |
NetMsg.WriteFloat( 4.0 * scale ) // duration | |
NetMsg.DispatchUserMessage( "Shake" ) | |
} ) | |
NetMsg.Start( "NotifyFileLoaded" ) | |
NetMsg.Send() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment