Script Help - adding to/editing Game Battler

voymasa

Veteran
Veteran
Joined
Jul 25, 2013
Messages
124
Reaction score
18
First Language
English
Primarily Uses
I've noticed some scripts have a "reference" I guess you could call it, in this form GameScript > GameSubScript, or something like that. Does that cause the script to add its code to that file? Can that be used to "insert" the code in between certain lines?

I've been putzing around with an 'auto-life' state that automatically revives the one affected once they die (and removes the state). I tried it with eventing (using immortal status and checking if hp is below 0), but it wasn't doing what I wanted it to.

I kind of figure I can insert the script code in between lines 150 and 151 of the Game_Battler Script (the lines @hp = 0 and clear_states). The code would be something to the effect of (the following is pseudo code):

 - check state for 'auto-life' state using actor.stateid[#]? (I think is the 'proper' conditional)

 - if true, then remove death state

    - recover hp (around 50% or mhp / 2)

    - remove auto-life state

    - stop the knock out function (I'm not quite familiar with the Ruby term for this, but simply stop it from clearing states and buffs and declaring the target dead)

 - if false, then let the knock out 'function' continue as normal.

I'm reading through the 'Help' file to try and understand the syntax (the only programming I am familiar with is Basic and C-based programming, which have different keywords and syntax). Any help understanding Ruby, would be greatly appreciated.

The problem I foresee is that it would still "knock out" the character even if brought back to life.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

You're talking about inheriting from a parent class, when you do something like this:

class Game_Battler < Game_BattlerBase

which just means that Game_Battler will have all the variables and methods from itself as well as those from Game_BattlerBase.

This really has little to do with your requirements. You are looking at overwriting or aliasing the original method, and using your own version instead. If the original code can still be run as a block, and yours run either before or after, then you should alias the original method, like this:

Code:
class Game_Battler < Game_BattlerBase  alias new_name_for_old_method original_method_name  def original_method_name    # add new stuff here if you want your code executed first    new_name_for_old_method # this calls the original method    # add new stuff here if you want your code executed last  endend
If you actually want to change what happens in the original method (you want to change a formula or some logic that it uses, or you want to make additions but in the middle of the method) then you need to overwrite the method, which just means copying from the def to the corresponding end (and also the class and corresponding end statements), keep what you want to keep, and change what you want to change. This makes it call your new method instead of the old method, rather than calling them both.
 

voymasa

Veteran
Veteran
Joined
Jul 25, 2013
Messages
124
Reaction score
18
First Language
English
Primarily Uses
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

You're talking about inheriting from a parent class, when you do something like this:

class Game_Battler < Game_BattlerBase

which just means that Game_Battler will have all the variables and methods from itself as well as those from Game_BattlerBase.

This really has little to do with your requirements. You are looking at overwriting or aliasing the original method, and using your own version instead. If the original code can still be run as a block, and yours run either before or after, then you should alias the original method, like this:

class Game_Battler < Game_BattlerBase alias new_name_for_old_method original_method_name def original_method_name # add new stuff here if you want your code executed first new_name_for_old_method # this calls the original method # add new stuff here if you want your code executed last endendIf you actually want to change what happens in the original method (you want to change a formula or some logic that it uses, or you want to make additions but in the middle of the method) then you need to overwrite the method, which just means copying from the def to the corresponding end (and also the class and corresponding end statements), keep what you want to keep, and change what you want to change. This makes it call your new method instead of the old method, rather than calling them both.
I think I follow your logic (which makes me feel slightly less stupid). I'll experiment.

I was just typing out some more thoughts when you responded, so I'll paste what I was typing here.

**From what I remember of C++, the "code" would be something like the following (function calls will be assumed to already have been defined via header files):

enum State (Death, Auto-Life, etc...)

for (i=0; i<4; i++)

{

  for (n=0; n<states.last; n++)

{ nCurrentStateA = party_member.get_state[n];

  if (nCurrentStateA == 0)

     {

        for (p=0; p<states.last; p++)

          { nCurrentStateB = party_member.get_state[p];

             if (nCurrentStateB == 1)

                {

                   party_member.remove_state("death");

                   party_member.heal_hp(party_member.getMaxHP*0.50);

                   party_member.remove_state("auto-life");

                }

           }

       }

   }

 

Sorry to all of those coders out there, I typed that in off the top of my head.

 

 

Okayyyyy, reading through the default scripts to identify which parameters I need to use. Could I assign @actor_id or @party_member.index(self) to a variable, say, nPartyMember, and throw a conditional check of nPartyMember.state_id(AUTOLIFE)?

 

 

Alright, here is my attempt (haven't tried to run it yet, because I just know that I'm not using valid references, but it follows the logic I want). 28 is the state ID of my Auto Life State:

 

## This script's purpose is to cause the system to check for the Auto-Life

## State and revive the party member before they are declared knocked out.

## Overrides the Knock Out section (starts at line 146 to 153)

## of the GameBattler Script

class Game_Battler < Game_BattlerBase

  def die

    @hp = 0

    @party_member.state[28]? {@party_member.remove_state[1],

    @party_member.hp=@party_member.mhp*0.5, @party_member.remove_state[28]}:

    {clear_states,

    clear_buffs}

  end

end

 

BTW, I still need help (I am using incorrect references for my conditional and effects, i just can figure whether it's supposed to be @party_member or @actor, or what).

I tested my script with the test battle option under the troops tab (script was loaded into the script editor). I received an error of expected {} association or something like that, and applied the state via an item (called autolife berry). State was successfully applied via item, but when my actor was killed it did not revive them. I think I may be placing the code in the wrong section, or as I thought before, I am using the wrong references. Any help would be greatly appreciated.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,868
Messages
1,017,066
Members
137,576
Latest member
SadaSoda
Top