some scripting questions

Started by M3T41 AG3, May 07, 2010, 02:51:25 pm

Previous topic - Next topic

M3T41 AG3

May 07, 2010, 02:51:25 pm Last Edit: May 14, 2010, 01:22:47 am by M3T41 AG3
when writing a menu is there a way to menu options go from left to right rather than up to down, and if so what is the code to do so.
also what code would i use to display an icon in the menu options (aka s1, s2)

edit2:
im leaving this open for futer questions

edit3:
question1: how do i get my custom menu to open when esc is pressed?

question2: Is there a way to make a second menu in the same scene?


question 4
im have ing a problem with the below code
Spoiler: ShowHide
exp_con = Sprite.new
  exp_con.bitmap = Bitmap.new(100, 22)
  exp_con.x = 37 #87 - (exp_con.bitmap.width / 2)
  exp_con.y = @face.src_rect.height + (exp_con.bitmap.height * 4)
  exp_con.z = 101
  exp_con.bitmap.fill_rect(0,0,98,18, Color.new(255,255,255))
  exp_con.bitmap.fill_rect(2,2,94,14, Color.new(0,0,0))
  exp_bar = Sprite.new
  exp_bar.bitmap = Bitmap.new(94,14)
  exp_bar.x = exp_con.x + 2
  exp_bar.y = exp_con.y + 2
  exp_bar.z = exp_con.z
  exp_bar.bitmap.font.name = ["Centaur", "Tahoma"]
  exp_val = $game_party.actors[0].exp
  exp_bar.bitmap.clear
  exp_barlength = (94 * exp_val) / $game_party.actors[0].rest_exp
  exp_color = Color.new(0,0,255)
  exp_bar.bitmap.fill_rect(0,0,exp_barlength,20, exp_color)
  exp_str = "EXP"
  exp_rect = exp_bar.bitmap.text_size(exp_str)
  exp_rect.x = (exp_bar.bitmap.width / 2) - (exp_rect.width / 2)
  exp_rect.y = (exp_bar.bitmap.height / 2) - (exp_rect.height / 2)
  exp_bar.bitmap.font.color = Color.new(0,0,0)
  for xo in [-1, 0, 1]
    for yo in [-1, 0, 1]
     exp_bar.bitmap.draw_text(exp_rect.x + xo, exp_rect.y + yo, exp_rect.width, exp_rect.height, exp_str)
    end
  end
  exp_bar.bitmap.font.color = Color.new(255,255,255)
  exp_bar.bitmap.draw_text(exp_rect, exp_str

the problem is with this line here
exp_barlength = (94 * exp_val) / $game_party.actors[0].rest_exp
or more specifically the end of it I need to know the word/syntax/proper-way-of-saying- the actors "exp-required-for-the-next-level"

nathmatt

here is 1 Blizzard made

#==============================================================================
# ** Window_HCommand
#------------------------------------------------------------------------------
#  This window deals with general command choices, but the display is
#  horizontal.
#==============================================================================

class Window_HCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     width    : window width
  #     commands : command text string array
  #--------------------------------------------------------------------------
  def initialize(width, commands)
    super
    self.width, self.height = commands.size * width + 32, 64
    @column_max = commands.size
    self.contents.dispose
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    refresh
    update_cursor_rect
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #     color : text color
  #--------------------------------------------------------------------------
  def draw_item(i, color)
    self.contents.font.color = color
    w = (self.width - 32) / @column_max
    x = i % @column_max * w
    rect = Rect.new(x, 0, self.contents.width / @column_max, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[i], 1)
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # If cursor position is less than 0
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # Get current row
    row = @index / @column_max
    # If current row is before top row
    if row < self.top_row
      # Scroll so that current row becomes top row
      self.top_row = row
    end
    # If current row is more to back than back row
    if row > self.top_row + (self.page_row_max - 1)
      # Scroll so that current row becomes back row
      self.top_row = row - (self.page_row_max - 1)
    end
    # Calculate cursor width
    cursor_width = (self.width - 32) / @column_max
    # Calculate cursor coordinates
    x = @index % @column_max * cursor_width
    # Update cursor rectangle
    self.cursor_rect.set(x, 0, cursor_width, 32)
  end
end
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


M3T41 AG3


Blizzard

There's also Window_CommandHorizontal from RMX-OS.

#==============================================================================
# Window_CommandHorizontal
#------------------------------------------------------------------------------
# This window deals with general command choices, but the display is
# horizontal.
#==============================================================================

class Window_CommandHorizontal < Window_Command
 
  #----------------------------------------------------------------------------
  # Initialization.
  #----------------------------------------------------------------------------
  def initialize(width, commands)
    super
    self.width, self.height = commands.size * width + 32, 64
    @column_max = commands.size
    self.contents.dispose
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    refresh
    update_cursor_rect
  end
  #----------------------------------------------------------------------------
  # Draws one item.
  #  i     - item index
  #  color - text color
  #----------------------------------------------------------------------------
  def draw_item(i, color)
    self.contents.font.color = color
    w = (self.width - 32) / @column_max
    x = i % @column_max * w
    rect = Rect.new(x, 0, self.contents.width / @column_max, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[i], 1)
  end
  #----------------------------------------------------------------------------
  # Updates the cursor rectangle.
  #----------------------------------------------------------------------------
  def update_cursor_rect
    # if no cursor position
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # match rows
    row = @index / @column_max
    self.top_row = row if row < self.top_row
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    # set cursor position
    cursor_width = (self.width - 32) / @column_max
    x = @index % @column_max * cursor_width
    self.cursor_rect.set(x, 0, cursor_width, 32)
  end
 
end


I think that I slightly improved the code since I can't see much difference on first sight.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

M3T41 AG3

May 19, 2010, 08:22:16 pm #4 Last Edit: May 19, 2010, 10:53:43 pm by M3T41 AG3
question 5: (and a bump so it gets awnsered)

is it posible to script somthing so that when you click on a sprite/bitmap(not a menu item) of some kind you can execute an action( aka opening a menu and what nots)?

question6:
is it possible to track mouse x and y movments through a specific area. (think mount and Blade (for thoes that know of it))

nathmatt

Question 5
yes and no you can make a selectable window with a selectable bitmap
Question 6
yes thats how the mouse selector works check out in area i believe thats what it is called in the mouse script
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


M3T41 AG3


M3T41 AG3

question 7:
if i wanted to make a script that would detect keyboard presses (mouse clicks too) and then make it work with blizz's mouse controller where should i start (reference,resource,and otherwise).

G_G

Get tons of add-ons, and turn on the Custom Controls script.
Then use these in conditional branches
Input.trigger?(Input::Key['Letter Here'])

It also has mouse buttons.

M3T41 AG3

how would i use that in a script i tried using an if statment but it never executed my if stztment was
class Z_scene
 
  def main
    loop do
     
     if Input.trigger?(Input::Key[';']) then
     print "key test works"
     end
    end
  end
end

SBR*

Quote from: M3T41 AG3 on May 23, 2010, 01:32:47 pm
how would i use that in a script i tried using an if statment but it never executed my if stztment was
class Z_scene
 
  def main
    loop do
     
     if Input.trigger?(Input::Key[';']) then
     print "key test works"
     end
    end
  end
end



Why use
if REQUIREMENT then
DO THIS
end
?

'then' is only for this
if REQUIREMENT then DO THIS end


(as far as I know)

M3T41 AG3

removing the then doesnt work either.

SBR*


nathmatt

May 24, 2010, 10:06:30 am #13 Last Edit: May 24, 2010, 10:08:52 am by nathmatt
are you calling the class ?

if you are then you also need to update the input

lass Z_scene

 def main
   loop do
    Input.update
    if Input.trigger?(Input::Key[';']) then
    print "key test works"
    end
   end
 end
end
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


SBR*

Quote from: nathmatt on May 24, 2010, 10:06:30 am
are you calling the class ?

if you are then you also need to update the input

lass Z_scene

 def main
   loop do
    Input.update
    if Input.trigger?(Input::Key[';']) then
    print "key test works"
    end
   end
 end
end



Lol, was just going here to say that. Really!

M3T41 AG3

i added the Input.update but it still does nothing. ...and that is the entire script.

SBR*

May 24, 2010, 10:26:31 am #16 Last Edit: May 25, 2010, 03:24:55 pm by SBR*
Quote from: M3T41 AG3 on May 24, 2010, 10:21:17 am
i added the Input.update but it still does nothing. ...and that is the entire script.


And how do you call the scene? You should call it this way:

$scene = Z_scene.new


EDIT: This script is a bit better:
class Z_scene

 def main
   Graphics.transition
   loop do
      Input.update
      Graphics.update
       if Input.trigger?(Input::C)
        print "key test works"
      end
   end
   Graphics.freeze
 end
end

M3T41 AG3

it works i dont know why but it does work much gratitude

G_G

You really don't need the 'then' after if branches

SBR*

Quote from: game_guy on May 24, 2010, 08:15:28 pm
You really don't need the 'then' after if branches


I know :P. Forgot to remove that. I'll edit my version.