[RESOLVED] Help with modifying a script for random battle formations.

Started by nystrai, November 21, 2012, 03:32:37 pm

Previous topic - Next topic

nystrai

Hi everyone, im pretty sure this is my first post. i've been reading on these forums for a while and i finally couldn't figure this out... so im breaking down and asking for help with this.


i've been wrapping up the battle part of my script and a function i've always wanted to have is random battle formations.

now im using tankentai and it has a pretty easy setup for battle formation, and i figured i could just cheap it out and spin a variable in the background and use a simple if/elsif statement to get a random battle formation out of a selection of like 6.. but basically it just used one of them and then stuck with that.

is anyone willing to help me modify this to randomly pick a formation..

this is the part of the script that deals with formations...

# Battle member starting positions
 #                   X   Y     X   Y     X   Y     X   Y     X   Y     X   Y
 ACTOR_POSITION = [[420,170],[500,200],[410,230],[510,260],[560,290]]
 ACTOR_POSITION2 = [[420,170],[500,200],[410,230],[510,260],[560,290]]
 ACTOR_POSITION3 = [[420,170],[500,200],[410,230],[510,260],[560,290]]
 ACTOR_POSITION4 = [[420,170],[500,200],[410,230],[510,260],[560,290]]
 ACTOR_POSITION5 = [[420,170],[500,200],[410,230],[510,260],[560,290]]
 ACTOR_POSITION6 = [[480,170],[500,200],[520,230],[540,260],[560,290]]

i added ACTOR_POSITION2 through ACTOR_POSITION6, i ended up just setting them all the same a while ago but i really want to get this
working now.

this is the section of the actual battle script that references that value.
def base_position
   if $game_variables[20] = 1
     base = ACTOR_POSITION2[self.index]
   @base_position_x = base[0]
   @base_position_y = base[1]
   @base_position_x = 640 - base[0] if $back_attack and BACK_ATTACK_MIRROR
   
   elsif $game_variables[20] = 2
     base = ACTOR_POSITION3[self.index]
   @base_position_x = base[0]
   @base_position_y = base[1]
   @base_position_x = 640 - base[0] if $back_attack and BACK_ATTACK_MIRROR
   
   elsif $game_variables[20] = 3
     base = ACTOR_POSITION4[self.index]
     @base_position_x = base[0]
   @base_position_y = base[1]
   @base_position_x = 640 - base[0] if $back_attack and BACK_ATTACK_MIRROR
   
   elsif $game_variables[20] = 4
     base = ACTOR_POSITION5[self.index]
   @base_position_x = base[0]
   @base_position_y = base[1]
   @base_position_x = 640 - base[0] if $back_attack and BACK_ATTACK_MIRROR
   
   elsif $game_variables[20] = 5
     base = ACTOR_POSITION6[self.index]
     @base_position_x = base[0]
   @base_position_y = base[1]
   @base_position_x = 640 - base[0] if $back_attack and BACK_ATTACK_MIRROR
   
   elsif $game_variables[20] = 0
   base = ACTOR_POSITION[self.index]
   @base_position_x = base[0]
   @base_position_y = base[1]
   @base_position_x = 640 - base[0] if $back_attack and BACK_ATTACK_MIRROR
  #ATTEMPT BREAK LOOP IF IN BATTLE
  end
end

basically i was trying to continuously generate a random number 1-6 and store it in variable 20, figuring that when a battle started it
would choose that formation. but its not working...
is there a better way that i can do this? im feeling pretty stupid right now, lol.

also on a side note. im having problems with blizzard's Party change script, the framerate seems to drop off sharply after using it, though it does work fine, also it might be my fault since i modified it for 5 party members.

at any rate please let me know if you guys have any ideas on how i could either make this work with a variable or simply replace this code with something better.

thanks again!

EDIT: the thought had dawned on me that i might possibly be able to fix this by creating an array with the ACTOR_POSITION values and using the roulette function to choose one. im not really that familiar with the roulette function though. if someone could point me in the right direction. lol

EDIT AGAIN: Im happy to say i figured this out. finally. i ended up using the variable method but i used a common event set to parallel to continuously generate the random number with a switch set to automatically flip to on in scene_title to activate the common event.
its great because it works. but it sucks because it effectively broke battle test. i just have to test on a map now. which isnt such a big deal since i have a five member party anyway.

thanks everyone. if anyone using tankentai wants to do something similar hit me up and ill help you out!

diagostimo

one problem is when your checking the value:

if $game_variables[20] = 1
#should be:
if $game_variables == 1

the = sign sets the value and == checks it
 
next instead of using if brances you could use a case, example:
[code]
case $game_variables[20]
when 1
  #code
when 2
  #code
end
#etc
[/code]

nystrai

ah... funny you should mention that. i actually caught that mistake while trying a few different things. i cant believe i forgot that = isn't the same as == lol. i seem to have made some progress... sort of... now it appears that im influencing the formation but its not passing the value or something because all of the characters are in the upper left hand corner on top of each other (which is what happens when no coordinates are passed to the battle system)

basically i guess what im looking for function wise is:

generate a random number between 0 and 5 make the value equal x
loop that random number generation.

the problem im having is that i think its still randomizing the value when battle starts and the system cant or something grab a number and the corresponding ACTOR_POSITION# so its just loading with no value.

is there a way to stop the number generation only while in combat?

by the way thanks for the answer and your help.

diagostimo

you can test what a scene is by the using the following:
$scene.is_a?(CLASS_NAME)
so in your case when setting the variable it should only set when the scene is scene map:
$scene.is_a?(Scene_Map)
honestly i dont think that would cause a problem as scene_battle has its own event interpreter aside from scene map and only updates that, also im guessing your using the game variables to get the random functionality, ruby has its own built in function that you can use:
random_number = rand(6)
what that example would do is generate a random number between 0 and 6, if you wanted to say generate a number between 6 and 12 you would:
random = rand(6) + 6
or:
random = 6 + rand(6)
you plus 6 to the getenerated value to set the start point at that, and say it generated 3, then 6 + 3 = 9, whala it beteen 6 and 12

really you should add that random function to the start of the method that gets the coordinate, then add a loop to check if it is the same as any of the other enemies coordinates, if it is re role the dice so they dont stack until there all unique, that way you could just make one big array containing values you want the dice to roll on instead of making an array of values for each enemies :)