CSHARP 27
_weapons.gsc Guest on 18th April 2021 07:24:47 PM
  1. #include common_scripts\utility;
  2. #include maps\mp\_utility;
  3. #include extreme\_ex_weapons;
  4.  
  5. init()
  6. {
  7.     // assigns weapons with stat numbers from 0-149
  8.     // attachments are now shown here, they are per weapon settings instead
  9.    
  10.     // generating weaponIDs array
  11.     level.weaponIDs = [];
  12.     max_weapon_num = 149;
  13.     attachment_num = 150;
  14.     for( i = 0; i <= max_weapon_num; i++ )
  15.     {
  16.         weapon_name = tablelookup( "mp/statstable.csv", 0, i, 4 );
  17.         if( !isdefined( weapon_name ) || weapon_name == "" )
  18.         {
  19.             level.weaponIDs[i] = "";
  20.             continue;
  21.         }
  22.         level.weaponIDs[i] = weapon_name + "_mp";
  23.        
  24.         // generating attachment combinations
  25.         attachment = tablelookup( "mp/statstable.csv", 0, i, 8 );
  26.         if( !isdefined( attachment ) || attachment == "" )
  27.             continue;
  28.            
  29.         attachment_tokens = strtok( attachment, " " );
  30.         if( !isdefined( attachment_tokens ) )
  31.             continue;
  32.            
  33.         if( attachment_tokens.size == 0 )
  34.         {
  35.             level.weaponIDs[attachment_num] = weapon_name + "_" + attachment + "_mp";
  36.             attachment_num++;
  37.         }
  38.         else
  39.         {
  40.             for( k = 0; k < attachment_tokens.size; k++ )
  41.             {
  42.                 level.weaponIDs[attachment_num] = weapon_name + "_" + attachment_tokens[k] + "_mp";
  43.                 attachment_num++;
  44.             }
  45.         }
  46.     }
  47.  
  48.     // generating weaponNames array
  49.     level.weaponNames = [];
  50.     for ( index = 0; index < max_weapon_num; index++ )
  51.     {
  52.         if ( !isdefined( level.weaponIDs[index] ) || level.weaponIDs[index] == "" )
  53.             continue;
  54.            
  55.         level.weaponNames[level.weaponIDs[index]] = index;
  56.     }
  57.    
  58.     // generating weaponlist array
  59.     level.weaponlist = [];
  60.     assertex( isdefined( level.weaponIDs.size ), "level.weaponIDs is corrupted" );
  61.     for( i = 0; i < level.weaponIDs.size; i++ )
  62.     {
  63.         if( !isdefined( level.weaponIDs[i] ) || level.weaponIDs[i] == "" )
  64.             continue;
  65.  
  66.         level.weaponlist[level.weaponlist.size] = level.weaponIDs[i];
  67.     }
  68.     // based on weaponList array, precache weapons in list
  69.     for ( index = 0; index < level.weaponList.size; index++ )
  70.     {
  71.         precacheItem( level.weaponList[index] );
  72.         println( "Precached weapon: " + level.weaponList[index] ); 
  73.     }
  74.  
  75.     precacheItem( "frag_grenade_short_mp" );
  76.    
  77.     precacheItem( "destructible_car" );
  78.    
  79.     precacheModel( "weapon_rpg7_stow" );
  80.    
  81.     precacheShellShock( "default" );
  82.     precacheShellShock( "concussion_grenade_mp" );
  83. //  thread maps\mp\_pipebomb::main();
  84. //  thread maps\mp\_ied::main();
  85.     thread maps\mp\_flashgrenades::main();
  86. //  thread maps\mp\_teargrenades::main();
  87.     thread maps\mp\_entityheadicons::init();
  88.  
  89.     claymoreDetectionConeAngle = 70;
  90.     level.claymoreDetectionDot = cos( claymoreDetectionConeAngle );
  91.     level.claymoreDetectionMinDist = 20;
  92.     level.claymoreDetectionGracePeriod = .75;
  93.     level.claymoreDetonateRadius = 192;
  94.     level.Proximityc4DetectionMinDist = 40;
  95.     level.Proximityc4DetonateRadius = 290;
  96.    
  97.     level.C4FXid = loadfx( "misc/light_c4_blink" );
  98.     level.claymoreFXid = loadfx( "misc/claymore_laser" );
  99.    
  100.     level thread onPlayerConnect();
  101.    
  102.     level.c4explodethisframe = false;
  103. }
  104.  
  105. onPlayerConnect()
  106. {
  107.     for(;;)
  108.     {
  109.         level waittill("connecting", player);
  110.  
  111.         player.usedWeapons = false;
  112.         player.hits = 0;
  113.  
  114.         player thread onPlayerSpawned();
  115.     }
  116. }
  117.  
  118. onPlayerSpawned()
  119. {
  120.     self endon("disconnect");
  121.  
  122.     for(;;)
  123.     {
  124.         self waittill("spawned_player");
  125.  
  126.         self.concussionEndTime = 0;
  127.         self.hasDoneCombat = false;
  128.         self thread watchWeaponUsage();
  129.         self thread watchGrenadeUsage();
  130.         self thread watchWeaponChange();
  131.        
  132.         self.droppedDeathWeapon = undefined;
  133.         self.tookWeaponFrom = [];
  134.        
  135.         self thread updateStowedWeapon();
  136.     }
  137. }
  138.  
  139. watchWeaponChange()
  140. {
  141.     self endon("death");
  142.     self endon("disconnect");
  143.    
  144.     self.lastDroppableWeapon = undefined;
  145.    
  146.     if ( mayDropWeapon( self getCurrentWeapon() ) )
  147.         self.lastDroppableWeapon = self getCurrentWeapon();
  148.    
  149.     while(1)
  150.     {
  151.         self waittill( "weapon_change", newWeapon );
  152.        
  153.         if ( mayDropWeapon( newWeapon ) )
  154.             self.lastDroppableWeapon = newWeapon;
  155.     }
  156. }
  157.  
  158. isPistol( weapon )
  159. {
  160.     return isdefined( level.side_arm_array[ weapon ] );
  161. }
  162.  
  163. hasScope( weapon )
  164. {
  165.     if ( isSubStr( weapon, "_acog_" ) )
  166.         return true;
  167.     if ( weapon == "m21_mp" )
  168.         return true;
  169.     if ( weapon == "aw50_mp" )
  170.         return true;
  171.     if ( weapon == "barrett_mp" )
  172.         return true;
  173.     if ( weapon == "dragunov_mp" )
  174.         return true;
  175.     if ( weapon == "m40a3_mp" )
  176.         return true;
  177.     if ( weapon == "remington700_mp" )
  178.         return true;
  179.     return false;
  180. }
  181.  
  182. isHackWeapon( weapon )
  183. {
  184.     if ( weapon == "radar_mp" || weapon == "airstrike_mp" || weapon == "helicopter_mp" )
  185.         return true;
  186.     if ( weapon == "briefcase_bomb_mp" )
  187.         return true;
  188.     return false;
  189. }
  190.  
  191. mayDropWeapon( weapon )
  192. {
  193.     if ( weapon == "none" )
  194.         return false;
  195.        
  196.     if ( isHackWeapon( weapon ) )
  197.         return false;
  198.    
  199.     invType = WeaponInventoryType( weapon );
  200.     if ( invType != "primary" )
  201.         return false;
  202.    
  203.     if ( weapon == "none" )
  204.         return false;
  205.    
  206.     if ( !isPrimaryWeapon( weapon ) )
  207.         return false;      
  208.    
  209.     switch ( level.primary_weapon_array[weapon] )
  210.     {
  211.         case "weapon_assault":
  212.             return ( getDvarInt( "class_assault_allowdrop" ) );
  213.         case "weapon_smg":
  214.             return ( getDvarInt( "class_specops_allowdrop" ) );
  215.         case "weapon_sniper":
  216.             return ( getDvarInt( "class_sniper_allowdrop" ) );
  217.         case "weapon_shotgun":
  218.             return ( getDvarInt( "class_demolitions_allowdrop" ) );
  219.         case "weapon_lmg":
  220.             return ( getDvarInt( "class_heavygunner_allowdrop" ) );
  221.     }
  222.     return true;
  223. }
  224.  
  225. dropWeaponForDeath( attacker )
  226. {
  227.     weapon = self.lastDroppableWeapon;
  228.    
  229.     if ( isdefined( self.droppedDeathWeapon ) )
  230.         return;
  231.    
  232.     if ( !isdefined( weapon ) )
  233.     {
  234.         /#
  235.         if ( getdvar("scr_dropdebug") == "1" )
  236.             println( "didn't drop weapon: not defined" );
  237.         #/
  238.         return;
  239.     }
  240.    
  241.     if ( weapon == "none" )
  242.     {
  243.         /#
  244.         if ( getdvar("scr_dropdebug") == "1" )
  245.             println( "didn't drop weapon: weapon == none" );
  246.         #/
  247.         return;
  248.     }
  249.    
  250.     if ( !self hasWeapon( weapon ) )
  251.     {
  252.         /#
  253.         if ( getdvar("scr_dropdebug") == "1" )
  254.             println( "didn't drop weapon: don't have it anymore (" + weapon + ")" );
  255.         #/
  256.         return;
  257.     }
  258.    
  259.     if ( !(self AnyAmmoForWeaponModes( weapon )) )
  260.     {
  261.         /#
  262.         if ( getdvar("scr_dropdebug") == "1" )
  263.             println( "didn't drop weapon: no ammo for weapon modes" );
  264.         #/
  265.         return;
  266.     }
  267.    
  268.     clipAmmo = self GetWeaponAmmoClip( weapon );
  269.     if ( !clipAmmo )
  270.     {
  271.         /#
  272.         if ( getdvar("scr_dropdebug") == "1" )
  273.             println( "didn't drop weapon: no ammo in clip" );
  274.         #/
  275.         return;
  276.     }
  277.  
  278.     stockAmmo = self GetWeaponAmmoStock( weapon );
  279.     stockMax = WeaponMaxAmmo( weapon );
  280.     if ( stockAmmo > stockMax )
  281.         stockAmmo = stockMax;
  282.  
  283.     item = self dropItem( weapon );
  284.     /#
  285.     if ( getdvar("scr_dropdebug") == "1" )
  286.         println( "dropped weapon: " + weapon );
  287.     #/
  288.    
  289.     self.droppedDeathWeapon = true;
  290.  
  291.     item ItemWeaponSetAmmo( clipAmmo, stockAmmo );
  292.     item itemRemoveAmmoFromAltModes();
  293.    
  294.     item.owner = self;
  295.     item.ownersattacker = attacker;
  296.    
  297.     item thread watchPickup();
  298.    
  299.     item thread deletePickupAfterAWhile();
  300. }
  301.  
  302. deletePickupAfterAWhile()
  303. {
  304.     self endon("death");
  305.    
  306.     wait 60;
  307.  
  308.     if ( !isDefined( self ) )
  309.         return;
  310.  
  311.     self delete();
  312. }
  313.  
  314. getItemWeaponName()
  315. {
  316.     classname = self.classname;
  317.     assert( getsubstr( classname, 0, 7 ) == "weapon_" );
  318.     weapname = getsubstr( classname, 7 );
  319.     return weapname;
  320. }
  321.  
  322. watchPickup()
  323. {
  324.     self endon("death");
  325.    
  326.     weapname = self getItemWeaponName();
  327.    
  328.     while(1)
  329.     {
  330.         self waittill( "trigger", player, droppedItem );
  331.        
  332.         if ( isdefined( droppedItem ) )
  333.             break;
  334.         // otherwise, player merely acquired ammo and didn't pick this up
  335.     }
  336.    
  337.     /#
  338.     if ( getdvar("scr_dropdebug") == "1" )
  339.         println( "picked up weapon: " + weapname + ", " + isdefined( self.ownersattacker ) );
  340.     #/
  341.  
  342.     assert( isdefined( player.tookWeaponFrom ) );
  343.    
  344.     // make sure the owner information on the dropped item is preserved
  345.     droppedWeaponName = droppedItem getItemWeaponName();
  346.     if ( isdefined( player.tookWeaponFrom[ droppedWeaponName ] ) )
  347.     {
  348.         droppedItem.owner = player.tookWeaponFrom[ droppedWeaponName ];
  349.         droppedItem.ownersattacker = player;
  350.         player.tookWeaponFrom[ droppedWeaponName ] = undefined;
  351.     }
  352.     droppedItem thread watchPickup();
  353.    
  354.     // take owner information from self and put it onto player
  355.     if ( isdefined( self.ownersattacker ) && self.ownersattacker == player )
  356.     {
  357.         player.tookWeaponFrom[ weapname ] = self.owner;
  358.     }
  359.     else
  360.     {
  361.         player.tookWeaponFrom[ weapname ] = undefined;
  362.     }
  363. }
  364.  
  365. itemRemoveAmmoFromAltModes()
  366. {
  367.     origweapname = self getItemWeaponName();
  368.    
  369.     curweapname = weaponAltWeaponName( origweapname );
  370.    
  371.     altindex = 1;
  372.     while ( curweapname != "none" && curweapname != origweapname )
  373.     {
  374.         self itemWeaponSetAmmo( 0, 0, altindex );
  375.         curweapname = weaponAltWeaponName( curweapname );
  376.         altindex++;
  377.     }
  378. }
  379.  
  380. dropOffhand()
  381. {
  382.     grenadeTypes = [];
  383.     // X$: dropping of primary grenades.
  384.     if(level.ex_wepo_drop_all)
  385.     {
  386.         grenadeTypes[grenadeTypes.size] = "frag_grenade_mp";
  387.         grenadeTypes[grenadeTypes.size] = "smoke_grenade_mp";
  388.         grenadeTypes[grenadeTypes.size] = "flash_grenade_mp";
  389.         grenadeTypes[grenadeTypes.size] = "concussion_grenade_mp";
  390.     }
  391.     else
  392.     {
  393.         if(level.ex_wepo_drop_frags) grenadeTypes[grenadeTypes.size] = "frag_grenade_mp";
  394.         if(level.ex_wepo_drop_smoke) grenadeTypes[grenadeTypes.size] = "smoke_grenade_mp";
  395.         if(level.ex_wepo_drop_flash) grenadeTypes[grenadeTypes.size] = "flash_grenade_mp";
  396.         if(level.ex_wepo_drop_stun) grenadeTypes[grenadeTypes.size] = "concussion_grenade_mp";
  397.     }
  398.  
  399.     for ( index = 0; index < grenadeTypes.size; index++ )
  400.     {
  401.         if ( !self hasWeapon( grenadeTypes[index] ) )
  402.             continue;
  403.            
  404.         count = self getAmmoCount( grenadeTypes[index] );
  405.        
  406.         if ( !count )
  407.             continue;
  408.            
  409.         self dropItem( grenadeTypes[index] );
  410.     }
  411. }
  412.  
  413.  
  414. getWeaponBasedGrenadeCount(weapon)
  415. {
  416.     return 2;
  417. }
  418.  
  419. getWeaponBasedSmokeGrenadeCount(weapon)
  420. {
  421.     return 1;
  422. }
  423.  
  424. getFragGrenadeCount()
  425. {
  426.     grenadetype = "frag_grenade_mp";
  427.  
  428.     count = self getammocount(grenadetype);
  429.     return count;
  430. }
  431.  
  432. getSmokeGrenadeCount()
  433. {
  434.     grenadetype = "smoke_grenade_mp";
  435.  
  436.     count = self getammocount(grenadetype);
  437.     return count;
  438. }
  439.  
  440.  
  441. watchWeaponUsage()
  442. {
  443.     self endon( "death" );
  444.     self endon( "disconnect" );
  445.     level endon ( "game_ended" );
  446.    
  447.     self.firingWeapon = false;
  448.    
  449.     for ( ;; )
  450.     {  
  451.         self waittill ( "begin_firing" );
  452.         self.hasDoneCombat = true;
  453.         self.firingWeapon = true;  
  454.        
  455.         curWeapon = self getCurrentWeapon();
  456.        
  457.         switch ( weaponClass( curWeapon ) )
  458.         {
  459.             case "rifle":
  460.             case "pistol":
  461.             case "mg":
  462.             case "smg":
  463.             case "spread":
  464.                 self thread watchCurrentFiring( curWeapon );
  465.                 break;
  466.             default:
  467.                 break;
  468.         }
  469.         self waittill ( "end_firing" );
  470.         self.firingWeapon = false;
  471.     }
  472. }
  473.  
  474. watchCurrentFiring( curWeapon )
  475. {
  476.     self endon("disconnect");
  477.    
  478.     startAmmo = self getWeaponAmmoClip( curWeapon );
  479.     wasInLastStand = isDefined( self.lastStand );
  480.    
  481.     self waittill ( "end_firing" );
  482.    
  483.     if ( !self hasWeapon( curWeapon ) )
  484.         return;
  485.    
  486.     // ignore the case where a player is firing as they enter last stand.
  487.     // it makes it too hard to calculate shotsFired properly.
  488.     if ( isDefined( self.lastStand ) && !wasInLastStand )
  489.         return;
  490.    
  491.     shotsFired = startAmmo - (self getWeaponAmmoClip( curWeapon )) + 1;
  492.  
  493.     if ( isDefined( self.lastStandParams ) && self.lastStandParams.lastStandStartTime == getTime() )
  494.     {
  495.         self.hits = 0;
  496.         return;
  497.     }
  498.  
  499.     assertEx( shotsFired >= 0, shotsFired + " startAmmo: " + startAmmo + " clipAmmo: " + self getWeaponAmmoclip( curWeapon ) + " w/ " + curWeapon  );  
  500.     if ( shotsFired <= 0 )
  501.         return;
  502.    
  503.     statTotal = self maps\mp\gametypes\_persistence::statGet( "total_shots" ) + shotsFired;    
  504.     statHits  = self maps\mp\gametypes\_persistence::statGet( "hits" ) + self.hits;
  505.     statMisses = self maps\mp\gametypes\_persistence::statGet( "misses" ) + shotsFired - self.hits;
  506.    
  507.     self maps\mp\gametypes\_persistence::statSet( "total_shots", statTotal );
  508.     self maps\mp\gametypes\_persistence::statSet( "hits", statHits );
  509.     self maps\mp\gametypes\_persistence::statSet( "misses", statMisses );
  510.     self maps\mp\gametypes\_persistence::statSet( "accuracy", int(statHits * 10000 / statTotal) );
  511. /*
  512.     self iprintLn( "total:    " + statTotal );
  513.     self iprintLn( "hits:     " + statHits );
  514.     self iprintLn( "misses:   " + statMisses );
  515.     self iprintLn( "accuracy: " + int(statHits * 10000 / statTotal) );
  516. */
  517.     self.hits = 0;
  518. }
  519.  
  520. checkHit( sWeapon )
  521. {
  522.     switch ( weaponClass( sWeapon ) )
  523.     {
  524.         case "rifle":
  525.         case "pistol":
  526.         case "mg":
  527.         case "smg":
  528.             self.hits++;
  529.             break;
  530.         case "spread":
  531.             self.hits = 1;
  532.             break;
  533.         default:
  534.             break;
  535.     }
  536. }
  537. /*
  538. updateWeaponUsageStats( startAmmo, endAmmo )
  539. {
  540.     shotsFired = startAmmo - endAmmo + 1;
  541.  
  542.     if ( shotsFired == 0 )
  543.         return;
  544.  
  545.     assert( shotsFired >= 0 );
  546.  
  547.     total = self maps\mp\gametypes\_persistence::statGet( "total_shots" ) + shotsFired;            
  548.     hits  = self maps\mp\gametypes\_persistence::statGet( "hits" );            
  549.     self maps\mp\gametypes\_persistence::statSet( "misses", total - hits );
  550.     self maps\mp\gametypes\_persistence::statSet( "total_shots", total );
  551.     self maps\mp\gametypes\_persistence::statSet( "accuracy", int(hits * 10000 / total) );
  552.  
  553.     self.clipammo = 0;
  554.     self.weapon = "none";
  555. }
  556. */
  557.  
  558. // returns true if damage should be done to the item given its owner and the attacker
  559. friendlyFireCheck( owner, attacker, forcedFriendlyFireRule )
  560. {
  561.     if ( !isdefined(owner) ) // owner has disconnected? allow it
  562.         return true;
  563.    
  564.     if ( !level.teamBased ) // not a team based mode? allow it
  565.         return true;
  566.    
  567.     friendlyFireRule = level.friendlyfire;
  568.     if ( isdefined( forcedFriendlyFireRule ) )
  569.         friendlyFireRule = forcedFriendlyFireRule;
  570.    
  571.     if ( friendlyFireRule != 0 ) // friendly fire is on? allow it
  572.         return true;
  573.    
  574.     if ( attacker == owner ) // owner may attack his own items
  575.         return true;
  576.    
  577.     if (!isdefined(attacker.pers["team"])) // attacker not on a team? allow it
  578.         return true;
  579.    
  580.     if ( attacker.pers["team"] != owner.pers["team"] ) // attacker not on the same team as the owner? allow it
  581.         return true;
  582.    
  583.     return false; // disallow it
  584. }
  585.  
  586. watchGrenadeUsage()
  587. {
  588.     self endon( "death" );
  589.     self endon( "disconnect" );
  590.    
  591.     self.throwingGrenade = false;
  592.     self.gotPullbackNotify = false;
  593.    
  594.     if ( getdvar("scr_deleteexplosivesonspawn") == "" )
  595.         setdvar("scr_deleteexplosivesonspawn", "1");
  596.     if ( getdvarint("scr_deleteexplosivesonspawn") == 1 )
  597.     {
  598.         // delete c4 from previous spawn
  599.         if ( isdefined( self.c4array ) )
  600.         {
  601.             for ( i = 0; i < self.c4array.size; i++ )
  602.             {
  603.                 if ( isdefined(self.c4array[i]) )
  604.                     self.c4array[i] delete();
  605.             }
  606.         }
  607.         self.c4array = [];
  608.         // delete claymores from previous spawn
  609.         if ( isdefined( self.claymorearray ) )
  610.         {
  611.             for ( i = 0; i < self.claymorearray.size; i++ )
  612.             {
  613.                 if ( isdefined(self.claymorearray[i]) )
  614.                     self.claymorearray[i] delete();
  615.             }
  616.         }
  617.         self.claymorearray = [];
  618.     }
  619.     else
  620.     {
  621.         if ( !isdefined( self.c4array ) )
  622.             self.c4array = [];
  623.         if ( !isdefined( self.claymorearray ) )
  624.             self.claymorearray = [];
  625.     }
  626.    
  627.     thread watchC4();
  628.     thread watchC4Detonation();
  629.     thread watchC4AltDetonation();
  630.     thread watchClaymores();
  631.     thread deleteC4AndClaymoresOnDisconnect();
  632.    
  633.     self thread watchForThrowbacks();
  634.    
  635.     for ( ;; )
  636.     {
  637.         self waittill ( "grenade_pullback", weaponName );
  638.        
  639.         self.hasDoneCombat = true;
  640.  
  641.         if ( weaponName == "claymore_mp" )
  642.             continue;
  643.        
  644.         self.throwingGrenade = true;
  645.         self.gotPullbackNotify = true;
  646.        
  647.         if ( weaponName == "c4_mp" )
  648.             self beginC4Tracking();
  649.         else
  650.             self beginGrenadeTracking();
  651.     }
  652. }
  653.  
  654.  
  655. beginGrenadeTracking()
  656. {
  657.     self endon ( "death" );
  658.     self endon ( "disconnect" );
  659.    
  660.     startTime = getTime();
  661.    
  662.     self waittill ( "grenade_fire", grenade, weaponName );
  663.    
  664.     if ( (getTime() - startTime > 1000) )
  665.         grenade.isCooked = true;
  666.    
  667.     if ( weaponName == "frag_grenade_mp" )
  668.     {
  669.         grenade thread maps\mp\gametypes\_shellshock::grenade_earthQuake();
  670.         grenade.originalOwner = self;
  671.     }
  672.        
  673.     self.throwingGrenade = false;
  674. }
  675.  
  676.  
  677. beginC4Tracking()
  678. {
  679.     self endon ( "death" );
  680.     self endon ( "disconnect" );
  681.    
  682.     self waittill_any ( "grenade_fire", "weapon_change" );
  683.     self.throwingGrenade = false;
  684. }
  685.  
  686. watchForThrowbacks()
  687. {
  688.     self endon ( "death" );
  689.     self endon ( "disconnect" );
  690.    
  691.     for ( ;; )
  692.     {
  693.         self waittill ( "grenade_fire", grenade, weapname );
  694.         if ( self.gotPullbackNotify )
  695.         {
  696.             self.gotPullbackNotify = false;
  697.             continue;
  698.         }
  699.         if ( !isSubStr( weapname, "frag_" ) )
  700.             continue;
  701.        
  702.         // no grenade_pullback notify! we must have picked it up off the ground.
  703.         grenade.threwBack = true;
  704.        
  705.         grenade thread maps\mp\gametypes\_shellshock::grenade_earthQuake();
  706.         grenade.originalOwner = self;
  707.     }
  708. }
  709.  
  710. watchC4()
  711. {
  712.     self endon( "spawned_player" );
  713.     self endon( "disconnect" );
  714.  
  715.     //maxc4 = 2;
  716.  
  717.     while(1)
  718.     {
  719.         self waittill( "grenade_fire", c4, weapname );     
  720.         if ( weapname == "c4" || weapname == "c4_mp" )
  721.         {
  722.             if ( !self.c4array.size )
  723.                 self thread watchC4AltDetonate();
  724.            
  725.             self.c4array[self.c4array.size] = c4;
  726.             c4.owner = self;
  727.             if(level.ex_proximityc4)
  728.             {
  729.                 c4 thread claymoreDetonation();
  730.                 c4 thread playC4Effects();
  731.             }
  732.             c4.activated = false;
  733.            
  734.             c4 thread maps\mp\gametypes\_shellshock::c4_earthQuake();
  735.             c4 thread c4Activate();
  736.             c4 thread c4Damage();
  737.             if(level.ex_c4blink)
  738.             {
  739.                 c4 thread playC4Effects(); //Blinking Red Light
  740.             }
  741.             if(level.ex_c4lasers)
  742.             {
  743.                 c4 thread playClaymoreEffects();  //Red lasers
  744.             }
  745.             c4 thread c4DetectionTrigger( self.pers["team"] );
  746.         }
  747.     }
  748. }
  749.  
  750.  
  751. watchClaymores()
  752. {
  753.     self endon( "spawned_player" );
  754.     self endon( "disconnect" );
  755.  
  756.     self.claymorearray = [];
  757.     while(1)
  758.     {
  759.         self waittill( "grenade_fire", claymore, weapname );       
  760.         if ( weapname == "claymore" || weapname == "claymore_mp" )
  761.         {
  762.             self.claymorearray[self.claymorearray.size] = claymore;
  763.             claymore.owner = self;
  764.             claymore thread c4Damage();
  765.             claymore thread claymoreDetonation();
  766.             if(level.ex_claymorelasers)
  767.             {
  768.                 claymore thread playClaymoreEffects();  //Red lasers
  769.             }
  770.             claymore thread claymoreDetectionTrigger_wait( self.pers["team"] );
  771.             claymore thread claymoreMonitor();
  772.             claymore maps\mp\_entityheadicons::setEntityHeadIcon(self.pers["team"], (0,0,20));
  773.            
  774.             /#
  775.             if ( getdvarint("scr_claymoredebug") )
  776.             {
  777.                 claymore thread claymoreDebug();
  778.             }
  779.             #/
  780.         }
  781.     }
  782. }
  783.  
  784. /#
  785. claymoreDebug()
  786. {
  787.     self waitTillNotMoving();
  788.     self thread showCone( acos( level.claymoreDetectionDot ), level.claymoreDetonateRadius, (1,.85,0) );
  789.     self thread showCone( 60, 256, (1,0,0) );
  790. }
  791.  
  792. vectorcross( v1, v2 )
  793. {
  794.     return ( v1[1]*v2[2] - v1[2]*v2[1], v1[2]*v2[0] - v1[0]*v2[2], v1[0]*v2[1] - v1[1]*v2[0] );
  795. }
  796.  
  797. showCone( angle, range, color )
  798. {
  799.     self endon("death");
  800.    
  801.     start = self.origin;
  802.     forward = anglestoforward(self.angles);
  803.     right = vectorcross( forward, (0,0,1) );
  804.     up = vectorcross( forward, right );
  805.    
  806.     fullforward = forward * range * cos( angle );
  807.     sideamnt = range * sin( angle );
  808.    
  809.     while(1)
  810.     {
  811.         prevpoint = (0,0,0);
  812.         for ( i = 0; i <= 20; i++ )
  813.         {
  814.             coneangle = i/20.0 * 360;
  815.             point = start + fullforward + sideamnt * (right * cos(coneangle) + up * sin(coneangle));
  816.             if ( i > 0 )
  817.             {
  818.                 line( start, point, color );
  819.                 line( prevpoint, point, color );
  820.             }
  821.             prevpoint = point;
  822.         }
  823.         wait .05;
  824.     }
  825. }
  826. #/
  827.  
  828. waitTillNotMoving()
  829. {
  830.     prevorigin = self.origin;
  831.     while(1)
  832.     {
  833.         wait .15;
  834.         if ( self.origin == prevorigin )
  835.             break;
  836.         prevorigin = self.origin;
  837.     }
  838. }
  839.  
  840. claymoreDetonation()
  841. {
  842.     self endon("death");
  843.    
  844.     self waitTillNotMoving();
  845.    
  846.     damagearea = spawn("trigger_radius", self.origin + (0,0,0-level.claymoreDetonateRadius), 0, level.claymoreDetonateRadius, level.claymoreDetonateRadius*2);
  847.     self thread deleteOnDeath( damagearea );
  848.    
  849.     while(1)
  850.     {
  851.         damagearea waittill("trigger", player);
  852.        
  853.         if ( getdvarint("scr_claymoreteamsafe") == 1 )
  854.         {
  855.             if ( isdefined( self.owner ) && player == self.owner )
  856.                 continue;
  857.             if ( !friendlyFireCheck( self.owner, player, 0 ) )
  858.                 continue;
  859.         }
  860.         if ( lengthsquared( player getVelocity() ) < 10 )
  861.             continue;
  862.        
  863.         if ( !player shouldAffectClaymore( self ) )
  864.             continue;
  865.        
  866.         if ( player damageConeTrace( self.origin, self ) > 0 )
  867.             break;
  868.     }
  869.    
  870.     self playsound ("claymore_activated");
  871.    
  872.     wait level.claymoreDetectionGracePeriod;
  873.    
  874.     self maps\mp\_entityheadicons::setEntityHeadIcon("none");
  875.     self detonate();
  876. }
  877.  
  878. shouldAffectClaymore( claymore )
  879. {
  880.     pos = self.origin + (0,0,32);
  881.    
  882.     dirToPos = pos - claymore.origin;
  883.     claymoreForward = anglesToForward( claymore.angles );
  884.    
  885.     dist = vectorDot( dirToPos, claymoreForward );
  886.     if ( dist < level.claymoreDetectionMinDist )
  887.         return false;
  888.    
  889.     dirToPos = vectornormalize( dirToPos );
  890.    
  891.     dot = vectorDot( dirToPos, claymoreForward );
  892.     return ( dot > level.claymoreDetectionDot );
  893. }
  894.  
  895. deleteOnDeath(ent)
  896. {
  897.     self waittill("death");
  898.     wait .05;
  899.     if ( isdefined(ent) )
  900.         ent delete();
  901. }
  902.  
  903. c4Activate()
  904. {
  905.     self endon("death");
  906.  
  907.     self waittillNotMoving();
  908.    
  909.     wait 0.05;
  910.    
  911.     self notify("activated");
  912.     self.activated = true;
  913. }
  914.  
  915. watchC4AltDetonate()
  916. {
  917.     self endon("death");
  918.     self endon( "disconnect" );
  919.     self endon( "detonated" );
  920.     level endon( "game_ended" );
  921.    
  922.     buttonTime = 0;
  923.     for( ;; )
  924.     {
  925.         if ( self UseButtonPressed() && !self playerADS())
  926.         {
  927.             buttonTime = 0;
  928.             while( self UseButtonPressed() )
  929.             {
  930.                 buttonTime += 0.05;
  931.                 wait( 0.05 );
  932.             }
  933.            
  934.             println( "pressTime1: " + buttonTime );
  935.             if ( buttonTime >= 0.5 )
  936.                 continue;
  937.            
  938.             buttonTime = 0;            
  939.             while ( !self UseButtonPressed() && buttonTime < 0.5 )
  940.             {
  941.                 buttonTime += 0.05;
  942.                 wait( 0.05 );
  943.             }
  944.            
  945.             println( "delayTime: " + buttonTime );
  946.             if ( buttonTime >= 0.5 )
  947.                 continue;
  948.  
  949.             if ( !self.c4Array.size )
  950.                 return;
  951.                
  952.             self notify ( "alt_detonate" );
  953.         }
  954.         wait ( 0.05 );
  955.     }
  956. }
  957.  
  958. watchC4Detonation()
  959. {
  960.     self endon("death");
  961.     self endon("disconnect");
  962.  
  963.     while(1)
  964.     {
  965.         self waittill( "detonate" );
  966.         weap = self getCurrentWeapon();
  967.         if ( weap == "c4_mp" )
  968.         {
  969.             newarray = [];
  970.             for ( i = 0; i < self.c4array.size; i++ )
  971.             {
  972.                 c4 = self.c4array[i];
  973.                 if ( isdefined(self.c4array[i]) )
  974.                 {
  975.                     //if ( c4.activated )
  976.                     //{
  977.                         c4 thread waitAndDetonate( 0.1 );
  978.                     //}
  979.                     //else
  980.                     //{
  981.                     //  newarray[ newarray.size ] = c4;
  982.                     //}
  983.                 }
  984.             }
  985.             self.c4array = newarray;
  986.             self notify ( "detonated" );
  987.         }
  988.     }
  989. }
  990.  
  991.  
  992. watchC4AltDetonation()
  993. {
  994.     self endon("death");
  995.     self endon("disconnect");
  996.  
  997.     while(1)
  998.     {
  999.         self waittill( "alt_detonate" );
  1000.         weap = self getCurrentWeapon();
  1001.         if ( weap != "c4_mp" )
  1002.         {
  1003.             newarray = [];
  1004.             for ( i = 0; i < self.c4array.size; i++ )
  1005.             {
  1006.                 c4 = self.c4array[i];
  1007.                 if ( isdefined(self.c4array[i]) )
  1008.                     c4 thread waitAndDetonate( 0.1 );
  1009.             }
  1010.             self.c4array = newarray;
  1011.             self notify ( "detonated" );
  1012.         }
  1013.     }
  1014. }
  1015.  
  1016.  
  1017. waitAndDetonate( delay )
  1018. {
  1019.     self endon("death");
  1020.     wait delay;
  1021.  
  1022.     self detonate();
  1023. }
  1024.  
  1025. deleteC4AndClaymoresOnDisconnect()
  1026. {
  1027.     self endon("death");
  1028.     self waittill("disconnect");
  1029.    
  1030.     c4array = self.c4array;
  1031.     claymorearray = self.claymorearray;
  1032.    
  1033.     wait .05;
  1034.    
  1035.     for ( i = 0; i < c4array.size; i++ )
  1036.     {
  1037.         if ( isdefined(c4array[i]) )
  1038.             c4array[i] delete();
  1039.     }
  1040.     for ( i = 0; i < claymorearray.size; i++ )
  1041.     {
  1042.         if ( isdefined(claymorearray[i]) )
  1043.             claymorearray[i] delete();
  1044.     }
  1045. }
  1046.  
  1047. c4Damage()
  1048. {
  1049.     self endon( "death" );
  1050.  
  1051.     self setcandamage(true);
  1052.     self.maxhealth = 100000;
  1053.     self.health = self.maxhealth;
  1054.    
  1055.     attacker = undefined;
  1056.    
  1057.     while(1)
  1058.     {
  1059.         self waittill ( "damage", damage, attacker, direction_vec, point, type, modelName, tagName, partName, iDFlags );
  1060.         if ( !isplayer(attacker) )
  1061.             continue;
  1062.        
  1063.         // don't allow people to destroy C4 on their team if FF is off
  1064.         if ( !friendlyFireCheck( self.owner, attacker ) )
  1065.             continue;
  1066.        
  1067.         if ( damage < 5 ) // ignore concussion grenades
  1068.             continue;
  1069.        
  1070.         break;
  1071.     }
  1072.    
  1073.     if ( level.c4explodethisframe )
  1074.         wait .1 + randomfloat(.4);
  1075.     else
  1076.         wait .05;
  1077.    
  1078.     if (!isdefined(self))
  1079.         return;
  1080.    
  1081.     level.c4explodethisframe = true;
  1082.    
  1083.     thread resetC4ExplodeThisFrame();
  1084.    
  1085.     self maps\mp\_entityheadicons::setEntityHeadIcon("none");
  1086.    
  1087.     if ( isDefined( type ) && (isSubStr( type, "MOD_GRENADE" ) || isSubStr( type, "MOD_EXPLOSIVE" )) )
  1088.         self.wasChained = true;
  1089.    
  1090.     if ( isDefined( iDFlags ) && (iDFlags & level.iDFLAGS_PENETRATION) )
  1091.         self.wasDamagedFromBulletPenetration = true;
  1092.    
  1093.     self.wasDamaged = true;
  1094.    
  1095.     // "destroyed_explosive" notify, for challenges
  1096.     if ( isdefined( attacker ) && isdefined( attacker.pers["team"] ) && isdefined( self.owner ) && isdefined( self.owner.pers["team"] ) )
  1097.     {
  1098.         if ( attacker.pers["team"] != self.owner.pers["team"] )
  1099.             attacker notify("destroyed_explosive");
  1100.     }
  1101.    
  1102.     self detonate( attacker );
  1103.     // won't get here; got death notify.
  1104. }
  1105.  
  1106. resetC4ExplodeThisFrame()
  1107. {
  1108.     wait .05;
  1109.     level.c4explodethisframe = false;
  1110. }
  1111.  
  1112. saydamaged(orig, amount)
  1113. {
  1114.     for (i = 0; i < 60; i++)
  1115.     {
  1116.         print3d(orig, "damaged! " + amount);
  1117.         wait .05;
  1118.     }
  1119. }
  1120.  
  1121. playC4Effects()
  1122. {
  1123.     self endon("death");
  1124.     self waittill("activated");
  1125.    
  1126.     while(1)
  1127.     {
  1128.         org = self getTagOrigin( "tag_fx" );
  1129.         ang = self getTagAngles( "tag_fx" );
  1130.        
  1131.         fx = spawnFx( level.C4FXid, org, anglesToForward( ang ), anglesToUp( ang ) );
  1132.         triggerfx( fx );
  1133.        
  1134.         self thread clearFXOnDeath( fx );
  1135.        
  1136.         originalOrigin = self.origin;
  1137.        
  1138.         while(1)
  1139.         {
  1140.             wait .25;
  1141.             if ( self.origin != originalOrigin )
  1142.                 break;
  1143.         }
  1144.        
  1145.         fx delete();
  1146.         self waittillNotMoving();
  1147.     }
  1148. }
  1149.  
  1150.  
  1151. c4DetectionTrigger( ownerTeam )
  1152. {
  1153.     if ( level.oldschool )
  1154.         return;
  1155.  
  1156.     self waittill( "activated" );
  1157.    
  1158.     trigger = spawn( "trigger_radius", self.origin-(0,0,128), 0, 512, 256 );
  1159.     trigger.detectId = "trigger" + getTime() + randomInt( 1000000 );
  1160.  
  1161.     trigger thread detectIconWaiter( level.otherTeam[ownerTeam] );
  1162.        
  1163.     self waittill( "death" );
  1164.     trigger notify ( "end_detection" );
  1165.  
  1166.     if ( isDefined( trigger.bombSquadIcon ) )
  1167.         trigger.bombSquadIcon destroy();
  1168.    
  1169.     trigger delete();
  1170. }
  1171.  
  1172.  
  1173. claymoreDetectionTrigger_wait( ownerTeam )
  1174. {
  1175.     self endon ( "death" );
  1176.     waitTillNotMoving();
  1177.  
  1178.     if ( level.oldschool )
  1179.         return;
  1180.  
  1181.     self thread claymoreDetectionTrigger( ownerTeam );
  1182. }
  1183.  
  1184. claymoreDetectionTrigger( ownerTeam )
  1185. {
  1186.     trigger = spawn( "trigger_radius", self.origin-(0,0,128), 0, 512, 256 );
  1187.     trigger.detectId = "trigger" + getTime() + randomInt( 1000000 );
  1188.        
  1189.     trigger thread detectIconWaiter( level.otherTeam[ownerTeam] );
  1190.  
  1191.     self waittill( "death" );
  1192.     trigger notify ( "end_detection" );
  1193.  
  1194.     if ( isDefined( trigger.bombSquadIcon ) )
  1195.         trigger.bombSquadIcon destroy();
  1196.    
  1197.     trigger delete();  
  1198. }
  1199.  
  1200.  
  1201. detectIconWaiter( detectTeam )
  1202. {
  1203.     self endon ( "end_detection" );
  1204.     level endon ( "game_ended" );
  1205.  
  1206.     while( !level.gameEnded )
  1207.     {
  1208.         self waittill( "trigger", player );
  1209.        
  1210.         if ( !isDefined( player.detectExplosives ) || !player.detectExplosives )
  1211.             continue;
  1212.            
  1213.         if ( player.team != detectTeam )
  1214.             continue;
  1215.            
  1216.         if ( isDefined( player.bombSquadIds[self.detectId] ) )
  1217.             continue;
  1218.  
  1219.         player thread showHeadIcon( self );
  1220.         /*
  1221.         if ( !isDefined( self.bombSquadIcon ) )
  1222.         {
  1223.             self.bombSquadIcon = newTeamHudElem( player.pers["team"] );
  1224.             self.bombSquadIcon.x = self.origin[0];
  1225.             self.bombSquadIcon.y = self.origin[1];
  1226.             self.bombSquadIcon.z = self.origin[2]+25+128;
  1227.             self.bombSquadIcon.alpha = 0;
  1228.             self.bombSquadIcon.archived = true;
  1229.             self.bombSquadIcon setShader( "waypoint_bombsquad", 14, 14 );
  1230.             self.bombSquadIcon setwaypoint( false );
  1231.         }
  1232.  
  1233.         self.bombSquadIcon fadeOverTime( 0.25 );
  1234.         self.bombSquadIcon.alpha = 0.85;
  1235.  
  1236.         while( isAlive( player ) && player isTouching( self ) )
  1237.             wait ( 0.05 );
  1238.        
  1239.         self.bombSquadIcon fadeOverTime( 0.25 );
  1240.         self.bombSquadIcon.alpha = 0;
  1241.         */
  1242.     }
  1243. }
  1244.  
  1245.  
  1246. setupBombSquad()
  1247. {
  1248.     self.bombSquadIds = [];
  1249.    
  1250.     if ( self.detectExplosives && !self.bombSquadIcons.size )
  1251.     {
  1252.         for ( index = 0; index < 4; index++ )
  1253.         {
  1254.             self.bombSquadIcons[index] = newClientHudElem( self );
  1255.             self.bombSquadIcons[index].x = 0;
  1256.             self.bombSquadIcons[index].y = 0;
  1257.             self.bombSquadIcons[index].z = 0;
  1258.             self.bombSquadIcons[index].alpha = 0;
  1259.             self.bombSquadIcons[index].archived = true;
  1260.             self.bombSquadIcons[index] setShader( "waypoint_bombsquad", 14, 14 );
  1261.             self.bombSquadIcons[index] setWaypoint( false );
  1262.             self.bombSquadIcons[index].detectId = "";
  1263.         }
  1264.     }
  1265.     else if ( !self.detectExplosives )
  1266.     {
  1267.         for ( index = 0; index < self.bombSquadIcons.size; index++ )
  1268.             self.bombSquadIcons[index] destroy();
  1269.            
  1270.         self.bombSquadIcons = [];
  1271.     }
  1272. }
  1273.  
  1274.  
  1275. showHeadIcon( trigger )
  1276. {
  1277.     triggerDetectId = trigger.detectId;
  1278.     useId = -1;
  1279.     for ( index = 0; index < 4; index++ )
  1280.     {
  1281.         detectId = self.bombSquadIcons[index].detectId;
  1282.  
  1283.         if ( detectId == triggerDetectId )
  1284.             return;
  1285.            
  1286.         if ( detectId == "" )
  1287.             useId = index;
  1288.     }
  1289.    
  1290.     if ( useId < 0 )
  1291.         return;
  1292.  
  1293.     self.bombSquadIds[triggerDetectId] = true;
  1294.    
  1295.     self.bombSquadIcons[useId].x = trigger.origin[0];
  1296.     self.bombSquadIcons[useId].y = trigger.origin[1];
  1297.     self.bombSquadIcons[useId].z = trigger.origin[2]+24+128;
  1298.  
  1299.     self.bombSquadIcons[useId] fadeOverTime( 0.25 );
  1300.     self.bombSquadIcons[useId].alpha = 1;
  1301.     self.bombSquadIcons[useId].detectId = trigger.detectId;
  1302.    
  1303.     while ( isAlive( self ) && isDefined( trigger ) && self isTouching( trigger ) )
  1304.         wait ( 0.05 );
  1305.        
  1306.     if ( !isDefined( self ) )
  1307.         return;
  1308.        
  1309.     self.bombSquadIcons[useId].detectId = "";
  1310.     self.bombSquadIcons[useId] fadeOverTime( 0.25 );
  1311.     self.bombSquadIcons[useId].alpha = 0;
  1312.     self.bombSquadIds[triggerDetectId] = undefined;
  1313. }
  1314.  
  1315.  
  1316. playClaymoreEffects()
  1317. {
  1318.     self endon("death");
  1319.    
  1320.     while(1)
  1321.     {
  1322.         self waittillNotMoving();
  1323.        
  1324.         org = self getTagOrigin( "tag_fx" );
  1325.         ang = self getTagAngles( "tag_fx" );
  1326.         fx = spawnFx( level.claymoreFXid, org, anglesToForward( ang ), anglesToUp( ang ) );
  1327.         triggerfx( fx );
  1328.        
  1329.         self thread clearFXOnDeath( fx );
  1330.        
  1331.         originalOrigin = self.origin;
  1332.        
  1333.         while(1)
  1334.         {
  1335.             wait .25;
  1336.             if ( self.origin != originalOrigin )
  1337.                 break;
  1338.         }
  1339.        
  1340.         fx delete();
  1341.     }
  1342. }
  1343.  
  1344. clearFXOnDeath( fx )
  1345. {
  1346.     fx endon("death");
  1347.     self waittill("death");
  1348.     fx delete();
  1349. }
  1350.  
  1351.  
  1352. // these functions are used with scripted weapons (like c4, claymores, artillery)
  1353. // returns an array of objects representing damageable entities (including players) within a given sphere.
  1354. // each object has the property damageCenter, which represents its center (the location from which it can be damaged).
  1355. // each object also has the property entity, which contains the entity that it represents.
  1356. // to damage it, call damageEnt() on it.
  1357. getDamageableEnts(pos, radius, doLOS, startRadius)
  1358. {
  1359.     ents = [];
  1360.    
  1361.     if (!isdefined(doLOS))
  1362.         doLOS = false;
  1363.        
  1364.     if ( !isdefined( startRadius ) )
  1365.         startRadius = 0;
  1366.    
  1367.     // players
  1368.     players = level.players;
  1369.     for (i = 0; i < players.size; i++)
  1370.     {
  1371.         if (!isalive(players[i]) || players[i].sessionstate != "playing")
  1372.             continue;
  1373.        
  1374.         playerpos = players[i].origin + (0,0,32);
  1375.         dist = distance(pos, playerpos);
  1376.         if (dist < radius && (!doLOS || weaponDamageTracePassed(pos, playerpos, startRadius, undefined)))
  1377.         {
  1378.             newent = spawnstruct();
  1379.             newent.isPlayer = true;
  1380.             newent.isADestructable = false;
  1381.             newent.entity = players[i];
  1382.             newent.damageCenter = playerpos;
  1383.             ents[ents.size] = newent;
  1384.         }
  1385.     }
  1386.    
  1387.     // grenades
  1388.     grenades = getentarray("grenade", "classname");
  1389.     for (i = 0; i < grenades.size; i++)
  1390.     {
  1391.         entpos = grenades[i].origin;
  1392.         dist = distance(pos, entpos);
  1393.         if (dist < radius && (!doLOS || weaponDamageTracePassed(pos, entpos, startRadius, grenades[i])))
  1394.         {
  1395.             newent = spawnstruct();
  1396.             newent.isPlayer = false;
  1397.             newent.isADestructable = false;
  1398.             newent.entity = grenades[i];
  1399.             newent.damageCenter = entpos;
  1400.             ents[ents.size] = newent;
  1401.         }
  1402.     }
  1403.  
  1404.     destructibles = getentarray("destructible", "targetname");
  1405.     for (i = 0; i < destructibles.size; i++)
  1406.     {
  1407.         entpos = destructibles[i].origin;
  1408.         dist = distance(pos, entpos);
  1409.         if (dist < radius && (!doLOS || weaponDamageTracePassed(pos, entpos, startRadius, destructibles[i])))
  1410.         {
  1411.             newent = spawnstruct();
  1412.             newent.isPlayer = false;
  1413.             newent.isADestructable = false;
  1414.             newent.entity = destructibles[i];
  1415.             newent.damageCenter = entpos;
  1416.             ents[ents.size] = newent;
  1417.         }
  1418.     }
  1419.  
  1420.     destructables = getentarray("destructable", "targetname");
  1421.     for (i = 0; i < destructables.size; i++)
  1422.     {
  1423.         entpos = destructables[i].origin;
  1424.         dist = distance(pos, entpos);
  1425.         if (dist < radius && (!doLOS || weaponDamageTracePassed(pos, entpos, startRadius, destructables[i])))
  1426.         {
  1427.             newent = spawnstruct();
  1428.             newent.isPlayer = false;
  1429.             newent.isADestructable = true;
  1430.             newent.entity = destructables[i];
  1431.             newent.damageCenter = entpos;
  1432.             ents[ents.size] = newent;
  1433.         }
  1434.     }
  1435.    
  1436.     return ents;
  1437. }
  1438.  
  1439. weaponDamageTracePassed(from, to, startRadius, ignore)
  1440. {
  1441.     midpos = undefined;
  1442.    
  1443.     diff = to - from;
  1444.     if ( lengthsquared( diff ) < startRadius*startRadius )
  1445.         midpos = to;
  1446.     dir = vectornormalize( diff );
  1447.     midpos = from + (dir[0]*startRadius, dir[1]*startRadius, dir[2]*startRadius);
  1448.  
  1449.     trace = bullettrace(midpos, to, false, ignore);
  1450.    
  1451.     if ( getdvarint("scr_damage_debug") != 0 )
  1452.     {
  1453.         if (trace["fraction"] == 1)
  1454.         {
  1455.             thread debugline(midpos, to, (1,1,1));
  1456.         }
  1457.         else
  1458.         {
  1459.             thread debugline(midpos, trace["position"], (1,.9,.8));
  1460.             thread debugline(trace["position"], to, (1,.4,.3));
  1461.         }
  1462.     }
  1463.    
  1464.     return (trace["fraction"] == 1);
  1465. }
  1466.  
  1467. // eInflictor = the entity that causes the damage (e.g. a claymore)
  1468. // eAttacker = the player that is attacking
  1469. // iDamage = the amount of damage to do
  1470. // sMeansOfDeath = string specifying the method of death (e.g. "MOD_PROJECTILE_SPLASH")
  1471. // sWeapon = string specifying the weapon used (e.g. "claymore_mp")
  1472. // damagepos = the position damage is coming from
  1473. // damagedir = the direction damage is moving in
  1474. damageEnt(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, damagepos, damagedir)
  1475. {
  1476.     if (self.isPlayer)
  1477.     {
  1478.         self.damageOrigin = damagepos;
  1479.         self.entity thread [[level.callbackPlayerDamage]](
  1480.             eInflictor, // eInflictor The entity that causes the damage.(e.g. a turret)
  1481.             eAttacker, // eAttacker The entity that is attacking.
  1482.             iDamage, // iDamage Integer specifying the amount of damage done
  1483.             0, // iDFlags Integer specifying flags that are to be applied to the damage
  1484.             sMeansOfDeath, // sMeansOfDeath Integer specifying the method of death
  1485.             sWeapon, // sWeapon The weapon number of the weapon used to inflict the damage
  1486.             damagepos, // vPoint The point the damage is from?
  1487.             damagedir, // vDir The direction of the damage
  1488.             "none", // sHitLoc The location of the hit
  1489.             0 // psOffsetTime The time offset for the damage
  1490.         );
  1491.     }
  1492.     else
  1493.     {
  1494.         // destructable walls and such can only be damaged in certain ways.
  1495.         if (self.isADestructable && (sWeapon == "artillery_mp" || sWeapon == "claymore_mp"))
  1496.             return;
  1497.        
  1498.         self.entity notify("damage", iDamage, eAttacker, (0,0,0), (0,0,0), "mod_explosive", "", "" );
  1499.     }
  1500. }
  1501.  
  1502. debugline(a, b, color)
  1503. {
  1504.     for (i = 0; i < 30*20; i++)
  1505.     {
  1506.         line(a,b, color);
  1507.         wait .05;
  1508.     }
  1509. }
  1510.  
  1511.  
  1512. onWeaponDamage( eInflictor, sWeapon, meansOfDeath, damage )
  1513. {
  1514.     self endon ( "death" );
  1515.     self endon ( "disconnect" );
  1516.  
  1517.     switch( sWeapon )
  1518.     {
  1519.         case "concussion_grenade_mp":
  1520.             // should match weapon settings in gdt
  1521.             radius = 512;
  1522.             scale = 1 - (distance( self.origin, eInflictor.origin ) / radius);
  1523.            
  1524.             if ( scale < 0 )
  1525.                 scale = 0;
  1526.            
  1527.             time = 2 + (4 * scale);
  1528.            
  1529.             wait ( 0.05 );
  1530.             self shellShock( "concussion_grenade_mp", time );
  1531.             self.concussionEndTime = getTime() + (time * 1000);
  1532.         break;
  1533.         default:
  1534.             // shellshock will only be done if meansofdeath is an appropriate type and if there is enough damage.
  1535.             maps\mp\gametypes\_shellshock::shellshockOnDamage( meansOfDeath, damage );
  1536.         break;
  1537.     }
  1538.    
  1539. }
  1540.  
  1541. // weapon stowing logic ===================================================================
  1542.  
  1543. // weapon class boolean helpers
  1544. isPrimaryWeapon( weaponname )
  1545. {
  1546.     return isdefined( level.primary_weapon_array[weaponname] );
  1547. }
  1548. isSideArm( weaponname )
  1549. {
  1550.     return isdefined( level.side_arm_array[weaponname] );
  1551. }
  1552. isInventory( weaponname )
  1553. {
  1554.     return isdefined( level.inventory_array[weaponname] );
  1555. }
  1556. isGrenade( weaponname )
  1557. {
  1558.     return isdefined( level.grenade_array[weaponname] );
  1559. }
  1560. getWeaponClass_array( current )
  1561. {
  1562.     if( isPrimaryWeapon( current ) )
  1563.         return level.primary_weapon_array;
  1564.     else if( isSideArm( current ) )
  1565.         return level.side_arm_array;
  1566.     else if( isGrenade( current ) )
  1567.         return level.grenade_array;
  1568.     else
  1569.         return level.inventory_array;
  1570. }
  1571.  
  1572. // thread loop life = player's life
  1573. updateStowedWeapon()
  1574. {
  1575.     self endon( "spawned" );
  1576.     self endon( "killed_player" );
  1577.     self endon( "disconnect" );
  1578.    
  1579.     //detach_all_weapons();
  1580.    
  1581.     self.tag_stowed_back = undefined;
  1582.     self.tag_stowed_hip = undefined;
  1583.    
  1584.     team = self.pers["team"];
  1585.     class = self.pers["class"];
  1586.    
  1587.     while ( true )
  1588.     {
  1589.         self waittill( "weapon_change", newWeapon );
  1590.        
  1591.         // weapon array reset, might have swapped weapons off the ground
  1592.         self.weapon_array_primary =[];
  1593.         self.weapon_array_sidearm = [];
  1594.         self.weapon_array_grenade = [];
  1595.         self.weapon_array_inventory =[];
  1596.    
  1597.         // populate player's weapon stock arrays
  1598.         weaponsList = self GetWeaponsList();
  1599.         for( idx = 0; idx < weaponsList.size; idx++ )
  1600.         {
  1601.             if ( isPrimaryWeapon( weaponsList[idx] ) )
  1602.                 self.weapon_array_primary[self.weapon_array_primary.size] = weaponsList[idx];
  1603.             else if ( isSideArm( weaponsList[idx] ) )
  1604.                 self.weapon_array_sidearm[self.weapon_array_sidearm.size] = weaponsList[idx];
  1605.             else if ( isGrenade( weaponsList[idx] ) )
  1606.                 self.weapon_array_grenade[self.weapon_array_grenade.size] = weaponsList[idx];
  1607.             else if ( isInventory( weaponsList[idx] ) )
  1608.                 self.weapon_array_inventory[self.weapon_array_inventory.size] = weaponsList[idx];
  1609.         }
  1610.  
  1611.         detach_all_weapons();
  1612.         stow_on_back();
  1613.         stow_on_hip();
  1614.     }
  1615. }
  1616.  
  1617. detach_all_weapons()
  1618. {
  1619.     if( isDefined( self.tag_stowed_back ) )
  1620.     {
  1621.         self detach( self.tag_stowed_back, "tag_stowed_back" );
  1622.         self.tag_stowed_back = undefined;
  1623.     }
  1624.     if( isDefined( self.tag_stowed_hip ) )
  1625.     {
  1626.         detach_model = getWeaponModel( self.tag_stowed_hip );
  1627.         self detach( detach_model, "tag_stowed_hip_rear" );
  1628.         self.tag_stowed_hip = undefined;
  1629.     }
  1630. }
  1631.  
  1632. stow_on_back()
  1633. {
  1634.     current = self getCurrentWeapon();
  1635.  
  1636.     self.tag_stowed_back = undefined;
  1637.    
  1638.     //  large projectile weaponry always show
  1639.     if ( self hasWeapon( "rpg_mp" ) && current != "rpg_mp" )
  1640.     {
  1641.         self.tag_stowed_back = "weapon_rpg7_stow";
  1642.     }
  1643.     else
  1644.     {
  1645.         for ( idx = 0; idx < self.weapon_array_primary.size; idx++ )
  1646.         {
  1647.             index_weapon = self.weapon_array_primary[idx];
  1648.             assertex( isdefined( index_weapon ), "Primary weapon list corrupted." );
  1649.            
  1650.             if ( index_weapon == current )
  1651.                 continue;
  1652.                
  1653.             if( isSubStr( current, "gl_" ) || isSubStr( index_weapon, "gl_" ) )
  1654.             {
  1655.                 index_weapon_tok = strtok( index_weapon, "_" );
  1656.                 current_tok = strtok( current, "_" );
  1657.                 // finding the alt-mode of current weapon; the tokens of both weapons are subsets of each other
  1658.                 for( i=0; i<index_weapon_tok.size; i++ )
  1659.                 {
  1660.                     if( !isSubStr( current, index_weapon_tok[i] ) || index_weapon_tok.size != current_tok.size )
  1661.                     {
  1662.                         i = 0;
  1663.                         break;
  1664.                     }
  1665.                 }
  1666.                 if( i == index_weapon_tok.size )
  1667.                     continue;
  1668.             }
  1669.  
  1670.             // camo only applicable for custom classes
  1671.             /*
  1672.             assertex( isdefined( self.curclass ), "Player missing current class" );
  1673.             if ( isDefined( self.custom_class ) && isDefined( self.custom_class[self.class_num]["camo_num"] ) && isSubStr( index_weapon, self.pers["primaryWeapon"] ) && isSubStr( self.curclass, "CUSTOM" ) )
  1674.                 self.tag_stowed_back = getWeaponModel( index_weapon, self.custom_class[self.class_num]["camo_num"] );
  1675.             else
  1676.             */
  1677.                 self.tag_stowed_back = getWeaponModel( index_weapon, 0 );
  1678.         }
  1679.     }
  1680.    
  1681.     if ( !isDefined( self.tag_stowed_back ) )
  1682.         return;
  1683.  
  1684.     self attach( self.tag_stowed_back, "tag_stowed_back", true );
  1685. }
  1686.  
  1687. stow_on_hip()
  1688. {
  1689.     current = self getCurrentWeapon();
  1690.  
  1691.     self.tag_stowed_hip = undefined;
  1692.     /*
  1693.     for ( idx = 0; idx < self.weapon_array_sidearm.size; idx++ )
  1694.     {
  1695.         if ( self.weapon_array_sidearm[idx] == current )
  1696.             continue;
  1697.            
  1698.         self.tag_stowed_hip = self.weapon_array_sidearm[idx];
  1699.     }
  1700.     */
  1701.    
  1702.     for ( idx = 0; idx < self.weapon_array_inventory.size; idx++ )
  1703.     {
  1704.         if ( self.weapon_array_inventory[idx] == current )
  1705.             continue;
  1706.  
  1707.         if ( !self GetWeaponAmmoStock( self.weapon_array_inventory[idx] ) )
  1708.             continue;
  1709.            
  1710.         self.tag_stowed_hip = self.weapon_array_inventory[idx];
  1711.     }
  1712.    
  1713.     if ( !isDefined( self.tag_stowed_hip ) )
  1714.         return;
  1715.  
  1716.     weapon_model = getWeaponModel( self.tag_stowed_hip );
  1717.     self attach( weapon_model, "tag_stowed_hip_rear", true );
  1718. }
  1719.  
  1720.  
  1721. stow_inventory( inventories, current )
  1722. {
  1723.     // deatch last weapon attached
  1724.     if( isdefined( self.inventory_tag ) )
  1725.     {
  1726.         detach_model = getweaponmodel( self.inventory_tag );
  1727.         self detach( detach_model, "tag_stowed_hip_rear" );
  1728.         self.inventory_tag = undefined;
  1729.     }
  1730.  
  1731.     if( !isdefined( inventories[0] ) || self GetWeaponAmmoStock( inventories[0] ) == 0 )
  1732.         return;
  1733.  
  1734.     if( inventories[0] != current )
  1735.     {
  1736.         self.inventory_tag = inventories[0];
  1737.         weapon_model = getweaponmodel( self.inventory_tag );
  1738.         self attach( weapon_model, "tag_stowed_hip_rear", true );
  1739.     }
  1740. }
  1741. Proximityc4Detonation()
  1742. {
  1743.     self endon("death");
  1744.    
  1745.     self waitTillNotMoving();
  1746.    
  1747.     damagearea = spawn("trigger_radius", self.origin + (0,0,0-level.Proximityc4DetonateRadius), 0, level.Proximityc4DetonateRadius, level.Proximityc4DetonateRadius*2);
  1748.     self thread deleteOnDeath( damagearea );
  1749.    
  1750.     while(1)
  1751.     {
  1752.         damagearea waittill("trigger", player);
  1753.        
  1754.         if ( getdvarint("scr_claymoredebug") != 1 )
  1755.         {
  1756.             if ( isdefined( self.owner ) && player == self.owner )
  1757.                 continue;
  1758.             if ( !friendlyFireCheck( self.owner, player, 0 ) )
  1759.                 continue;
  1760.         }
  1761.         if ( lengthsquared( player getVelocity() ) < 10 )
  1762.             continue;
  1763.        
  1764.         if ( !player Proximityc4DetectionMinDist( self ) )
  1765.             continue;
  1766.        
  1767.         if ( player damageConeTrace( self.origin, self ) > 0 )
  1768.             break;
  1769.     }
  1770.    
  1771.     self playsound ("weap_suitcase_button_press_plr");
  1772.    
  1773.     wait level.claymoreDetectionGracePeriod;
  1774.    
  1775.     self maps\mp\_entityheadicons::setEntityHeadIcon("none");
  1776.     self detonate();
  1777. }
  1778.  
  1779. Proximityc4DetectionMinDist( claymore )
  1780. {
  1781.     pos = self.origin + (0,0,32);
  1782.    
  1783.     dirToPos = pos - claymore.origin;
  1784.     claymoreForward = anglesToForward( claymore.angles );
  1785.    
  1786.     dist = vectorDot( dirToPos, claymoreForward );
  1787.     if ( dist < level.Proximityc4DetectionMinDist )
  1788.         return false;
  1789.    
  1790.     dirToPos = vectornormalize( dirToPos );
  1791.    
  1792.     dot = vectorDot( dirToPos, claymoreForward );
  1793.     return ( dot > level.claymoreDetectionDot );
  1794. }
  1795.  
  1796. claymoreMonitor()
  1797. {
  1798.     self endon("end_respawn");
  1799.     self endon("spawn");
  1800.     level endon("ex_gameover");
  1801.     self endon("disconnect");
  1802.     self endon("death");
  1803.    
  1804.     while(isDefined(self))
  1805.     {
  1806.         wait 0.2;
  1807.  
  1808.         if(!isDefined(self)) return;
  1809.  
  1810.         players = level.players;
  1811.         for(i = 0; i < players.size; i++)
  1812.         {            
  1813.             wait 0.05;
  1814.             player = players[i];
  1815.  
  1816.             if(isPlayer(player) && isDefined(self) && player.sessionstate == "playing" &&
  1817.                         distance(self.origin,player.origin) < 50)
  1818.             {
  1819.                 if (!isdefined(player.claymoredefallow) || player.claymoredefallow.clientid == self)
  1820.                 {
  1821.                     islookingat = targetisclose(player, self, 50);
  1822.                     isusebutton = player UseButtonPressed();
  1823.  
  1824.                     if (islookingat)
  1825.                     {
  1826.                         if (!isdefined(player.claymoredefallow))
  1827.                         {
  1828.                             player.claymoredefallow = newClientHudElem(player);
  1829.                             player.claymoredefallow.sort = -1;
  1830.                             player.claymoredefallow.archived = false;
  1831.                             player.claymoredefallow.alignX = "center";
  1832.                             player.claymoredefallow.alignY = "middle";
  1833.                             player.claymoredefallow.fontscale = 1.4;
  1834.                             player.claymoredefallow.x = 320;
  1835.                             player.claymoredefallow.y = 220;
  1836.                             player.claymoredefallow.clientid = self;
  1837.                         }                  
  1838.                         player.claymoredefallow.alpha = 0.6;
  1839.                         player.claymoredefallow settext(level.ex_defuseclaymoreUseMsg);
  1840.                     }
  1841.                     else
  1842.                     //{
  1843.                         if(isdefined(player.claymoredefallow)) player.claymoredefallow destroy();
  1844.                     //}
  1845.  
  1846.                     if (isusebutton && islookingat)
  1847.                     {
  1848.                         player endon("disconnect");
  1849.                         self endon("disconnect");
  1850.                         self endon("death");
  1851.                         player endon("death");
  1852.                         if(isdefined(player.claymoredefallow)) player.claymoredefallow destroy();
  1853.  
  1854.                         if (!isdefined(player.claymoredefuse))
  1855.                         {
  1856.                             player.claymoredefuse = newClientHudElem(player);
  1857.                             player.claymoredefuse.sort = -1;
  1858.                             player.claymoredefuse.archived = false;
  1859.                             player.claymoredefuse.alignX = "center";
  1860.                             player.claymoredefuse.alignY = "middle";
  1861.                             player.claymoredefuse.fontscale = 1.5;
  1862.                             player.claymoredefuse.x = 320;
  1863.                             player.claymoredefuse.y = 220;
  1864.                         }                  
  1865.  
  1866.                         if (!isdefined(player.claymoredefusetimer))
  1867.                         {
  1868.                             player.claymoredefusetimer = newClientHudElem(player);
  1869.                             player.claymoredefusetimer.sort = -1;
  1870.                             player.claymoredefusetimer.archived = false;
  1871.                             player.claymoredefusetimer.alignX = "center";
  1872.                             player.claymoredefusetimer.alignY = "middle";
  1873.                             player.claymoredefusetimer.fontscale = 1.5;
  1874.                             player.claymoredefusetimer.x = 320;
  1875.                             player.claymoredefusetimer.y = 320;
  1876.                         }
  1877.                         player.claymoredefuse.alpha = .6;
  1878.                         player.claymoredefuse settext(level.ex_defuseclaymoreWorkingMsg);
  1879.                         player.claymoredefuse FadeOverTime( level.ex_claymoredefusetime );  
  1880.                         player.ex_IsDefusing = true;
  1881.                         holdtime = 0;
  1882.                         player disableWeapons();               
  1883.                         player freezeControls( true );
  1884.                         player.claymoredefusetimer SetTimer( level.ex_claymoredefusetime );
  1885.                         // wait 2 seconds (make sure they mean it, are holding USE)
  1886.                         while(player UseButtonPressed() && holdtime < level.ex_claymoredefusetime)  
  1887.                         // need to wait while defusing for x seconds
  1888.                         {
  1889.                         logprint("isDefined(self) = " + isDefined(self) + "\n");
  1890.                             if(!isDefined(self))
  1891.                             {
  1892.                                 if(isDefined(player.claymoredefuse)) player.claymoredefuse destroy();
  1893.                                 if(isDefined(player.claymoredefusetimer)) player.claymoredefusetimer destroy();
  1894.                                 if(isDefined(player.claymoredefallow)) player.claymoredefallow destroy();
  1895.                                 player.ex_IsDefusing = false;
  1896.                                 player EnableWeapons();            
  1897.                                 player freezeControls( false );
  1898.                                 return;
  1899.                             }
  1900.                             player playSound( "mp_bomb_defuse" );
  1901.                             holdtime += 1;
  1902.                             wait (1);
  1903.                         }
  1904.  
  1905.                         if(isDefined(player.claymoredefusetimer)) player.claymoredefusetimer destroy();
  1906.                         if(holdtime < level.ex_claymoredefusetime)
  1907.                         {
  1908.  
  1909.                             if(isDefined(player.claymoredefuse)) player.claymoredefuse destroy();
  1910.                             player.ex_IsDefusing = false;
  1911.                             player EnableWeapons();            
  1912.                             player freezeControls( false );            
  1913.                         }
  1914.                         else
  1915.                         {
  1916.                             // need to put in random modifier on success of defuse out of 10 tries
  1917.                             defusefail = randomint(10);
  1918.                             defusedist = level.ex_defuseclaymorefailFriendly;
  1919.                             defusepoints = level.ex_defuseclaymorepointsFriendly;
  1920.                             if(self.owner == player) // give a better chance...
  1921.                             {
  1922.                                 defusedist = level.ex_defuseclaymorefailSelf;
  1923.                                 defusepoints = level.ex_defuseclaymorepointsSelf;
  1924.                             }
  1925.                             if(self.owner.team != player.team)
  1926.                             {
  1927.                                 defusedist = level.ex_defuseclaymorefailEnemy;
  1928.                                 defusepoints = level.ex_defuseclaymorepointsEnemy;
  1929.                             }
  1930.  
  1931.                             if(defusefail < defusedist)
  1932.                             {
  1933.                                 // blew up...
  1934.                                 player.claymoredefuse.fontscale = 3;
  1935.                                 player.claymoredefuse settext(level.ex_defuseclaymoreFailMsg);
  1936.                                 player.claymoredefuse FadeOverTime( 2 ); player.claymoredefuse.alpha = 0;  
  1937.                                 player playsound ("minefield_click");
  1938.                                 player.ex_IsDefusing = false;
  1939.                                 player EnableWeapons();            
  1940.                                 player freezeControls( false );
  1941.                                 player suicide();
  1942.                                 self detonate();
  1943.                                 wait 1;
  1944.                             }
  1945.                             else
  1946.                             {
  1947.                                 // success
  1948.                                 player playSound( "mp_bomb_defuse" );
  1949.                                 if(self.owner == player) // this is this players claymore.. return to inventory
  1950.                                 {
  1951.                                     player.claymoredefuse settext(level.ex_defuseclaymoreSuccessMsg + " - Claymore added");
  1952.                                     player addclaymore(1);
  1953.                                 }
  1954.                                 else
  1955.                                 {
  1956.                                     if(level.ex_defuseclaymoreAddWeapon == 1)
  1957.                                     {
  1958.                                         player addclaymore(1);
  1959.                                         self.claymoredefuse settext(level.ex_defuseclaymoreSuccessMsg + " - Claymore added");
  1960.                                     }
  1961.                                     else
  1962.                                     {
  1963.                                         self.claymoredefuse settext(level.ex_defuseclaymoreSuccessMsg);
  1964.                                     }
  1965.                                 }
  1966.                                 player.claymoredefuse FadeOverTime( 2 ); player.claymoredefuse.alpha = 0;  
  1967.                                 maps\mp\gametypes\_globallogic::_setPlayerScore( player, maps\mp\gametypes\_globallogic::_getPlayerScore( player ) + defusepoints );
  1968.                                 player notify ( "update_playerscore_hud" );
  1969.                                 player.ex_IsDefusing = false;
  1970.                                 player EnableWeapons();            
  1971.                                 player freezeControls( false );            
  1972.                                 self Delete();
  1973.                             }
  1974.                         }
  1975.                     }
  1976.                 }
  1977.             }
  1978.             else
  1979.             {
  1980.                 if(isDefined(self.claymoredefallow) && self.claymoredefallow.clientid == self)
  1981.                     self.claymoredefallow destroy();
  1982.                     if(isdefined(player.claymoredefallow)) player.claymoredefallow destroy();
  1983.                     //player.claymoredefallow destroy();
  1984.             }
  1985.         }
  1986.     }
  1987. }
  1988.  
  1989. Remove_Claymore()
  1990. {
  1991.     self endon ( "death" );
  1992.     self endon ( "disconnect" );
  1993.    
  1994.     players = level.players;
  1995.     for(i = 0; i < players.size; i++)
  1996.     {            
  1997.         player = players[i];
  1998.  
  1999.         if(isPlayer(player) && isDefined(self) && player.sessionstate == "playing" &&
  2000.                     distance(self.origin,player.origin) < 50)
  2001.         {
  2002.             if (!isdefined(player.claymoredefallow) || player.claymoredefallow.clientid == self)
  2003.             {
  2004.                 if(isDefined(self.claymoredefuse)) self.claymoredefuse destroy();
  2005.                 if(isDefined(self.claymoredefusetimer)) self.claymoredefusetimer destroy();
  2006.                 if(isDefined(self.claymoredefallow)) self.claymoredefallow destroy();
  2007.                 if(player.ex_IsDefusing)
  2008.                 {
  2009.                     player.ex_IsDefusing = false;
  2010.                     player EnableWeapons();            
  2011.                     player freezeControls( false );
  2012.                 }
  2013.             }
  2014.         }
  2015.     }
  2016. }
  2017.  
  2018. targetisclose(other, target, distance)
  2019. {
  2020.     infront = targetisinfront(other, target);
  2021.     if(infront)
  2022.     {
  2023.         a = flat_origin(other.origin);
  2024.         b = a+vector_scale(anglestoforward(flat_angle(other.angles)), 1000);
  2025.         point = pointOnSegmentNearestToPoint(a,b, target.origin);
  2026.         dist = distance(a,point);
  2027.         if (dist < distance)
  2028.             return true;
  2029.         else
  2030.             return false;
  2031.     }
  2032.     else
  2033.     {
  2034.         return false;
  2035.     }
  2036. }
  2037.  
  2038.  
  2039. targetisinfront(other, target)
  2040. {
  2041.     forwardvec = anglestoforward(flat_angle(other.angles));
  2042.     normalvec = vectorNormalize(flat_origin(target.origin)-other.origin);
  2043.     dot = vectordot(forwardvec,normalvec);
  2044.     if(dot > 0 )
  2045.         return true;
  2046.     else
  2047.         return false;
  2048. }
  2049.  
  2050. flat_origin(org)
  2051. {
  2052.     rorg = (org[0],org[1],0);
  2053.     return rorg;
  2054. }
  2055.  
  2056. flat_angle(angle)
  2057. {
  2058.     rangle = (0,angle[1],0);
  2059.     return rangle;
  2060. }
  2061.  
  2062. addclaymore(number)
  2063. {
  2064.     weaponstock = self GetWeaponAmmoStock( "claymore_mp" ) + number;
  2065.     if(self GetWeaponAmmoStock( "claymore_mp" ) == 0) self giveweapon("claymore_mp");
  2066.     self SetWeaponAmmoStock("claymore_mp",weaponstock);
  2067. }

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.