Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
an RMXP battle HIT counter
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Ok, I did a victory counter a while ago... and you asked for a hit counter because I said it could be done with the same kind of code... I should have shut my month on this :crybaby:

Here's an hit counter:

This script is a script you will have to add yourself and customize the way you want it to work.

First thing first, the basic code.

PART 1

Open GAME_PARTY, and find the line:

SEARCH FOR:
Code:
def setup_starting_members

And add this code ABOVE it:

Code:
#DUBEALEX COUNTER MINI-SCRIPT
   def add_count(counter,actor)
    
     #hit counter start
     if counter == "hit_counter"
      
       #count the total counts of all actor
       if @hit_counter[0] == nil #If counter is at 0, start it
         @hit_counter[0]=1
       else #Else, increment it of 1
         @hit_counter[0]+=1
       end  
       #end of total count
      
       #start of per actor counter
       if @hit_counter[actor] == nil #If counter is at 0, start it
         @hit_counter[actor]=1
       else #Else, increment it of 1
         @hit_counter[actor]+=1
       end  
     end
     #end of per actor counter
     #end of hit counter
    
   end  
   #END OF COUNTER SCRIPT

Then, find:
Code:
attr_reader   :steps

And below it, add:

Code:
attr_accessor :hit_counter

and find:
Code:
@actors = []

and BELOW it, add:
Code:
@hit_counter = []

Okay, here's how it works:

1) def add_count(counter,actor)

this create our main counter method, add_count is used in the battle system (see PART 2) to add data to the right counter. The thing in parenthesis are arguments that we send from the battle system to our counters so we know which one to increment in case we have more than 1. The first argument is the name of the counter, and the second is the actor ID of the one of his attacking (which you should not have to touch). This line stays like this, you dont have to customize it.

2) if counter == "hit_counter"

This is out main IF block for our first counter, the HIT counter. It check if the argument "counter" is equal to "hit_counter", and if so, will add data to the counter, otherwise, nothiung will happen.

3) if @hit_counter[actor] == nil #If counter is at 0, start it

This checks if the counter for a particular actor ID is actually empty or not. Cause if it's empty (NIL), we cannot increment it, and RMXP return a sad error. So, if it's empty, we set it to 1 so it's not empty anymore. We set it to 1 we the following line:

@hit_counter[actor]=1

4) else #Else, increment it of 1

Well, this happens if the counter isn't empty, so we can freely ADD 1 to the counter, with the following line:

@hit_counter[actor]+=1

The rest of the code is to CLOSE our IF block for that counter. It ends at the following comments:

Code:
#end of hit counter

If you want to add counter, you simply do the same process as explained above, but you replace hit_counter by the name of your counter.

--> Remember to change the TOTAL COUNT as you changed the PER ACTOR COUNT, they do the same thing, it should be easy to edit.

PART 2

Open SCENE_BATTLE4, and find line:

Code:
target.damage_pop = true

It shold be around line #433

Then, BELOW it, add the following lines:

Code:
#DUBEALEX COUNTER MINI SCRIPT  
       hit_actor=@active_battler.index
       hit_actor+=1
      
       #Hit Count - No MISS and only HEROS (No Skills)
       if @active_battler.is_a?(Game_Actor) and target.damage != "Miss" and @active_battler.current_action.kind ==0
          $game_party.add_count("hit_counter",hit_actor)
       end
        
       #END OF COUNTER SCRIPT

This code will count the number of HIT the player does to an enemy, when he doesn't miss or defend. Here's what does what, so you can customize:

1) hit_actor=@active_battler.index

This line create a new local variable hit_actor for us to use, that is shorter. It stores the active battler actor ID. So we know who is attacking.

2) hit_actor+=1

Here, we increment of 1 the content of our variable hit_actor because an INDEX begins by 0, and the game_actors id begins by 1 in the database.

3) if @active_battler.is_a?(Game_Actor) and target.damage != "Miss" and @active_battler.current_action.kind ==0

This long line is our IF statement that is making sure the variable is incremented when we want, and not everytime an action is made. Here's how to customize that IF to increment a variable the way you want:

4) @active_battler.is_a?(Game_Actor)

This make sure that the active battler (the one who attacks) is a actor (an hero) and not an enemy. If you omit this part, enemy and hero's hit will both be counted.

If you want to do the same to count enemy counter, you use the following line:

Code:
@active_battler.is_a?(Game_Enemy)

5) target.damage != "Miss"

This part of the IF check if the attacker MISSED the target or not. in our case, we count the HIT, so a MISS won't count. != means "NOT EQUAL TO".

6) @active_battler.current_action.kind ==0

And the last part of the IF check what was the action type the attacker did. RMXP defines 3 attack type, as follows:

0 = Normal Attack (fight) and Defend (guard)
1 = Skill usage
2 = Items usage

7) $game_party.add_count("hit_counter",hit_actor)

This lines actually add the data to the counter in Game_Party (the first script we added), this way the counters are saved when you save a game.

add_count is our method that adds values into the right counter. so in the parenthesis we send 2 argument, the counter in which we wanna send data, and the actor ID we want to increment. Since ACTOR ID start at 1, we used the ID 0 of every counter as a total of all the actors.

So, if you created (in Game_Party) a new counter named "miss_counter", you simply write "miss_counter" in place of "hit_counter" -- The rest of the line stays the same. Dont change hit_actor, it's fine.

Okay, now, what if you want to add more counter ?

Add more IF just after the one you did, and change the condition. Example:

If you want to count the number of MISS, you would add those pack of lines below the other IF:

Code:
#MISS COUNTER
if @active_battler.is_a?(Game_Actor) and target.damage == "Miss"
    $game_party.add_count("miss_counter",hit_actor)
end

And then, you need to add this counter into Game Party also, like this:

Just below the default hit counter I did, add those lines:

Code:
if counter == "miss_counter"
    if @miss_counter[actor] == nil #If counter is at 0, start it
        @miss_counter[actor]=1
    else #Else, increment it of 1
        @miss_counter[actor]+=1
    end
end

And you will need to define the counter as the hit counter is defined, where @hit_counter = [] is written (in the initialize method), you need to add below it @miss_counter = []

You also need to add the ATTR_ACCESSOR to be able to access it from call script in your game, just add it below the hit counter, as follows:

attr_accessor :miss_counter

I guess you got the point.

Now, if you need to add this data in a message, you can simply put the data you want temporalely into a game variable like that:

*Add this in a CALL SCRIPT event just before you message that will show your counter numbers.

Code:
$game_variables[ID] = $game_party.your_counter_name[ACTOR_ID]

Remember that the index 0 is the sum of all the counters found in the same counter.

And you write this in your message:

Code:
\v[VARIABLE_ID]

NOw, have fun, and go in peace
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Battle Trophies GoldenShadow 0 2,563 09-07-2006, 01:00 PM
Last Post: GoldenShadow
  Obtain Experience as You Battle Tsunokiette 0 2,128 06-28-2006, 01:00 PM
Last Post: Tsunokiette
  Change Cursor with differend commands in Battle Divinity 0 2,251 06-22-2006, 01:00 PM
Last Post: Divinity
  Battle Memory mudgolem 0 2,065 06-21-2006, 01:00 PM
Last Post: mudgolem
  Before Battle Switch Sheol 0 2,317 04-20-2006, 01:00 PM
Last Post: Sheol
  After Battle Changes 1.1 Sheol 0 2,177 02-07-2006, 01:00 PM
Last Post: Sheol
  New Battle System V1.5 (Added Side View) Guedez 0 2,475 01-12-2006, 01:00 PM
Last Post: Guedez
  Little Battle Edit Darkness Seraph 0 1,817 12-26-2005, 01:00 PM
Last Post: Darkness Seraph
  Battle Event List & Pre-Battle Troop Setup SephirothSpawn 0 2,511 12-25-2005, 01:00 PM
Last Post: SephirothSpawn
  Random Battle Music Boss & Final Boss setup Eccid 0 2,059 11-03-2005, 01:00 PM
Last Post: Eccid



Users browsing this thread: