Toranks

gamemaps version

May 29th, 2022 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.55 KB | None | 0 0
  1. /************************************************************************************************
  2. *    Thirdperson Over The Shoulder Mod, thirdpersonovertheshoulder.nut
  3. *    
  4. *   A script that controls some variables related to the thirdpersonshoulder view
  5. *   on Left 4 Dead 2
  6. *
  7. *    @author Claucker
  8. *    @version 0.3a 11 December 2017
  9. ************************************************************************************************/
  10.  
  11. // Include the VScript Library
  12. IncludeScript( "VSLib" );
  13.  
  14. // Stores the shoguns audio files path
  15. ::SOUND_AUTOSHOTGUN <- "weapons/auto_shotgun/gunfire/auto_shotgun_fire_1.wav";
  16. ::SOUND_SPASSHOTGUN <- "weapons/auto_shotgun_spas/gunfire/shotgun_fire_1.wav";
  17. ::SOUND_PUMPSHOTGUN <- "weapons/shotgun/gunfire/shotgun_fire_1.wav";
  18. ::SOUND_CHROMESHOTGUN <- "weapons/shotgun_chrome/gunfire/shotgun_fire_1.wav";
  19.  
  20. ::entities <- {
  21.  
  22.     player = {}
  23. };
  24.  
  25. ::hostID <- null;
  26. ::distance <- 0.0;
  27.  
  28. function Notifications::OnMapFirstStart::SetEntitiesAtStart()
  29. {
  30.     ::distance = 0.0;
  31.     ::hostID = FileToString( "thirdpersonmod/user.txt" );
  32. }
  33.  
  34. // Start functions when the entity spawns
  35. function Notifications::OnSpawn::StartAimSetup( ent, params)
  36. {      
  37.     if ( ::IsTheEntityAPlayer( ent ) )
  38.     {
  39.         ::entities.player[ ent.GetSteamID() ] <- ent;
  40.        
  41.         // If the user is spawning on a Single Player gamemode or hosting
  42.         if ( ::IsTheHost( ent ) && ( ::hostID == null || ::hostID == "" ) )
  43.         {
  44.             StringToFile( "thirdpersonmod/user.txt",  ent.GetSteamID().tostring() ); // create a file called user.txt inside ems/thirdpersonmod/
  45.             ::hostID = FileToString( "thirdpersonmod/user.txt" );
  46.            
  47.             ::StartTimers( ::hostID );
  48.         }
  49.         else if ( ::hostID == ent.GetSteamID() )
  50.         {
  51.             ::StartTimers( ::hostID );
  52.         }
  53.     }
  54. }
  55.  
  56. // Plays the right shotgun sound
  57. function Notifications::OnWeaponFire::CheckShotguns( ent, weapons, params )
  58. {
  59.     // Check if the entity spawned is the correct player
  60.     if ( ::IsTheEntityAPlayer( ent ) && ::IsThirdPerson() )
  61.     {
  62.         if ( weapons.tostring() == "weapon_autoshotgun" )
  63.         {
  64.             ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_AUTOSHOTGUN );
  65.         }
  66.         else if ( weapons.tostring() == "weapon_shotgun_spas" )
  67.         {
  68.             ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_SPASSHOTGUN );
  69.         }
  70.         else if ( weapons.tostring() == "weapon_pumpshotgun" )
  71.         {
  72.             ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_PUMPSHOTGUN );
  73.         }
  74.         else if ( weapons.tostring() == "weapon_shotgun_chrome" )
  75.         {
  76.             ::entities.player[ ent.GetSteamID() ].EmitSound( ::SOUND_CHROMESHOTGUN );
  77.         }
  78.     }
  79. }
  80.  
  81. ::StartTimers <- function ( hostID )
  82. {
  83.     Timers.AddTimer( 0.1, false, SetConVars, ::entities.player[ hostID ] );
  84.     Timers.AddTimer( 0.5, true, UpdateAimDistance, ::entities.player[ hostID ] );   // Starts updating the cam values
  85. }
  86.  
  87. // Changes the distance based on the new values
  88. // for the player's eyes position and the looking location
  89. ::UpdateAimDistance <- function ( player )
  90. {  
  91.     for ( local i = 0; i < 1.0; i += 0.25 )
  92.     {
  93.         ::distance = Utils.CalculateDistance( player.GetEyePosition() , player.GetLookingLocation() );
  94.        
  95.         if( ::distance > 120 )
  96.             Convars.SetValue( "c_thirdpersonshoulderaimdist", ::distance ); // updates the thirdpersonshoulder aim value
  97.     }
  98. }
  99.  
  100. // Set the cam values
  101. ::SetConVars <- function ( ent )
  102. {
  103.     // Global
  104.     Convars.SetValue( "cl_crosshair_dynamic", 1 );
  105.     Convars.SetValue( "cam_collision", 1 );
  106.     Convars.SetValue( "cam_idealdelta", 4.0 );
  107.     Convars.SetValue( "cam_idealdist", 40 );
  108.     Convars.SetValue( "cam_ideallag", 4.0 );
  109.     Convars.SetValue( "cam_idealpitch", 0 );
  110.     Convars.SetValue( "cam_idealyaw", 0 );
  111.  
  112.     // DEFAULT CFG
  113.     Convars.SetValue( "c_mindistance", 30 );
  114.     Convars.SetValue( "c_minpitch", 0 );
  115.     Convars.SetValue( "c_minyaw",  -135 );
  116.     Convars.SetValue( "c_maxdistance", 200 );
  117.     Convars.SetValue( "c_maxpitch", 90 );
  118.     Convars.SetValue( "c_maxyaw", 135 );
  119.     Convars.SetValue( "cam_idealdelta", 4.0 );
  120.     Convars.SetValue( "cam_idealdist", 150 );
  121.     Convars.SetValue( "cam_ideallag", 4.0 );
  122.     Convars.SetValue( "cam_idealpitch", 0 );
  123.     Convars.SetValue( "cam_idealyaw" , 0 );
  124.     Convars.SetValue( "crosshair", 1 );
  125.    
  126.     // RUNCAMERA
  127.     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;\" " );
  128.     ent.ClientCommand( "alias -tpsrun \"+tpscamera;\" " );
  129.    
  130.     // NORMALCAMERA
  131.     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;\" " );
  132.     ent.ClientCommand( "alias -tpscamera \" \";" );
  133.    
  134.     // TPSFOCUS
  135.     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;\" " );
  136.     ent.ClientCommand( "alias -tpsfocus \"+tpsrun; +tpscamera;\"; " );
  137.  
  138.     ent.ClientCommand( "+tpscamera" );
  139. }
  140.  
  141. ::IsThirdPerson <- function ()
  142. {
  143.     return ( Convars.GetStr ( "c_thirdpersonshoulder" ) == "1" );
  144. }
  145.  
  146. ::IsTheEntityAPlayer <- function ( player )
  147. {
  148.     return  ( !player.IsBot() && player.IsPlayer() );
  149. }
  150.  
  151. ::IsTheHost <- function ( ent )
  152. {
  153.     return ( Director.IsSinglePlayerGame() || ent.IsServerHost() )
  154. }
Add Comment
Please, Sign In to add comment