i got this very basic inventory script, it works, sort of , kinda buggy (sometimes it selects multiple weapons)
however my weapon selection using 'mouse scroll wheel' gets clamped.
how do i keep on cycling thru the available weapons? for example when reaching weapon 1 and scrolling down how to make it switch to the last available weapon slot and then down again?
if event.is_action_pressed("mouseUP"):
if !inventoryOpen:
inventoryOpen = true
var now = Time.get_unix_time_from_system()
if (now > nextselect) :
nextselect = now + .3
weapon_change_number += 1
var asp = AudioStreamPlayer.new()
self.add_child(asp)
asp.stream = hideweaponSound
asp.play()
if !asp.is_playing():
asp.queue_free()
#hidecurrentweapon
if weapons[current_weapon_name].isequipped == true:
hideweapon()
if event.is_action_pressed("mouseDOWN") :
if !inventoryOpen:
inventoryOpen = true
var now = Time.get_unix_time_from_system()
if (now > nextselect) :
nextselect = now + .3
weapon_change_number -= 1
var asp = AudioStreamPlayer.new()
self.add_child(asp)
asp.stream = hideweaponSound
asp.play()
if !asp.is_playing():
asp.queue_free()
#hidecurrentweapon
if weapons[current_weapon_name].isequipped == true:
hideweapon()
if event.is_action_pressed("fire") && inventoryOpen:
inventoryOpen = false
close_Inventory()
if weapons[current_weapon_name].isequipped == false:
selectweapon()
#select weaponindex and unhide selectedweapon
func selectweapon():
var asp = AudioStreamPlayer.new()
self.add_child(asp)
asp.stream = selectweaponSound
asp.play()
if !asp.is_playing():
asp.queue_free()
weapons[current_weapon_name].start()
func hideweapon():
weapons[current_weapon_name].hide()
var asp = AudioStreamPlayer.new()
self.add_child(asp)
asp.stream = hideweaponSound
asp.play()
if !asp.is_playing():
asp.queue_free()
func process_Input(_delta):
if inventoryOpen:
open_Inventory()
else:
close_Inventory()
func open_Inventory():
weaponInventory.visible = true
weaponIcon.visible = false
Ammotext.visible = false
reticle.visible = false
weapon_change_number = clamp(weapon_change_number, 0, WEAPON_NUMBER_TO_NAME.size() - 1)
#print(WEAPON_NUMBER_TO_NAME[weapon_change_number])
currentweaponIcon = weaponIconNumberToName[weapon_change_number]
current_weapon_name = WEAPON_NUMBER_TO_NAME[weapon_change_number]
# for icon in weaponInventory.get_children():
# #print(icon.name, " at index: ", icon.get_index())
#
func close_Inventory():
weaponInventory.visible = false
weaponIcon.visible = true
Ammotext.visible = true
reticle.visible = true