Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************************************************************
- * Thirdperson Over The Shoulder Mod, thirdpersonovertheshoulder.nut
- *
- * A script that controls some variables related to the thirdpersonshoulder view
- * on Left 4 Dead 2
- *
- * @author Claucker
- * @version 0.3a 11 December 2017
- ************************************************************************************************/
- // Include the VScript Library
- IncludeScript( "VSLib" );
- // Stores the shoguns audio files path
- ::SOUND_AUTOSHOTGUN <- "weapons/auto_shotgun/gunfire/auto_shotgun_fire_1.wav";
- ::SOUND_SPASSHOTGUN <- "weapons/auto_shotgun_spas/gunfire/shotgun_fire_1.wav";
- ::SOUND_PUMPSHOTGUN <- "weapons/shotgun/gunfire/shotgun_fire_1.wav";
- ::SOUND_CHROMESHOTGUN <- "weapons/shotgun_chrome/gunfire/shotgun_fire_1.wav";
- ::entities <- {
- player = {}
- };
- ::hostID <- null;
- ::distance <- 0.0;
- function Notifications::OnMapFirstStart::SetEntitiesAtStart()
- {
- ::distance = 0.0;
- ::hostID = FileToString( "thirdpersonmod/user.txt" );
- }
- // Start functions when the entity spawns
- function Notifications::OnSpawn::StartAimSetup( ent, params)
- {
- if ( ::IsTheEntityAPlayer( ent ) )
- {
- ::entities.player[ ent.GetSteamID() ] <- ent;
- // If the user is spawning on a Single Player gamemode or hosting
- if ( ::IsTheHost( ent ) && ( ::hostID == null || ::hostID == "" ) )
- {
- StringToFile( "thirdpersonmod/user.txt", ent.GetSteamID().tostring() ); // create a file called user.txt inside ems/thirdpersonmod/
- ::hostID = FileToString( "thirdpersonmod/user.txt" );
- ::StartTimers( ::hostID );
- }
- else if ( ::hostID == ent.GetSteamID() )
- {
- ::StartTimers( ::hostID );
- }
- }
- }
- // Plays the right shotgun sound
- function Notifications::OnWeaponFire::CheckShotguns( ent, weapons, params )
- {
- // Check if the entity spawned is the correct player
- if ( ::IsTheEntityAPlayer( ent ) && ::IsThirdPerson() )
- {
- if ( weapons.tostring() == "weapon_autoshotgun" )
- {
- ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_AUTOSHOTGUN );
- }
- else if ( weapons.tostring() == "weapon_shotgun_spas" )
- {
- ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_SPASSHOTGUN );
- }
- else if ( weapons.tostring() == "weapon_pumpshotgun" )
- {
- ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_PUMPSHOTGUN );
- }
- else if ( weapons.tostring() == "weapon_shotgun_chrome" )
- {
- ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_CHROMESHOTGUN );
- }
- }
- }
- ::StartTimers <- function ( hostID )
- {
- Timers.AddTimer( 0.1, false, SetConVars, ::entities.player[ hostID ] );
- Timers.AddTimer( 0.5, true, UpdateAimDistance, ::entities.player[ hostID ] ); // Starts updating the cam values
- }
- // Changes the distance based on the new values
- // for the player's eyes position and the looking location
- ::UpdateAimDistance <- function ( player )
- {
- for ( local i = 0; i < 1.0; i += 0.25 )
- {
- ::distance = Utils.CalculateDistance( player.GetEyePosition() , player.GetLookingLocation() );
- if( ::distance > 120 )
- Convars.SetValue( "c_thirdpersonshoulderaimdist", ::distance ); // updates the thirdpersonshoulder aim value
- }
- }
- // Set the cam values
- ::SetConVars <- function ( ent )
- {
- // Global
- Convars.SetValue( "cl_crosshair_dynamic", 1 );
- Convars.SetValue( "cam_collision", 1 );
- Convars.SetValue( "cam_idealdelta", 4.0 );
- Convars.SetValue( "cam_idealdist", 40 );
- Convars.SetValue( "cam_ideallag", 4.0 );
- Convars.SetValue( "cam_idealpitch", 0 );
- Convars.SetValue( "cam_idealyaw", 0 );
- // DEFAULT CFG
- Convars.SetValue( "c_mindistance", 30 );
- Convars.SetValue( "c_minpitch", 0 );
- Convars.SetValue( "c_minyaw", -135 );
- Convars.SetValue( "c_maxdistance", 200 );
- Convars.SetValue( "c_maxpitch", 90 );
- Convars.SetValue( "c_maxyaw", 135 );
- Convars.SetValue( "cam_idealdelta", 4.0 );
- Convars.SetValue( "cam_idealdist", 150 );
- Convars.SetValue( "cam_ideallag", 4.0 );
- Convars.SetValue( "cam_idealpitch", 0 );
- Convars.SetValue( "cam_idealyaw" , 0 );
- Convars.SetValue( "crosshair", 1 );
- // RUNCAMERA
- ent.ClientCommand( "alias +tpsrun \"crosshair 0; c_mindistance 30; c_minpitch 0; c_minyaw -135; c_maxdistance 200; c_maxpitch 90; c_maxyaw 135; cam_idealdelta 4.0; cam_idealdist 80; cam_ideallag 4.0; cam_idealpitch 0; cam_idealyaw 0; c_thirdpersonshoulderheight 0;\" " );
- ent.ClientCommand( "alias -tpsrun \"+tpscamera;\" " );
- // NORMALCAMERA
- ent.ClientCommand( "alias +tpscamera \"-speed; crosshair 1; cam_idealpitch 0; cam_ideallag 0; cam_idealdist 50; cam_idealdelta 4; cam_idealyaw 0; c_thirdpersonshoulderoffset 25; c_thirdpersonshoulderheight 0; c_thirdpersonshoulderdist 50;\" " );
- ent.ClientCommand( "alias -tpscamera \" \";" );
- // TPSFOCUS
- ent.ClientCommand( "alias +tpsfocus \"+tpsrun; +speed; crosshair 1; cam_idealyaw 0; c_thirdpersonshoulderheight 0; c_thirdpersonshoulderoffset 20; c_thirdpersonshoulderdist 25; cam_idealdist 15; c_mindistance 15;\" " );
- ent.ClientCommand( "alias -tpsfocus \"+tpsrun; +tpscamera;\"; " );
- ent.ClientCommand( "+tpscamera" );
- }
- ::IsThirdPerson <- function ()
- {
- return ( Convars.GetStr ( "c_thirdpersonshoulder" ) == "1" );
- }
- ::IsTheEntityAPlayer <- function ( player )
- {
- return ( !player.IsBot() && player.IsPlayer() );
- }
- ::IsTheHost <- function ( ent )
- {
- return ( Director.IsSinglePlayerGame() || ent.IsServerHost() )
- }
Add Comment
Please, Sign In to add comment