Guest User

Untitled

a guest
Jan 30th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. local playerinventory_send_equipped_orig = PlayerInventory._send_equipped_weapon
  2. function PlayerInventory:_send_equipped_weapon()
  3.    
  4.     if not Utils:IsInHeist() then
  5.         return playerinventory_send_equipped_orig(self)
  6.     end
  7.    
  8.     local index, blueprint_string, cosmetics_string = self:get_spoofed_weapon()
  9.     if not index then
  10.         index, blueprint_string, cosmetics_string = self:get_wp_weapon_sync_data()
  11.         if Utils:IsCurrentWeaponPrimary() then
  12.             self:set_spoofed_weapon(true, index, blueprint_string, cosmetics_string)
  13.         else
  14.             self:set_spoofed_weapon(false, index, blueprint_string, cosmetics_string)
  15.         end
  16.     end
  17.    
  18.     self._unit:network():send("set_equipped_weapon", index, blueprint_string, cosmetics_string)
  19. end
  20.  
  21. function PlayerInventory:set_spoofed_weapon(is_primary, index, blueprint_string, cosmetics_string)
  22.     if is_primary then
  23.         self._spoofed_primary_index = index
  24.         self._spoofed_primary_blueprint_string = blueprint_string
  25.         self._spoofed_primary_cosmetics_string = cosmetics_string
  26.     else
  27.         self._spoofed_secondary_index = index
  28.         self._spoofed_secondary_blueprint_string = blueprint_string
  29.         self._spoofed_secondary_cosmetics_string = cosmetics_string        
  30.     end
  31. end
  32.  
  33. --At least Utils has a valid use case now, I guess?
  34. function PlayerInventory:get_spoofed_weapon()
  35.     if Utils:IsCurrentWeaponPrimary() then
  36.         return self._spoofed_primary_index, self._spoofed_primary_blueprint_string, self._spoofed_primary_cosmetics_string
  37.     else
  38.         return self._spoofed_secondary_index, self._spoofed_secondary_blueprint_string, self._spoofed_secondary_cosmetics_string
  39.     end
  40. end
  41.  
  42. --Literally copied from PlayerInventory:_send_equipped_weapon().
  43. function PlayerInventory:get_wp_weapon_sync_data()
  44.     local eq_weap_name = self:equipped_unit():base()._factory_id or self:equipped_unit():name()
  45.     local index = self._get_weapon_sync_index(eq_weap_name)
  46.     if not index then
  47.         debug_pause("[PlayerInventory:_send_equipped_weapon] cannot sync weapon", eq_weap_name, self._unit)
  48.         return
  49.     end
  50.     local blueprint_string = self:equipped_unit():base().blueprint_to_string and self:equipped_unit():base():blueprint_to_string() or ""
  51.     local cosmetics_string = ""
  52.     local cosmetics_id = self:equipped_unit():base().get_cosmetics_id and self:equipped_unit():base():get_cosmetics_id() or nil
  53.     if cosmetics_id then
  54.         local cosmetics_quality = self:equipped_unit():base().get_cosmetics_quality and self:equipped_unit():base():get_cosmetics_quality() or nil
  55.         local cosmetics_bonus = self:equipped_unit():base().get_cosmetics_bonus and self:equipped_unit():base():get_cosmetics_bonus() or nil
  56.         local entry = tostring(cosmetics_id)
  57.         local quality = tostring(tweak_data.economy:get_index_from_entry("qualities", cosmetics_quality) or 1)
  58.         local bonus = cosmetics_bonus and "1" or "0"
  59.         cosmetics_string = entry .. "-" .. quality .. "-" .. bonus
  60.     else
  61.         cosmetics_string = "nil-1-0"
  62.     end
  63.     return index, blueprint_string, cosmetics_string  
  64. end
Advertisement
Add Comment
Please, Sign In to add comment