The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: Rune on May 20, 2007, 11:57:09 AM

Title: Savepoint
Post by: Rune on May 20, 2007, 11:57:09 AM
Here's us a nice little script I put together :D

Spoiler for Script + Instructions:
Insert this above main and call it Scene_Savepoint
Code: [Select]
#+++++++++++++++++++++++++++++++#
#                        Savepoint Ver 1                            #
#                             By Rune                                  #
#+++++++++++++++++++++++++++++++#

# Window_Savepoint #

class Window_Savepoint < Window_Base
  def initialize
    super(0, 0, 320, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.name = "Tahoma"
    self.contents.font.size = 22
    self.contents.font.color = Color.new(0, 255, 0)
    self.contents.draw_text(100, 0, 96, 32, "Savepoint")
  end
end

# Window_Base edit #

class Window_Base
  def draw_actor_graphic(actor, x, y)
    bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
    cw = bitmap.width / 4
    ch = bitmap.height / 4
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  end
  def draw_actor_name(actor, x, y)
    self.contents.font.color = crisis_color
    self.contents.draw_text(x, y, 120, 32, actor.name)
  end
  def draw_actor_class(actor, x, y)
    self.contents.font.color = Color.new(0, 255, 0)
    self.contents.draw_text(x, y, 236, 32, actor.class_name)
  end
  def draw_actor_level(actor, x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, "Level")
    self.contents.font.color = normal_color
    self.contents.draw_text(x + 32, y, 24, 32, actor.level.to_s, 2)
  end
  def make_battler_state_text(battler, width, need_normal)
    brackets_width = self.contents.text_size("[]").width
    text = ""
    for i in battler.states
      if $data_states[i].rating >= 1
        if text == ""
          text = $data_states[i].name
        else
          new_text = text + "/" + $data_states[i].name
          text_width = self.contents.text_size(new_text).width
          if text_width > width - brackets_width
            break
          end
          text = new_text
        end
      end
    end
    if text == ""
      if need_normal
        text = "[Normal]"
      end
    else
      text = "[" + text + "]"
    end
    return text
  end
  def draw_actor_state(actor, x, y, width = 120)
    text = make_battler_state_text(actor, width, true)
    self.contents.font.color = actor.hp == 0 ? knockout_color : crisis_color
    self.contents.draw_text(x, y, width, 32, text)
  end
  def draw_actor_exp(actor, x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x - 16, y - 8, 24, 32, "Exp")
    self.contents.font.color = normal_color
    self.contents.draw_text(x - 64, y + 16, 84, 32, actor.exp_s, 2)
    self.contents.draw_text(x + 24, y + 16, 12, 32, "/", 1)
    self.contents.draw_text(x + 36, y + 16, 84, 32, actor.next_exp_s)
  end
  def draw_actor_hp(actor, x, y, width = 144)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
    if width - 32 >= 108
      hp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      hp_x = x + width - 48
      flag = false
    end
    self.contents.font.color = actor.hp == 0 ? knockout_color :
      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
    self.contents.draw_text(hp_x - 44, y + 16, 48, 32, actor.hp.to_s, 2)
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(hp_x + 4, y + 16, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 16, y + 16, 48, 32, actor.maxhp.to_s)
    end
  end
  def draw_actor_sp(actor, x, y, width = 144)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
    if width - 32 >= 108
      sp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      sp_x = x + width - 48
      flag = false
    end
    self.contents.font.color = actor.sp == 0 ? knockout_color :
      actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    self.contents.draw_text(sp_x - 44, y + 16, 48, 32, actor.sp.to_s, 2)
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(sp_x + 4, y + 16, 12, 32, "/", 1)
      self.contents.draw_text(sp_x + 16, y + 16, 48, 32, actor.maxsp.to_s)
    end
  end
end

# Window_MenuStatus edit #

class Window_MenuStatus
  def initialize
    super(0, 0, 640, 240)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = $defaultfontsize
    refresh
    self.active = false
    self.index = -1
  end
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      x = i * 160
      y = 116
      actor = $game_party.actors[i]
      draw_actor_graphic(actor, x + 16, y - 60)
      draw_actor_name(actor, x + 32, y - 120)
      draw_actor_class(actor, x + 32, y - 80)
      draw_actor_level(actor, x + 32, y - 100)
      draw_actor_state(actor, x + 16, y - 60)
      draw_actor_exp(actor, x + 16, y + 50)
      draw_actor_hp(actor, x, y - 40)
      draw_actor_sp(actor, x, y)
    end
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(@index * 160, 0, 128, self.height - 32)
    end
  end
end

# Window_HealCost #

class Window_HealCost < Window_Base
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    @price = $game_variables[!!!!]
    self.contents.clear
    self.contents.font.name = "Tahoma"
    self.contents.font.color = system_color
    self.contents.font.size = 22
    self.contents.draw_text(0, 0, 128, 32, "Heal Cost:  ")
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 32, 128, 32, @price.to_s, 1)
    self.contents.font.color = system_color
    self.contents.draw_text(86, 32, 128, 32, $data_system.words.gold)
  end
end

#    Actual Scene    #
# Scene_Savepoint #

class Scene_Savepoint
  def initialize(sav_index = 0)
    @sav_index = sav_index
    @price = $game_variables[!!!!]
  end
  def main
    @spriteset = Spriteset_Map.new
    s1 = "Cancel"
    s2 = "Save"
    s3 = "Heal"
    @command_window = Window_Command.new(320, [s1, s2, s3], 3)
    @command_window.index = @sav_index
    @command_window.x = 160
    @command_window.y = 176
    if $game_party.actors.size == 0
      @command_window.disable_item(1)
      @command_window.disable_item(2)
    end
    @steps_window = Window_Steps.new
    @steps_window.x = 480
    @steps_window.y = 144
    @status_window = Window_MenuStatus.new
    @status_window.x = 0
    @status_window.y = 240
    @gold_window = Window_Gold.new
    @gold_window.x = 480
    @gold_window.y = 0
    @heal_window = Window_HealCost.new
    @heal_window.x = 0
    @heal_window.y = 144
    @savpnt_window = Window_Savepoint.new
    @savpnt_window.x = 160
    @savpnt_window.y = 112
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @spriteset.dispose
    @command_window.dispose
    @steps_window.dispose
    @status_window.dispose
    @gold_window.dispose
    @heal_window.dispose
    @savpnt_window.dispose
  end
  def refresh_options
    if @price > $game_party.gold
      @command_window.disable_item(2)
    end
  end
  def update
    @spriteset.update
    @command_window.update
    @steps_window.update
    @status_window.update
    @gold_window.update
    @heal_window.update
    @savpnt_window.update
    if @command_window.active
      update_command
      return
    end
    if @status_window.active
      update_status
      return
    end
  end
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(4)
      return
    end
    if Input.trigger?(Input::C)
      if $game_party.actors.size == 0 and @command_window.index < 4
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      case @command_window.index
      when 0
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Menu.new(4)
      when 1
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Save.new
      when 2
        if @price > $game_party.gold
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        Audio.se_play("Audio/SE/107-Heal03")
        $game_party.lose_gold($game_variables[!!!!])
        refresh_options
        @status_window.refresh
        @status_window.update
        for actor in $game_party.actors
          actor.recover_all
        end
      end
    end
  end
end

Instructions:
    Make a variable and call it Heal Cost or something similar... you can change the value of this at different points in the game if you like
    Ctrl + f to find !!!!
    Change !!!! to the number of whatever variable you set as your heal cost...
    Have fun ;8
[EDIT]
    To call, use this in a call script event.
Code: [Select]
$scene = Scene_Savepoint.new


Spoiler for Screeny:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi163.photobucket.com%2Falbums%2Ft302%2Fpsychomathic-paniac%2Fsavepointscreeny.jpg&hash=0ead6a43b0e3ff47c69e69cd6afe94f1e9cbc515)

This script goes well with this script (http://rmrk.net/index.php/topic,17374.0.html)
Title: Re: Savepoint
Post by: Kokowam on May 20, 2007, 12:17:24 PM
Wow, that seems pretty cool! Also, there's 3 "!!!!"s so... don't forget the other two and reply with "it's not working" or something. XP
Title: Re: Savepoint
Post by: Rune on May 20, 2007, 12:23:16 PM
Thanks ;8
If anyone has any queries i'm right here ;8
Title: Re: Savepoint
Post by: Esmeralda on May 20, 2007, 12:34:07 PM
Can you make the Savepoint text another color?
Title: Re: Savepoint
Post by: Falcon on May 20, 2007, 12:38:36 PM
Cool, but kind of useless since you don't need a script to make a savepoint.
Title: Re: Savepoint
Post by: Esmeralda on May 20, 2007, 12:39:25 PM
But you could use it as a special savepoint. I think of a hospital.
Title: Re: Savepoint
Post by: Falcon on May 20, 2007, 12:42:05 PM
Ferenn, edit the line in bold to change the savepoint color:

  def refresh
    self.contents.clear
    self.contents.font.name = "Tahoma"
    self.contents.font.size = 22
    self.contents.font.color = Color.new(0, 255, 0)
    self.contents.draw_text(100, 0, 96, 32, "Savepoint")
  end
end

Just edit the variables in the () to change the color. Additionally, if you have Trickster's MACL, you could use Color.red, etc.
Title: Re: Savepoint
Post by: Esmeralda on May 20, 2007, 12:43:21 PM
Ah, thanks.  ;8

Though it was a detail, I'm glad for the help.
Title: Re: Savepoint
Post by: Rune on May 20, 2007, 12:52:21 PM
Cool, but kind of useless since you don't need a script to make a savepoint.

Some people like fancy savepoints :P
Title: Re: Savepoint
Post by: Esmeralda on May 20, 2007, 01:06:54 PM
How do I call it?  :tpg:
Title: Re: Savepoint
Post by: Rune on May 20, 2007, 01:15:58 PM
Argh! >.< I knew there was someting I was forgetting...

Use this
Code: [Select]
$scene = Scene_Savepoint.new

[EDIT]
First post edited
Title: Re: Savepoint
Post by: Esmeralda on May 20, 2007, 01:19:31 PM
I get an error saying

Script 'RuneSave' line 199: Argument Error Occured

wrong number of arguments(3 for 2)

 :tpg:
Title: Re: Savepoint
Post by: Rune on May 20, 2007, 01:22:58 PM
RuneSave?
Title: Re: Savepoint
Post by: Esmeralda on May 20, 2007, 01:24:26 PM
That's the script name. ;8
Title: Re: Savepoint
Post by: Rune on May 20, 2007, 01:30:56 PM
Put this before the Scene itself...
Spoiler for:
Code: [Select]
class Window_Command < Window_Selectable
  def initialize(width, commands, column_max = 1, style = 0, inf_scroll = 1)
    super(0, 0, width, (commands.size * 1.0 / column_max).ceil * 32 + 32)
    @inf_scroll = inf_scroll
    @item_max = commands.size
    @commands = commands
    @column_max = column_max
    @style = style
    self.contents = Bitmap.new(width - 32, (@item_max * 1.0 / @column_max).ceil * 32)
    self.contents.font.name = "Tahoma"
    self.contents.font.size = 22
    refresh
    self.index = 0
  end
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(index%@column_max * (self.width / @column_max) + 4, 32 * (index/@column_max), self.width / @column_max - 40, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index], @style)
  end
  def disable_item(index)
    draw_item(index, disabled_color)
  end
  def update_help
    @help_window.set_actor($game_party.actors[$scene.actor_index])
  end
end

That scriptlet's in the script mentioned in my first post
This script goes well with this script (http://rmrk.net/index.php/topic,17374.0.html)
So either add that scriptlet or get the mentioned script
Title: Re: Savepoint
Post by: :) on May 20, 2007, 01:33:00 PM
Me likely. :D
Title: Re: Savepoint
Post by: Esmeralda on May 20, 2007, 01:36:05 PM
Now it's working  ;8
Title: Re: Savepoint
Post by: Rune on May 20, 2007, 01:36:39 PM
Me likely. :D

 :tpg: Thanks :tpg:
Script Database ahoy!! ;8

Now it's working  ;8

Glad to be of assistanceing... ness... whatever ;8
Title: Re: Savepoint
Post by: Rune on May 26, 2007, 07:30:04 PM
Thought this might need a little bump...

Spoiler for:
If this wasn't needed, shoot me
Title: Re: Savepoint
Post by: Falcon on May 26, 2007, 07:39:45 PM
Why would you bump a topic that's been inactive for not even a week? On top of that it's in the database. You don't see all the other scripters bumping our topics.
Title: Re: Savepoint
Post by: Rune on May 26, 2007, 07:46:51 PM
True...
Seems like ages since I posted this though...
Title: Re: Savepoint
Post by: hero_kenshi on August 20, 2007, 05:50:50 AM
dude nice script... im learning c#
anywho....
umm is there a way i can take out the heal party and just have the save,  but when you save it auto heals? 

P.s gotta love the bean  :bean:
Title: Re: Savepoint
Post by: Rune on August 24, 2007, 09:56:17 PM
Um... hold on... haven't touched scripting in ages...

Right!

Take out
Code: [Select]
s3 = "Heal"
And then take out the s3 in the line beneath it and change the end 3 to a 2.

Take out
Code: [Select]
when 2
        if @price > $game_party.gold
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        Audio.se_play("Audio/SE/107-Heal03")
        $game_party.lose_gold($game_variables[!!!!])
        refresh_options
        @status_window.refresh
        @status_window.update
        for actor in $game_party.actors
          actor.recover_all
        end

After where it says
Code: [Select]
$scene = Scene_Save.new
add
Code: [Select]
        for actor in $game_party.actors
          actor.recover_all
        end

This hasn't been tested yet, so say if you have any problems ;)
Title: Re: Savepoint
Post by: Demonic Blade on December 18, 2007, 05:05:40 PM
 ??? Is it possible to not heal at all (It'd be cheating in most games to just exit and enter again to heal yourself...)?
Title: Re: Savepoint
Post by: modern algebra on December 20, 2007, 07:11:42 PM
Umm, he explains that in the post above. Take out everything he says and then don't add anything.
Title: Re: Savepoint
Post by: Demonic Blade on December 20, 2007, 08:15:40 PM
Umm, he explains that in the post above. Take out everything he says and then don't add anything.

 :-[, umm... THAT was kinda stupid of me... well thx anyway, didn't think of that... hehe  ::) :-[ :lol:
Title: Re: Savepoint
Post by: Demonic Blade on December 22, 2007, 09:54:53 AM
I keep getting this error message even though I have both of those things in the quote:
"????? 'Save_Point' ? 176 ?? NameError ????????
Undefined local variable or method `s3' for # <Scene_Savepoint:0x4638db0>"
Please help me, I only took away the ability to heal.

Put this before the Scene itself...
Spoiler for:
Code: [Select]
class Window_Command < Window_Selectable
  def initialize(width, commands, column_max = 1, style = 0, inf_scroll = 1)
    super(0, 0, width, (commands.size * 1.0 / column_max).ceil * 32 + 32)
    @inf_scroll = inf_scroll
    @item_max = commands.size
    @commands = commands
    @column_max = column_max
    @style = style
    self.contents = Bitmap.new(width - 32, (@item_max * 1.0 / @column_max).ceil * 32)
    self.contents.font.name = "Tahoma"
    self.contents.font.size = 22
    refresh
    self.index = 0
  end
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(index%@column_max * (self.width / @column_max) + 4, 32 * (index/@column_max), self.width / @column_max - 40, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index], @style)
  end
  def disable_item(index)
    draw_item(index, disabled_color)
  end
  def update_help
    @help_window.set_actor($game_party.actors[$scene.actor_index])
  end
end

That scriptlet's in the script mentioned in my first post
This script goes well with this script (http://rmrk.net/index.php/topic,17374.0.html)
So either add that scriptlet or get the mentioned script
Title: Re: Savepoint
Post by: modern algebra on December 23, 2007, 01:36:32 AM
Ah, I think that was an oversight in his previous description. I have not looked at it, but I imagine that the line giving the error has the phrase:

Window_Command.new (x, [s1, s2, s3]), where x is some number. Just deleted the ", s3" part of it.
Title: Re: Savepoint
Post by: Demonic Blade on December 23, 2007, 08:38:05 AM
Sry, forget it... just realized I deleted it, because sth else was wrong with the scripting (another standard script), and I had to start over my game... I'll put it into my new version (3rd) of the game... I'll edit this post when/if the problem occurs again...
Title: Re: Savepoint
Post by: Rune on December 30, 2007, 10:15:09 PM
Just so you all know, i'm alive. I've just been rather busy is all.

@D B - Sorry to hear that matey :( all apologies if any part of it was my fault
Title: Re: Savepoint
Post by: Demonic Blade on December 31, 2007, 02:36:38 PM
No no, that isn't your fault. It's just that I like to personalize my game with a bunch of script to make it really original, and well, doing that can be fatal. I've become wiser though. Now I first test the scripts in Test Games I make... ;)
Title: Re: Savepoint
Post by: Wlachen on May 21, 2009, 11:29:29 PM
sry but im a noob...ummm where do u put that $cene thing
Title: Re: Savepoint
Post by: Rune on May 22, 2009, 04:13:39 PM
From an event: In the event you wish to call the Savepoint from, make a Call Script and shove it in there.

From the menu: It would need another option to be created.

PM me if you want it to be accessible from the menu and send me the menu system you're using so I can alter it and get back to you.
Title: Re: Savepoint
Post by: vacancydenied on July 27, 2009, 03:36:02 PM
How would I go about making it so the healing price varies depending on how much hp is lost. I haven't tested the script yet but I was wondering if it's possible to do something like Shin Megami Tensei where you pay per character to heal. I just pretty much repeated myself but I would love this script even more if I could get that to happen.

Whether or not it's possible I want to thank you for the script. =)

Edit: I tried it out and I keep getting this error.