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.

Switch Off on script open, and on when script closed

Hey Me again, I have two scripts that I need help with. What I want them to do is when the open the turn a switch off, and when they close they turn the switch back on.

The first one is the CIS by Samo, the Thief
Code:
#============================================================================
#============================================================================
#============================================================================

 #              CIS (Custom Item System)    V1.0
  #                         by Samo, the thief

#

 #INSTRUCTIONS:

 #- Place this script above Main.

 #- Go to Scene_Menu (or your CMS (CUSTOM MENU SYSTEM)) and find any line that
 #says this:

 #$scene = Scene_Item.new

 #and replace them with

##----------CIS--------------

#$scene = Scene_Samo_Item.new

#-#---------CIS---------------



  #FEATURES:
  #<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #- Colors Added.
    #- Animations of Windows added.
    #- More Nice and Organized Inventory
    ##- Better targeting characters
    #- Information of Items when selecting one
    #- Map Background added
   # - You can make Unique items, so they draw in brown (like in D2)
  #  - Giving a better look at a boring window.
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
 
  # CUSTOMIZING:
  # -----------
  # - Go and find the lines with
  
  #    $UNIQUE_ITEMS = [X, X, X ,X]
  #   $UNIQUE_WEAPONS = [X, X]
  #   $UNIQUE_ARMORS = [X, X, X, X, X, X, X]
  
  #  and put there all the numbers you want. Have in mind that these are the ids
  #  of Items, Weapons, and armors that will have the mod [UNIQUE].
  
  
 #   Please, give me the credit if you use it. Enjoy it!
 #                               Samo, the thief.
  
  
# ============================================================================ 
# ============================================================================ 
# ============================================================================ 
 

class Scene_Samo_Item
  def initialize
    $UNIQUE_ITEMS = []
    $UNIQUE_WEAPONS = [1]
    $UNIQUE_ARMORS = [1, 6, 13]
    end
# ------------------------------------  
  def main
    @help_window = Window_Help.new
    @help_window.y = 480
    @help_window.opacity = 215
    @item_window = Window_Samo_Item.new
    @item_window.x = -320
    @item_window.y = 64
    @item_window.opacity = 200
    @item_window.help_window = @help_window
    @target_window = Window_Samo_Target.new
    @target_window.x = 640
    @target_window.y = 0
    @target_window.opacity = 175
    @inventory_window = Window_Inventory.new
    @inventory_window.y = -64
    @inventory_window.opacity = 215
    @item = @item_window.item
    @spriteset = Spriteset_Map.new
    @window_information = Window_Information_CIS.new(@item)
    @window_information.opacity = 200
    @window_information.x = 640
    @window_information.visible = true
    @target_window.visible = false
    @target_window.active = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    @spriteset.dispose
    @item_window.dispose
    @target_window.dispose
    @window_information.dispose
    @inventory_window.dispose
  end
# ------------------------------------  
  def update
    if @help_window.y != 416
      @help_window.y -= 4
    end
    if @inventory_window.y != 0
      @inventory_window.y += 4
    end
    if @item_window.x != 0
      @item_window.x += 20
    end
    if @window_information.x != 320
      @window_information.x -= 20
    end
    if @target_window.x != 320
      @target_window.x -= 20
    end
    @help_window.update
    @item_window.update
    @target_window.update
    @window_information.update
    if @item_window.active
      update_item
      return
    end
    if @target_window.active
      update_target
      return
    end
  end
# ------------------------------------  

  def update_item
    @item = @item_window.item
    if Input.repeat?(Input::DOWN)
      @window_information.refresh (@item)
      end
      if Input.repeat?(Input::UP)
      @window_information.refresh (@item)
    end
      if Input.repeat?(Input::L)
      @window_information.refresh (@item)
    end
          if Input.repeat?(Input::R)
      @window_information.refresh (@item)
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(0)
      return
    end
    if Input.trigger?(Input::C)
      @item = @item_window.item
      unless @item.is_a?(RPG::Item)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      unless $game_party.item_can_use?(@item.id)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      if @item.scope >= 3
        @item_window.active = false
        @target_window.visible = true
        @target_window.active = true
        @target_window.x = 640
        if @item.scope == 4 || @item.scope == 6
          @target_window.index = -1
        else
          @target_window.index = 0
        end
      else
        if @item.common_event_id > 0
          $game_temp.common_event_id = @item.common_event_id
          $game_system.se_play(@item.menu_se)
          if @item.consumable
            $game_party.lose_item(@item.id, 1)
            @item_window.draw_item(@item_window.index)
          end
          $scene = Scene_Map.new
          return
        end
      end
      return
    end
  end
# ------------------------------------  
  def update_target
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      unless $game_party.item_can_use?(@item.id)
        @item_window.refresh
      end
      @item_window.active = true
      @target_window.visible = false
      @target_window.active = false
      return
    end
    if Input.trigger?(Input::C)
      if $game_party.item_number(@item.id) == 0
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      if @target_window.index == -1
        used = false
        for i in $game_party.actors
          used |= i.item_effect(@item)
        end
      end
      if @target_window.index >= 0
        target = $game_party.actors[@target_window.index]
        used = target.item_effect(@item)
      end
      if used
        $game_system.se_play(@item.menu_se)
        if @item.consumable
          $game_party.lose_item(@item.id, 1)
          @item_window.draw_item(@item_window.index)
        end
        @target_window.refresh
        if @item.common_event_id > 0
          $game_temp.common_event_id = @item.common_event_id
          $scene = Scene_Map.new
          return
        end
      end
      unless used
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end
  end
end





#==============================================================================
# â–  Window_Item
#------------------------------------------------------------------------------

class Window_Samo_Item < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 320, 300)
    @column_max = 1
    refresh
    self.index = 0
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  end
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 1...$data_items.size
      if $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end
    unless $game_temp.in_battle
      for i in 1...$data_weapons.size
        if $game_party.weapon_number(i) > 0
          @data.push($data_weapons[i])
        end
      end
      for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0
          @data.push($data_armors[i])
        end
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    
        case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      color = Color.new(60,175,0,255) 
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      color = Color.new(0,175,255,255) 
    when RPG::Armor
      number = $game_party.armor_number(item.id)
       color  =Color.new(0,95,107,255) 
     end
      case item
    when RPG::Item
    if $UNIQUE_ITEMS.include?(item.id)
    color = Color.new(164,143,121,255) 
    end
    when RPG::Weapon
    if $UNIQUE_WEAPONS.include?(item.id)
    color =  Color.new(164,143,121,255) 
    end
    when RPG::Armor
    if $UNIQUE_ARMORS.include?(item.id)
    color =  Color.new(164,143,121,255) 
    end
      end

    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = color
      @opacity = 255
    else
      self.contents.font.color = color
      @opacity = 128
    end
    x = 4 + index % 2
    y =  index / 1 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.draw_text(x + 28, y, 212, 32, item.name, @opacity)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end






#==============================================================================
# Â
 

khmp

Sponsor

The first, in the Scene_Samo_Item's initialize:
Code:
$game_switches[n] = false

At the bottom of Scene_Same_Item's main:
Code:
$game_switches[n] = true

The second, in the Scene_ConfigurationType initialize:
Code:
$game_switches[n] = false

At the bottom of Scene_ConfigurationType main:
Code:
$game_switches[n] = true

Good luck with it l0rdph0enix! :thumb:
 
Ok that helps but I guess the problem clarified itself once i did that. As you know I'm using alot of individual hud's for my interface. along with this png
http://i31.tinypic.com/o89gle.png[/img]
Well it's handled by a common even that states that if a switch is on the pic shows, and if the switch is off the pic is erased. Which you would think would work, when a script turns the switch off the pic should go away, but nope, it stays. not only does that pic stay but so do ones i use in the compass system and the hunger system.

The main reason i wanted that big pic to show was so that it would label the different huds for the user, should i just say screw it and take the label away or do you know another way i can do it. and how can I make my compass hud show one of the 4 png's i have for the compass depending on which direction the player is facing (i can convert the 4 pngs into one sprite if it's easier).

lol don't worry you've got credit in my credits and a special thanks ;)
 

khmp

Sponsor

For telling them not to show and to show use the visible flag which is a boolean in a sprite/window object that when false will not show said sprite/window. So make sure you are checking the status of the switch to determine the visibility of any number of objects you are displaying/hiding.

If your hunger, time, compass object are like this:
Code:
@hunger_hud, @time_hud, @compass_hud

You can manipulate there visible flags like this:
Code:
@hunger_hud.visible = @time_hud.visible = @compass_hud.visible = $game_switches[n]

For your compass problem I have a solution. One way you can do it is have an image to represent each one of 4 directions a standard character can be facing. But what if its 8? Do you want to load 8 images? How about two images instead? One for the background image. And one for the pointer.

We will rotate the pointer based on the player's direction. Now because RMXP doesn't do any antialiasing (edge blurring), angle makes the rotated image look like crap. So my suggestion would make the compass support transparency and have empty spots for where the pointer would be. And we'd draw the pointer underneath the compass background. The transparency of the background will allow it to be seen through it. Sometime you won't be able to cheat and will just have to eat the ugliness of Sprite.angle.

Here's the example:
http://files.filefront.com/CompassTeste ... einfo.html

Good luck with it l0rdph0enix! :thumb:

If you have any questions on it let me know.
 
And it's another GOAL!! for KHMP. Once again you're awsome, the compass test you provided was exactly what i was looking for. Cept how do I change it's location on the screen? :P I thought i did it at line 19 "    super()" but that just gives me an error when i change it to something like "    super(525, 0, 115, 94)". But other then that it works grand.
 

khmp

Sponsor

Sprite objects aren't the same as Window objects. Sprite objects take in a Viewport object in their initialize rather than dimension definitions. The Viewport is used to define where the sprite is limited to in terms of drawing. That aside. To move the compass to where you need it to go shoot down to Scene_Map.main and have a line like this:
Code:
@compass.x = x # Where x is the x coordinate where you want to move it to.
@compass.y = y # Where y is the y coordinate where you want to move it to.
 

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