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.

Calling Switches from Scripts

Heya all. I have a char gen script. When a user selects a specific Profession, i want to be able to call in game switches with their selected profession..

What i would like to do, if someone selects FIGHTER.. It would make it, so when they enter the game they have Switches 101 200 and 316. Those switches activate a certain line of profession exclusive quests that give an introduction on game play mechanics as they directly affect their character.

What i would like to do, is edit the char generator, so if they select fighter, it auto calls the scripts.. Anyone have any suggestions? Prehapes this can be acomplished without editing the scripts at all..

Any advice?

Thanks

michael
 
i downloaded this script from the forums. This is what it is

#==============================================================================
# â–  RPG::Class
#------------------------------------------------------------------------------
#  Contains data on classes.
#==============================================================================
module RPG
class Class
def initialize
@id = 0
@name = ""
@graphic = ""
@position = 0
@weapon_set = []
@armor_set = []
@element_ranks = Table.new(1)
@state_ranks = Table.new(1)
@learnings = []
end
attr_accessor :id
attr_accessor :name
attr_accessor :graphic
attr_accessor :position
attr_accessor :weapon_set
attr_accessor :armor_set
attr_accessor :element_ranks
attr_accessor :state_ranks
attr_accessor :learnings
end
end

#==============================================================================
# â–  RPG::Update
#------------------------------------------------------------------------------
#  Updates classes in module RPG.
#==============================================================================
module RPG
class Update
def initialize
update_classes
def update_classes
case $gender
when "Male"
$data_classes[1].graphic = ["211-Ninja01"]
$data_classes[2].graphic = ["009-Lancer01b"]

when "Female"
$data_classes[1].graphic = ["Graphic1"]
$data_classes[2].graphic = ["012-Lance"]

end
end


end
end

Now no matter where i put the switch script that you recomended jobber, i get the same error as i posted.
 
Well thanks Raizel, I tried your way, so my script looks like this

case $gender
when "Male"
$data_classes[1].graphic = ["211-Ninja01"]
$game_switches = Game_Switches.new
$game_switches[183] = true
$data_classes[2].graphic = ["009-Lancer01b"]

when "Female"
$data_classes[1].graphic = ["Graphic1"]
$data_classes[2].graphic = ["012-Lance"]

end
end


end
end


Doing this doesnt crash my game!! Which is on the right track, although, doing it this way does not actually load that particuler switch when a new user first enters the game.. Any ideas?
 
Hello =) Just a question... In my character creator, I need it so that I have more classes in my classes editor, than in my RPG::Class script. Is this possible? If so, please help. ANY help would be GREATLY appreciated! =) Thanks, everyone! =)

~DarkShadowWing~
 
Ok, here is a script that I wrote in about 1 hour to help this get resolved. I know it has bugs and doesnt look as pretty as it should be... but it gets the job done. Please let me know if you have any questions. (keep in mind that I dont normally come onto RMXP very often, so forgive my absence if I dont respond. I am far more active on CA then here.) Oh yeah.. to adjust character hue when in the bottom window, just use the left/right arrows.

Code:
#=======================================================================
#  Select Class/Gender by GubiD
#  v0.1 Oct 6,2007
#=======================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Initial Party Setup
  #--------------------------------------------------------------------------
  def setup_starting_members
    $new_scene = 1
    $scene = Scene_Character_Gen.new
    while $new_scene != nil
      $scene.main
    end
  end
  
  #  @actors = []
  #  for i in $data_system.party_members
  #    @actors.push($game_actors[i])
  #  end
  #end
end


class Spriteset_Gen_Char
  attr_reader  :character_sprites, :viewport2
  def initialize
    # Make viewports
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    # Make character sprites
    @character_sprites = []
    # Make picture sprites
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    # Make timer sprite
    @timer_sprite = Sprite_Timer.new
    # Frame update
    update
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    # Dispose of character sprites
    for sprite in @character_sprites
      sprite.dispose
    end
    # Dispose of picture sprites
    for sprite in @picture_sprites
      sprite.dispose
    end
    # Dispose of timer sprite
    @timer_sprite.dispose
    # Dispose of viewports
    @viewport1.dispose
    @viewport2.dispose
    @viewport3.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update character sprites
    for sprite in @character_sprites
      sprite.update
    end
    # Update picture sprites
    for sprite in @picture_sprites
      sprite.update
    end
    # Update timer sprite
    @timer_sprite.update
    # Set screen color tone and shake position
    @viewport1.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake
    # Set screen flash color
    @viewport3.color = $game_screen.flash_color
    # Update viewports
    @viewport1.update
    @viewport3.update
  end
end


class Sprite_Character_Gen < RPG::Sprite
  attr_accessor :character           
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    update
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If tile ID, file name, or hue are different from current ones
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      # Remember tile ID, file name, and hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      # If tile ID value is valid
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      # If tile ID value is invalid
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 4
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    # Set visible situation
    self.visible = (not @character.transparent)
    # If graphic is character
    if @tile_id == 0
      # Set rectangular transfer
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    # Set sprite coordinates
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    # Set opacity level, blend method, and bush depth
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    # Animation
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end



class Char_New
  attr_accessor  :tile_id,:character_name,:character_hue,:transparent,:pattern
  attr_accessor  :direction,:opacity,:blend_type,:bush_depth,:animation_id
  attr_reader    :x,:y
  def initialize(name)
    @tile_id = 0
    @character_name = name
    @character_hue = 0
    @transparent = false
    @pattern = 0
    @direction = 2
    @real_x = 0
    @real_y = 0
    @prelock_direction = 0
    @opacity = 255
    @blend_type = 0
    @bush_depth = 0
    @animation_id = 0
    @anime_count = 0
    @move_speed = 3
    @step_anime = true
    @original_pattern = 0
  end
  
  def moveto(x, y)
    @x = x % 20 #$game_map.width
    @y = y % 15 #$game_map.height
    @real_x = @x * 128
    @real_y = @y * 128
    @prelock_direction = 0
  end
  
  def update
    # If animation count exceeds maximum value
    # * Maximum value is move speed * 1 taken from basic value 18
    if @anime_count > 18 - @move_speed * 2
      # If stop animation is OFF when stopping
      if not @step_anime
        # Return to original pattern
        @pattern = @original_pattern
      # If stop animation is ON when moving
      else
        # Update pattern
        @pattern = (@pattern + 1) % 4
      end
      # Clear animation count
      @anime_count = 0
    end
  end
  
  def dispose
    @character_name = ""
  end
  
  
  #--------------------------------------------------------------------------
  # * Get Screen X-Coordinates
  #--------------------------------------------------------------------------
  def screen_x
    # Get screen coordinates from real coordinates and map display position
    return (@real_x - 0 + 3) / 4 + 16
  end
  #--------------------------------------------------------------------------
  # * Get Screen Y-Coordinates
  #--------------------------------------------------------------------------
  def screen_y
    # Get screen coordinates from real coordinates and map display position
    y = (@real_y - $game_map.display_y + 3) / 4 + 16#32
    # Make y-coordinate smaller via jump count
    #if @jump_count >= @jump_peak
    #  n = @jump_count - @jump_peak
    #else
    #  n = @jump_peak - @jump_count
    #end
    return y #- (@jump_peak * @jump_peak - n * n) / 2
  end
  #--------------------------------------------------------------------------
  # * Get Screen Z-Coordinates
  #     height : character height
  #--------------------------------------------------------------------------
  def screen_z(height = 0)
    # If display flag on closest surface is ON
    # Get screen coordinates from real coordinates and map display position
    z = (@real_y - 0 + 3) / 4 + 32
    # If tile
    if @tile_id > 0
      # Add tile priority * 32
      return z #+ $game_map.priorities[@tile_id] * 32
    # If character
    else
      # If height exceeds 32, then add 31
      return z + ((height > 32) ? 31 : 0)
    end
  end
end


class Window_Gender < Window_Selectable
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    $gender = nil
    @column_max = 2
    @item_max = 2
    refresh
  end
  
  def refresh
    self.contents.clear
    x = 240
    s1 = "Male"
    s2 = "Female"
    for i in 0..1
      if i == 0 ? text = s1 : text = s2
        self.contents.draw_text(x*i,0,320,40,text,1)
      end
    end
  end
  
  def update_cursor_rect
    self.cursor_rect.set(@index * 240 + (130-(@index*10)), 0, 80, 32)
    if @index == 0
      $gender = "Male"
    else
      $gender = "Female"
    end
  end
end

class Window_Choose_Class < Window_Selectable 
  def initialize
    super(0, 64, 640, 240)
    self.contents = Bitmap.new(width - 32, height - 32)
    @column_max = 2
    refresh
  end
  
  def class_name
    return @data[self.index].name
  end
  
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 1...$data_classes.size
      if $data_classes[i].name != ""
        @data.push($data_classes[i])
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_class_name(i)
      end
    end
  end
  
  def draw_class_name(index)
    profession = @data[index]
    #find position to draw
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(x + 28, y, 212, 32, profession.name, 0)
  end
end

class Window_Choose_Look < Window_Selectable
  def initialize(class_window, sprites, viewport)
    super(0, 304, 640, 240)
    self.contents = Bitmap.new(width - 32, height - 32)
    @class_window = class_window
    @sprites = sprites
    @viewport = viewport
    @pics = []
    refresh
  end
  alias choose_char_dis dispose
  def dispose
    clear_sprites
    choose_char_dis
  end
  
  def clear_sprites
    for sprite in @sprites
      sprite.dispose
    end
  end

  def refresh
    graphics = []
    case $gender
    when "Male"
      case @class_window.class_name
      when "Lancer"
        graphics.push("009-Lancer01")
        graphics.push("010-Lancer02")
        graphics.push("011-Lancer03")
      else
        graphics.push("001-Fighter01")
      end
    when "Female"
      case @class_window.class_name
      when "Lancer"
        graphics.push("012-Lancer04")
      else
        graphics.push("002-Fighter02")
      end
    end
    @item_max = graphics.size
    @pics.clear
    for sprite in @sprites
      sprite.dispose
    end
    @sprites.clear
    if @item_max > 0
      for i in 0...@item_max
        draw_character(i, graphics[i])
      end
    end
  end
  
  def draw_character(index, name)
    actor = Char_New.new(name)
    @pics[index] = actor
    @sprites.push(Sprite_Character.new(@viewport, @pics[index]))
    x = 4 + (index*5)
    y = 13
    @pics[index].moveto(x,y)
    @sprites.push(@pics[index])
  end
  
  def update_cursor_rect
    if @index != -1
      self.cursor_rect.set(((@pics[@index].x * 128)+ 3) / 4 -19, 80, 40, 40)
    else
      self.cursor_rect.set(-40, -50, 0,0)
    end
  end  
  
  def selected_hue
    return @pics[@index].character_hue
  end
  
  def selected_name
    return @pics[@index].character_name
  end
  
  def change_hue(hue)
    @pics[@index].character_hue = hue
  end
end

class Game_Actor < Game_Battler
  attr_accessor :character_name,:character_hue
end


class Scene_Character_Gen
  def main
    @spriteset = Spriteset_Gen_Char.new
    @gender = Window_Gender.new
    @class_name = Window_Choose_Class.new
    @choose_look = Window_Choose_Look.new(@class_name, @spriteset.character_sprites, @spriteset.viewport2)
    @gender.active = true
    @gender.index = 0
    current = $game_party.actors.size
    actor = $game_actors[$data_system.party_members[current]]
    p sprintf("Choose a graphic for %s", actor.name)
        
    if $data_system.battle_transition == ""
      Graphics.transition(20)
    else
      Graphics.transition(40, "Graphics/Transitions/" +
        $data_system.battle_transition)
    end
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    @gender.dispose
    @class_name.dispose
    @choose_look.dispose
  end
  
  def update
    @spriteset.update
    if @gender.active
      @gender.update
      gender_update 
      return
    end
    if @class_name.active
      @class_name.update
      name_update 
      return
    end
    if @choose_look.active
      @choose_look.update
      choose_update
      return
    end
  end
  
  def gender_update
    if Input.trigger?(Input::B)
      if $game_party.actors.size == 0
        $game_system.se_play($data_system.buzzer_se)
      else
        $scene = Scene_Map.new
        $new_scene = nil
      end
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @gender.active = false
      @class_name.active = true
      @class_name.index = 0
    end
  end
  
  def name_update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
       @gender.active = true
       @class_name.active = false
       @class_name.index = -1
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @class_name.active = false
      @choose_look.active = true
      @choose_look.refresh
      @choose_look.index = 0
    end
  end
  
  def choose_update
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      hue = @choose_look.selected_hue - 3
      @choose_look.change_hue(hue)
    end
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      hue = @choose_look.selected_hue + 3
      @choose_look.change_hue(hue)
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @class_name.active = true
      @choose_look.active = false
      @choose_look.index = -1
    end
    if Input.trigger?(Input::C)
      if $game_party.actors.size != $data_system.party_members.size
        $game_system.se_play($data_system.decision_se)
        current = $game_party.actors.size
        actor = $game_actors[$data_system.party_members[current]]
        $game_party.actors.push(actor)
        $game_party.actors[current].character_name = @choose_look.selected_name
        $game_party.actors[current].character_hue = @choose_look.selected_hue
        if $game_party.actors.size != $data_system.party_members.size
          current = $game_party.actors.size
          actor = $game_actors[$data_system.party_members[current]]
          p sprintf("Choose a graphic for %s", actor.name)
          @gender.active = true
          @choose_look.active = false
          @choose_look.index = -1
          @choose_look.refresh
          @choose_look.update
          @class_name.index = -1
          @class_name.update
        else
          $new_scene = nil
          $scene = Scene_Map.new
        end
        
      else
        $new_scene = nil
      end
    end
  end
end
 
I really appricate you taking the time to work on this for me! I know I am not the best scripter in the world and dig the fact you put time into my project at your own time expense! As it, its not directly intergrating into my game but I have another friend who is well familer with my script setup that it should be doable. If i have any questions, mind if i respond here, or send you a PM?

Thanks

Michael
 
Hello everyone =) I just needed to know if anybody could read this script, and explain to me what's wrong with it. I've tried everything, and it doesn't wanna seem to work.

Here is the script:

Code:
if $scene.is_a?(Scene_Create)
if @class_id > 7
@class_id == 7 if $scene.is_a?(Scene_Create)
else
@class_id += 1 if $scene.is_a?(Scene_Create) and @class_id < 7
return
end
end

Basically, all's I need it to do, is if the class id inside of Scene_Create ONLY, is greater than the max number of classes, then the class id = the max number of classes. HOWEVER, when it is NOT in Scene_Create, but rather, used inside of a script in the game itself that I call, via talking to an NPC, using this script: $game_actors[1].class_id += 1 , I need it to exceed beyond 8 ONLY INSIDE the game, and I need it to change to that class, as soon as u finish talking to the NPC with the variable stored in it =)

ANY help would be GREATLY appreciated! =)

Thank you to all who took their time to read and help me! =)

~DarkShadowWing~
 

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