Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 70.17 KB | None | 0 0
  1. #include maps\_utility;
  2. #include common_scripts\utility;
  3. #include maps\_zombiemode_utility;
  4. #include maps\trem_hintstrings;
  5. init()
  6. {
  7.     init_weapons();
  8.     init_weapon_upgrade();
  9.     init_pay_turret();
  10.     init_weapon_cabinet();
  11.     treasure_chest_init();
  12.     level thread add_limited_tesla_gun();
  13.     level.box_moved = false;
  14. }
  15.  
  16. add_zombie_weapon( weapon_name, hint, cost, weaponVO, variation_count, ammo_cost  )
  17. {
  18.     if( IsDefined( level.zombie_include_weapons ) && !IsDefined( level.zombie_include_weapons[weapon_name] ) )
  19.     {
  20.         return;
  21.     }
  22.    
  23.     add_weapon_to_sound_array(weaponVO,variation_count);
  24.  
  25.     // Check the table first
  26.     table = "mp/zombiemode.csv";
  27.     table_cost = TableLookUp( table, 0, weapon_name, 1 );
  28.     table_ammo_cost = TableLookUp( table, 0, weapon_name, 2 );
  29.  
  30.     if( IsDefined( table_cost ) && table_cost != "" )
  31.     {
  32.         cost = round_up_to_ten( int( table_cost ) );
  33.     }
  34.  
  35.     if( IsDefined( table_ammo_cost ) && table_ammo_cost != "" )
  36.     {
  37.         ammo_cost = round_up_to_ten( int( table_ammo_cost ) );
  38.     }
  39.  
  40.     PrecacheItem( weapon_name );
  41.     PrecacheString( hint );
  42.  
  43.     struct = SpawnStruct();
  44.  
  45.     if( !IsDefined( level.zombie_weapons ) )
  46.     {
  47.         level.zombie_weapons = [];
  48.     }
  49.  
  50.     struct.weapon_name = weapon_name;
  51.     struct.weapon_classname = "weapon_" + weapon_name;
  52.     struct.hint = hint;
  53.     struct.cost = cost;
  54.     struct.sound = weaponVO;
  55.     struct.variation_count = variation_count;
  56.     struct.is_in_box = level.zombie_include_weapons[weapon_name];
  57.  
  58.     if( !IsDefined( ammo_cost ) )
  59.     {
  60.         ammo_cost = round_up_to_ten( int( cost * 0.5 ) );
  61.     }
  62.  
  63.     struct.ammo_cost = ammo_cost;
  64.  
  65.     level.zombie_weapons[weapon_name] = struct;
  66. }
  67.  
  68. default_weighting_func()
  69. {
  70.     return 1;
  71. }
  72.  
  73. default_tesla_weighting_func()
  74. {
  75.     num_to_add = 1;
  76.     if( isDefined( level.pulls_since_last_tesla_gun ) )
  77.     {
  78.         // player has dropped the tesla for another weapon, so we set all future polls to 20%
  79.         if( isDefined(level.player_drops_tesla_gun) && level.player_drops_tesla_gun == true )
  80.         {                      
  81.             num_to_add += int(.2 * level.zombie_include_weapons.size);     
  82.         }
  83.        
  84.         // player has not seen tesla gun in late rounds
  85.         if( !isDefined(level.player_seen_tesla_gun) || level.player_seen_tesla_gun == false )
  86.         {
  87.             // after round 10 the Tesla gun percentage increases to 20%
  88.             if( level.round_number > 10 )
  89.             {
  90.                 num_to_add += int(.2 * level.zombie_include_weapons.size);
  91.             }      
  92.             // after round 5 the Tesla gun percentage increases to 15%
  93.             else if( level.round_number > 5 )
  94.             {
  95.                 // calculate the number of times we have to add it to the array to get the desired percent
  96.                 num_to_add += int(.15 * level.zombie_include_weapons.size);
  97.             }                      
  98.         }
  99.     }
  100.     return num_to_add;
  101. }
  102.  
  103. default_ray_gun_weighting_func()
  104. {
  105.     if( level.box_moved == true )
  106.     {  
  107.         num_to_add = 1;
  108.         // increase the percentage of ray gun
  109.         if( isDefined( level.pulls_since_last_ray_gun ) )
  110.         {
  111.             // after 12 pulls the ray gun percentage increases to 15%
  112.             if( level.pulls_since_last_ray_gun > 11 )
  113.             {
  114.                 num_to_add += int(level.zombie_include_weapons.size*0.15);         
  115.             }          
  116.             // after 8 pulls the Ray Gun percentage increases to 10%
  117.             else if( level.pulls_since_last_ray_gun > 7 )
  118.             {
  119.                 num_to_add += int(.1 * level.zombie_include_weapons.size);
  120.             }      
  121.         }
  122.         return num_to_add; 
  123.     }
  124.     else
  125.     {
  126.         return 0;
  127.     }
  128. }
  129.  
  130.  
  131. //
  132. //  Slightly elevate the chance to get it until someone has it, then make it even
  133. default_cymbal_monkey_weighting_func()
  134. {
  135.     players = get_players();
  136.     count = 0;
  137.     for( i = 0; i < players.size; i++ )
  138.     {
  139.         if( players[i] has_weapon_or_upgrade( "zombie_cymbal_monkey" ) )
  140.         {
  141.             count++;
  142.         }
  143.     }
  144.     if ( count > 0 )
  145.     {
  146.         return 1;
  147.     }
  148.     else
  149.     {
  150.         if( level.round_number < 10 )
  151.         {
  152.             return 3;
  153.         }
  154.         else
  155.         {
  156.             return 5;
  157.         }
  158.     }
  159. }
  160.  
  161.  
  162. include_zombie_weapon( weapon_name, in_box, weighting_func )
  163. {
  164.     if( !IsDefined( level.zombie_include_weapons ) )
  165.     {
  166.         level.zombie_include_weapons = [];
  167.     }
  168.     if( !isDefined( in_box ) )
  169.     {
  170.         in_box = true;
  171.     }
  172.  
  173.     level.zombie_include_weapons[weapon_name] = in_box;
  174.    
  175.     if( !isDefined( weighting_func ) )
  176.     {
  177.         level.weapon_weighting_funcs[weapon_name] = maps\_zombiemode_weapons::default_weighting_func;
  178.     }
  179.     else
  180.     {
  181.         level.weapon_weighting_funcs[weapon_name] = weighting_func;
  182.     }
  183. }
  184.  
  185. init_weapons()
  186. {
  187.     // Zombify
  188.     PrecacheItem( "zombie_melee" );
  189.  
  190.  
  191.     // Pistols
  192.     add_zombie_weapon( "colt",                                  &"ZOMBIE_WEAPON_COLT_50",                   50,     "vox_crappy",   8 );
  193.     add_zombie_weapon( "colt_dirty_harry",                      &"ZOMBIE_WEAPON_COLT_DH_100",               100,    "vox_357",      5 );
  194.     add_zombie_weapon( "nambu",                                 &"ZOMBIE_WEAPON_NAMBU_50",                  50,     "vox_crappy",   8 );
  195.     add_zombie_weapon( "sw_357",                                &"ZOMBIE_WEAPON_SW357_100",                 100,    "vox_357",      5 );
  196.     add_zombie_weapon( "zombie_sw_357",                         &"ZOMBIE_WEAPON_SW357_100",                 100,    "vox_357",      5 );
  197.     add_zombie_weapon( "zombie_sw_357_upgraded",                &"ZOMBIE_WEAPON_SW357_100",                 100,    "vox_357",      5 );
  198.     add_zombie_weapon( "tokarev",                               &"ZOMBIE_WEAPON_TOKAREV_50",                50,     "vox_crappy",   8 );
  199.     add_zombie_weapon( "walther",                               &"ZOMBIE_WEAPON_WALTHER_50",                50,     "vox_crappy",   8 );
  200.     add_zombie_weapon( "zombie_colt",                           &"ZOMBIE_WEAPON_ZOMBIECOLT_25",             25,     "vox_crappy",   8 );
  201.     add_zombie_weapon( "zombie_colt_upgraded",                  &"ZOMBIE_WEAPON_ZOMBIECOLT_25",             25,     "vox_crappy",   8 );
  202.  
  203.     // Bolt Action                                             
  204.     add_zombie_weapon( "kar98k",                                &"ZOMBIE_WEAPON_KAR98K_200",                200,    "",             0);
  205.     add_zombie_weapon( "zombie_kar98k",                         &"ZOMBIE_WEAPON_KAR98K_200",                200,    "",             0);
  206.     add_zombie_weapon( "zombie_kar98k_upgraded",                &"ZOMBIE_WEAPON_KAR98K_200",                200,    "",             0);
  207.     add_zombie_weapon( "kar98k_bayonet",                        &"ZOMBIE_WEAPON_KAR98K_B_200",              200,    "",             0);
  208.     add_zombie_weapon( "mosin_rifle",                           &"ZOMBIE_WEAPON_MOSIN_200",                 200,    "",             0);
  209.     add_zombie_weapon( "mosin_rifle_bayonet",                   &"ZOMBIE_WEAPON_MOSIN_B_200",               200,    "",             0 );
  210.     add_zombie_weapon( "springfield",                           &"ZOMBIE_WEAPON_SPRINGFIELD_200",           200,    "",             0 );
  211.     add_zombie_weapon( "zombie_springfield",                    &"ZOMBIE_WEAPON_SPRINGFIELD_200",           200,    "",             0 );
  212.     add_zombie_weapon( "springfield_bayonet",                   &"ZOMBIE_WEAPON_SPRINGFIELD_B_200",         200,    "",             0 );
  213.     add_zombie_weapon( "zombie_type99_rifle",                   &"ZOMBIE_WEAPON_TYPE99_200",                200,    "",             0 );
  214.     add_zombie_weapon( "zombie_type99_rifle_upgraded",          &"ZOMBIE_WEAPON_TYPE99_200",                200,    "",             0 );
  215.     add_zombie_weapon( "type99_rifle_bayonet",                  &"ZOMBIE_WEAPON_TYPE99_B_200",              200,    "",             0 );
  216.  
  217.     // Semi Auto                                               
  218.     add_zombie_weapon( "zombie_gewehr43",                       &"ZOMBIE_WEAPON_GEWEHR43_600",              600,    "" ,            0 );
  219.     add_zombie_weapon( "zombie_gewehr43_upgraded",              &"ZOMBIE_WEAPON_GEWEHR43_600",              600,    "" ,            0 );
  220.     add_zombie_weapon( "zombie_m1carbine",                      &"ZOMBIE_WEAPON_M1CARBINE_600",             600,    "" ,            0 );
  221.     add_zombie_weapon( "zombie_m1carbine_upgraded",             &"ZOMBIE_WEAPON_M1CARBINE_600",             600,    "" ,            0 );
  222.     add_zombie_weapon( "m1carbine_bayonet",                     &"ZOMBIE_WEAPON_M1CARBINE_B_600",           600,    "" ,            0 );
  223.     add_zombie_weapon( "zombie_m1garand",                       &"ZOMBIE_WEAPON_M1GARAND_600",              600,    "" ,            0 );
  224.     add_zombie_weapon( "zombie_m1garand_upgraded",              &"ZOMBIE_WEAPON_M1GARAND_600",              600,    "" ,            0 );
  225.     add_zombie_weapon( "m1garand_bayonet",                      &"ZOMBIE_WEAPON_M1GARAND_B_600",            600,    "" ,            0 );
  226.     add_zombie_weapon( "svt40",                                 &"ZOMBIE_WEAPON_SVT40_600",                 600,    "" ,            0 );
  227.  
  228.     // Grenades                                                
  229.     add_zombie_weapon( "fraggrenade",                           &"ZOMBIE_WEAPON_FRAGGRENADE_250",           250,    "" ,            0 );
  230.     add_zombie_weapon( "molotov",                               &"ZOMBIE_WEAPON_MOLOTOV_200",               200,    "vox_crappy",   8 );
  231.     add_zombie_weapon( "molotov_zombie",                        &"ZOMBIE_WEAPON_MOLOTOV_200",               200,    "vox_crappy",   8 );
  232.     add_zombie_weapon( "stick_grenade",                         &"ZOMBIE_WEAPON_STICKGRENADE_250",          250,    "" ,            0 );
  233.     add_zombie_weapon( "stielhandgranate",                      &"ZOMBIE_WEAPON_STIELHANDGRANATE_250",      250,    "" ,            0, 250 );
  234.     add_zombie_weapon( "type97_frag",                           &"ZOMBIE_WEAPON_TYPE97FRAG_250",            250,    "" ,            0 );
  235.  
  236.     // Scoped
  237.     add_zombie_weapon( "kar98k_scoped_zombie",                  &"ZOMBIE_WEAPON_KAR98K_S_750",              750,    "vox_ppsh",     5);
  238.     add_zombie_weapon( "kar98k_scoped_bayonet_zombie",          &"ZOMBIE_WEAPON_KAR98K_S_B_750",            750,    "vox_ppsh",     5);
  239.     add_zombie_weapon( "mosin_rifle_scoped_zombie",             &"ZOMBIE_WEAPON_MOSIN_S_750",               750,    "vox_ppsh",     5);
  240.     add_zombie_weapon( "mosin_rifle_scoped_bayonet_zombie",     &"ZOMBIE_WEAPON_MOSIN_S_B_750",             750,    "vox_ppsh",     5);
  241.     add_zombie_weapon( "ptrs41_zombie",                         &"ZOMBIE_WEAPON_PTRS41_750",                750,    "vox_ppsh",     5);
  242.     add_zombie_weapon( "ptrs41_zombie_upgraded",                &"ZOMBIE_WEAPON_PTRS41_750",                750,    "vox_ppsh",     5);
  243.     add_zombie_weapon( "springfield_scoped_zombie",             &"ZOMBIE_WEAPON_SPRINGFIELD_S_750",         750,    "vox_ppsh",     5);
  244.     add_zombie_weapon( "springfield_scoped_bayonet_zombie",     &"ZOMBIE_WEAPON_SPRINGFIELD_S_B_750",       750,    "vox_ppsh",     5);
  245.     add_zombie_weapon( "type99_rifle_scoped_zombie",            &"ZOMBIE_WEAPON_TYPE99_S_750",              750,    "vox_ppsh",     5);
  246.     add_zombie_weapon( "type99_rifle_scoped_bayonet_zombie",    &"ZOMBIE_WEAPON_TYPE99_S_B_750",            750,    "vox_ppsh",     5);
  247.  
  248.     // Full Auto                                                                                   
  249.     add_zombie_weapon( "zombie_mp40",                           &"ZOMBIE_WEAPON_MP40_1000",                 1000,   "vox_mp40",     2 );
  250.     add_zombie_weapon( "zombie_mp40_upgraded",                  &"ZOMBIE_WEAPON_MP40_1000",                 1000,   "vox_mp40",     2 );
  251.     add_zombie_weapon( "zombie_ppsh",                           &"ZOMBIE_WEAPON_PPSH_2000",                 2000,   "vox_ppsh",     5 );
  252.     add_zombie_weapon( "zombie_ppsh_upgraded",                  &"ZOMBIE_WEAPON_PPSH_2000",                 2000,   "vox_ppsh",     5 );
  253.     add_zombie_weapon( "zombie_stg44",                          "Press and hold &&1 to buy STG-44 [Cost:1200]",                 1200,   "vox_mg",       9 );
  254.     add_zombie_weapon( "zombie_stg44_upgraded",                 "Press and hold &&1 to buy STG-44 [Cost:1200]",                 1200,   "vox_mg",       9 );
  255.     add_zombie_weapon( "zombie_thompson",                       &"ZOMBIE_WEAPON_THOMPSON_1200",             1200,   "",             0 );
  256.     add_zombie_weapon( "zombie_thompson_upgraded",              &"ZOMBIE_WEAPON_THOMPSON_1200",             1200,   "",             0 );
  257.     add_zombie_weapon( "zombie_type100_smg",                    &"ZOMBIE_WEAPON_TYPE100_1000",              1000,   "",             0 );
  258.     add_zombie_weapon( "zombie_type100_smg_upgraded",           &"ZOMBIE_WEAPON_TYPE100_1000",              1000,   "",             0 );
  259.  
  260.     // Shotguns                                            
  261.     add_zombie_weapon( "zombie_doublebarrel",                   &"ZOMBIE_WEAPON_DOUBLEBARREL_1200",         1200,   "vox_shotgun", 6);
  262.     add_zombie_weapon( "zombie_doublebarrel_upgraded",          &"ZOMBIE_WEAPON_DOUBLEBARREL_1200",         1200,   "vox_shotgun", 6);
  263.     add_zombie_weapon( "zombie_doublebarrel_sawed",             &"ZOMBIE_WEAPON_DOUBLEBARREL_SAWED_1200",   1200,   "vox_shotgun", 6);
  264.     add_zombie_weapon( "zombie_doublebarrel_sawed_upgraded",    &"ZOMBIE_WEAPON_DOUBLEBARREL_SAWED_1200",   1200,   "vox_shotgun", 6);
  265.     add_zombie_weapon( "zombie_shotgun",                        &"ZOMBIE_WEAPON_SHOTGUN_1500",              1500,   "vox_shotgun", 6);
  266.     add_zombie_weapon( "zombie_shotgun_upgraded",               &"ZOMBIE_WEAPON_SHOTGUN_1500",              1500,   "vox_shotgun", 6);
  267.  
  268.     // Heavy Machineguns                                   
  269.     add_zombie_weapon( "zombie_30cal",                          &"ZOMBIE_WEAPON_30CAL_3000",                3000,   "vox_mg",       9 );
  270.     add_zombie_weapon( "zombie_30cal_upgraded",                 &"ZOMBIE_WEAPON_30CAL_3000",                3000,   "vox_mg",       9 );
  271.     add_zombie_weapon( "zombie_bar",                            &"ZOMBIE_WEAPON_BAR_1800",                  1800,   "vox_bar",      5 );
  272.     add_zombie_weapon( "zombie_bar_upgraded",                   &"ZOMBIE_WEAPON_BAR_1800",                  1800,   "vox_bar",      5 );
  273.     add_zombie_weapon( "dp28",                                  &"ZOMBIE_WEAPON_DP28_2250",                 2250,   "vox_mg" ,      9 );
  274.     add_zombie_weapon( "zombie_fg42",                           &"ZOMBIE_WEAPON_FG42_1500",                 1500,   "vox_mg" ,      9 );
  275.     add_zombie_weapon( "zombie_fg42_upgraded",                  &"ZOMBIE_WEAPON_FG42_1500",                 1500,   "vox_mg" ,      9 );
  276.     add_zombie_weapon( "fg42_scoped",                           &"ZOMBIE_WEAPON_FG42_S_1500",               1500,   "vox_mg" ,      9 );
  277.     add_zombie_weapon( "zombie_mg42",                           &"ZOMBIE_WEAPON_MG42_3000",                 3000,   "vox_mg" ,      9 );
  278.     add_zombie_weapon( "zombie_mg42_upgraded",                  &"ZOMBIE_WEAPON_MG42_3000",                 3000,   "vox_mg" ,      9 );
  279.     add_zombie_weapon( "type99_lmg",                            &"ZOMBIE_WEAPON_TYPE99_LMG_1750",           1750,   "vox_mg" ,      9 );
  280.  
  281.     // Grenade Launcher                                    
  282.     add_zombie_weapon( "m1garand_gl_zombie",                    &"ZOMBIE_WEAPON_M1GARAND_GL_1500",          1500,   "",             0 );
  283.     add_zombie_weapon( "m1garand_gl_zombie_upgraded",           &"ZOMBIE_WEAPON_M1GARAND_GL_1500",          1500,   "",             0 );
  284.     add_zombie_weapon( "mosin_launcher_zombie",                 &"ZOMBIE_WEAPON_MOSIN_GL_1200",             1200,   "",             0 );
  285.  
  286.     // Bipods                                              
  287.     add_zombie_weapon( "30cal_bipod",                           &"ZOMBIE_WEAPON_30CAL_BIPOD_3500",          3500,   "vox_mg",       5 );
  288.     add_zombie_weapon( "bar_bipod",                             &"ZOMBIE_WEAPON_BAR_BIPOD_2500",            2500,   "vox_bar",      5 );
  289.     add_zombie_weapon( "dp28_bipod",                            &"ZOMBIE_WEAPON_DP28_BIPOD_2500",           2500,   "vox_mg",       5 );
  290.     add_zombie_weapon( "fg42_bipod",                            &"ZOMBIE_WEAPON_FG42_BIPOD_2000",           2000,   "vox_mg",       5 );
  291.     add_zombie_weapon( "mg42_bipod",                            &"ZOMBIE_WEAPON_MG42_BIPOD_3250",           3250,   "vox_mg",       5 );
  292.     add_zombie_weapon( "type99_lmg_bipod",                      &"ZOMBIE_WEAPON_TYPE99_LMG_BIPOD_2250",     2250,   "vox_mg",       5 );
  293.  
  294.     // Rocket Launchers
  295.     add_zombie_weapon( "bazooka",                               &"ZOMBIE_WEAPON_BAZOOKA_2000",              2000,   "",             0 );
  296.     add_zombie_weapon( "panzerschrek_zombie",                   &"ZOMBIE_WEAPON_PANZERSCHREK_2000",         2000,   "vox_panzer",   5 );
  297.     add_zombie_weapon( "panzerschrek_zombie_upgraded",          &"ZOMBIE_WEAPON_PANZERSCHREK_2000",         2000,   "vox_panzer",   5 );
  298.  
  299.     // Flamethrower                                        
  300.     add_zombie_weapon( "m2_flamethrower_zombie",                &"ZOMBIE_WEAPON_M2_FLAMETHROWER_3000",      3000,   "vox_flame",    7);
  301.     add_zombie_weapon( "m2_flamethrower_zombie_upgraded",       &"ZOMBIE_WEAPON_M2_FLAMETHROWER_3000",      3000,   "vox_flame",    7);
  302.  
  303.     // Special                                             
  304.     add_zombie_weapon( "mine_bouncing_betty",                   &"ZOMBIE_WEAPON_SATCHEL_2000",              2000,   "" );
  305.     add_zombie_weapon( "mortar_round",                          &"ZOMBIE_WEAPON_MORTARROUND_2000",          2000,   "" );
  306.     add_zombie_weapon( "satchel_charge",                        &"ZOMBIE_WEAPON_SATCHEL_2000",              2000,   "vox_monkey",   3 );
  307.     add_zombie_weapon( "zombie_cymbal_monkey",                  &"ZOMBIE_WEAPON_SATCHEL_2000",              2000,   "vox_monkey",   3 );
  308.     add_zombie_weapon( "ray_gun",                               &"ZOMBIE_WEAPON_RAYGUN_10000",              10000"vox_raygun",   6 );
  309.     add_zombie_weapon( "ray_gun_upgraded",                      &"ZOMBIE_WEAPON_RAYGUN_10000",              10000"vox_raygun",   6 );
  310.     add_zombie_weapon( "tesla_gun",                             &"ZOMBIE_BUY_TESLA",                        10,     "vox_tesla",    5 );
  311.     add_zombie_weapon( "tesla_gun_upgraded",                    &"ZOMBIE_BUY_TESLA",                        10,     "vox_tesla",    5 );
  312.  
  313.     if(level.script != "nazi_zombie_prototype")
  314.     {
  315.         Precachemodel("zombie_teddybear");
  316.     }
  317.     // ONLY 1 OF THE BELOW SHOULD BE ALLOWED
  318.     add_limited_weapon( "m2_flamethrower_zombie", 1 );
  319.     add_limited_weapon( "tesla_gun", 1);
  320. }  
  321.  
  322. //remove this function and whenever it's call for production. this is only for testing purpose.
  323. add_limited_tesla_gun()
  324. {
  325.  
  326.     weapon_spawns = GetEntArray( "weapon_upgrade", "targetname" );
  327.  
  328.     for( i = 0; i < weapon_spawns.size; i++ )
  329.     {
  330.         hint_string = weapon_spawns[i].zombie_weapon_upgrade;
  331.         if(hint_string == "tesla_gun")
  332.         {
  333.             weapon_spawns[i] waittill("trigger");
  334.             weapon_spawns[i] trigger_off();
  335.             break;
  336.  
  337.         }
  338.        
  339.     }
  340.  
  341. }
  342.  
  343.  
  344. add_limited_weapon( weapon_name, amount )
  345. {
  346.     if( !IsDefined( level.limited_weapons ) )
  347.     {
  348.         level.limited_weapons = [];
  349.     }
  350.  
  351.     level.limited_weapons[weapon_name] = amount;
  352. }                                          
  353.  
  354. // For pay turrets
  355. init_pay_turret()
  356. {
  357.     pay_turrets = [];
  358.     pay_turrets = GetEntArray( "pay_turret", "targetname" );
  359.    
  360.     for( i = 0; i < pay_turrets.size; i++ )
  361.     {
  362.         cost = level.pay_turret_cost;
  363.         if( !isDefined( cost ) )
  364.         {
  365.             cost = 1000;
  366.         }
  367.         pay_turrets[i] _sethintstring( &"ZOMBIE_PAY_TURRET", cost );
  368.         pay_turrets[i] SetCursorHint( "HINT_NOICON" );
  369.         pay_turrets[i] UseTriggerRequireLookAt();
  370.        
  371.         pay_turrets[i] thread pay_turret_think( cost );
  372.     }
  373. }
  374.  
  375. // For buying weapon upgrades in the environment
  376. init_weapon_upgrade()
  377. {
  378.     weapon_spawns = [];
  379.     weapon_spawns = GetEntArray( "weapon_upgrade", "targetname" );
  380.  
  381.     for( i = 0; i < weapon_spawns.size; i++ )
  382.     {
  383.         hint_string = get_weapon_hint( weapon_spawns[i].zombie_weapon_upgrade );
  384.  
  385.         weapon_spawns[i] _sethintstring( hint_string );
  386.         weapon_spawns[i] setCursorHint( "HINT_NOICON" );
  387.         weapon_spawns[i] UseTriggerRequireLookAt();
  388.  
  389.         weapon_spawns[i] thread weapon_spawn_think();
  390.         model = getent( weapon_spawns[i].target, "targetname" );
  391.         model hide();
  392.     }
  393. }
  394.  
  395. // weapon cabinets which open on use
  396. init_weapon_cabinet()
  397. {
  398.     // the triggers which are targeted at doors
  399.     weapon_cabs = GetEntArray( "weapon_cabinet_use", "targetname" );
  400.  
  401.     for( i = 0; i < weapon_cabs.size; i++ )
  402.     {
  403.  
  404.         weapon_cabs[i] _sethintstring( &"ZOMBIE_CABINET_OPEN_1500" );
  405.         weapon_cabs[i] setCursorHint( "HINT_NOICON" );
  406.         weapon_cabs[i] UseTriggerRequireLookAt();
  407.     }
  408.  
  409.     array_thread( weapon_cabs, ::weapon_cabinet_think );
  410. }
  411.  
  412. // returns the trigger hint string for the given weapon
  413. get_weapon_hint( weapon_name )
  414. {
  415.     AssertEx( IsDefined( level.zombie_weapons[weapon_name] ), weapon_name + " was not included or is not part of the zombie weapon list." );
  416.  
  417.     return level.zombie_weapons[weapon_name].hint;
  418. }
  419.  
  420. get_weapon_cost( weapon_name )
  421. {
  422.     AssertEx( IsDefined( level.zombie_weapons[weapon_name] ), weapon_name + " was not included or is not part of the zombie weapon list." );
  423.  
  424.     return level.zombie_weapons[weapon_name].cost;
  425. }
  426.  
  427. get_ammo_cost( weapon_name )
  428. {
  429.     AssertEx( IsDefined( level.zombie_weapons[weapon_name] ), weapon_name + " was not included or is not part of the zombie weapon list." );
  430.  
  431.     return level.zombie_weapons[weapon_name].ammo_cost;
  432. }
  433.  
  434. get_is_in_box( weapon_name )
  435. {
  436.     AssertEx( IsDefined( level.zombie_weapons[weapon_name] ), weapon_name + " was not included or is not part of the zombie weapon list." );
  437.    
  438.     return level.zombie_weapons[weapon_name].is_in_box;
  439. }
  440.  
  441. is_weapon_upgraded( weaponname )
  442. {
  443.     if( !isdefined( weaponname ) )
  444.     {
  445.         return false;
  446.     }
  447.  
  448.     weaponname = ToLower( weaponname );
  449.  
  450.     upgraded = issubstr( weaponname, "_upgraded" );
  451.  
  452.     return upgraded;
  453.  
  454. }
  455.  
  456. has_upgrade( weaponname )
  457. {
  458.     has_upgrade = false;
  459.     if( IsDefined( level.zombie_include_weapons[weaponname+"_upgraded"] ) )
  460.     {
  461.         has_upgrade = self HasWeapon( weaponname+"_upgraded" );
  462.     }
  463.     return has_upgrade;
  464. }
  465.  
  466. has_weapon_or_upgrade( weaponname )
  467. {
  468.     has_weapon = false;
  469.     if (self maps\_laststand::player_is_in_laststand())
  470.     {
  471.         for( m = 0; m < self.weaponInventory.size; m++ )
  472.         {
  473.             if (self.weaponInventory[m] == weaponname || self.weaponInventory[m] == weaponname+"_upgraded" )
  474.             {
  475.                 has_weapon = true;
  476.             }
  477.         }
  478.     }
  479.     else
  480.     {
  481.         // If the weapon you're checking doesn't exist, it will return undefined
  482.         if( IsDefined( level.zombie_include_weapons[weaponname] ) )
  483.         {
  484.             has_weapon = self HasWeapon( weaponname );
  485.         }
  486.    
  487.         if( !has_weapon && isdefined( level.zombie_include_weapons[weaponname+"_upgraded"] ) )
  488.         {
  489.             has_weapon = self HasWeapon( weaponname+"_upgraded" );
  490.         }
  491.     }
  492.  
  493.     return has_weapon;
  494. }
  495.  
  496. using_weapon_or_upgrade( weaponname )
  497. {
  498.     if( self GetCurrentWeapon() == weaponname || self GetCurrentWeapon() == weaponname+"_upgraded" )
  499.     {
  500.         return true;
  501.     }
  502.     return false;
  503. }
  504.  
  505. // for the random weapon chest
  506. treasure_chest_init()
  507. {
  508.     flag_init("moving_chest_enabled");
  509.     flag_init("moving_chest_now");
  510.    
  511.    
  512.     level.chests = GetEntArray( "treasure_chest_use", "targetname" );
  513.  
  514.     if (level.chests.size > 1)
  515.     {
  516.  
  517.         flag_set("moving_chest_enabled");
  518.    
  519.         while ( 1 )
  520.         {
  521.             level.chests = array_randomize(level.chests);
  522.  
  523.             if( isdefined( level.random_pandora_box_start ) )
  524.                 break;
  525.    
  526.             if ( !IsDefined( level.chests[0].script_noteworthy ) || ( level.chests[0].script_noteworthy != "start_chest" ) )
  527.             {
  528.                 break;
  529.             }
  530.  
  531.         }      
  532.        
  533.         level.chest_index = 0;
  534.  
  535.         while(level.chest_index < level.chests.size)
  536.         {
  537.                
  538.             if( isdefined( level.random_pandora_box_start ) )
  539.                 break;
  540.  
  541.             if(level.chests[level.chest_index].script_noteworthy == "start_chest")
  542.             {
  543.                  break;
  544.             }
  545.            
  546.             level.chest_index++;    
  547.       }
  548.  
  549.         //init time chest accessed amount.
  550.        
  551.         if(level.script != "nazi_zombie_prototype")
  552.         {
  553.             level.chest_accessed = 0;
  554.         }
  555.  
  556.         if(level.script == "nazi_zombie_sumpf" || level.script == "nazi_zombie_factory" )
  557.         {
  558.             // Anchor target will grab the weapon spawn point inside the box, so the fx will be centered on it too
  559.             anchor = GetEnt(level.chests[level.chest_index].target, "targetname");
  560.             anchorTarget = GetEnt(anchor.target, "targetname");
  561.  
  562.             level.pandora_light = Spawn( "script_model", anchorTarget.origin );
  563.             level.pandora_light.angles = anchorTarget.angles + (-90, 0, 0);
  564.             //temp_fx_origin rotateto((-90, (box_origin.angles[1] * -1), 0), 0.05);
  565.             level.pandora_light SetModel( "tag_origin" );
  566.             playfxontag(level._effect["lght_marker"], level.pandora_light, "tag_origin");
  567.         }
  568.         // DCS:)
  569.         {
  570.             // Anchor target will grab the weapon spawn point inside the box, so the fx will be centered on it too
  571.             anchor = GetEnt(level.chests[level.chest_index].target, "targetname");
  572.             anchorTarget = GetEnt(anchor.target, "targetname");
  573.  
  574.             level.pandora_light = Spawn( "script_model", anchorTarget.origin );
  575.             level.pandora_light.angles = (-90, 0, 0);
  576.             level.pandora_light SetModel( "tag_origin" );
  577.             //playfxontag(level._effect["lght_marker"], level.pandora_light, "tag_origin");
  578.         }      
  579.        
  580.         //determine magic box starting location at random or normal
  581.         init_starting_chest_location();
  582.    
  583.     }
  584.  
  585.     array_thread( level.chests, ::treasure_chest_think );
  586.  
  587. }
  588.  
  589. init_starting_chest_location()
  590. {
  591.  
  592.     for( i = 0; i < level.chests.size; i++ )
  593.     {
  594.  
  595.         if( isdefined( level.random_pandora_box_start ) && level.random_pandora_box_start == true )
  596.         {
  597.             if( i != 0 )
  598.             {
  599.                 level.chests[i] hide_chest();  
  600.             }
  601.             else
  602.             {
  603.                 level.chest_index = i;
  604.                 unhide_magic_box( i );
  605.             }
  606.  
  607.         }
  608.         else
  609.         {
  610.             if ( !IsDefined(level.chests[i].script_noteworthy ) || ( level.chests[i].script_noteworthy != "start_chest" ) )
  611.             {
  612.                 level.chests[i] hide_chest();  
  613.             }
  614.             else
  615.             {
  616.                 level.chest_index = i;
  617.                 unhide_magic_box( i );
  618.             }
  619.         }
  620.     }
  621.  
  622.  
  623. }
  624.  
  625. unhide_magic_box( index )
  626. {
  627.    
  628.     //PI CHANGE - altered to allow for more than one piece of rubble
  629.     rubble = getentarray( level.chests[index].script_noteworthy + "_rubble", "script_noteworthy" );
  630.     if ( IsDefined( rubble ) )
  631.     {
  632.         for ( x = 0; x < rubble.size; x++ )
  633.         {
  634.             rubble[x] hide();
  635.         }
  636.         //END PI CHANGE
  637.     }
  638.     else
  639.     {
  640.         println( "^3Warning: No rubble found for magic box" );
  641.     }
  642. }
  643.  
  644. set_treasure_chest_cost( cost )
  645. {
  646.     level.zombie_treasure_chest_cost = cost;
  647. }
  648.  
  649. hide_chest()
  650. {
  651.     pieces = self get_chest_pieces();
  652.  
  653.     for(i=0;i<pieces.size;i++)
  654.     {
  655.         pieces[i] disable_trigger();
  656.         pieces[i] hide();
  657.     }  
  658. }
  659.  
  660. get_chest_pieces()
  661. {
  662.     // self = trigger
  663.  
  664.     lid = GetEnt(self.target, "targetname");
  665.     org = GetEnt(lid.target, "targetname");
  666.     box = GetEnt(org.target, "targetname");
  667.  
  668.     pieces = [];
  669.     pieces[pieces.size] = self;
  670.     pieces[pieces.size] = lid;
  671.     pieces[pieces.size] = org;
  672.     pieces[pieces.size] = box;
  673.  
  674.     return pieces;
  675. }
  676.  
  677. play_crazi_sound()
  678. {
  679.     self playlocalsound("laugh_child");
  680. }
  681.  
  682. show_magic_box()
  683. {
  684.     pieces = self get_chest_pieces();
  685.     for(i=0;i<pieces.size;i++)
  686.     {
  687.         pieces[i] enable_trigger();
  688.     }
  689.    
  690.     // PI_CHANGE_BEGIN - JMA - we want to play another effect on swamp
  691.     anchor = GetEnt(self.target, "targetname");
  692.     anchorTarget = GetEnt(anchor.target, "targetname");
  693.  
  694.     if(isDefined(level.script) && (level.script != "nazi_zombie_sumpf") && (level.script != "nazi_zombie_factory") )
  695.     {
  696.         playfx( level._effect["poltergeist"],pieces[0].origin);
  697.     }
  698.     else
  699.     {      
  700.         level.pandora_light.angles = (-90, anchorTarget.angles[1] + 180, 0);
  701.         level.pandora_light moveto(anchorTarget.origin, 0.05);
  702.         wait(1);   
  703.         playfx( level._effect["lght_marker_flare"],level.pandora_light.origin );
  704. //      playfxontag(level._effect["lght_marker_flare"], level.pandora_light, "tag_origin");
  705.     }
  706.     // PI_CHANGE_END
  707.    
  708.     playsoundatposition( "box_poof", pieces[0].origin );
  709.     wait(.5);
  710.     for(i=0;i<pieces.size;i++)
  711.     {
  712.         if( pieces[i].classname != "trigger_use" )
  713.         {
  714.             pieces[i] show();
  715.         }
  716.     }
  717.     pieces[0] playsound ( "box_poof_land" );
  718.     pieces[0] playsound( "couch_slam" );
  719. }
  720.  
  721. treasure_chest_think()
  722. {  
  723.     cost = 950;
  724.     if( IsDefined( level.zombie_treasure_chest_cost ) )
  725.     {
  726.         cost = level.zombie_treasure_chest_cost;
  727.     }
  728.     else
  729.     {
  730.         cost = self.zombie_cost;
  731.     }
  732.  
  733.     self set_hint_string( self, "default_treasure_chest_" + cost );
  734.     self setCursorHint( "HINT_NOICON" );
  735.  
  736.     //self thread decide_hide_show_chest_hint( "move_imminent" );
  737.  
  738.     // waittill someuses uses this
  739.     user = undefined;
  740.     while( 1 )
  741.     {
  742.         self waittill( "trigger", user );
  743.  
  744.         if( user in_revive_trigger() )
  745.         {
  746.             wait( 0.1 );
  747.             continue;
  748.         }
  749.  
  750.         // make sure the user is a player, and that they can afford it
  751.         if( is_player_valid( user ) && user.score >= cost )
  752.         {
  753.             user maps\_zombiemode_score::minus_to_player_score( cost );
  754.             break;
  755.         }
  756.         else if ( user.score < cost )
  757.         {
  758.             user thread maps\_zombiemode_perks::play_no_money_perk_dialog();
  759.             continue;  
  760.         }
  761.  
  762.         wait 0.05;
  763.     }
  764.  
  765.     // trigger_use->script_brushmodel lid->script_origin in radiant
  766.     lid = getent( self.target, "targetname" );
  767.     weapon_spawn_org = getent( lid.target, "targetname" );
  768.  
  769.     //open the lid
  770.     lid thread treasure_chest_lid_open();
  771.  
  772.     // SRS 9/3/2008: added to help other functions know if we timed out on grabbing the item
  773.     self.timedOut = false;
  774.  
  775.     // mario kart style weapon spawning
  776.     weapon_spawn_org thread treasure_chest_weapon_spawn( self, user );
  777.  
  778.     // the glowfx  
  779.     weapon_spawn_org thread treasure_chest_glowfx();
  780.  
  781.     // take away usability until model is done randomizing
  782.     self disable_trigger();
  783.  
  784.     weapon_spawn_org waittill( "randomization_done" );
  785.  
  786.     if (flag("moving_chest_now"))
  787.     {
  788.         user thread treasure_chest_move_vo();
  789.         self treasure_chest_move(lid);
  790.  
  791.     }
  792.     else
  793.     {
  794.         // Let the player grab the weapon and re-enable the box //
  795.         self.grab_weapon_hint = true;
  796.         self.chest_user = user;
  797.         self _sethintstring( &"ZOMBIE_TRADE_WEAPONS" );
  798.         self setCursorHint( "HINT_NOICON" );
  799.         self setvisibletoplayer( user );
  800.  
  801.         // Limit its visibility to the player who bought the box
  802.         self enable_trigger();
  803.         self thread treasure_chest_timeout();
  804.  
  805.         // make sure the guy that spent the money gets the item
  806.         // SRS 9/3/2008: ...or item goes back into the box if we time out
  807.         while( 1 )
  808.         {
  809.             self waittill( "trigger", grabber );
  810.  
  811.             if( grabber == user || grabber == level )
  812.             {
  813.  
  814.  
  815.                 if( grabber == user && is_player_valid( user ) && user GetCurrentWeapon() != "mine_bouncing_betty" )
  816.                 {
  817.                     bbPrint( "zombie_uses: playername %s playerscore %d round %d cost %d name %s x %f y %f z %f type magic_accept",
  818.                         user.playername, user.score, level.round_number, cost, weapon_spawn_org.weapon_string, self.origin );
  819.                     self notify( "user_grabbed_weapon" );
  820.                     user thread treasure_chest_give_weapon( weapon_spawn_org.weapon_string );
  821.                     break;
  822.                 }
  823.                 else if( grabber == level )
  824.                 {
  825.                     // it timed out
  826.                     self.timedOut = true;
  827.                     bbPrint( "zombie_uses: playername %s playerscore %d round %d cost %d name %s x %f y %f z %f type magic_reject",
  828.                         user.playername, user.score, level.round_number, cost, weapon_spawn_org.weapon_string, self.origin );
  829.                     break;
  830.                 }
  831.             }
  832.  
  833.             wait 0.05;
  834.         }
  835.  
  836.         self.grab_weapon_hint = false;
  837.         self.chest_user = undefined;
  838.  
  839.         weapon_spawn_org notify( "weapon_grabbed" );
  840.  
  841.         //increase counter of amount of time weapon grabbed.
  842.         if(level.script != "nazi_zombie_prototype")
  843.         {
  844.         level.chest_accessed += 1;
  845.            
  846.             // PI_CHANGE_BEGIN
  847.             // JMA - we only update counters when it's available
  848.             if( isDefined(level.script) && (level.script == "nazi_zombie_sumpf" || level.script == "nazi_zombie_factory") && level.box_moved == true && isDefined(level.pulls_since_last_ray_gun) )
  849.             {
  850.                 level.pulls_since_last_ray_gun += 1;
  851.             }
  852.            
  853.             if( isDefined(level.script) && (level.script == "nazi_zombie_sumpf" || level.script == "nazi_zombie_factory") && isDefined(level.pulls_since_last_tesla_gun) )
  854.             {              
  855.                 level.pulls_since_last_tesla_gun += 1;
  856.             }
  857.             // PI_CHANGE_END
  858.         }  
  859.         self disable_trigger();
  860.  
  861.         // spend cash here...
  862.         // give weapon here...
  863.         lid thread treasure_chest_lid_close( self.timedOut );
  864.  
  865.         //Chris_P
  866.         //magic box dissapears and moves to a new spot after a predetermined number of uses
  867.  
  868.         wait 3;
  869.         self enable_trigger();
  870.         self setvisibletoall();
  871.     }
  872.  
  873.     flag_clear("moving_chest_now");
  874.     self thread treasure_chest_think();
  875. }
  876.  
  877.  
  878. //
  879. //  Disable trigger if can't buy weapon and also if someone else is using the chest
  880. decide_hide_show_chest_hint( endon_notify )
  881. {
  882.     if( isDefined( endon_notify ) )
  883.     {
  884.         self endon( endon_notify );
  885.     }
  886.  
  887.     while( true )
  888.     {
  889.         players = get_players();
  890.         for( i = 0; i < players.size; i++ )
  891.         {
  892.             // chest_user defined if someone bought a weapon spin, false when chest closed
  893.             if ( (IsDefined(self.chest_user) && players[i] != self.chest_user ) ||
  894.                  !players[i] can_buy_weapon() )
  895.             {
  896.                 self SetInvisibleToPlayer( players[i], true );
  897.             }
  898.             else
  899.             {
  900.                 self SetInvisibleToPlayer( players[i], false );
  901.             }
  902.         }
  903.         wait( 0.1 );
  904.     }
  905. }
  906.  
  907. decide_hide_show_hint( endon_notify )
  908. {
  909.     if( isDefined( endon_notify ) )
  910.     {
  911.         self endon( endon_notify );
  912.     }
  913.  
  914.     while( true )
  915.     {
  916.         players = get_players();
  917.         for( i = 0; i < players.size; i++ )
  918.         {
  919.             if( players[i] can_buy_weapon() )
  920.             {
  921.                 self SetInvisibleToPlayer( players[i], false );
  922.             }
  923.             else
  924.             {
  925.                 self SetInvisibleToPlayer( players[i], true );
  926.             }
  927.         }
  928.         wait( 0.1 );
  929.     }
  930. }
  931.  
  932. can_buy_weapon()
  933. {
  934.     if( isDefined( self.is_drinking ) && self.is_drinking )
  935.     {
  936.         return false;
  937.     }
  938.     if( self GetCurrentWeapon() == "mine_bouncing_betty" )
  939.     {
  940.         return false;
  941.     }
  942.     if( self in_revive_trigger() )
  943.     {
  944.         return false;
  945.     }
  946.    
  947.     return true;
  948. }
  949.  
  950. treasure_chest_move_vo()
  951. {
  952.  
  953.     self endon("disconnect");
  954.  
  955.     index = maps\_zombiemode_weapons::get_player_index(self);
  956.     sound = undefined;
  957.  
  958.     if(!isdefined (level.player_is_speaking))
  959.     {
  960.         level.player_is_speaking = 0;
  961.     }
  962.     variation_count = 5;
  963.     sound = "plr_" + index + "_vox_box_move" + "_" + randomintrange(0, variation_count);
  964.  
  965.  
  966.     //This keeps multiple voice overs from playing on the same player (both killstreaks and headshots).
  967.     if (level.player_is_speaking != 1 && isDefined(sound))
  968.     {  
  969.         level.player_is_speaking = 1;
  970.         self playsound(sound, "sound_done");           
  971.         self waittill("sound_done");
  972.         level.player_is_speaking = 0;
  973.     }
  974.  
  975. }
  976.  
  977.  
  978. treasure_chest_move(lid)
  979. {
  980.     level waittill("weapon_fly_away_start");
  981.  
  982.     players = get_players();
  983.    
  984.     array_thread(players, ::play_crazi_sound);
  985.  
  986.     level waittill("weapon_fly_away_end");
  987.  
  988.     lid thread treasure_chest_lid_close(false);
  989.     self setvisibletoall();
  990.  
  991.     fake_pieces = [];
  992.     pieces = self get_chest_pieces();
  993.  
  994.     for(i=0;i<pieces.size;i++)
  995.     {
  996.         if(pieces[i].classname == "script_model")
  997.         {
  998.             fake_pieces[fake_pieces.size] = spawn("script_model",pieces[i].origin);
  999.             fake_pieces[fake_pieces.size - 1].angles = pieces[i].angles;
  1000.             fake_pieces[fake_pieces.size - 1] setmodel(pieces[i].model);
  1001.             pieces[i] disable_trigger();
  1002.             pieces[i] hide();
  1003.         }
  1004.         else
  1005.         {
  1006.             pieces[i] disable_trigger();
  1007.             pieces[i] hide();
  1008.         }
  1009.     }
  1010.  
  1011.     anchor = spawn("script_origin",fake_pieces[0].origin);
  1012.     soundpoint = spawn("script_origin", anchor.origin);
  1013.     playfx( level._effect["poltergeist"],anchor.origin);
  1014.  
  1015.     anchor playsound("box_move");
  1016.     for(i=0;i<fake_pieces.size;i++)
  1017.     {
  1018.         fake_pieces[i] linkto(anchor);
  1019.     }
  1020.  
  1021.     playsoundatposition ("whoosh", soundpoint.origin );
  1022.     playsoundatposition ("ann_vox_magicbox", soundpoint.origin );
  1023.  
  1024.  
  1025.     anchor moveto(anchor.origin + (0,0,50),5);
  1026.     //anchor rotateyaw(360 * 10,5,5);
  1027.     if(level.chests[level.chest_index].script_noteworthy == "magic_box_south" || level.chests[level.chest_index].script_noteworthy == "magic_box_bathroom" || level.chests[level.chest_index].script_noteworthy == "magic_box_hallway")
  1028.     {
  1029.         anchor Vibrate( (50, 0, 0), 10, 0.5, 5 );
  1030.     }
  1031.     else if(level.script != "nazi_zombie_sumpf")
  1032.     {
  1033.         anchor Vibrate( (0, 50, 0), 10, 0.5, 5 );
  1034.     }
  1035.     else
  1036.     {
  1037.        //Get the normal of the box using the positional data of the box and lid
  1038.        direction = pieces[3].origin - pieces[1].origin;
  1039.        direction = (direction[1], direction[0], 0);
  1040.        
  1041.        if(direction[1] < 0 || (direction[0] > 0 && direction[1] > 0))
  1042.        {
  1043.             direction = (direction[0], direction[1] * -1, 0);
  1044.        }
  1045.        else if(direction[0] < 0)
  1046.        {
  1047.             direction = (direction[0] * -1, direction[1], 0);
  1048.        }
  1049.        
  1050.         anchor Vibrate( direction, 10, 0.5, 5);
  1051.     }
  1052.    
  1053.     //anchor thread rotateroll_box();
  1054.     anchor waittill("movedone");
  1055.     //players = get_players();
  1056.     //array_thread(players, ::play_crazi_sound);
  1057.     //wait(3.9);
  1058.    
  1059.     playfx(level._effect["poltergeist"], anchor.origin);
  1060.    
  1061.     //TUEY - Play the 'disappear' sound
  1062.     playsoundatposition ("box_poof", soundpoint.origin);
  1063.     for(i=0;i<fake_pieces.size;i++)
  1064.     {
  1065.         fake_pieces[i] delete();
  1066.     }
  1067.  
  1068.  
  1069.     //gzheng-Show the rubble
  1070.     //PI CHANGE - allow for more than one object of rubble per box
  1071.     rubble = getentarray(self.script_noteworthy + "_rubble", "script_noteworthy");
  1072.    
  1073.     if ( IsDefined( rubble ) )
  1074.     {
  1075.         for (i = 0; i < rubble.size; i++)
  1076.         {
  1077.             rubble[i] show();
  1078.         }
  1079.     }
  1080.     else
  1081.     {
  1082.         println( "^3Warning: No rubble found for magic box" );
  1083.     }
  1084.  
  1085.     wait(0.1);
  1086.     anchor delete();
  1087.     soundpoint delete();
  1088.  
  1089.     old_chest_index = level.chest_index;
  1090.  
  1091.     wait(5);
  1092.  
  1093.     //chest moving logic
  1094.     //PI CHANGE - for sumpf, this doesn't work because chest_index is always incremented twice (here and line 724) - while this would work with an odd number of chests,
  1095.     //           with an even number it skips half of the chest locations in the map
  1096.  
  1097.     level.verify_chest = false;
  1098.     //wait(3);
  1099.     //make sure level is asylum, factory, or sumpf and make magic box only appear in location player have open, it's off by default
  1100.     //also make sure box doesn't respawn in old location.
  1101.     //PI WJB: removed check on "magic_box_explore_only" dvar because it is only ever used here and when it is set in _zombiemode.gsc line 446
  1102.     // where it is declared and set to 0, causing this while loop to never happen because the check was to see if it was equal to 1
  1103.     if( level.script == "nazi_zombie_asylum" || level.script == "nazi_zombie_factory" || level.script == "nazi_zombie_sumpf")
  1104.     {
  1105.         level.chest_index++;
  1106.  
  1107.     /*  while(level.chests[level.chest_index].origin == level.chests[old_chest_index].origin)
  1108.         {  
  1109.             level.chest_index++;
  1110.         }*/
  1111.  
  1112.         if (level.chest_index >= level.chests.size)
  1113.         {
  1114.             //PI CHANGE - this way the chests won't move in the same order the second time around
  1115.             temp_chest_name = level.chests[level.chest_index - 1].script_noteworthy;
  1116.             level.chest_index = 0;
  1117.             level.chests = array_randomize(level.chests);
  1118.             //in case it happens to randomize in such a way that the chest_index now points to the same location
  1119.             // JMA - want to avoid an infinite loop, so we use an if statement
  1120.             if (temp_chest_name == level.chests[level.chest_index].script_noteworthy)
  1121.             {
  1122.                 level.chest_index++;
  1123.             }
  1124.             //END PI CHANGE
  1125.         }
  1126.  
  1127.         //verify_chest_is_open();
  1128.         wait(0.01);
  1129.            
  1130.     }
  1131.     level.chests[level.chest_index] show_magic_box();
  1132.    
  1133.     //turn off magic box light.
  1134.     level notify("magic_box_light_switch");
  1135.     //PI CHANGE - altered to allow for more than one object of rubble per box
  1136.     unhide_magic_box( level.chest_index );
  1137.    
  1138. }
  1139.  
  1140. rotateroll_box()
  1141. {
  1142.     angles = 40;
  1143.     angles2 = 0;
  1144.     //self endon("movedone");
  1145.     while(isdefined(self))
  1146.     {
  1147.         self RotateRoll(angles + angles2, 0.5);
  1148.         wait(0.7);
  1149.         angles2 = 40;
  1150.         self RotateRoll(angles * -2, 0.5);
  1151.         wait(0.7);
  1152.     }
  1153.    
  1154.  
  1155.  
  1156. }
  1157. //verify if that magic box is open to players or not.
  1158. verify_chest_is_open()
  1159. {
  1160.  
  1161.     //for(i = 0; i < 5; i++)
  1162.     //PI CHANGE - altered so that there can be more than 5 valid chest locations
  1163.     for (i = 0; i < level.open_chest_location.size; i++)
  1164.     {
  1165.         if(isdefined(level.open_chest_location[i]))
  1166.         {
  1167.             if(level.open_chest_location[i] == level.chests[level.chest_index].script_noteworthy)
  1168.             {
  1169.                 level.verify_chest = true;
  1170.                 return;    
  1171.             }
  1172.         }
  1173.  
  1174.     }
  1175.  
  1176.     level.verify_chest = false;
  1177.  
  1178.  
  1179. }
  1180.  
  1181.  
  1182. treasure_chest_timeout()
  1183. {
  1184.     self endon( "user_grabbed_weapon" );
  1185.  
  1186.     wait( 12 );
  1187.     self notify( "trigger", level );
  1188. }
  1189.  
  1190. treasure_chest_lid_open()
  1191. {
  1192.     openRoll = 105;
  1193.     openTime = 0.5;
  1194.  
  1195.     self RotateRoll( 105, openTime, ( openTime * 0.5 ) );
  1196.  
  1197.     play_sound_at_pos( "open_chest", self.origin );
  1198.     play_sound_at_pos( "music_chest", self.origin );
  1199. }
  1200.  
  1201. treasure_chest_lid_close( timedOut )
  1202. {
  1203.     closeRoll = -105;
  1204.     closeTime = 0.5;
  1205.  
  1206.     self RotateRoll( closeRoll, closeTime, ( closeTime * 0.5 ) );
  1207.     play_sound_at_pos( "close_chest", self.origin );
  1208. }
  1209.  
  1210. treasure_chest_ChooseRandomWeapon( player )
  1211. {
  1212.  
  1213.     keys = GetArrayKeys( level.zombie_weapons );
  1214.  
  1215.     // Filter out any weapons the player already has
  1216.     filtered = [];
  1217.     for( i = 0; i < keys.size; i++ )
  1218.     {
  1219.         if( !get_is_in_box( keys[i] ) )
  1220.         {
  1221.             continue;
  1222.         }
  1223.        
  1224.         if( player has_weapon_or_upgrade( keys[i] ) )
  1225.         {
  1226.             continue;
  1227.         }
  1228.  
  1229.         if( !IsDefined( keys[i] ) )
  1230.         {
  1231.             continue;
  1232.         }
  1233.  
  1234.         filtered[filtered.size] = keys[i];
  1235.     }
  1236.    
  1237.     // Filter out the limited weapons
  1238.     if( IsDefined( level.limited_weapons ) )
  1239.     {
  1240.         keys2 = GetArrayKeys( level.limited_weapons );
  1241.         players = get_players();
  1242.         pap_triggers = GetEntArray("zombie_vending_upgrade", "targetname");
  1243.         for( q = 0; q < keys2.size; q++ )
  1244.         {
  1245.             count = 0;
  1246.             for( i = 0; i < players.size; i++ )
  1247.             {
  1248.                 if( players[i] has_weapon_or_upgrade( keys2[q] ) )
  1249.                 {
  1250.                     count++;
  1251.                 }
  1252.             }
  1253.  
  1254.             // Check the pack a punch machines to see if they are holding what we're looking for
  1255.             for ( k=0; k<pap_triggers.size; k++ )
  1256.             {
  1257.                 if ( IsDefined(pap_triggers[k].current_weapon) && pap_triggers[k].current_weapon == keys2[q] )
  1258.                 {
  1259.                     count++;
  1260.                 }
  1261.             }
  1262.  
  1263.             if( count >= level.limited_weapons[keys2[q]] )
  1264.             {
  1265.                 filtered = array_remove( filtered, keys2[q] );
  1266.             }
  1267.         }
  1268.     }
  1269.  
  1270.     return filtered[RandomInt( filtered.size )];
  1271. }
  1272.  
  1273. treasure_chest_ChooseWeightedRandomWeapon( player )
  1274. {
  1275.  
  1276.     keys = GetArrayKeys( level.zombie_weapons );
  1277.  
  1278.     // Filter out any weapons the player already has
  1279.     filtered = [];
  1280.     for( i = 0; i < keys.size; i++ )
  1281.     {
  1282.         if( !get_is_in_box( keys[i] ) )
  1283.         {
  1284.             continue;
  1285.         }
  1286.        
  1287.         if( player has_weapon_or_upgrade( keys[i] ) )
  1288.         {
  1289.             continue;
  1290.         }
  1291.  
  1292.         if( !IsDefined( keys[i] ) )
  1293.         {
  1294.             continue;
  1295.         }
  1296.  
  1297.         num_entries = [[ level.weapon_weighting_funcs[keys[i]] ]]();
  1298.        
  1299.         for( j = 0; j < num_entries; j++ )
  1300.         {
  1301.             filtered[filtered.size] = keys[i];
  1302.         }
  1303.     }
  1304.    
  1305.     // Filter out the limited weapons
  1306.     if( IsDefined( level.limited_weapons ) )
  1307.     {
  1308.         keys2 = GetArrayKeys( level.limited_weapons );
  1309.         players = get_players();
  1310.         pap_triggers = GetEntArray("zombie_vending_upgrade", "targetname");
  1311.         for( q = 0; q < keys2.size; q++ )
  1312.         {
  1313.             count = 0;
  1314.             for( i = 0; i < players.size; i++ )
  1315.             {
  1316.                 if( players[i] has_weapon_or_upgrade( keys2[q] ) )
  1317.                 {
  1318.                     count++;
  1319.                 }
  1320.             }
  1321.  
  1322.             // Check the pack a punch machines to see if they are holding what we're looking for
  1323.             for ( k=0; k<pap_triggers.size; k++ )
  1324.             {
  1325.                 if ( IsDefined(pap_triggers[k].current_weapon) && pap_triggers[k].current_weapon == keys2[q] )
  1326.                 {
  1327.                     count++;
  1328.                 }
  1329.             }
  1330.  
  1331.             if( count >= level.limited_weapons[keys2[q]] )
  1332.             {
  1333.                 filtered = array_remove( filtered, keys2[q] );
  1334.             }
  1335.         }
  1336.     }
  1337.    
  1338.     return filtered[RandomInt( filtered.size )];
  1339. }
  1340.  
  1341. treasure_chest_weapon_spawn( chest, player )
  1342. {
  1343.     assert(IsDefined(player));
  1344.     // spawn the model
  1345.     model = spawn( "script_model", self.origin );
  1346.     model.angles = self.angles +( 0, 90, 0 );
  1347.  
  1348.     floatHeight = 40;
  1349.  
  1350.     //move it up
  1351.     model moveto( model.origin +( 0, 0, floatHeight ), 3, 2, 0.9 );
  1352.  
  1353.     // rotation would go here
  1354.  
  1355.     // make with the mario kart
  1356.     modelname = undefined;
  1357.     rand = undefined;
  1358.     number_cycles = 40;
  1359.     for( i = 0; i < number_cycles; i++ )
  1360.     {
  1361.  
  1362.         if( i < 20 )
  1363.         {
  1364.             wait( 0.05 );
  1365.         }
  1366.         else if( i < 30 )
  1367.         {
  1368.             wait( 0.1 );
  1369.         }
  1370.         else if( i < 35 )
  1371.         {
  1372.             wait( 0.2 );
  1373.         }
  1374.         else if( i < 38 )
  1375.         {
  1376.             wait( 0.3 );
  1377.         }
  1378.  
  1379.         if( i+1 < number_cycles )
  1380.         {
  1381.             rand = treasure_chest_ChooseRandomWeapon( player );
  1382.         }
  1383.         else
  1384.         {
  1385.             rand = treasure_chest_ChooseWeightedRandomWeapon( player );
  1386.         }
  1387.  
  1388.         /#
  1389.         if( maps\_zombiemode_tesla::tesla_gun_exists() )   
  1390.         {
  1391.             if ( i == 39 && GetDvar( "scr_spawn_tesla" ) != "" )
  1392.             {
  1393.                 SetDvar( "scr_spawn_tesla", "" );
  1394.                 rand = "tesla_gun";
  1395.             }
  1396.         }
  1397.         #/
  1398.  
  1399.         modelname = GetWeaponModel( rand );
  1400.         model setmodel( modelname );
  1401.  
  1402.  
  1403.     }
  1404.  
  1405.     self.weapon_string = rand; // here's where the org get it's weapon type for the give function
  1406.  
  1407.     // random change of getting the joker that moves the box
  1408.     random = Randomint(100);
  1409.  
  1410.     if( !isdefined( level.chest_min_move_usage ) )
  1411.     {
  1412.         level.chest_min_move_usage = 4;
  1413.     }
  1414.  
  1415.     //increase the chance of joker appearing from 0-100 based on amount of the time chest has been opened.
  1416.     if(level.script != "nazi_zombie_prototype" && getdvar("magic_chest_movable") == "1")
  1417.     {
  1418.  
  1419.         if(level.chest_accessed < level.chest_min_move_usage)
  1420.         {      
  1421.             // PI_CHANGE_BEGIN - JMA - RandomInt(100) can return a number between 0-99.  If it's zero and chance_of_joker is zero
  1422.             //                                  we can possibly have a teddy bear one after another.
  1423.             chance_of_joker = -1;
  1424.             // PI_CHANGE_END
  1425.         }
  1426.         else
  1427.         {
  1428.             chance_of_joker = level.chest_accessed + 20;
  1429.            
  1430.             // make sure teddy bear appears on the 8th pull if it hasn't moved from the initial spot
  1431.             if( (!isDefined(level.magic_box_first_move) || level.magic_box_first_move == false ) && level.chest_accessed >= 8)
  1432.             {
  1433.                 chance_of_joker = 100;
  1434.             }
  1435.            
  1436.             // pulls 4 thru 8, there is a 15% chance of getting the teddy bear
  1437.             // NOTE:  this happens in all cases
  1438.             if( level.chest_accessed >= 4 && level.chest_accessed < 8 )
  1439.             {
  1440.                 if( random < 15 )
  1441.                 {
  1442.                     chance_of_joker = 100;
  1443.                 }
  1444.                 else
  1445.                 {
  1446.                     chance_of_joker = -1;
  1447.                 }
  1448.             }
  1449.            
  1450.             // after the first magic box move the teddy bear percentages changes
  1451.             if( isDefined(level.magic_box_first_move) && level.magic_box_first_move == true )
  1452.             {
  1453.                 // between pulls 8 thru 12, the teddy bear percent is 30%
  1454.                 if( level.chest_accessed >= 8 && level.chest_accessed < 13 )
  1455.                 {
  1456.                     if( random < 30 )
  1457.                     {
  1458.                         chance_of_joker = 100;
  1459.                     }
  1460.                     else
  1461.                     {
  1462.                         chance_of_joker = -1;
  1463.                     }
  1464.                 }
  1465.                
  1466.                 // after 12th pull, the teddy bear percent is 50%
  1467.                 if( level.chest_accessed >= 13 )
  1468.                 {
  1469.                     if( random < 50 )
  1470.                     {
  1471.                         chance_of_joker = 100;
  1472.                     }
  1473.                     else
  1474.                     {
  1475.                         chance_of_joker = -1;
  1476.                     }
  1477.                 }
  1478.             }
  1479.         }
  1480.  
  1481.         if (random <= chance_of_joker)
  1482.         {
  1483.             model SetModel("zombie_teddybear");
  1484.         //  model rotateto(level.chests[level.chest_index].angles, 0.01);
  1485.             //wait(1);
  1486.             model.angles = self.angles;    
  1487.             wait 1;
  1488.             flag_set("moving_chest_now");
  1489.             self notify( "move_imminent" );
  1490.             level.chest_accessed = 0;
  1491.  
  1492.             player maps\_zombiemode_score::add_to_player_score( 950 );
  1493.  
  1494.             //allow power weapon to be accessed.
  1495.             level.box_moved = true;
  1496.         }
  1497.     }
  1498.  
  1499.     self notify( "randomization_done" );
  1500.  
  1501.     if (flag("moving_chest_now"))
  1502.     {
  1503.         wait .5;    // we need a wait here before this notify
  1504.         level notify("weapon_fly_away_start");
  1505.         wait 2;
  1506.         model MoveZ(500, 4, 3);
  1507.         model waittill("movedone");
  1508.         model delete();
  1509.         self notify( "box_moving" );
  1510.         level notify("weapon_fly_away_end");
  1511.     }
  1512.     else
  1513.     {
  1514.  
  1515.         //turn off power weapon, since player just got one
  1516.         if( rand == "tesla_gun" || rand == "ray_gun" )
  1517.         {
  1518.             // PI_CHANGE_BEGIN - JMA - reset the counters for tesla gun and ray gun pulls
  1519.             if( isDefined( level.script ) && (level.script == "nazi_zombie_sumpf" || level.script == "nazi_zombie_factory") )
  1520.             {
  1521.                 if( rand == "ray_gun" )
  1522.                 {
  1523.                     level.box_moved = false;
  1524.                     level.pulls_since_last_ray_gun = 0;
  1525.                 }
  1526.                
  1527.                 if( rand == "tesla_gun" )
  1528.                 {
  1529.                     level.pulls_since_last_tesla_gun = 0;
  1530.                     level.player_seen_tesla_gun = true;
  1531.                 }          
  1532.             }
  1533.             else
  1534.             {
  1535.                 level.box_moved = false;
  1536.             }
  1537.             // PI_CHANGE_END           
  1538.         }
  1539.  
  1540.         model thread timer_til_despawn(floatHeight);
  1541.         self waittill( "weapon_grabbed" );
  1542.  
  1543.         if( !chest.timedOut )
  1544.         {
  1545.             model Delete();
  1546.         }
  1547.  
  1548.  
  1549.     }
  1550. }
  1551. timer_til_despawn(floatHeight)
  1552. {
  1553.  
  1554.  
  1555.     // SRS 9/3/2008: if we timed out, move the weapon back into the box instead of deleting it
  1556.     putBackTime = 12;
  1557.     self MoveTo( self.origin - ( 0, 0, floatHeight ), putBackTime, ( putBackTime * 0.5 ) );
  1558.     wait( putBackTime );
  1559.  
  1560.     if(isdefined(self))
  1561.     {  
  1562.         self Delete();
  1563.     }
  1564. }
  1565.  
  1566. treasure_chest_glowfx()
  1567. {
  1568.     fxObj = spawn( "script_model", self.origin +( 0, 0, 0 ) );
  1569.     fxobj setmodel( "tag_origin" );
  1570.     fxobj.angles = self.angles +( 90, 0, 0 );
  1571.  
  1572.     playfxontag( level._effect["chest_light"], fxObj, "tag_origin"  );
  1573.  
  1574.     self waittill_any( "weapon_grabbed", "box_moving" );
  1575.  
  1576.     fxobj delete();
  1577. }
  1578.  
  1579. // self is the player string comes from the randomization function
  1580. treasure_chest_give_weapon( weapon_string )
  1581. {
  1582.     primaryWeapons = self GetWeaponsListPrimaries();
  1583.     current_weapon = undefined;
  1584.  
  1585.     if( self HasWeapon( weapon_string ) )
  1586.     {
  1587.         self GiveMaxAmmo( weapon_string );
  1588.         self SwitchToWeapon( weapon_string );
  1589.         return;
  1590.     }
  1591.  
  1592.     // This should never be true for the first time.
  1593.     if( primaryWeapons.size >= 2 ) // he has two weapons
  1594.     {
  1595.         current_weapon = self getCurrentWeapon(); // get hiss current weapon
  1596.  
  1597.         if ( current_weapon == "mine_bouncing_betty" )
  1598.         {
  1599.             current_weapon = undefined;
  1600.         }
  1601.  
  1602.         if( isdefined( current_weapon ) )
  1603.         {
  1604.             if( !( weapon_string == "fraggrenade" || weapon_string == "stielhandgranate" || weapon_string == "molotov" || weapon_string == "zombie_cymbal_monkey" ) )
  1605.             {
  1606.                 // PI_CHANGE_BEGIN
  1607.                 // JMA - player dropped the tesla gun
  1608.                 if( isDefined(level.script) && (level.script == "nazi_zombie_sumpf" || level.script == "nazi_zombie_factory") )
  1609.                 {
  1610.                     if( current_weapon == "tesla_gun" )
  1611.                     {
  1612.                         level.player_drops_tesla_gun = true;
  1613.                     }
  1614.                 }
  1615.                 // PI_CHANGE_END
  1616.                
  1617.                 self TakeWeapon( current_weapon );
  1618.         }
  1619.     }
  1620.     }
  1621.  
  1622.     if( IsDefined( primaryWeapons ) && !isDefined( current_weapon ) )
  1623.     {
  1624.         for( i = 0; i < primaryWeapons.size; i++ )
  1625.         {
  1626.             if( primaryWeapons[i] == "zombie_colt" )
  1627.             {
  1628.                 continue;
  1629.             }
  1630.  
  1631.             if( weapon_string != "fraggrenade" && weapon_string != "stielhandgranate" && weapon_string != "molotov" && weapon_string != "zombie_cymbal_monkey" )
  1632.             {
  1633.                 // PI_CHANGE_BEGIN
  1634.                 // JMA - player dropped the tesla gun
  1635.                 if( isDefined(level.script) && (level.script == "nazi_zombie_sumpf" || level.script == "nazi_zombie_factory") )
  1636.                 {
  1637.                     if( primaryWeapons[i] == "tesla_gun" )
  1638.                     {
  1639.                         level.player_drops_tesla_gun = true;
  1640.                     }
  1641.                 }
  1642.                 // PI_CHANGE_END
  1643.            
  1644.                 self TakeWeapon( primaryWeapons[i] );
  1645.             }
  1646.         }
  1647.     }
  1648.  
  1649.     self play_sound_on_ent( "purchase" );
  1650.  
  1651.     if( weapon_string == "molotov" || weapon_string == "molotov_zombie" )
  1652.     {
  1653.         // PI_CHANGE_BEGIN
  1654.         // JMA 051409 sanity check to see if we have the weapon before we remove it
  1655.         has_weapon = self HasWeapon( "zombie_cymbal_monkey" );
  1656.         if( isDefined(has_weapon) && has_weapon )
  1657.         {
  1658.             self TakeWeapon( "zombie_cymbal_monkey" );
  1659.         }
  1660.         // PI_CHANGE_END
  1661.     }
  1662.     if( weapon_string == "zombie_cymbal_monkey" )
  1663.     {
  1664.         // PI_CHANGE_BEGIN
  1665.         // JMA 051409 sanity check to see if we have the weapon before we remove it
  1666.         has_weapon = self HasWeapon( "molotov" );
  1667.         if( isDefined(has_weapon) && has_weapon )
  1668.         {
  1669.             self TakeWeapon( "molotov" );
  1670.         }
  1671.  
  1672.         if( isDefined(level.zombie_weapons) && isDefined(level.zombie_weapons["molotov_zombie"]) )
  1673.         {
  1674.             has_weapon = self HasWeapon( "molotov_zombie" );
  1675.             if( isDefined(has_weapon) && has_weapon )
  1676.             {
  1677.                 self TakeWeapon( "molotov_zombie" );
  1678.             }
  1679.         }
  1680.         // PI_CHANGE_END
  1681.        
  1682.         self maps\_zombiemode_cymbal_monkey::player_give_cymbal_monkey();
  1683.         play_weapon_vo(weapon_string);
  1684.         return;
  1685.     }
  1686.  
  1687.     self GiveWeapon( weapon_string, 0 );
  1688.     self GiveMaxAmmo( weapon_string );
  1689.     self SwitchToWeapon( weapon_string );
  1690.  
  1691.     play_weapon_vo(weapon_string);
  1692.  
  1693.     // self playsound (level.zombie_weapons[weapon_string].sound);
  1694. }
  1695.  
  1696. weapon_cabinet_think()
  1697. {
  1698.     weapons = getentarray( "cabinet_weapon", "targetname" );
  1699.  
  1700.     doors = getentarray( self.target, "targetname" );
  1701.     for( i = 0; i < doors.size; i++ )
  1702.     {
  1703.         doors[i] NotSolid();
  1704.     }
  1705.  
  1706.     self.has_been_used_once = false;
  1707.  
  1708.     self decide_hide_show_hint();
  1709.  
  1710.     while( 1 )
  1711.     {
  1712.         self waittill( "trigger", player );
  1713.  
  1714.         if( !player can_buy_weapon() )
  1715.         {
  1716.             wait( 0.1 );
  1717.             continue;
  1718.         }
  1719.  
  1720.         cost = 1500;
  1721.         if( self.has_been_used_once )
  1722.         {
  1723.             cost = get_weapon_cost( self.zombie_weapon_upgrade );
  1724.         }
  1725.         else
  1726.         {
  1727.             if( IsDefined( self.zombie_cost ) )
  1728.             {
  1729.                 cost = self.zombie_cost;
  1730.             }
  1731.         }
  1732.  
  1733.         ammo_cost = get_ammo_cost( self.zombie_weapon_upgrade );
  1734.  
  1735.         if( !is_player_valid( player ) )
  1736.         {
  1737.             player thread ignore_triggers( 0.5 );
  1738.             continue;
  1739.         }
  1740.  
  1741.         if( self.has_been_used_once )
  1742.         {
  1743.             player_has_weapon = player has_weapon_or_upgrade( self.zombie_weapon_upgrade );
  1744.             /*
  1745.             player_has_weapon = false;
  1746.             weapons = player GetWeaponsList();
  1747.             if( IsDefined( weapons ) )
  1748.             {
  1749.                 for( i = 0; i < weapons.size; i++ )
  1750.                 {
  1751.                     if( weapons[i] == self.zombie_weapon_upgrade )
  1752.                     {
  1753.                         player_has_weapon = true;
  1754.                     }
  1755.                 }
  1756.             }
  1757.             */
  1758.  
  1759.             if( !player_has_weapon )
  1760.             {
  1761.                 if( player.score >= cost )
  1762.                 {
  1763.                     self play_sound_on_ent( "purchase" );
  1764.                     player maps\_zombiemode_score::minus_to_player_score( cost );
  1765.                     player weapon_give( self.zombie_weapon_upgrade );
  1766.                 }
  1767.                 else // not enough money
  1768.                 {
  1769.                     play_sound_on_ent( "no_purchase" );
  1770.                     player thread maps\_zombiemode_perks::play_no_money_perk_dialog();
  1771.                 }          
  1772.             }
  1773.             else if ( player.score >= ammo_cost )
  1774.             {
  1775.                 ammo_given = player ammo_give( self.zombie_weapon_upgrade );
  1776.                 if( ammo_given )
  1777.                 {
  1778.                     self play_sound_on_ent( "purchase" );
  1779.                     player maps\_zombiemode_score::minus_to_player_score( ammo_cost ); // this give him ammo to early
  1780.                 }
  1781.             }
  1782.             else // not enough money
  1783.             {
  1784.                 play_sound_on_ent( "no_purchase" );
  1785.                 player thread maps\_zombiemode_perks::play_no_money_perk_dialog();
  1786.             }
  1787.         }
  1788.         else if( player.score >= cost ) // First time the player opens the cabinet
  1789.         {
  1790.             self.has_been_used_once = true;
  1791.  
  1792.             self play_sound_on_ent( "purchase" );
  1793.  
  1794.             self _sethintstring( &"ZOMBIE_WEAPONCOSTAMMO", cost, ammo_cost );
  1795.             //      self _sethintstring( get_weapon_hint( self.zombie_weapon_upgrade ) );
  1796.             self setCursorHint( "HINT_NOICON" );
  1797.             player maps\_zombiemode_score::minus_to_player_score( self.zombie_cost );
  1798.  
  1799.             doors = getentarray( self.target, "targetname" );
  1800.  
  1801.             for( i = 0; i < doors.size; i++ )
  1802.             {
  1803.                 if( doors[i].model == "dest_test_cabinet_ldoor_dmg0" )
  1804.                 {
  1805.                     doors[i] thread weapon_cabinet_door_open( "left" );
  1806.                 }
  1807.                 else if( doors[i].model == "dest_test_cabinet_rdoor_dmg0" )
  1808.                 {
  1809.                     doors[i] thread weapon_cabinet_door_open( "right" );
  1810.                 }
  1811.             }
  1812.  
  1813.             player_has_weapon = player has_weapon_or_upgrade( self.zombie_weapon_upgrade );
  1814.             /*
  1815.             player_has_weapon = false;
  1816.             weapons = player GetWeaponsList();
  1817.             if( IsDefined( weapons ) )
  1818.             {
  1819.                 for( i = 0; i < weapons.size; i++ )
  1820.                 {
  1821.                     if( weapons[i] == self.zombie_weapon_upgrade )
  1822.                     {
  1823.                         player_has_weapon = true;
  1824.                     }
  1825.                 }
  1826.             }
  1827.             */
  1828.  
  1829.             if( !player_has_weapon )
  1830.             {
  1831.                 player weapon_give( self.zombie_weapon_upgrade );
  1832.             }
  1833.             else
  1834.             {
  1835.                 if( player has_upgrade( self.zombie_weapon_upgrade ) )
  1836.                 {
  1837.                     player ammo_give( self.zombie_weapon_upgrade+"_upgraded" );
  1838.                 }
  1839.                 else
  1840.                 {
  1841.                     player ammo_give( self.zombie_weapon_upgrade );
  1842.                 }
  1843.             }  
  1844.         }
  1845.         else // not enough money
  1846.         {
  1847.             play_sound_on_ent( "no_purchase" );
  1848.             player thread maps\_zombiemode_perks::play_no_money_perk_dialog();
  1849.         }      
  1850.     }
  1851. }
  1852.  
  1853. pay_turret_think( cost )
  1854. {
  1855.     if( !isDefined( self.target ) )
  1856.     {
  1857.         return;
  1858.     }
  1859.     turret = GetEnt( self.target, "targetname" );
  1860.    
  1861.     if( !isDefined( turret ) )
  1862.     {
  1863.         return;
  1864.     }
  1865.    
  1866.     turret makeTurretUnusable();
  1867.    
  1868.     while( true )
  1869.     {
  1870.         self waittill( "trigger", player );
  1871.        
  1872.         if( !is_player_valid( player ) )
  1873.         {
  1874.             player thread ignore_triggers( 0.5 );
  1875.             continue;
  1876.         }
  1877.  
  1878.         if( player in_revive_trigger() )
  1879.         {
  1880.             wait( 0.1 );
  1881.             continue;
  1882.         }
  1883.  
  1884.         if(isdefined(player.is_drinking))
  1885.         {
  1886.             wait(0.1);
  1887.             continue;
  1888.         }
  1889.        
  1890.         if( player.score >= cost )
  1891.         {
  1892.             player maps\_zombiemode_score::minus_to_player_score( cost );
  1893.             turret makeTurretUsable();
  1894.             turret UseBy( player );
  1895.             self disable_trigger();
  1896.            
  1897.             player.curr_pay_turret = turret;
  1898.            
  1899.             turret thread watch_for_laststand( player );
  1900.             turret thread watch_for_fake_death( player );
  1901.             if( isDefined( level.turret_timer ) )
  1902.             {
  1903.                 turret thread watch_for_timeout( player, level.turret_timer );
  1904.             }
  1905.            
  1906.             while( isDefined( turret getTurretOwner() ) && turret getTurretOwner() == player )
  1907.             {
  1908.                 wait( 0.05 );
  1909.             }
  1910.            
  1911.             turret notify( "stop watching" );
  1912.            
  1913.             player.curr_pay_turret = undefined;
  1914.            
  1915.             turret makeTurretUnusable();
  1916.             self enable_trigger();
  1917.         }
  1918.         else // not enough money
  1919.         {
  1920.             play_sound_on_ent( "no_purchase" );
  1921.             player thread maps\_zombiemode_perks::play_no_money_perk_dialog();
  1922.         }
  1923.     }
  1924. }
  1925.  
  1926. watch_for_laststand( player )
  1927. {
  1928.     self endon( "stop watching" );
  1929.    
  1930.     while( !player maps\_laststand::player_is_in_laststand() )
  1931.     {
  1932.         if( isDefined( level.intermission ) && level.intermission )
  1933.         {
  1934.             intermission = true;
  1935.         }
  1936.         wait( 0.05 );
  1937.     }
  1938.    
  1939.     if( isDefined( self getTurretOwner() ) && self getTurretOwner() == player )
  1940.     {
  1941.         self UseBy( player );
  1942.     }
  1943. }
  1944.  
  1945. watch_for_fake_death( player )
  1946. {
  1947.     self endon( "stop watching" );
  1948.    
  1949.     player waittill( "fake_death" );
  1950.    
  1951.     if( isDefined( self getTurretOwner() ) && self getTurretOwner() == player )
  1952.     {
  1953.         self UseBy( player );
  1954.     }
  1955. }
  1956.  
  1957. watch_for_timeout( player, time )
  1958. {
  1959.     self endon( "stop watching" );
  1960.    
  1961.     self thread cancel_timer_on_end( player );
  1962.    
  1963.     player thread maps\_zombiemode_timer::start_timer( time, "stop watching" );
  1964.    
  1965.     wait( time );
  1966.    
  1967.     if( isDefined( self getTurretOwner() ) && self getTurretOwner() == player )
  1968.     {
  1969.         self UseBy( player );
  1970.     }
  1971. }
  1972.  
  1973. cancel_timer_on_end( player )
  1974. {
  1975.     self waittill( "stop watching" );
  1976.     player notify( "stop watching" );
  1977. }
  1978.  
  1979. weapon_cabinet_door_open( left_or_right )
  1980. {
  1981.     if( left_or_right == "left" )
  1982.     {
  1983.         self rotateyaw( 120, 0.3, 0.2, 0.1 );  
  1984.     }
  1985.     else if( left_or_right == "right" )
  1986.     {
  1987.         self rotateyaw( -120, 0.3, 0.2, 0.1 );  
  1988.     }  
  1989. }
  1990.  
  1991. weapon_spawn_think()
  1992. {
  1993.     cost = get_weapon_cost( self.zombie_weapon_upgrade );
  1994.     ammo_cost = get_ammo_cost( self.zombie_weapon_upgrade );
  1995.     is_grenade = (WeaponType( self.zombie_weapon_upgrade ) == "grenade");
  1996.     if(is_grenade)
  1997.     {
  1998.         ammo_cost = cost;
  1999.     }
  2000.  
  2001.     self thread decide_hide_show_hint();
  2002.  
  2003.     self.first_time_triggered = false;
  2004.     for( ;; )
  2005.     {
  2006.         self waittill( "trigger", player );        
  2007.         // if not first time and they have the weapon give ammo
  2008.  
  2009.         if( !is_player_valid( player ) )
  2010.         {
  2011.             player thread ignore_triggers( 0.5 );
  2012.             continue;
  2013.         }
  2014.  
  2015.         if( !player can_buy_weapon() )
  2016.         {
  2017.             wait( 0.1 );
  2018.             continue;
  2019.         }
  2020.  
  2021.         // Allow people to get ammo off the wall for upgraded weapons
  2022.         player_has_weapon = player has_weapon_or_upgrade( self.zombie_weapon_upgrade );
  2023.         /*
  2024.         player_has_weapon = false;
  2025.         weapons = player GetWeaponsList();
  2026.         if( IsDefined( weapons ) )
  2027.         {
  2028.             for( i = 0; i < weapons.size; i++ )
  2029.             {
  2030.                 if( weapons[i] == self.zombie_weapon_upgrade )
  2031.                 {
  2032.                     player_has_weapon = true;
  2033.                 }
  2034.             }
  2035.         }      
  2036.         */
  2037.  
  2038.         if( !player_has_weapon )
  2039.         {
  2040.             // else make the weapon show and give it
  2041.             if( player.score >= cost )
  2042.             {
  2043.                 if( self.first_time_triggered == false )
  2044.                 {
  2045.                     model = getent( self.target, "targetname" );
  2046.                     //                  model show();
  2047.                     model thread weapon_show( player );
  2048.                     self.first_time_triggered = true;
  2049.  
  2050.                     if(!is_grenade)
  2051.                     {
  2052.                         self _sethintstring( &"ZOMBIE_WEAPONCOSTAMMO", cost, ammo_cost );
  2053.                     }
  2054.                 }
  2055.  
  2056.                 player maps\_zombiemode_score::minus_to_player_score( cost );
  2057.  
  2058.                 bbPrint( "zombie_uses: playername %s playerscore %d round %d cost %d name %s x %f y %f z %f type weapon",
  2059.                         player.playername, player.score, level.round_number, cost, self.zombie_weapon_upgrade, self.origin );
  2060.  
  2061.                 player weapon_give( self.zombie_weapon_upgrade );
  2062.             }
  2063.             else
  2064.             {
  2065.                 play_sound_on_ent( "no_purchase" );
  2066.                 player thread maps\nazi_zombie_sumpf_blockers::play_no_money_purchase_dialog();
  2067.                
  2068.             }
  2069.         }
  2070.         else
  2071.         {
  2072.             // MM - need to check and see if the player has an upgraded weapon.  If so, the ammo cost is much higher
  2073.             if ( player has_upgrade( self.zombie_weapon_upgrade ) )
  2074.             {
  2075.                 ammo_cost = 4500;
  2076.             }
  2077.             else
  2078.             {
  2079.                 ammo_cost = get_ammo_cost( self.zombie_weapon_upgrade );
  2080.             }
  2081.  
  2082.             // if the player does have this then give him ammo.
  2083.             if( player.score >= ammo_cost )
  2084.             {
  2085.                 if( self.first_time_triggered == false )
  2086.                 {
  2087.                     model = getent( self.target, "targetname" );
  2088.                     //                  model show();
  2089.                     model thread weapon_show( player );
  2090.                     self.first_time_triggered = true;
  2091.                     if(!is_grenade)
  2092.                     {
  2093.                         self _sethintstring( &"ZOMBIE_WEAPONCOSTAMMO", cost, get_ammo_cost( self.zombie_weapon_upgrade ) );
  2094.                     }
  2095.                 }
  2096.  
  2097.                 if( player HasWeapon( self.zombie_weapon_upgrade ) && player has_upgrade( self.zombie_weapon_upgrade ) )
  2098.                 {
  2099.                     ammo_given = player ammo_give( self.zombie_weapon_upgrade, true );
  2100.                 }
  2101.                 else if( player has_upgrade( self.zombie_weapon_upgrade ) )
  2102.                 {
  2103.                     ammo_given = player ammo_give( self.zombie_weapon_upgrade+"_upgraded" );
  2104.                 }
  2105.                 else
  2106.                 {
  2107.                     ammo_given = player ammo_give( self.zombie_weapon_upgrade );
  2108.                 }
  2109.                
  2110.                 if( ammo_given )
  2111.                 {
  2112.                         player maps\_zombiemode_score::minus_to_player_score( ammo_cost ); // this give him ammo to early
  2113.  
  2114.                     bbPrint( "zombie_uses: playername %s playerscore %d round %d cost %d name %s x %f y %f z %f type ammo",
  2115.                         player.playername, player.score, level.round_number, ammo_cost, self.zombie_weapon_upgrade, self.origin );
  2116.                 }
  2117.             }
  2118.             else
  2119.             {
  2120.                 play_sound_on_ent( "no_purchase" );
  2121.             }
  2122.         }
  2123.     }
  2124. }
  2125.  
  2126. weapon_show( player )
  2127. {
  2128.     player_angles = VectorToAngles( player.origin - self.origin );
  2129.  
  2130.     player_yaw = player_angles[1];
  2131.     weapon_yaw = self.angles[1];
  2132.  
  2133.     yaw_diff = AngleClamp180( player_yaw - weapon_yaw );
  2134.  
  2135.     if( yaw_diff > 0 )
  2136.     {
  2137.         yaw = weapon_yaw - 90;
  2138.     }
  2139.     else
  2140.     {
  2141.         yaw = weapon_yaw + 90;
  2142.     }
  2143.  
  2144.     self.og_origin = self.origin;
  2145.     self.origin = self.origin +( AnglesToForward( ( 0, yaw, 0 ) ) * 8 );
  2146.  
  2147.     wait( 0.05 );
  2148.     self Show();
  2149.  
  2150.     play_sound_at_pos( "weapon_show", self.origin, self );
  2151.  
  2152.     time = 1;
  2153.     self MoveTo( self.og_origin, time );
  2154. }
  2155.  
  2156. weapon_give( weapon, is_upgrade )
  2157. {
  2158.     primaryWeapons = self GetWeaponsListPrimaries();
  2159.     current_weapon = undefined;
  2160.  
  2161.     //if is not an upgraded perk purchase
  2162.     if( !IsDefined( is_upgrade ) )
  2163.     {
  2164.         is_upgrade = false;
  2165.     }
  2166.  
  2167.     // This should never be true for the first time.
  2168.     if( primaryWeapons.size >= 2 ) // he has two weapons
  2169.     {
  2170.         current_weapon = self getCurrentWeapon(); // get his current weapon
  2171.  
  2172.         if ( current_weapon == "mine_bouncing_betty" )
  2173.         {
  2174.             current_weapon = undefined;
  2175.         }
  2176.  
  2177.         if( isdefined( current_weapon ) )
  2178.         {
  2179.             if( !( weapon == "fraggrenade" || weapon == "stielhandgranate" || weapon == "molotov" || weapon == "zombie_cymbal_monkey" ) )
  2180.             {
  2181.                 self TakeWeapon( current_weapon );
  2182.             }
  2183.         }
  2184.     }
  2185.  
  2186.     if( weapon == "zombie_cymbal_monkey" )
  2187.     {
  2188.         // PI_CHANGE_BEGIN
  2189.         // JMA 051409 sanity check to see if we have the weapon before we remove it
  2190.         has_weapon = self HasWeapon( "molotov" );
  2191.         if( isDefined(has_weapon) && has_weapon )
  2192.         {
  2193.             self TakeWeapon( "molotov" );
  2194.         }
  2195.  
  2196.         if( isDefined(level.zombie_weapons) && isDefined(level.zombie_weapons["molotov_zombie"]) )
  2197.         {      
  2198.             has_weapon = self HasWeapon( "molotov_zombie" );
  2199.             if( isDefined(has_weapon) && has_weapon )
  2200.             {
  2201.                 self TakeWeapon( "molotov_zombie" );
  2202.             }
  2203.         }
  2204.         // PI_CHANGE_END
  2205.                
  2206.         self maps\_zombiemode_cymbal_monkey::player_give_cymbal_monkey();
  2207.         play_weapon_vo( weapon );
  2208.         return;
  2209.     }
  2210.     if( (weapon == "molotov" || weapon == "molotov_zombie") )
  2211.     {
  2212.             self TakeWeapon( "zombie_cymbal_monkey" );
  2213.     }
  2214.  
  2215.     self play_sound_on_ent( "purchase" );
  2216.     self GiveWeapon( weapon, 0 );
  2217.     self GiveMaxAmmo( weapon );
  2218.     self SwitchToWeapon( weapon );
  2219.      
  2220.     play_weapon_vo(weapon);
  2221. }
  2222. play_weapon_vo(weapon)
  2223. {
  2224.     index = get_player_index(self);
  2225.     if(!IsDefined (level.zombie_weapons[weapon].sound))
  2226.     {
  2227.         return;
  2228.     }  
  2229.    
  2230.     if( level.zombie_weapons[weapon].sound == "vox_monkey" )
  2231.     {
  2232.         plr = "plr_" + index + "_";
  2233.         create_and_play_dialog( plr, "vox_monkey", .25, "resp_monk" );
  2234.         return;
  2235.     }
  2236.     //  iprintlnbold (index);
  2237.     if( level.zombie_weapons[weapon].sound != "" )
  2238.     {
  2239.         weap = level.zombie_weapons[weapon].sound;
  2240. //      iprintlnbold("Play_Weap_VO_" + weap);
  2241.         switch(weap)
  2242.         {
  2243.             case "vox_crappy":
  2244.                 if (level.vox_crappy_available.size < 1 )
  2245.                 {
  2246.                     level.vox_crappy_available = level.vox_crappy;
  2247.                 }
  2248.                 sound_to_play = random(level.vox_crappy_available);
  2249.                 level.vox_crappy_available = array_remove(level.vox_crappy_available,sound_to_play);
  2250.                 break;
  2251.  
  2252.             case "vox_mg":
  2253.                 if (level.vox_mg_available.size < 1 )
  2254.                 {
  2255.                     level.vox_mg_available = level.vox_mg;
  2256.                 }
  2257.                 sound_to_play = random(level.vox_mg_available);
  2258.                 level.vox_mg_available = array_remove(level.vox_mg_available,sound_to_play);
  2259.                 break;
  2260.             case "vox_shotgun":
  2261.                 if (level.vox_shotgun_available.size < 1 )
  2262.                 {
  2263.                     level.vox_shotgun_available = level.vox_shotgun;
  2264.                 }
  2265.                 sound_to_play = random(level.vox_shotgun_available);
  2266.                 level.vox_shotgun_available = array_remove(level.vox_shotgun_available,sound_to_play);
  2267.                 break;
  2268.             case "vox_357":
  2269.                 if (level.vox_357_available.size < 1 )
  2270.                 {
  2271.                     level.vox_357_available = level.vox_357;
  2272.                 }
  2273.                 sound_to_play = random(level.vox_357_available);
  2274.                 level.vox_357_available = array_remove(level.vox_357_available,sound_to_play);
  2275.                 break;
  2276.             case "vox_bar":
  2277.                 if (level.vox_bar_available.size < 1 )
  2278.                 {
  2279.                     level.vox_bar_available = level.vox_bar;
  2280.                 }
  2281.                 sound_to_play = random(level.vox_bar_available);
  2282.                 level.vox_bar_available = array_remove(level.vox_bar_available,sound_to_play);
  2283.                 break;
  2284.             case "vox_flame":
  2285.                 if (level.vox_flame_available.size < 1 )
  2286.                 {
  2287.                     level.vox_flame_available = level.vox_flame;
  2288.                 }
  2289.                 sound_to_play = random(level.vox_flame_available);
  2290.                 level.vox_flame_available = array_remove(level.vox_flame_available,sound_to_play);
  2291.                 break;
  2292.             case "vox_raygun":
  2293.                 if (level.vox_raygun_available.size < 1 )
  2294.                 {
  2295.                     level.vox_raygun_available = level.vox_raygun;
  2296.                 }
  2297.                 sound_to_play = random(level.vox_raygun_available);
  2298.                 level.vox_raygun_available = array_remove(level.vox_raygun_available,sound_to_play);
  2299.                 break;
  2300.             case "vox_tesla":
  2301.                 if (level.vox_tesla_available.size < 1 )
  2302.                 {
  2303.                     level.vox_tesla_available = level.vox_tesla;
  2304.                 }
  2305.                 sound_to_play = random(level.vox_tesla_available);
  2306.                 level.vox_tesla_available = array_remove(level.vox_tesla_available,sound_to_play);
  2307.                 break;
  2308.             case "vox_sticky":
  2309.                 if (level.vox_sticky_available.size < 1 )
  2310.                 {
  2311.                     level.vox_sticky_available = level.vox_sticky;
  2312.                 }
  2313.                 sound_to_play = random(level.vox_sticky_available);
  2314.                 level.vox_sticky_available = array_remove(level.vox_sticky_available,sound_to_play);
  2315.                 break;
  2316.             case "vox_ppsh":
  2317.                 if (level.vox_ppsh_available.size < 1 )
  2318.                 {
  2319.                     level.vox_ppsh_available = level.vox_ppsh;
  2320.                 }
  2321.                 sound_to_play = random(level.vox_ppsh_available);
  2322.                 level.vox_ppsh_available = array_remove(level.vox_ppsh_available,sound_to_play);
  2323.                 break;
  2324.             case "vox_mp40":
  2325.             if (level.vox_mp40_available.size < 1 )
  2326.                 {
  2327.                     level.vox_mp40_available = level.vox_mp40;
  2328.                 }
  2329.                 sound_to_play = random(level.vox_mp40_available);
  2330.                 level.vox_mp40_available = array_remove(level.vox_mp40_available,sound_to_play);
  2331.                 break;                 
  2332.            
  2333.             default:
  2334.                 sound_var = randomintrange(0, level.zombie_weapons[weapon].variation_count);
  2335.                 sound_to_play = level.zombie_weapons[weapon].sound + "_" + sound_var;
  2336.                
  2337.         }
  2338.  
  2339.         plr = "plr_" + index + "_";
  2340.         //self playsound ("plr_" + index + "_" + sound_to_play);
  2341.         //iprintlnbold (sound_to_play);
  2342.        
  2343.         //thread setup_response_line( self, index, "monk" );
  2344.         self maps\_zombiemode_spawner::do_player_playdialog(plr, sound_to_play, 0.05);
  2345.     }
  2346. }
  2347. do_player_weap_dialog(player_index, sound_to_play, waittime)
  2348. {
  2349.     if(!IsDefined (level.player_is_speaking))
  2350.     {
  2351.         level.player_is_speaking = 0;
  2352.     }
  2353.     if(level.player_is_speaking != 1)
  2354.     {
  2355.         level.player_is_speaking = 1;
  2356.         self playsound(player_index + sound_to_play, "sound_done" + sound_to_play);        
  2357.         self waittill("sound_done" + sound_to_play);
  2358.         wait(waittime);    
  2359.         level.player_is_speaking = 0;
  2360.     }
  2361.    
  2362. }
  2363. get_player_index(player)
  2364. {
  2365.     assert( IsPlayer( player ) );
  2366.     assert( IsDefined( player.entity_num ) );
  2367. /#
  2368.     // used for testing to switch player's VO in-game from devgui
  2369.     if( player.entity_num == 0 && GetDVar( "zombie_player_vo_overwrite" ) != "" )
  2370.     {
  2371.         new_vo_index = GetDVarInt( "zombie_player_vo_overwrite" );
  2372.         return new_vo_index;
  2373.     }
  2374. #/
  2375.     return player.entity_num;
  2376. }
  2377.  
  2378. ammo_give( weapon, also_has_upgrade )
  2379. {
  2380.     // We assume before calling this function we already checked to see if the player has this weapon...
  2381.  
  2382.     if( !isDefined( also_has_upgrade ) )
  2383.     {
  2384.         also_has_upgrade = false;
  2385.     }
  2386.  
  2387.     // Should we give ammo to the player
  2388.     give_ammo = false;
  2389.  
  2390.     // Check to see if ammo belongs to a primary weapon
  2391.     if( weapon != "fraggrenade" && weapon != "stielhandgranate" && weapon != "molotov" )
  2392.     {
  2393.         if( isdefined( weapon ) )  
  2394.         {
  2395.             // get the max allowed ammo on the current weapon
  2396.             stockMax = WeaponMaxAmmo( weapon );
  2397.             if( also_has_upgrade )
  2398.             {
  2399.                 stockMax += WeaponMaxAmmo( weapon+"_upgraded" );
  2400.             }
  2401.  
  2402.             // Get the current weapon clip count
  2403.             clipCount = self GetWeaponAmmoClip( weapon );
  2404.  
  2405.             currStock = self GetAmmoCount( weapon );
  2406.  
  2407.             // compare it with the ammo player actually has, if more or equal just dont give the ammo, else do
  2408.             if( ( currStock - clipcount ) >= stockMax )
  2409.             {
  2410.                 give_ammo = false;
  2411.             }
  2412.             else
  2413.             {
  2414.                 give_ammo = true; // give the ammo to the player
  2415.             }
  2416.         }
  2417.     }
  2418.     else
  2419.     {
  2420.         // Ammo belongs to secondary weapon
  2421.         if( self has_weapon_or_upgrade( weapon ) )
  2422.         {
  2423.             // Check if the player has less than max stock, if no give ammo
  2424.             if( self getammocount( weapon ) < WeaponMaxAmmo( weapon ) )
  2425.             {
  2426.                 // give the ammo to the player
  2427.                 give_ammo = true;                  
  2428.             }
  2429.         }      
  2430.     }  
  2431.  
  2432.     if( give_ammo )
  2433.     {
  2434.         self playsound( "cha_ching" );
  2435.         self GivemaxAmmo( weapon );
  2436.         if( also_has_upgrade )
  2437.         {
  2438.             self GiveMaxAmmo( weapon+"_upgraded" );
  2439.         }
  2440.         return true;
  2441.     }
  2442.  
  2443.     if( !give_ammo )
  2444.     {
  2445.         return false;
  2446.     }
  2447. }
  2448. add_weapon_to_sound_array(vo,num)
  2449. {
  2450.     if(!isDefined(vo))
  2451.     {
  2452.         return;
  2453.     }
  2454.     player = getplayers();
  2455.     for(i=0;i<player.size;i++)
  2456.     {
  2457.         index = maps\_zombiemode_weapons::get_player_index(player);
  2458.         player_index = "plr_" + index + "_";
  2459.         num = maps\_zombiemode_spawner::get_number_variants(player_index + vo);
  2460.     }
  2461. //  iprintlnbold(vo);
  2462.  
  2463.     switch(vo)
  2464.     {
  2465.         case "vox_crappy":
  2466.             if(!isDefined(level.vox_crappy))
  2467.             {
  2468.                 level.vox_crappy = [];
  2469.                 for(i=0;i<num;i++)
  2470.                 {
  2471.                     level.vox_crappy[level.vox_crappy.size] = "vox_crappy_" + i;                       
  2472.                 }              
  2473.             }
  2474.             level.vox_crappy_available = level.vox_crappy;
  2475.             break;
  2476.  
  2477.         case "vox_mg":
  2478.             if(!isDefined(level.vox_mg))
  2479.             {
  2480.                 level.vox_mg = [];
  2481.                 for(i=0;i<num;i++)
  2482.                 {
  2483.                     level.vox_mg[level.vox_mg.size] = "vox_mg_" + i;                       
  2484.                 }              
  2485.             }
  2486.             level.vox_mg_available = level.vox_mg;
  2487.             break;
  2488.         case "vox_shotgun":
  2489.             if(!isDefined(level.vox_shotgun))
  2490.             {
  2491.                 level.vox_shotgun = [];
  2492.                 for(i=0;i<num;i++)
  2493.                 {
  2494.                     level.vox_shotgun[level.vox_shotgun.size] = "vox_shotgun_" + i;                    
  2495.                 }              
  2496.             }
  2497.             level.vox_shotgun_available = level.vox_shotgun;
  2498.             break;
  2499.         case "vox_357":
  2500.             if(!isDefined(level.vox_357))
  2501.             {
  2502.                 level.vox_357 = [];
  2503.                 for(i=0;i<num;i++)
  2504.                 {
  2505.                     level.vox_357[level.vox_357.size] = "vox_357_" + i;                    
  2506.                 }              
  2507.             }
  2508.             level.vox_357_available = level.vox_357;
  2509.             break;
  2510.         case "vox_bar":
  2511.             if(!isDefined(level.vox_bar))
  2512.             {
  2513.                 level.vox_bar = [];
  2514.                 for(i=0;i<num;i++)
  2515.                 {
  2516.                     level.vox_bar[level.vox_bar.size] = "vox_bar_" + i;                    
  2517.                 }              
  2518.             }
  2519.             level.vox_bar_available = level.vox_bar;
  2520.             break;
  2521.         case "vox_flame":
  2522.             if(!isDefined(level.vox_flame))
  2523.             {
  2524.                 level.vox_flame = [];
  2525.                 for(i=0;i<num;i++)
  2526.                 {
  2527.                     level.vox_flame[level.vox_flame.size] = "vox_flame_" + i;                      
  2528.                 }              
  2529.             }
  2530.             level.vox_flame_available = level.vox_flame;
  2531.             break;
  2532.  
  2533.         case "vox_raygun":
  2534.             if(!isDefined(level.vox_raygun))
  2535.             {
  2536.                 level.vox_raygun = [];
  2537.                 for(i=0;i<num;i++)
  2538.                 {
  2539.                     level.vox_raygun[level.vox_raygun.size] = "vox_raygun_" + i;                       
  2540.                 }              
  2541.             }
  2542.             level.vox_raygun_available = level.vox_raygun;
  2543.             break;
  2544.         case "vox_tesla":
  2545.             if(!isDefined(level.vox_tesla))
  2546.             {
  2547.                 level.vox_tesla = [];
  2548.                 for(i=0;i<num;i++)
  2549.                 {
  2550.                     level.vox_tesla[level.vox_tesla.size] = "vox_tesla_" + i;                      
  2551.                 }              
  2552.             }
  2553.             level.vox_tesla_available = level.vox_tesla;
  2554.             break;
  2555.         case "vox_sticky":
  2556.             if(!isDefined(level.vox_sticky))
  2557.             {
  2558.                 level.vox_sticky = [];
  2559.                 for(i=0;i<num;i++)
  2560.                 {
  2561.                     level.vox_sticky[level.vox_sticky.size] = "vox_sticky_" + i;                       
  2562.                 }              
  2563.             }
  2564.             level.vox_sticky_available = level.vox_sticky;
  2565.             break;
  2566.         case "vox_ppsh":
  2567.             if(!isDefined(level.vox_ppsh))
  2568.             {
  2569.                 level.vox_ppsh = [];
  2570.                 for(i=0;i<num;i++)
  2571.                 {
  2572.                     level.vox_ppsh[level.vox_ppsh.size] = "vox_ppsh_" + i;                     
  2573.                 }              
  2574.             }
  2575.             level.vox_ppsh_available = level.vox_ppsh;
  2576.             break;     
  2577.         case "vox_mp40":
  2578.             if(!isDefined(level.vox_mp40))
  2579.             {
  2580.                 level.vox_mp40 = [];
  2581.                 for(i=0;i<num;i++)
  2582.                 {
  2583.                     level.vox_mp40[level.vox_mp40.size] = "vox_mp40_" + i;                     
  2584.                 }              
  2585.             }
  2586.             level.vox_mp40_available = level.vox_mp40;
  2587.             break;
  2588.         case "vox_monkey":
  2589.             if(!isDefined(level.vox_monkey))
  2590.             {
  2591.                 level.vox_monkey = [];
  2592.                 for(i=0;i<num;i++)
  2593.                 {
  2594.                     level.vox_monkey[level.vox_monkey.size] = "vox_monkey_" + i;                       
  2595.                 }              
  2596.             }
  2597.             level.vox_monkey_available = level.vox_monkey;
  2598.             break; 
  2599.     }
  2600.  
  2601. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement