Advertisement
Guest User

spawnprimary.lua

a guest
Sep 4th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.98 KB | None | 0 0
  1. --[[ * SimpleMenu implementation of Spawn Primary Weapons by gir489 v3
  2.      *
  3.      * Credits;
  4.      *          Harfatus for SimpleMenu.
  5.      *          SquareOne for the precache fix for U31.
  6.      *
  7.      * Changelog:
  8.      *      v1: Initial release
  9.      *      v2: Compensated for the U31 update
  10.      *      v3: Compensated for the U35 update
  11.      *
  12.      *  Not for use in Pirate Perfagtion Trainer]]
  13.  
  14. if not SimpleMenu then
  15.     SimpleMenu = class()
  16.  
  17.     function SimpleMenu:init(title, message, options)
  18.         self.dialog_data = { title = title, text = message, button_list = {},
  19.                              id = tostring(math.random(0,0xFFFFFFFF)) }
  20.         self.visible = false
  21.         for _,opt in ipairs(options) do
  22.             local elem = {}
  23.             elem.text = opt.text
  24.             opt.data = opt.data or nil
  25.             opt.callback = opt.callback or nil
  26.             elem.callback_func = callback(self, self, "_do_callback",
  27.                                           { data = opt.data,
  28.                                             callback = opt.callback})
  29.             elem.cancel_button = opt.is_cancel_button or false
  30.             if opt.is_focused_button then
  31.                 self.dialog_data.focus_button = #self.dialog_data.button_list+1
  32.             end
  33.             table.insert(self.dialog_data.button_list, elem)
  34.         end
  35.         return self
  36.     end
  37.  
  38.     function SimpleMenu:_do_callback(info)
  39.         if info.callback then
  40.             if info.data then
  41.                 info.callback(info.data)
  42.             else
  43.                 info.callback()
  44.             end
  45.         end
  46.         self.visible = false
  47.     end
  48.  
  49.     function SimpleMenu:show()
  50.         if self.visible then
  51.             return
  52.         end
  53.         self.visible = true
  54.         managers.system_menu:show(self.dialog_data)
  55.     end
  56.  
  57.     function SimpleMenu:hide()
  58.         if self.visible then
  59.             managers.system_menu:close(self.dialog_data.id)
  60.             self.visible = false
  61.             return
  62.         end
  63.     end
  64. end
  65.  
  66. patched_update_input = patched_update_input or function (self, t, dt )
  67.     if self._data.no_buttons then
  68.         return
  69.     end
  70.    
  71.     local dir, move_time
  72.     local move = self._controller:get_input_axis( "menu_move" )
  73.  
  74.     if( self._controller:get_input_bool( "menu_down" )) then
  75.         dir = 1
  76.     elseif( self._controller:get_input_bool( "menu_up" )) then
  77.         dir = -1
  78.     end
  79.    
  80.     if dir == nil then
  81.         if move.y > self.MOVE_AXIS_LIMIT then
  82.             dir = 1
  83.         elseif move.y < -self.MOVE_AXIS_LIMIT then
  84.             dir = -1
  85.         end
  86.     end
  87.  
  88.     if dir ~= nil then
  89.         if( ( self._move_button_dir == dir ) and self._move_button_time and ( t < self._move_button_time + self.MOVE_AXIS_DELAY ) ) then
  90.             move_time = self._move_button_time or t
  91.         else
  92.             self._panel_script:change_focus_button( dir )
  93.             move_time = t
  94.         end
  95.     end
  96.  
  97.     self._move_button_dir = dir
  98.     self._move_button_time = move_time
  99.    
  100.     local scroll = self._controller:get_input_axis( "menu_scroll" )
  101.     -- local sdir
  102.     if( scroll.y > self.MOVE_AXIS_LIMIT ) then
  103.         self._panel_script:scroll_up()
  104.         -- sdir = 1
  105.     elseif( scroll.y < -self.MOVE_AXIS_LIMIT ) then
  106.         self._panel_script:scroll_down()
  107.         -- sdir = -1
  108.     end
  109. end
  110. managers.system_menu.DIALOG_CLASS.update_input = patched_update_input
  111. managers.system_menu.GENERIC_DIALOG_CLASS.update_input = patched_update_input
  112.  
  113. spawnprimarycallback = spawnprimarycallback or function(info)
  114.     if ( managers.player:player_unit() ) then
  115.         local weapon = Global.blackmarket_manager.crafted_items.primaries[info]
  116.         if weapon then
  117.             managers.blackmarket:equip_weapon("primaries", info)
  118.             managers.network:session():send_to_peers_synched("set_unit", managers.player:player_unit(), managers.network:session():local_peer():character(), managers.blackmarket:outfit_string(), managers.network:session():local_peer():outfit_version(), managers.network:session():local_peer():id())
  119.             managers.dyn_resource:load(Idstring("unit"), Idstring(tweak_data.weapon.factory[weapon.factory_id].unit), "packages/dyn_resources", false)
  120.             managers.player:player_unit():inventory():add_unit_by_factory_name( weapon.factory_id, false, false, weapon.blueprint, weapon.texture_switches )
  121.         end
  122.     end
  123. end
  124.  
  125. function NewRaycastWeaponBase:set_timer(timer, ...)
  126.     NewRaycastWeaponBase.super.set_timer(self, timer)
  127.     for _,data in ipairs(self._parts) do
  128.         if ( data and data.unit ) then
  129.             data.unit:set_timer(timer)
  130.             data.unit:set_animation_timer(timer)
  131.         end
  132.     end
  133. end
  134.  
  135. opts = {}
  136. for i,weapon in pairs(Global.blackmarket_manager.crafted_items.primaries) do
  137.     if ( weapon ) then
  138.         table.insert( opts, { text = managers.blackmarket:get_weapon_name_by_category_slot("primaries",i):gsub("\"", ""), callback = spawnprimarycallback, data = i } )
  139.     end
  140. end
  141. table.insert( opts, { text = "Close", is_cancel_button = true } )
  142. mymenu = SimpleMenu:new("Spawn Primary Weapons", "Select the weapon you want to spawn.", opts)
  143. mymenu:show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement