Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[RESOLVED]NeoABS Addon--Weapon Cycling Please

MAJOR, MAJOR EDIT HERE.
I want the exact same concept, but made to work with Mr. Mo's new NeoABS.


I'm looking to feature in my game an easier weapons switching mechanism than turning to the menu every time, like a button that cycles between weapons (for example, L or R swaps your weapon to the one above or below it in the inventory). The script provider will be credited and given my eternal gratitude. Thank you!
 
Did this in fast reply, so let me know if it doesn't work.

Insert above Main.
Code:
module MapWeaponCycling
  Up = Input::R
  Down = Input::L
end

class Game_Actor
  def cycle_weapon_up
    if equip_fix?(0)
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    id = weapon_id
    loop do
      id = id == $data_weapons.size ? 1 : id + 1
      if id == @weapon_id
        $game_system.se_play($data_system.buzzer_se)
        break
      end
      next unless equippable?($data_weapons[id])
      $game_system.se_play($data_system.equip_se)
      equip(0, id)
      break
    end
  end
  def cycle_weapon_down
    if equip_fix?(0)
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    id = weapon_id
    loop do
      id = id == 1 ? $data_weapons.size : id - 1
      if id == @weapon_id
        $game_system.se_play($data_system.buzzer_se)
        break
      end
      next unless equippable?($data_weapons[id])
      $game_system.se_play($data_system.equip_se)
      equip(0, id)
      break
    end
  end
end

class Scene_Map
  alias_method :seph_weaponcycling_scnmap_update, :update
  def update
    if Input.trigger?(MapWeaponCycling::Up)
      $game_party.actors[0].cycle_weapon_up
    elsif Input.trigger?(MapWeaponCycling::Up)
      $game_party.actors[0].cycle_weapon_down
    end
    seph_weaponcycling_scnmap_update
  end
end

Just alter your
Up = Input::R
Down = Input::L

with the input buttons you wish to press for the change.
 
Ok so I tried this script but theres things I dont like ok firsts thing is that it plays the equip SE even though theres no weapon in your inventory and next is that could you teach us how to change the SE that it plays when you use it. Oh and yes could you make a script for me that displays the current weapon being used that can be seen at the upper left just the icon.
 
Actually, what would be interesting is if there were different select a weapon for different slots based on the type of weapon.

For example you could add a type of gun, sword, bow, and spear, and the script would scan the slots in order to scroll through the weapons and equip you with the next one. If the slot is empty, move on to the next. This would also reduce the lag and strange occurances that comes with checking the entire set of weapons that the hero posesses.

Unfortanetly, I have no idea how to script it. It would probobly require some aliasing and a modification to the HUD. A new scene class would allow the player to select the weapons.

Just my thoughts...
 
Zetaraptor03":3o9jb1ob said:
Unfortanetly, I have no idea how to script it. It would probobly require some aliasing and a modification to the HUD. A new scene class would allow the player to select the weapons.

I think that the NeoABS HUD shows an icon and, if applicable, ammo counter for equipped weapons already.
 
It wouldn't even be an add-on really. The way this forum goes, you would have had a better chance getting help in RGSS Support, sad really. Anyways, add this above main somewhere:
[removed]

hope it works :)

Edit:
Found an error with it, 1 sec.
Edit:
Damn... I completely forgot RMXP doesn't remember the order of weapons in the inventory so you are pretty much out of luck on this one.
I'm going to try another approach which should work.
Edit:
Got it working! :D

Code:
class Scene_Map
  alias mrmo_scene_map_ws_update update
  def update
    mrmo_scene_map_ws_update
    # Check For Keys
    if Input.trigger?(Input::L)
      swap_weapon(1)
    elsif Input.trigger?(Input::R)
      swap_weapon(2)
    end
  end
  
  def swap_weapon(dir)
    actor = $game_party.actors[0]
    # If equipment is fixed, return
    return $game_system.se_play($data_system.buzzer_se) if actor.equip_fix?(0)
    # Add equippable weapons
    data = []
    weapon_set = $data_classes[actor.class_id].weapon_set
    for i in 1...$data_weapons.size
      if $game_party.weapon_number(i) > 0 and weapon_set.include?(i)
        data.push($data_weapons[i])
      end
    end
    return $game_system.se_play($data_system.buzzer_se) if data.empty?
    cur_id = actor.weapon_id
    weapon_id = nil
    if cur_id != 0
      # Loop Do
      count = 0
      data.each { |w|
        count+=1
        if w.id > cur_id
          break weapon_id = w.id if dir == 2
        elsif w.id < cur_id
          break weapon_id = w.id if dir == 1
        elsif count == data.size
          break if dir == 2
          break weapon_id = w.id if dir == 1
        end
      }
    end
    # Get Item
    weapon_id = data[0].id if weapon_id.nil?
    # Play equip SE
    $game_system.se_play($data_system.equip_se)
    # Equip
    actor.equip(0,weapon_id)
  end
end
 
Mr.Mo":1obzo5q9 said:
Edit:
Found an error with it, 1 sec.
Edit:
Damn... I completely forgot RMXP doesn't remember the order of weapons in the inventory so you are pretty much out of luck on this one.
I'm going to try another approach which should work.

Well, it works with two weapons just fine. Are you saying that with more than two weapons, the selection will be randomized?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top