The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on February 20, 2008, 05:42:29 AM

Title: Gameover -> Common Event
Post by: modern algebra on February 20, 2008, 05:42:29 AM
Gameover -> Common Event
Version: 1.0
Author: modern algebra
Date: February 20th, 2008


Description


Requested by zzzdude, I figured I would post it in case anyone else wanted it. Instead of calling up the GameOver scene when you die in battle, it calls a common event you specify. This can be used for an epilogue, or any kind of evented Game Over cutscene. Bear in mind that you do have to call the Game Over screen at the end, or else arrange an alternate game over. You will need to set everything in the common event. The script does not do anything a regular Game Over scene does.

Paste it into it's own script page in the editor, just above main.

Features


Instructions

Just paste this code above main. Then, go down to line 6 and set @gameover_ce_id to the ID of the common event you want to use as the common event it calls when you hit gameover. This only works for game overs in battle. If you leave it as 0, then it will game over as default. If you ever want to change what common event is called during the game or to set it back to default, just use a call script like this:

$game_system.gameover_ce_id = <new common event ID>

Script


Code: [Select]
class Game_System
  attr_accessor :gameover_ce_id
  alias modalg_gameover_to_common_event_init initialize
  def initialize
    modalg_gameover_to_common_event_init
    @gameover_ce_id = 0 # Default Common Event ID
  end
end

class Scene_Battle
  alias modern_algebra_gameover_common_event_call call_gameover
  def call_gameover
    if $game_system.gameover_ce_id != 0
      $game_party.clear_actions
      $game_party.remove_states_battle
      $game_troop.clear
      if $game_temp.battle_proc != nil
        $game_temp.battle_proc.call (2)
        $game_temp.battle_proc = nil
      end
      unless $BTEST
        $game_temp.map_bgm.play
        $game_temp.map_bgs.play
      end
      $scene = Scene_Map.new
      @message_window.clear
      Graphics.fadeout(30)
      $game_temp.common_event_id = $game_system.gameover_ce_id
      $scene = Scene_Map.new
    else
      modern_algebra_gameover_common_event_call
    end
  end
end



Credit


No credit is necessary for such a simple script, but it was written by me

Support


Please post your questions here if you run into problems

Author's Notes


This, when I made it for RMXP, was just released as a scriptlet. But, I figure I will test releasing them independently to see what happens. Once the VX database gets more scripts I will probably merge them all back into the Useful Scriptlets topic. It has a few changes from the XP version. Mainly it overwrites the call_gameover method and throws in a few safety features.


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
Title: Re: Gameover -> Common Event
Post by: GasparXR on February 23, 2008, 06:13:02 PM
Is there a way to call script to set the ID to a different Comment Event? Otherwise I could just use Confitional Branches to call a seperate event... I know it seems like a stupid question to me...
Title: Re: Gameover -> Common Event
Post by: modern algebra on February 23, 2008, 11:05:23 PM
Here, try this I guess::

Code: [Select]
class Game_System
  attr_accessor :gameover_ce_id
  alias modalg_gameover_to_common_event_init initialize
  def initialize
    modalg_gameover_to_common_event_init
    @gameover_ce_id = 0 # Default Common Event ID
  end
end

class Scene_Battle
  alias modern_algebra_gameover_common_event_call call_gameover
  def call_gameover
    if $game_system.gameover_ce_id != 0
      $game_party.clear_actions
      $game_party.remove_states_battle
      $game_troop.clear
      if $game_temp.battle_proc != nil
        $game_temp.battle_proc.call (2)
        $game_temp.battle_proc = nil
      end
      unless $BTEST
        $game_temp.map_bgm.play
        $game_temp.map_bgs.play
      end
      $scene = Scene_Map.new
      @message_window.clear
      Graphics.fadeout(30)
      $game_temp.common_event_id = $game_system.gameover_ce_id
      $scene = Scene_Map.new
    else
      modern_algebra_gameover_common_event_call
    end
  end
end


I just added some code. It ought to work but I might have made some kind of error. Just post if you encounter problems.

To change the ID, use the code:

Code: [Select]
$game_system.gameover_ce_id = value
Title: Re: Gameover -> Common Event
Post by: GasparXR on February 24, 2008, 12:06:12 AM
Okay, thanks!
Title: Re: Gameover -> Common Event
Post by: maia on October 06, 2009, 09:05:53 PM
This script did not work for me unfortunately I keep getting errors here:

    if $game_temp.common_event_id > 0
      setup($data_common_events[$game_temp.common_event_id].list)
      $game_temp.common_event_id = 0
      return
    end
Title: Re: Gameover -> Common Event
Post by: modern algebra on October 06, 2009, 09:27:34 PM
Hmm, that's strange. What does the error say exactly? Also, have you set the line in this script:


Code: [Select]
   @gameover_ce_id = 0 # Default Common Event ID

to be some number greater than the maximum number of common events in your game? That would likely cause the problem.


This script needs to be updated with recognition of other methods of automatic death.
Title: Re: Gameover -> Common Event
Post by: Raphie123 on October 15, 2009, 05:04:22 AM
Unfortunatly, your script doesn't work with Vampyr SBABS :( I tried it but I still go on the title screen when I die. I guess it's because SBABS script overwrite (or whatever it's called) the gameover script... Anyway, if there's a way to fix it, it would be very appreciated if you could help me. If not, it's not too bad, I'll find a way to avoid Game Over :P

Thank you :)

Raphie123
Title: Re: Gameover -> Common Event
Post by: Sebastian Cool ^-^ on November 10, 2009, 11:05:03 AM
Guy!! You know me to impress!! Algebra!!

Look at this!!
i'm an idiot!!
Title: Re: Gameover -> Common Event
Post by: selavy_rrose on April 22, 2010, 07:09:00 PM
Hello again,
I did try this script on a totally new project that I only started to check if the script works, and yes, it worked.
That made me wonder, what's wrong with my game. Then I did copy all the scripts back from the clean project, I did copy the graphics and all from my project to the clean project, and it didn't work, I think it must be a switch that interferes with it. Now it gives me this error:
Script 'Game_Interpreter' line 77: NoMethodError occured.
undefined method '>' for nil:NilClass

What can I do that it will work?
Title: Re: Gameover -> Common Event
Post by: modern algebra on April 22, 2010, 08:07:09 PM
It might be another script that's interfering, particularly if that other script overwrites the initialize method of Game_System.

Have you tried putting this script below any other custom scripts you might be using, but still above Main?
Title: Re: Gameover -> Common Event
Post by: selavy_rrose on April 22, 2010, 10:25:50 PM
Thank you,
all the scripts I've been changing were in Script editor and not custom scripts, thats why, to check it, I had to revert to originals by copying them from a clean new project, but it didn't change anything, that's why I think its a switch, or maybe a variable set in the game?
I did change battle backgrounds, main font and line spacing by fiddling with script editor, and graphics of course, but graphics are easier for me, and photoshop is very handy :)
Actually now thinking about it the only other custom script is the default font 2 lines in Materials. Still don't know how to change a font in a single event though, I have tried.
Title: Re: Gameover -> Common Event
Post by: modern algebra on April 22, 2010, 10:38:28 PM
It's definitely not a variable or switch.

Hmm, well in the script, try replacing:

Code: [Select]
  def initialize
    modalg_gameover_to_common_event_init
    @gameover_ce_id = 0 # Default Common Event ID
  end

with:

Code: [Select]
  def initialize
    @gameover_ce_id = 0 # Default Common Event ID
    modalg_gameover_to_common_event_init
  end


Also, what do you have @gameover_ce_id set to? It should be an ID of the common event you want to call, which means a positive integer.
Title: Re: Gameover -> Common Event
Post by: h3llh0und on April 24, 2010, 05:12:59 PM
It's definitely not a variable or switch.

Hmm, well in the script, try replacing:

Code: [Select]
  def initialize
    modalg_gameover_to_common_event_init
    @gameover_ce_id = 0 # Default Common Event ID
  end

with:

Code: [Select]
  def initialize
    @gameover_ce_id = 0 # Default Common Event ID
    modalg_gameover_to_common_event_init
  end


Also, what do you have @gameover_ce_id set to? It should be an ID of the common event you want to call, which means a positive integer.


My game always ignore this script... the only way I can see for it to work (I already tried) is changing the Scene_Gameover script....

the problem is that I don't know how to call your script, can you give me the line of code to force "scene_gameover" to call your script?
Title: Re: Gameover -> Common Event
Post by: selavy_rrose on April 24, 2010, 09:28:49 PM
That's a good idea! Now I copied the following part into gameover scene so my player is dead and walking now when defeated, but yeah, if you could please tell us the line to call the event from scene gameover.
Code: [Select]
==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
#  This class performs game over screen processing.
#==============================================================================

class Scene_Gameover < Scene_Base

  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    if $game_temp.common_event_id != 013
      $game_party.clear_actions
      $game_party.remove_states_battle
      $game_troop.clear
      if $game_temp.battle_proc != nil
        $game_temp.battle_proc.call (2)
        $game_temp.battle_proc = nil
      end
      unless $BTEST
        $game_temp.map_bgm.play
        $game_temp.map_bgs.play
      end
      $scene = Scene_Map.new
      Graphics.fadeout(30)
      $game_temp.common_event_id = 013
      $scene = Scene_Map.new
    end
  end
end
Title: Re: Gameover -> Common Event
Post by: h3llh0und on April 24, 2010, 10:45:59 PM
That's a good idea! Now I copied the following part into gameover scene so my player is dead and walking now when defeated, but yeah, if you could please tell us the line to call the event from scene gameover.

yeah... I was messing here with the game over scene and I could make the "gameover" process stop...

the problem is that it keep repeating itself, I can't find a way to stop the gameover script from running ;/

the result is a loop of my screen going black and back to the map, and then again, and again... and agaain...
Title: Re: Gameover -> Common Event
Post by: selavy_rrose on April 24, 2010, 11:57:57 PM
You could put a "break loop" in but I don't know yet how to do it in script :(
Title: Re: Gameover -> Common Event
Post by: h3llh0und on April 25, 2010, 12:02:56 AM
it's just "break"

the problem is that it's not a loop... it's like a hidden witch is activated and everytime the game_over script stops, it check the "hidden" switch and launch again

searched everywhere for this process the only thing I found was this

Code: [Select]
  def command_353
    $game_temp.next_scene = "gameover"
    return false
  end

on game_interpreter...

I tried to put $game_temp.next_scene = ""

but it didn't work xD
Title: Re: Gameover -> Common Event
Post by: selavy_rrose on April 25, 2010, 12:12:00 AM
try to change false to true? But I don't know, I just try to mess with the script and some of it occasionally works. :S ::)
Title: Re: Gameover -> Common Event
Post by: Cascading Dragon on April 25, 2010, 12:26:46 AM
h3llh0und, the only reason I can see that happening is through another script. Go through and comment out each script one at a time to see what is interfering.
Title: Re: Gameover -> Common Event
Post by: Theguywiththeface on July 06, 2010, 01:46:57 AM
Hey, sorry for the necropost. but i really like this script. However it doesnt work with ABS battle systems or any other overworld fighting. :-[ Is there anyway you can make a fix for this plz?


 :lol: :lol:
Title: Re: Gameover -> Common Event
Post by: ShinUon on October 02, 2012, 12:14:19 PM
Necro, but I second that request. I've tried to modify the script to work with ABS, but it's resulting in really strange results.

The reason why this doesn't work with ABS is because ABS systems (I believe) don't go into Scene_Battle, which is what this script modifies. So I tried to modify Scene_Map.

I added the code below to the script. Note that I've kept it simple for debugging reasons. That's also why it's an override.
Code: [Select]
class Scene_Map
 
  def call_gameover
      #Graphics.fadeout(120) #Uncommenting confirms this code block DOES get called

      $game_temp.common_event_id = $game_system.gameover_ce_id

  end
 
end

Result: it only calls the common event after I open/close the menu. So it only works after a scene change, I think? However, it's clear that block of code IS being executed, as the fadeout line does work immediately (when you remove the comment).

Anyway, I am really confused what the problem is. modern algebra (or anyone else), if you have any insights, it'd be appreciated.



(Here are additional details that complicate things (and might be a separate issue), but I include them in case they actually provide insight into anything.)
Spoiler for:
Minor note: In testing, I found if I used an event (e.g. event w/ fire graphic that caused damage) to reduce my HP to 0, my character would freeze up. If I let an evented enemy deliver the finishing blow, then it doesn't... but I get the problem outlined above.

I'm using Vampyr SBABS 12. Initially I tried to see what it was doing due to the difference in behavior noted above (evented enemy damage vs. event damage). However, considering even evented enemy damage has issues, I stopped focusing on trying ot figure out how Vampyr executed game over.

Edit: Mistyped. Meant Scene_ classes, not Game_ classes. Fixed
Title: Re: Gameover -> Common Event
Post by: modern algebra on October 06, 2012, 02:33:55 AM
I haven't looked at whatever ABS script you're using, but my assumption would be that the GameOver screen is being called before the method which calls the common event. You would need to delete the $scene = Scene_GameOver.new line (or whatever; I haven't looked at this script in forever, nor am I all that familiar with VX anymore.)
Title: Re: Gameover -> Common Event
Post by: D&P3 on October 06, 2012, 06:59:06 AM
Hello again,
I did try this script on a totally new project that I only started to check if the script works, and yes, it worked.
That made me wonder, what's wrong with my game. Then I did copy all the scripts back from the clean project, I did copy the graphics and all from my project to the clean project, and it didn't work, I think it must be a switch that interferes with it. Now it gives me this error:
Script 'Game_Interpreter' line 77: NoMethodError occured.
undefined method '>' for nil:NilClass

What can I do that it will work?
Since it was never answered, I'd just like to let people know that you get that error because you're trying to compare nothing against a number.
You fix it be starting a new game rather than reloading from an old one.
Title: Re: Gameover -> Common Event
Post by: ShinUon on October 06, 2012, 08:17:05 PM
I haven't looked at whatever ABS script you're using, but my assumption would be that the GameOver screen is being called before the method which calls the common event. You would need to delete the $scene = Scene_GameOver.new line (or whatever; I haven't looked at this script in forever, nor am I all that familiar with VX anymore.)

?? Are you responding to me? I think there's some confusion because that's not the issue. I don't get sent to the game over screen. The problem is nothing happens (e.g. common event) until I open/close the menu.

And regarding what the script (Vampyr SBABS 12) is doing, it sets $game_temp.next_scene = "gameover". That gets processed in Scene_Map in a case switch block, which goes to call_gameover. So shouldn't be any problems there.