Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ * SimpleMenu implementation of Spawn Secondary Weapons by gir489 v3
- *
- * Credits;
- * Harfatus for SimpleMenu.
- * SquareOne for the precache fix for U31.
- *
- * Changelog:
- * v1: Initial release
- * v2: Compensated for the U31 update
- * v3: Compensated for the U35 update
- *
- * Not for use in Pirate Perfagtion Trainer]]
- if not SimpleMenu then
- SimpleMenu = class()
- function SimpleMenu:init(title, message, options)
- self.dialog_data = { title = title, text = message, button_list = {},
- id = tostring(math.random(0,0xFFFFFFFF)) }
- self.visible = false
- for _,opt in ipairs(options) do
- local elem = {}
- elem.text = opt.text
- opt.data = opt.data or nil
- opt.callback = opt.callback or nil
- elem.callback_func = callback(self, self, "_do_callback",
- { data = opt.data,
- callback = opt.callback})
- elem.cancel_button = opt.is_cancel_button or false
- if opt.is_focused_button then
- self.dialog_data.focus_button = #self.dialog_data.button_list+1
- end
- table.insert(self.dialog_data.button_list, elem)
- end
- return self
- end
- function SimpleMenu:_do_callback(info)
- if info.callback then
- if info.data then
- info.callback(info.data)
- else
- info.callback()
- end
- end
- self.visible = false
- end
- function SimpleMenu:show()
- if self.visible then
- return
- end
- self.visible = true
- managers.system_menu:show(self.dialog_data)
- end
- function SimpleMenu:hide()
- if self.visible then
- managers.system_menu:close(self.dialog_data.id)
- self.visible = false
- return
- end
- end
- end
- patched_update_input = patched_update_input or function (self, t, dt )
- if self._data.no_buttons then
- return
- end
- local dir, move_time
- local move = self._controller:get_input_axis( "menu_move" )
- if( self._controller:get_input_bool( "menu_down" )) then
- dir = 1
- elseif( self._controller:get_input_bool( "menu_up" )) then
- dir = -1
- end
- if dir == nil then
- if move.y > self.MOVE_AXIS_LIMIT then
- dir = 1
- elseif move.y < -self.MOVE_AXIS_LIMIT then
- dir = -1
- end
- end
- if dir ~= nil then
- if( ( self._move_button_dir == dir ) and self._move_button_time and ( t < self._move_button_time + self.MOVE_AXIS_DELAY ) ) then
- move_time = self._move_button_time or t
- else
- self._panel_script:change_focus_button( dir )
- move_time = t
- end
- end
- self._move_button_dir = dir
- self._move_button_time = move_time
- local scroll = self._controller:get_input_axis( "menu_scroll" )
- -- local sdir
- if( scroll.y > self.MOVE_AXIS_LIMIT ) then
- self._panel_script:scroll_up()
- -- sdir = 1
- elseif( scroll.y < -self.MOVE_AXIS_LIMIT ) then
- self._panel_script:scroll_down()
- -- sdir = -1
- end
- end
- managers.system_menu.DIALOG_CLASS.update_input = patched_update_input
- managers.system_menu.GENERIC_DIALOG_CLASS.update_input = patched_update_input
- spawnsecondarycallback = spawnsecondarycallback or function(info)
- if ( managers.player:player_unit() ) then
- local weapon = Global.blackmarket_manager.crafted_items.secondaries[info]
- if weapon then
- managers.blackmarket:equip_weapon("secondaries", info)
- 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())
- managers.dyn_resource:load(Idstring("unit"), Idstring(tweak_data.weapon.factory[weapon.factory_id].unit), "packages/dyn_resources", false)
- managers.player:player_unit():inventory():add_unit_by_factory_name( weapon.factory_id, false, false, weapon.blueprint, weapon.texture_switches )
- end
- end
- end
- function NewRaycastWeaponBase:set_timer(timer, ...)
- NewRaycastWeaponBase.super.set_timer(self, timer)
- for _,data in ipairs(self._parts) do
- if ( data and data.unit ) then
- data.unit:set_timer(timer)
- data.unit:set_animation_timer(timer)
- end
- end
- end
- opts = {}
- for i,weapon in pairs(Global.blackmarket_manager.crafted_items.secondaries) do
- if ( weapon ) then
- table.insert( opts, { text = managers.blackmarket:get_weapon_name_by_category_slot("secondaries",i):gsub("\"", ""), callback = spawnsecondarycallback, data = i } )
- end
- end
- table.insert( opts, { text = "Close", is_cancel_button = true } )
- mymenu = SimpleMenu:new("Spawn Secondary Weapons", "Select the weapon you want to spawn.", opts)
- mymenu:show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement