Advertisement
Guest User

Payday 2 Bodybags secure for cash v2 *FIXED 1*

a guest
Jul 14th, 2014
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.62 KB | None | 0 0
  1.  
  2. local DEAD_BODY_COST            =   300         -- Base cost for dead body
  3. local HOSTAGE_SELL_DISTANCE     =   6 * 100     -- Distance to loot zone, when we can sell a hostage
  4. local BODYBAGS_STAY_IN_CAR      =   false       -- Bodybags visual will stay in car after secure
  5.  
  6. if not SellHostage then
  7.     -- GET UNIT TYPE
  8.     if get_unit_type == nil then
  9.         get_unit_type = function(unit)
  10.             return unit:base() and unit:base()._tweak_table
  11.         end
  12.     end
  13.  
  14.     if get_by_id == nil then
  15.         -- FIND BY ID (Laggy!)
  16.         get_by_id = function(id, mask)
  17.             local all_found = World:find_units_quick( "all", mask )        
  18.             for _,unit in ipairs(all_found) do
  19.                 if unit.id ~= nil and unit:id() == id then
  20.                     return unit
  21.                 end
  22.             end                
  23.                    
  24.             return nil
  25.         end
  26.     end
  27.    
  28.     if inGame == nil then  
  29.         -- INGAME CHECK
  30.         inGame = function()
  31.             if not game_state_machine then return false end
  32.             return string.find(game_state_machine:current_state_name(), "game")
  33.         end
  34.     end
  35.    
  36.     if inGame() then
  37.         -- Get bag value
  38.         if not MoneyManager.def_get_bag_value then MoneyManager.def_get_bag_value = MoneyManager.get_bag_value end 
  39.         function MoneyManager:get_bag_value(carry_id, multiplier)
  40.             if Network:is_client() then
  41.                 return self:def_get_bag_value(carry_id, multiplier)
  42.             end
  43.            
  44.             --\\ Bodybags to sale (2)      
  45.             if carry_id == "person" then --new
  46.                 return DEAD_BODY_COST   -- Bodybags cost
  47.             end
  48.                        
  49.             return self:def_get_bag_value(carry_id, multiplier)
  50.         end
  51.        
  52.         -- Check loot items for trigger zone
  53.         if not ElementAreaTrigger.def_project_instigators then ElementAreaTrigger.def_project_instigators = ElementAreaTrigger.project_instigators end 
  54.         function ElementAreaTrigger:project_instigators()
  55.             if self.def_project_instigators == nil then
  56.                 return {}
  57.             end
  58.            
  59.             local instigators = self:def_project_instigators()
  60.  
  61.             if Network:is_client() then
  62.                 return instigators
  63.             end
  64.            
  65.             -- new --
  66.             if self.hostages_to_sale == nil then
  67.                 self.hostages_to_sale = {}
  68.             end
  69.            
  70.             -- Check for zones with same position (probably don't have sense)
  71.             if self.h_bAlowed == nil and self._values.instigator == "loot" then
  72.                 local _id = self:id()
  73.  
  74.                 local pos, rot = self:get_orientation()
  75.                 if managers.loot.h_ea_pos_store == nil then managers.loot.h_ea_pos_store = {} end
  76.                
  77.                 if pos ~= nil then
  78.                     if managers.loot.h_ea_pos_store[_id] == nil then
  79.                         managers.loot.h_ea_pos_store[_id] = {pos, true}
  80.                         self.h_bAlowed = true
  81.                     end
  82.                    
  83.                     for ea_id, ea_data in pairs(managers.loot.h_ea_pos_store) do
  84.                         if ea_id ~= _id then
  85.                             local ea_pos    = ea_data[1]
  86.                             local ea_alowed = ea_data[2]
  87.                            
  88.                             if ea_alowed == true then
  89.                                 local distance = mvector3.distance(ea_pos, pos)
  90.                                 if distance <= 800 then
  91.                                     managers.loot.h_ea_pos_store[_id][2] = false
  92.                                     self.h_bAlowed = false
  93.                                     break
  94.                                 end
  95.                             end
  96.                         end
  97.                     end
  98.                 else
  99.                     self.h_bAlowed = false
  100.                 end
  101.             end
  102.            
  103.             -- Add bodybags and hostages to loot
  104.             if self.h_bAlowed == true and self._values.instigator == "loot" then
  105.                 local all_found = World:find_units_quick( "all", 14 )
  106.                        
  107.                 --\\ Bodybags to sale (1)
  108.                 for _,unit in ipairs(all_found) do
  109.                     if unit:carry_data() and unit:carry_data():carry_id() == "person" then
  110.                         table.insert(instigators, unit)
  111.                     end
  112.                 end
  113.                
  114.                 --\\ Add hostages to loot list
  115.                 local all_found = World:find_units_quick( "all", managers.slot:get_mask("civilians") )         
  116.                 for _,unit in ipairs(all_found) do
  117.                     if unit.brain ~= nil then
  118.                         local brain = unit:brain()
  119.                         if brain ~= nil then
  120.                             local objective = brain:objective()
  121.                             local objective_type = objective and objective.type            
  122.                             if objective_type == "follow" or objective_type == "surrender" then
  123.                                 table.insert(instigators, unit)        
  124.  
  125.                                 if self.hostages_to_sale[unit:id()]  == nil then
  126.                                     self.hostages_to_sale[unit:id()] = "fresh"     
  127.                                 end
  128.                             end
  129.                         end
  130.                     end
  131.                 end        
  132.             end
  133.            
  134.             return instigators
  135.         end
  136.        
  137.         -- Is unit inside area check
  138.         if not ElementAreaTrigger.def__is_inside then ElementAreaTrigger.def__is_inside = ElementAreaTrigger._is_inside end    
  139.         function ElementAreaTrigger:_is_inside(pos)
  140.             if self.hostages_to_sale == nil then
  141.                 self.hostages_to_sale = {}
  142.             end
  143.            
  144.             if self._values.instigator == "loot" then
  145.                 -- Find unit by his position
  146.                 local target_unit = nil
  147.                
  148.                 for unit_id, sale_state in pairs(self.hostages_to_sale) do
  149.                     if sale_state == "fresh" then
  150.                         local unit = get_by_id(unit_id, managers.slot:get_mask("civilians"))
  151.                        
  152.                         if unit ~= nil  then
  153.                             local unit_pos = unit:position()
  154.                             if unit_pos.x == pos.x and unit_pos.y == pos.y and unit_pos.z == pos.z then
  155.                                 target_unit = unit
  156.                                 break
  157.                             end
  158.                         end
  159.                     end
  160.                 end
  161.                
  162.                 -- Check that hostage near loot car
  163.                 if target_unit ~= nil then
  164.                     local all_shapes = self:get_shapes()
  165.                        
  166.                     for _,shape in ipairs(all_shapes) do
  167.                         if shape ~= nil then
  168.                             local distance = mvector3.distance(shape:position(), pos)
  169.                             if distance <= HOSTAGE_SELL_DISTANCE then  
  170.                                 self.hostages_to_sale[target_unit:id()] = "sold"
  171.                                 return true
  172.                             end
  173.                         end
  174.                     end    
  175.                 end
  176.                
  177.             end
  178.            
  179.             return self:def__is_inside(pos)
  180.         end
  181.  
  182.         local civ_types = {
  183.             civilian        =   true,
  184.             civilian_female =   true,
  185.             bank_manager    =   true,          
  186.         }
  187.        
  188.         -- Carry in trigger callback
  189.         function ElementCarry:on_executed(instigator)      
  190.             if not self._values.enabled or not alive(instigator) then
  191.                 return
  192.             end
  193.        
  194.             local isHostage = (instigator:carry_data() == nil and civ_types[get_unit_type(instigator)] == true) --new  
  195.             if managers.loot.h_secured_persons == nil then managers.loot.h_secured_persons  = {} end --new
  196.            
  197.             if self._values.type_filter and self._values.type_filter ~= "none" then
  198.                 if managers.loot.h_saved_filter_type == nil then managers.loot.h_saved_filter_type = self._values.type_filter end --new - protect from double item remove -> crash
  199.                
  200.                 local carry_ext = instigator:carry_data()
  201.                 if carry_ext ~= nil then --new
  202.                     local carry_id  = carry_ext:carry_id()
  203.                     local disable_f = false --new
  204.                    
  205.                     if carry_id == "person" and managers.loot.h_saved_filter_type == self._values.type_filter then --new
  206.                         disable_f = true
  207.                     end
  208.                    
  209.                     if not disable_f then --new
  210.                         if carry_id ~= self._values.type_filter then
  211.                             return
  212.                         end
  213.                     end
  214.                 end
  215.             end
  216.  
  217.             if self._values.operation == "remove" then --new
  218.                 if Network:is_server() then
  219.                     if isHostage == true then --new
  220.                         if managers.loot.h_secured_persons[instigator:id()] == "secured" then
  221.                             managers.loot:secure( "money" )
  222.                             managers.loot.h_secured_persons[instigator:id()] = "removed"
  223.                                
  224.                             if instigator:damage():has_sequence("secured") then
  225.                                 instigator:damage():run_sequence_simple("secured")
  226.                             else
  227.                                 debug_pause("[ElementCarry:on_executed] instigator missing secured sequence", instigator)
  228.                             end
  229.                                
  230.                             instigator:set_slot(0)
  231.                         end
  232.                     else   
  233.                         local carry_ext = instigator:carry_data() --new
  234.                         if carry_ext == nil or BODYBAGS_STAY_IN_CAR == false or carry_ext:carry_id() ~= "person" then --new
  235.                             instigator:set_slot(0)
  236.                         end
  237.                     end                
  238.                 end
  239.                
  240.             elseif self._values.operation == "add_to_respawn" then
  241.                 if Network:is_server() then
  242.                     local carry_ext = instigator:carry_data()
  243.                     if carry_ext ~= nil then --new
  244.                         local carry_id = carry_ext:carry_id()
  245.                         local multiplier = carry_ext:multiplier()
  246.                         managers.loot:add_to_respawn(carry_id, multiplier)
  247.                         instigator:set_slot(0)
  248.                     end
  249.                 end
  250.  
  251.             elseif self._values.operation == "freeze" then
  252.                 if instigator:damage():has_sequence("freeze") then
  253.                     instigator:damage():run_sequence_simple("freeze")
  254.                 else
  255.                     debug_pause("[ElementCarry:on_executed] instigator missing freeze sequence", instigator)
  256.                 end
  257.  
  258.             elseif self._values.operation == "secure" or self._values.operation == "secure_silent" then
  259.                 if managers.loot.h_secured_persons[instigator:id()] == nil then --new  
  260.                     if isHostage == true and Network:is_server() then --new
  261.                         managers.loot.h_secured_persons[instigator:id()] = "secured"                   
  262.                     end
  263.                    
  264.                     if instigator:carry_data() then
  265.                         local carry_ext = instigator:carry_data()
  266.                         carry_ext:disarm()
  267.                    
  268.                         if Network:is_server() then
  269.                             local silent = self._values.operation == "secure_silent"
  270.                             local carry_id = carry_ext:carry_id()
  271.                             local multiplier = carry_ext:multiplier()
  272.                             managers.loot:secure(carry_id, multiplier, silent)
  273.                         end
  274.  
  275.                         carry_ext:set_value(0)
  276.                         if instigator:damage():has_sequence("secured") then
  277.                             instigator:damage():run_sequence_simple("secured")
  278.                         else
  279.                             debug_pause("[ElementCarry:on_executed] instigator missing secured sequence", instigator)
  280.                         end
  281.                     else
  282.                         debug_pause("[ElementCarry:on_executed] instigator missing carry_data extension", instigator)
  283.                     end
  284.                 end
  285.             end
  286.                        
  287.             ElementCarry.super.on_executed(self, instigator)
  288.         end
  289.        
  290.        
  291.         if not PlayerManager.def_dye_pack_exploded then PlayerManager.def_dye_pack_exploded = PlayerManager.dye_pack_exploded end          
  292.         function PlayerManager:dye_pack_exploded()
  293.             local carry_data = self:get_my_carry_data()
  294.             if not carry_data then
  295.                 return
  296.             end
  297.  
  298.             if carry_data.value == nil then --new - duno, but sometimes it nil for bodybag (eg on Election Day 2)
  299.                 return
  300.             end
  301.            
  302.             return self:def_dye_pack_exploded()
  303.         end
  304.    
  305.         SellHostage = true
  306.         return
  307.     end
  308. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement