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.

Mr. Mo's ABS Add-on Request

Hey everyone, I just realized that Mr. Mo's ABS HUD doesn't show ammo for ranged weapons, so I was hoping someone could create an add-on for me.

It's for Mr. Mo's ABS Full, not Lite. I really have no requirements for it except for that it can show ammo for the ranged weapon you're currently carrying and that weapon only, but can change to show the ammo of the other weapons when you switch weapons.

Thanks to anyone who can come up with this, it should be fairly simple. :)

And also, whoever makes this will get full credit in my game, Lethal Dusk.
 

poccil

Sponsor

Here.  I originally made this script to respond to another request, but modified it to improve flexibility.

The following functions are defined:
  • showVarDisplay(num,x,y) - Creates a new VariableDisplay
    numbered _num_ and which is positioned on the coordinates _x_ and _y_.
  • updateVarDisplays - Updates all VariableDisplays.  To be called on
    Spriteset_Map's update function.
  • hideVarDisplay(num) - Closes the VariableDisplay numbered _num_.
  • setVarDisplayUpdate(num,method,param) - Sets the method for updating
    the VariableDisplay numbered _num_.  The optional _param_ is passed to that method.
  • getVarDisplay(num) - Gets the VariableDisplay numbered _num_.
VariableDisplay has these changeable properties:
x,y,z,opacity,visible - Work like Sprite's properties
fontface, fontsize, textcolor - Font, size, and color of the text
picture - File name of background graphic
update - Updates the display.

The code for the script follows:

Code:
class VariableDisplay
###############################
 # Default font face.
 DEFAULTFONT="Arial"
 # Default text size.
 DEFAULTSIZE=22
 # Default text color.
 DEFAULTCOLOR=Color.new(255,255,255)
 # Picture filename.  Must be in Graphics/Pictures.
 DEFAULTPICTURE="mapback.png"
 # Default Z order.
 DEFAULTZ=100
###############################
 attr_reader :x,:y,:picture,:fontface
 attr_reader :fontsize,:textcolor,:z,:opacity,:visible
 def initialize(x,y,picture=nil)
  @z=DEFAULTZ
  @sprite=Sprite.new(nil)
  @sprite.z=@z
  @sprite2=Sprite.new(nil)
  @sprite2.z=@z
  @picture=nil
  @picturename=picture ? picture : DEFAULTPICTURE
  @bitmap=nil
  @x=x
  @y=y
  @changeBitmap=true
  @fontface=DEFAULTFONT
  @fontsize=DEFAULTSIZE
  @textcolor=DEFAULTCOLOR
  @gettingtext=false
  @opacity=255
  @visible=true
  @method=nil
  @params=nil
  privRefresh
 end
 def setUpdateMethod(value,params)
  @method=Kernel.method(value.to_sym)
  begin
   @params=params.clone
  rescue TypeError
   @params=params
  end
  privRefresh
 end
 def dispose
  @picture.dispose
  @bitmap.dispose
  @sprite.dispose
  @sprite2.dispose
 end
 def z=(value)
  @z=value
  privRefresh
 end
 def fontsize=(value)
  @fontsize=value
  @changeBitmap=true
  privRefresh
 end
 def fontface=(value)
  @fontface=value
  @changeBitmap=true
  privRefresh
 end
 def picture=(value)
  @picture=value
  @changeBitmap=true
  privRefresh
 end
 def textcolor=(value)
  @textcolor=value
  @changeBitmap=true
  privRefresh
 end
 def x=(value)
  @x=value
  privRefresh
 end
 def y=(value)
  @y=value
  privRefresh
 end
 def z=(value)
  @z=value
  privRefresh
 end
 def opacity=(value)
  @opacity=value
  privRefresh
 end
 def visible=(value)
  @visible=value
  privRefresh
 end
 def update
  privRefresh
 end
 private
 def privRefresh
  if @changeBitmap
   @picture.dispose if @picture
   @picture=RPG::Cache.picture(@picturename)
   @bitmap.dispose if @bitmap
   @bitmap=Bitmap.new(@picture.width,@picture.height)
   @bitmap.font.name=[@fontface,"Arial","Times New Roman"]
   @bitmap.font.size=@fontsize
   @bitmap.font.color=@textcolor
   @sprite.bitmap=@picture
   @sprite2.bitmap=@bitmap
   @changeBitmap=false
  end
  return if @gettingtext
  @bitmap.clear
  if @method
   @gettingtext=true
   text=@method.call(self,@params)
   @gettingtext=false
   @bitmap.draw_text(0,0,@bitmap.width,@bitmap.height,text,1)
  end
  @sprite.x=@x
  @sprite.y=@y
  @sprite.z=@z
  @sprite.opacity=@opacity
  @sprite.visible=@visible
  @sprite2.x=@x
  @sprite2.y=@y
  @sprite2.z=@z
  @sprite2.opacity=@opacity
  @sprite2.visible=@visible
 end
end

################

class Game_Temp
 attr_accessor :vardisplays
end

def showVarDisplay(num,x,y)
 if !$game_temp.vardisplays
  $game_temp.vardisplays=[]
 end
 display=VariableDisplay.new(x,y)
 $game_temp.vardisplays[num]=display
 return display
end
def getVarDisplay(num)
 return nil if !$game_temp.vardisplays
 return $game_temp.vardisplays[num]
end
def hideVarDisplay(num)
 display=getVarDisplay(num)
 if display
  display.dispose
  $game_temp.vardisplays[num]=nil
 end
end
def setVarDisplayUpdate(num,meth,params=nil)
 display=getVarDisplay(num)
 if display
  display.setUpdateMethod(meth,params)
 end
end
def updateVarDisplays
 return if !$game_temp.vardisplays
 for display in $game_temp.vardisplays
  display.update if display
 end
end


class Spriteset_Map
  alias petero_vardisplays_Spriteset_Map_update update
  def update
    updateVarDisplays
    petero_vardisplays_Spriteset_Map_update
  end
end

Two functions follow:  One for displaying an arbitrary variable, and another for displaying the ammo as you requested.

Code:
def getVariable(display,param)
 return $game_variables[param].inspect
end

def getWeaponAmmo(display,param)
 actor=$game_party.actors[0]
 weapon=$ABS.RANGE_WEAPONS[actor.weapon_id]
 if !weapon || weapon[3]==0
  return ""
 end
 ammo=$game_party.item_number(weapon[3])
 if ammo==0
  # Red color
  display.textcolor=Color.new(255, 64, 0)
 elsif ammo<=10
  # Yellow color
  display.textcolor=Color.new(255, 255, 64, 255)
 else
  # Normal color
  display.textcolor=VariableDisplay::DEFAULTCOLOR
 end
 return "#{ammo}"
end

Example for displaying an ammo window:

Code:
#Displays window 0 with X of 200 and Y of 100
showVarDisplay(0,200,100)
setVarDisplayUpdate(0,"getWeaponAmmo")
 

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