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.

Special Support - A great place to learn to Script

Everyone wants to learn to script, but no one really knows where to start. In my honest opinion, the best place to learn is just by reading the default scripts. I learned to script with the japanese RMXP, so I didn't have English comments at my disposal, so everyone of the new generation has that upperhand. Anyways, what I think the best thing to do to learn to script is read the default scripts, and understand each line.

So what I am offering here is support for anyone trying to learn to script. If there is a line of code you don't understand, ask me here. If there is something you want to know, like where in the script editor does something happen, ask here.
  • Ask about a certain line of code : What it means, does, etc.
  • Ask where the coding is for a certain function
PLEASE DO NOT ASK SOMETHING OTHER THAN EXISTING CODE, OR WHERE IN THE DEFAULT SCRIPTS TO FIND A CERTAIN BLOCK OF CODE. Your post will be deleted.

This is a Trial and Error topic. Hopefully, it can lead to more a use full FAQ for beginners.
 
Hm... is there a function of Window_Selectable or Window_Command or whatever that disables a choice? Like turning off a choice in a window. Specifically, what I want to do is make the player unable to select that 'empty space' in the equipment select screen, so he must be always equipping something. I figured there is an 'enabled' flag that I just need to turn off, only I can't find out how.
 
There is a "disable_item" method in Window_Command, but all it does is draw the item 'greyed out'. You have to handle the disabled item in the update method of the scene. Look at Scene_Menu, line 152 for Save.

If the user selects the empty spot, you just want the window to do nothing. (not return the empty weapon back to the 'right' window)

What if we modify the update_item method of Scene_Equip... my comments in ##

Code:
 

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Get currently selected data on the item window  ## do this first so we can test it

      item = @item_window.item

      ## If the item is nil, just return without doing anything. (play the buzzer so the player know he's doing something wrong)

      if item == nil

        # Play buzzer SE

        $game_system.se_play($data_system.buzzer_se)

        return

      end

      ## otherwise... continue as normal and swap out the equipment.

      # Play equip SE

      $game_system.se_play($data_system.equip_se)

      # Change equipment

      ##  the conditional statement is no longer necessary, as item will never be nil. but it doesn't need to be changed

      @actor.equip(@right_window.index, item == nil ? 0 : item.id)

      # Activate right window

      @right_window.active = true

      @item_window.active = false

      @item_window.index = -1

      # Remake right window and item window contents

      @right_window.refresh

      @item_window.refresh

      return

    end

 
 

cairn

Member

Hello there everyone. I was screwing around a bit with script commands looking at the help file that comes with rmxp and decided to try to change the attributes of a spell in the middle of an event. I checked around the file, some of the scripts, and got to the variable. I got to the following peace of code:

Code:
$data_skills[1] = [1, "Heal", "9-Magic17", "Heal all allies", 4, 0, 2, 15, "105-Heal01", 0, 0, -150, 0, 0, 0, 0, 0, 50, 100, 0, 100, 15, [], [], []]
.

A strange thing though, is that I am getting an error on the default script, Window_Skill, on line 71, its says that icon_name is an undefined method.

I know that its possible to screw around somethings that you set on the database on mid game because I managed to change the usable weapons and armors of a certain class.
That's about it, hopefully someone could give me some clarifications on this matter.
 
The skills aren't arrays, they are RPG::Skill objects.
Instead of this..
[rgss]$data_skills[1] = [1, "Heal", "9-Magic17", etc...]
[/rgss]
...it should be like this:
[rgss]$data_skills[1] = RPG::Skill.new
$data_skills[1].id = 1
$data_skills[1].name = "Heal"
$data_skills[1].icon_name = "9-Magic17"
# Etc...
[/rgss]

The same happens for any other "RPG::" class, except for RPG::Cache (it's not for Database objects).

If more people tried to figure how things works like you did we would have much more programmers around. :) Keep it up, sounds like you'll be a very good scripter someday. ^^
SEE YA!!!!!
 

cairn

Member

wow man, thanks O.O. Regardless of the small time I have, I'm trying my best to get the way that RGSS works since I started with RMXP, and only now I'm noticing how it works. Thanks for the help dude! :thumb:
 
I'm looking for a way to make it so when you equip a new weapon it changes your Char's graphic. Basicly what i'm trying to do is make it so when you dont have a weapon equiped you'r char's graphic is normal but when you equip a sword it changes to the graphic of that char to one holding a sword etc
 
@FF12_Master:
In that case, you should check the "Game_Battler 3" script, that contains a bunch of functions concerning the damage calculations.

@mrslayer:
You'll need to edit the "Sprite_Character" script. On RMXP, you'll have to bump some new code into the update() method. On RMVX this is done on update_bitmap() method -- although the changes will be basically the same.
For checking the character's currently equipped weapon, you'll use the @character variable, that points to the Game_Actor object of the character.


SEE YA!!!!!
 
Code:
class Game_System

  attr_accessor :font                    # font

  attr_accessor :size                    # size

  alias re_init initialize

  def initialize

    @font = "Arial"

    @size = 20

    re_init

  end

end

 

class Font

  alias change_font initialize

  def initialize

    change_font

    self.name = $game_system.font

    self.size = $game_system.size

  end

end

I need to know if this is setup right. It does indeed change the font but I want it where I can use $game_system.font = "Font here" but everytime I use it it never works. Can someone help please?

@kiralim: Check in Scene_File for save_windows.x or .y I think :P

EDIT: @kiralim: use this in Scene_File under line 29
Code:
 

@savefile_windows.x = whatever

@savefile_windows.y = whatever

 
 
My question is how do the Input.Triggers work? I read the Script Support topic on changing the directional buttons to WASD, but I didn't really understand it. I know the code for the Input.Triggers (for the directional buttons only) exist in the Game_Player page, but I don't know where the rest are (Action, Cancel, etc. buttons) or how to change them.
~ShadowofUndine
 
gameguy27":39p6e9rs said:
@kiralim: Check in Scene_File for save_windows.x or .y I think :P

EDIT: @kiralim: use this in Scene_File under line 29
Code:
 

@savefile_windows.x = whatever

@savefile_windows.y = whatever

 
Hey gameguy27, thanks for offering help. But nothing changed. Also if it helps, I'm using Moghunter's Scene_File:
Code:
#_______________________________________________________________________________

# MOG Scene File Ayumi V1.0           

#_______________________________________________________________________________

# By Moghunter          

#_______________________________________________________________________________

if true # True = Enable / False = Disable (Script)

module MOG

#Transition Time. 

MSVT = 0

#Transition Type. 

MSVTT = "006-Stripe02"

end

$mogscript = {} if $mogscript == nil

$mogscript["menu_ayumi"] = true

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

# Window_Base #

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

class Window_Base < Window

def drw_win_file(x,y)

dwf = RPG::Cache.picture("something")

cw = dwf.width 

ch = dwf.height 

src_rect = Rect.new(0, 0, cw, ch)

self.contents.blt(x , y - ch, dwf, src_rect)    

end   

def nada

face = RPG::Cache.picture("")

end  

def draw_heroface3(actor,x,y)

face = RPG::Cache.picture(actor.name + "_fc3") rescue nada

cw = face.width 

ch = face.height 

src_rect = Rect.new(0, 0, cw, ch)

self.contents.blt(x , y - ch, face, src_rect)    

end  

def draw_actor_level6(actor, x, y)

self.contents.font.color = Color.new(255,131,31,255)

self.contents.draw_text(x + 1, y + 1, 32, 32, "LV")  

self.contents.font.color = Color.new(255,131,31,255)

self.contents.draw_text(x, y, 32, 32, "LV")

self.contents.font.color = Color.new(255,131,31,255)

self.contents.draw_text(x + 17, y + 1, 24, 32, actor.level.to_s, 2)

self.contents.font.color = Color.new(255,131,31,255)

self.contents.draw_text(x + 16, y, 24, 32, actor.level.to_s, 2)

end

def draw_actor_name6(actor, x, y)

self.contents.font.color = Color.new(255,131,31,255)

self.contents.draw_text(x + 1, y + 1, 100, 32, actor.name,1)  

self.contents.font.color = Color.new(255,131,31,255)

self.contents.draw_text(x, y, 100, 32, actor.name,1)

end

end

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

# Game_Map #

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

class Game_Map

def map_name

@mapinfo = load_data("Data/MapInfos.rxdata") if @mapinfo == nil

return @mapinfo[@map_id].name

end

end

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

# Window_SaveFile #

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

class Window_SaveFile < Window_Base

  attr_reader   :filename                

  attr_reader   :selected                

  def initialize(file_index, filename)

    super(0, 64 + file_index * 138, 640, 240)    

    self.contents = Bitmap.new(width - 32, height - 32)  

    self.opacity = 0

    @file_index = file_index

    @filename = "Save#{@file_index + 1}.rxdata"

    @time_stamp = Time.at(0)

    @file_exist = FileTest.exist?(@filename)

    if @file_exist

      file = File.open(@filename, "r")

      @time_stamp = file.mtime

      @characters = Marshal.load(file)

      @frame_count = Marshal.load(file)

      @game_system = Marshal.load(file)

      @game_switches = Marshal.load(file)

      @game_variables = Marshal.load(file)

      @game_self_switches = Marshal.load(file)

      @game_screen = Marshal.load(file)

      @game_actors = Marshal.load(file)

      @game_party = Marshal.load(file)

      @game_troop = Marshal.load(file)

      @game_map = Marshal.load(file)

      @total_sec = @frame_count / Graphics.frame_rate

      file.close 

    end

    @wiref = 0

    refresh

    @selected = false

  end  

  def refresh

    self.contents.clear

    self.contents.font.name = "techno overload BRK"

    drw_win_file(0,190)

    name = "#{@file_index + 1}"

    self.contents.font.color = Color.new(0,0,0,255)

    self.contents.draw_text(55, 75, 600, 32, name)

    self.contents.font.color = Color.new(255,131,31,255)

    self.contents.draw_text(55, 75, 600, 32, name)    

    @name_width = contents.text_size(name).width

    if @file_exist

      for i in [email=0...@characters.size]0...@characters.size[/email]

        #bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])

        #cw = bitmap.rect.width / 4

        #ch = bitmap.rect.height / 4

        #src_rect = Rect.new(cw * @wiref + 1 , 0, cw, ch)

        #x = 300 - @characters.size + i * 64 - cw / 4

        #self.contents.blt(x - 10, 150 - ch, bitmap, src_rect)

        #x = 116

        actors = @game_party.actors

        for i in 0...[actors.size, 4].min

        x     = i * 60

        actor = actors[i]        

        self.contents.font.size = 20

        draw_actor_level6(actor, x + 156, 57)

        actor = actors[0]     

        draw_heroface3(actor,300, 122)    

        #draw_actor_name6(actor, 160, 155)

        self.contents.font.size = 22

        end          

      end      

      hour = @total_sec / 60 / 60

      min = @total_sec / 60 % 60

      sec = @total_sec % 60

      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)

      self.contents.font.color = Color.new(0,0,0,255)

      self.contents.draw_text(5, 57, 550, 32, time_string, 2)

      self.contents.draw_text(156 , 90, 300, 32, @game_map.map_name.to_s)

      self.contents.font.color = Color.new(255,131,31,255)

      self.contents.draw_text(156 , 90, 300, 32, @game_map.map_name.to_s)  

      self.contents.draw_text(4, 57, 550, 32, time_string, 2)   

   end

  end

  def selected=(selected)

    @selected = selected

  end

end

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

# Scene_File #

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

class Scene_File

  def initialize(help_text)

    @help_text = help_text

  end

  def main

    @mnback = Plane.new

    @mnback.bitmap = RPG::Cache.picture("MN_BK3")

    @mnback.opacity = 100

    @mnback.z = 0

    @mnlay = Sprite.new

    @mnlay.bitmap = RPG::Cache.picture("Lay_File.PNG")

    @mnlay.z = 2

    @help_window = Window_Help.new

    @help_window.set_text(@help_text)

    @help_window.opacity = 0

    @savefile_windows = []

    for i in 0..2

      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))

    end

    @savefile_windows[0]

    @file_index = $game_temp.last_file_index

    @savefile_windows[@file_index].selected = true

    @savefile_windows[0].y = 40    

    @savefile_windows[1].y= 105

    @savefile_windows[2].y= 170    

    @win_move_time = 0

    @win_move = 0

    @win_dire = 0

    @win_opac = 255

    @win1_y = 0

    @win2_y = 0

    @win3_y = 0

    Graphics.transition(MOG::MSVT, "Graphics/Transitions/" + MOG::MSVTT)

    loop do

      Graphics.update

      Input.update

      update

      if $scene != self

        break

      end

    end

    for i in 0..50

    @mnback.ox += 1

    @savefile_windows[0].x += 10    

    @savefile_windows[1].x -= 10

    @savefile_windows[2].x += 10

    for i in @savefile_windows

    i.contents_opacity -= 5

    end  

    Graphics.update  

    end      

    Graphics.freeze

    @help_window.dispose

    @mnback.dispose

    @mnlay.dispose

    for i in @savefile_windows

      i.dispose

    end

  end

  def update

    @mnback.ox += 1

    @win_opac += 3

    @win_move_time += 1    

    if @win_opac > 255

       @win_opac = 255

    end         

    if @win_move_time > 60

    @win_dire += 1

    @win_move_time = 0    

    end

    if @win_dire > 1

       @win_dire = 0

    end

    if @win_dire == 0

       @win_move += 0

    else   

       @win_move -= 0

    end         

    if @file_index == 0

    @savefile_windows[0].z = 2  

    @savefile_windows[1].z = 1 

    @savefile_windows[2].z = 0   

    @savefile_windows[0].x = @win_move 

    @savefile_windows[1].x = 0 

    @savefile_windows[1].x= 0

    @savefile_windows[2].x = 0    

    @savefile_windows[0].contents_opacity = @win_opac

    @savefile_windows[1].contents_opacity = 200

    @savefile_windows[2].contents_opacity =  200    

    elsif @file_index == 1

    @savefile_windows[0].z = 1  

    @savefile_windows[1].z = 2 

    @savefile_windows[2].z = 1    

    @savefile_windows[0].x = 0 

    @savefile_windows[1].x = @win_move 

    @savefile_windows[2].x = 0     

    @savefile_windows[0].contents_opacity =  200

    @savefile_windows[1].contents_opacity = @win_opac

    @savefile_windows[2].contents_opacity =  200

    else

    @savefile_windows[0].z = 0  

    @savefile_windows[1].z = 1 

    @savefile_windows[2].z = 2       

    @savefile_windows[0].x = 0 

    @savefile_windows[1].x = 0 

    @savefile_windows[2].x = @win_move  

    @savefile_windows[0].contents_opacity = 200

    @savefile_windows[1].contents_opacity = 200

    @savefile_windows[2].contents_opacity = @win_opac    

    end    

    @help_window.update    

    for i in @savefile_windows

      i.update

    end

    if Input.trigger?(Input::C)

      on_decision(make_filename(@file_index))

      $game_temp.last_file_index = @file_index

      return

    end

    if Input.trigger?(Input::B)

      on_cancel

      return

    end

    if Input.repeat?(Input::DOWN)

      if Input.trigger?(Input::DOWN) or @file_index < 3

        $game_system.se_play($data_system.cursor_se)

        @savefile_windows[@file_index].selected = false

        @file_index = (@file_index + 1) % 3

        @savefile_windows[@file_index].selected = true

        return

      end

    end

    if Input.repeat?(Input::UP)

      if Input.trigger?(Input::UP) or @file_index > 0

        $game_system.se_play($data_system.cursor_se)

        @savefile_windows[@file_index].selected = false

        @file_index = (@file_index - 1) % 3

        @savefile_windows[@file_index].selected = true

        return

      end

    end

  end

  def make_filename(file_index)

    return "Save#{file_index + 1}.rxdata"

  end

end

end
 
ShadowofUndine":a0a9tiyj said:
My question is how do the Input.Triggers work? I read the Script Support topic on changing the directional buttons to WASD, but I didn't really understand it. I know the code for the Input.Triggers (for the directional buttons only) exist in the Game_Player page, but I don't know where the rest are (Action, Cancel, etc. buttons) or how to change them.
~ShadowofUndine

First of all you'll need a Fulll Keyboard Support Script. RMXP Doesnt support the whole keyboard right away.

Now to change the action and cancel key you'd have to change alot of scripts.
In Scene_Map line 123
Code:
if Input.trigger?(Input::B)
Change the B in it. But I recommend Using Blizzard's Tons of Addons. It has a custom controls which also provides the whole keyboard. If you use his than replace line 123 with
Code:
if Input.trigger?(Input::Key['W'])

Now Scene_Title and the rest just search for either
Code:
Input.trigger?(Input::B)
or
Code:
Input.trigger?(Input::C)

Change all of those in all of the Scenes. There are also more Inputs than that as well in some of the Scenes.
 

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