Advertisement
Janne252

Custom map script: Blocking units

Apr 21st, 2014
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.01 KB | None | 0 0
  1.     -- List of available units, stored as variables for easy access
  2.     _grenadier_squad = {squad = "grenadier_squad_mp"}
  3.     _assault_grenadier_squad = {ability = "assault_grenadiers"}
  4.     _hmg42_team = {squad = "mg42_heavy_machine_gun_squad_mp"}
  5.     _mortar_team = {squad = "mortar_team_81mm_mp"}
  6.     _officer_squad = {ability = "assault_field_officer"}
  7.     _osttruppen_squad = {ability = "ostruppen"}
  8.     _panzer_grenadier_squad = {squad = "panzer_grenadier_squad_mp"}
  9.     _urban_assault_panzer_grenadier_squad = {ability = "urban_assault_grenadiers"}
  10.     _pioneer_squad = {squad = "pioneer_squad_mp"}
  11.     _sniper_squad = {squad = "sniper_squad_mp"}
  12.     _stormtrooper_squad = {ability = "stormtroopers"}
  13.    
  14.     _pak40_at_gun_squad = {squad = "pak40_75mm_at_gun_squad_mp", isvehicle = true}
  15.     _pak43_at_gun_squad = {ability = "pak_43_emplacement_unlock", entity = "pak43_88mm_at_gun_mp", isvehicle = true}
  16.     _brummbar_squad = {squad = "brummbar_squad_mp", isvehicle = true}
  17.     _elefant_squad = {ability = "elefant_unlock", isvehicle = true}
  18.     _mechanized_250_halftrack_grenadiers_squad = {ability = "mechanized_grenadier_group", isvehicle = true}
  19.     _mortar_250_halftrack_squad = {ability = "mortar_halftrack", isvehicle = true}
  20.     _sdkfz_251_halftrack_squad = {squad = "sdkfz_251_halftrack_squad_mp", isvehicle = true}
  21.     _le_fh18_howitzer_squad = {ability = "howitzer_105mm_emplacement_unlock", entity = "howitzer_105mm_le_fh18_mp", isvehicle = true}
  22.     _opel_blitz_supply_truck_squad = {ability = "supply_truck", isvehicle = true}
  23.     _ostwind_squad = {squad = "ostwind_squad_mp", isvehicle = true}
  24.     _panther_squad = {squad = "panther_squad_mp", isvehicle = true}
  25.     _panzer_iv_squad = {squad = "panzer_iv_squad_mp", isvehicle = true}
  26.     _panzer_iv_command_squad = {ability = "armor_commander", isvehicle = true}
  27.     _panzerwerfer_squad = {squad = "panzerwerfer_squad_mp", isvehicle = true}
  28.     _scoutcar_222_squad = {squad = "scoutcar_sdkfz222_mp", isvehicle = true}
  29.     _stug_3_e_squad = {ability = "stug_iii_e", isvehicle = true}
  30.     _stug_3_squad = {squad = "stug_iii_squad_mp", isvehicle = true}
  31.     _tiger_ace_squad = {ability = "tiger_tank_ace", isvehicle = true}
  32.     _tiger_squad = {ability = "tiger_tank", isvehicle = true}
  33.     _puma_squad = {ability = "puma_dispatch", isvehicle = true}
  34.  
  35.     _combat_engineer_squad = {squad = "combat_engineer_squad_mp"}
  36.     _conscript_squad = {squad = "conscript_squad_mp"}
  37.     _dshk_38_hmg_squad = {ability = "dshk_mp"}
  38.     _maxim_hmg_squad = {squad = "m1910_maxim_heavy_machine_gun_squad_mp"}
  39.     _mortar_squad = {squad = "pm-82_41_mortar_squad_mp"}
  40.     _mortar_120mm_squad = {ability = "cmd_120mm_mortar_crew"}
  41.     _partisan_squad = {ability = "partisans_commander_anti_infantry"}
  42.     _partisan_at_squad = {ability = "partisans_commander_anti_vehicle"}
  43.     _sniper_squad = {squad = "sniper_team_mp"}
  44.     _guards_troops_squad = {ability = "cmd_guard_troops"}
  45.     _penal_battalion_squad = {squad = "penal_battalion_mp"}
  46.     _shock_troop_squad = {ability = "cmd_shock_troops"}
  47.  
  48.     _is_2_squad = {ability = "cmd_is2_heavy_tank", isvehicle = true}
  49.     _isu_152_squad = {ability = "cmd_isu-152", isvehicle = true}
  50.     _katyusha_squad = {squad = "katyusha_bm-13n_squad_mp", isvehicle = true}
  51.     _kv_1_squad = {ability = "cmd_kv-1_unlock", isvehicle = true}
  52.     _kv_2_squad = {ability = "kv-2", isvehicle = true}
  53.     _kv_8_squad = {ability = "cmd_kv-8_unlock_mp", isvehicle = true}
  54.     _m3a1_squad = {squad = "m3a1_scout_car_squad_mp", isvehicle = true}
  55.     _m5_squad = {squad = "m5_halftrack_squad_mp", isvehicle = true}
  56.     _howitzer_203mm_squad = {ability = "b4_203mm_howitzer", entity = "artillery_203mm_b4", isvehicle = true}
  57.     _howitzer_152mm_squad = {ability = "cmd_ml_20", entity = "m1937_152mm_ml_20_artillery_mp", isvehicle = true}
  58.     _zis_3_at_gun_squad = {squad = "m1942_zis-3_76mm_at_gun_squad_mp", isvehicle = true}
  59.     _k_45mm_at_gun_squad = {ability = "m-42_at_gun", isvehicle = true}
  60.     _su_76_squad = {squad = "su-76m_mp", isvehicle = true}
  61.     _su_85_squad = {squad = "su-85_mp", isvehicle = true}
  62.     _t_34_squad = {squad = "t_34_76_squad_mp", isvehicle = true}
  63.     _t_34_85_squad = {ability = "cmd_t34_85_medium_tank", isvehicle = true}
  64.     _t_34_85_one_squad = {ability = "cmd_advanced_t34_85_medium_tank", isvehicle = true}
  65.     _t_70_squad = {squad = "t-70m_mp", isvehicle = true}
  66.     _m4c_sherman_squad = {ability = "sherman_soviet_dispatch", isvehicle = true}
  67.    
  68.     -- List of units in a table
  69.     _unitList = {
  70.         _panzer_iv_command_squad,_dshk_38_hmg_squad,_conscript_squad,_sdkfz_251_halftrack_squad,_stormtrooper_squad,_tiger_ace_squad,_t_70_squad,
  71.         _partisan_at_squad,_tiger_squad,_t_34_85_squad,_kv_2_squad,_mortar_squad,_penal_battalion_squad,_le_fh18_howitzer_squad,_su_76_squad,_sniper_squad,
  72.         _m5_squad,_zis_3_at_gun_squad,_isu_152_squad,_is_2_squad,_mortar_team,_pak43_at_gun_squad,_howitzer_203mm_squad,_osttruppen_squad,_maxim_hmg_squad,
  73.         _k_45mm_at_gun_squad,_grenadier_squad,_brummbar_squad,_combat_engineer_squad,_panzer_grenadier_squad,_assault_grenadier_squad,_officer_squad,
  74.         _howitzer_152mm_squad,_t_34_squad,_katyusha_squad,_kv_1_squad,_scoutcar_222_squad,_kv_8_squad,_pioneer_squad,_su_85_squad,_pak40_at_gun_squad,
  75.         _t_34_85_one_squad,_elefant_squad,_partisan_squad,_guards_troops_squad,_mortar_120mm_squad,_m3a1_squad,_stug_3_squad,_stug_3_e_squad,_panzerwerfer_squad,
  76.         _panzer_iv_squad,_shock_troop_squad,_ostwind_squad,_opel_blitz_supply_truck_squad,_mortar_250_halftrack_squad,_mechanized_250_halftrack_grenadiers_squad,
  77.         _hmg42_team,_panther_squad,_urban_assault_panzer_grenadier_squad,
  78.     }
  79.  
  80.     -- List of units to block
  81.     _block_list = {
  82.         _zis_3_at_gun_squad, _t_70_squad,
  83.         _conscript_squad, _katyusha_squad,
  84.     }
  85.    
  86.     -- Method of blocking units.
  87.     --  ITEM_REMOVED = The production icon/ability icon of the unit is removed.
  88.     --  ITEM_LOCKED = The production icon/ability icon of the unit is visible but locked
  89.     _block_method = ITEM_LOCKED
  90.    
  91.     -- Block all vehicles by default, true/false
  92.     _disable_vehicles = true
  93.    
  94.     -- Free text, displayed as a reason if the blocking method is ITEM_LOCKED
  95.     _block_message = "You are not allowed to use this unit."
  96.    
  97.     -- String converstion to a loc string
  98.     local _loc = LOC(_block_message)
  99.     _loc[1] = _block_message
  100.     _block_message = _loc
  101.  
  102.     -- Helper function for applying unit restrictions
  103.     local _blockItem = function(item)
  104.         for i = 1, World_GetPlayerCount() do
  105.             local player = World_GetPlayerAt(i)
  106.             if item.squad then
  107.                 Player_SetSquadProductionAvailabilityInternal(player, BP_GetSquadBlueprint(item.squad), _block_method, _block_message)
  108.             end
  109.             if item.entity then
  110.                 Player_SetEntityProductionAvailabilityInternal(player, BP_GetEntityBlueprint(item.entity), _block_method, _block_message)
  111.             end
  112.             if item.ability then
  113.                 Player_SetAbilityAvailabilityInternal(player, BP_GetAbilityBlueprint(item.ability), _block_method, _block_message)
  114.             end
  115.         end
  116.     end
  117.     -- Apply unit restrictions based on the table _block_list
  118.     for key, item in ipairs(_block_list) do
  119.         _blockItem(item)
  120.     end
  121.    
  122.     -- Block all vehicles if _disable_vehicles set to true
  123.     if _disable_vehicles then
  124.         for key, item in pairs(_unitList) do
  125.             if item.isvehicle then
  126.                 _blockItem(item)
  127.             end
  128.         end
  129.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement