Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> game_battler methods vs game_character [SOLVED]
mr_melee
post Apr 13 2012, 11:09 AM
Post #1


Level 1
Group Icon

Group: Member
Posts: 10
Type: Developer
RM Skill: Undisclosed




I had a conflict with the scene map that I worked out, and it turns out I had missed a few lines. here is the updated script, which now gets you to an empty battle process. pne major change i made from gubid's tutorial was that instead of the long name method alias, i redefined the update_events method of the game_map class to an if statement saying "if in battle, do nothing". this, i believe achieves the same effect.

revised battle system
###new map entry to force battle to stay on map

class Scene_Map < Scene_Base

# * Switch to Battle Screen

def call_battle

if @in_battle == nil
@spriteset.update
Graphics.update
$game_player.make_encounter_count
$game_player.straighten
$game_temp.map_bgm = RPG::BGM.last
$game_temp.map_bgs = RPG::BGS.last
RPG::BGM.stop
RPG::BGS.stop
$game_system.battle_bgm.play
#$game_temp.next_scene = nil
@in_battle = true
p "1"
else
p "2"
update_battle_routine
end

end

end

def update_battle_routine
setup_battle if @battle_setup == nil
while @in_battle
update_basic
update_battle

end

end

def setup_battle
@battle_phase = 0
@enemies = []
@enemies_to_index = []
@actors = []
@actor_to_index = []
@projectiles = []
projectiles_to_index = []
@neutrals = []
@neutrals_to_index = []
list = ['actor', 'enemy', 'projectile', 'neutral']
for event in $game_map.events.values

if event.name.include?(list[0])
@actors << event
@actor_to_index[event.id] = event.name.downcase.delete(list[0])
end

if event.name.include?(list[1])
@enemies << event
@enemies_to_index[event.id] = event.name.downcase.delete(list[1])
end

if event.name.include?(list[2])
@projectiles << event
@projectiles_to_index[event.id] = event.name.downcase.delete(list[2])
end

if event.name.include?(list[3])
@neutrals << event
@neutrals_to_index[event.id] = event.name.downcase.delete(list[3])
end

end

reset_at
finish_setup_events
@battle_setup = true
end

def finish_setup_events
for battler in battlers
battler.in_battle if battler.erased == false
end

end

def battlers
return @enemies + @actors + @neutrals
end

def reset_at
for battler in battlers
battler.reset_at
end


def update_battle
case @battle_phase

when 0 #goto position
upd_goto_position

when 1 #battle wait anim

when 2 #party select
p "you made it"
when 3 #actor action select

when 4 #process action
case @battle_step

when 1
battle_step1 #select battler
when 2
battle_step2 #run animation
when 3
battle_step3 #deliver damage
when 4
# battle_step4 #pop damage
end

when 5 #battle completion
@caterpillar = false
end

end

def upd_goto_position
@CATERPILLAR = false
if @prepared_move

all_at_pos = true
for event in @actors + @neutrals
if event.moving?
all_at_pos = false
end

end

## goto position

if all_at_pos == true
## turn to closest enemy
@battle_phase = 1
end


else
@position = []
for event in @actors
x, y = event.x, event.y
event.moveto($game_player.x, $game_player.y)
event.goto_xy(x,y)
end


$game_player.hide
@prepared_move = true
end

end

end



class Game_Player < Game_Character
alias move_by_input_battle_disable move_by_input
def move_by_input
if $game_temp.in_battle == false
move_by_input_battle_disable
end

end

end

class Game_Event < Game_Character
attr_reader :at
attr_reader :erased
attr_reader :name

alias init_gm_event_name_data initialize unless $@
def initialize(map_id, event)
init_gm_event_name_data(map_id, event)
@name = event.name

end



def reset_at
@at = rand(1000)
end

def in_battle(value = true)
@in_battle = value
if value == true
@pose = 0
if @name.include?("actor")
index = @name.downcase.delete("actor").to_i - 1
actor = $game_party.members[index]
@tile_id = 0
@character_name = actor.character_name
@character_index = actor.character_index

else if @name.include?("neutral")
index = @name.downcase.delete("neutral").to_i
actor = $game_actors[index]
@tile_id = 0
@character_name = actor.character_name
@character_index = actor.character_index

end

end

end

end

end

class Game_Character
def character_name
name = @character_name
if $game_temp.in_battle == true
return name + "_" + "walk" if moving?
name = name + "_" + "wait" if @pose == 0
## name = name + "_" + "skill" if @pose == 1
##name = name + "_" + "attack" if @pose == 2
end
return name

end

def turn_to(who)
retun if !who
sx = @x - who.x
sy = @y - who.y
if sx.abs > sy.abs
sx > 0 ? @direction = 4 : @direction = 6
return sx.abs
else
sy > 0 ? @direction = 0 : @direction = 2
return sy.abs
end

end

def goto_xy(x,y)
if $game_map.valid?(x,y)

@x = x
@y = y
end

end

end

class Game_Map
def update_events
if @in_battle == nil
for event in @events.values
event.update
end
for common_event in @common_events.values
common_event.update
end
else

end
end
end

class Game_Player < Game_Character

def hide
@character_name = ""
@character_index = 0
end

class Position
attr_accessor :x, :y
def initialize(x,y)
@x, @y = x,y

end

end

end





if you have any suggestions at this point on how to finish constructing the Action Time system. I believe gubid refered to it as both at and ct
I decided to use the AT terminology to define that timer, that is what I'm tackling first. A small problem. I think at this point I want to either take it to a strict menu based battle or go to a button menu. i'm leaning towards the button menu. thank you to anyone that checked this out, I was able to correct the many errors, but if you see any way of reorganizing this i'd appreciate it. I think that the call_battle changes might end up as their own script as a foundation for the engine. again, any suggestions appreciated. This is something I haven't been able to find, I am not a programmer, just hoping to shed light on the subject for other users.

I liked gubid's approach because he is manipulating existing methods to suit his needs, though it is an incomplete tutorial of constructing the battle system. the particular challenge he tackles is succeeding in stopping the traditional battle scene to initialize, and setting up the battle process, which is definitely the hardest part. I think the added challenge of a button menu makes this system a little more
functional and different from what is already out there for rpg maker. plus it fulfills my expectations in a battle system.

food for thought.

This post has been edited by mr_melee: Apr 16 2012, 12:05 AM
Go to the top of the page
 
+Quote Post
   
mr_melee
post Apr 14 2012, 01:01 PM
Post #2


Level 1
Group Icon

Group: Member
Posts: 10
Type: Developer
RM Skill: Undisclosed




So, here is where I am at today... I have done a few minor corrections to the code, I added a Position class to create
a position on the events so that when the actors move towards their respective events they turn to them. In most cases
this will be a sufficient way of setting up battle, but i want them also to then face the enemy, as in some cases the enemy will
not be in the direction they are facing. So, I have outlined methods in the Game_Battler class that establish a position for the
battler, the distance to the battle from an x,y; and the distance to another specified battler. Those methods are here:

game_battler methods
class Game_Battler


# sets battler base position
def set_base_position(x, y)
@base_x = x
@base_y = y
end

# returns distance from?
def distance_to_position(x, y)
return (@screen_x - x).abs + (@screen_y - y).abs
end

# returns distance to battler
def distance_to_battler(battler)
return distance_to_position(battler.screen_x, battler.screen_y)
end

# turn to the specified coordinates
def turn_pos(x, y)
sx = @real_x - x
sy = @real_y - y
if sx.abs > sy.abs # if next long distance is more
@direction = sx > 0 ? 4 : 6 # turn to these directions
else # if same vertical distance
@direction = sy > 0 ? 8 : 2 # is long or more, turn to one of these
end

end

end


so, now... my question is, do these methods then make my position class irrelevent if I designate that all battlers set their
base positions to their respective events? I know that the "game_actor" and "game_enemy" are subclassed game_battler classes,
and these attr_accessors are inherited values to their subclasses, but I don't know how to invoke them outside of the class
method. Basically at the start of battle, when "update_battle" runs its "upd_goto_position" method, I want each battler to set their base position to their own event. then after the "all_at_pos" boolean returns true, the actors and enemies face eachother's base position.
I believe that in doing this i also set up coordinates for attack and skill movement. So say a character attacks, they check
the target's base position and see if is above/below/beside and moves to the last tile between them and their target, attacks
and returns to their own base position.

in the situation where the actors themselves turn to their event when they walk to them they are invoked by a series of commands:

for event in @actors
x, y = event.x, event.y
event.moveto($game_player.x, $game_player.y)
event.goto_xy(x,y)
end

if i were to implement my game_battler methods, would it be in a similar way and how do i specify which event to which battler?
it seems to be that i address it the same, addressing the "event" in @actors or @enemies and specifying that x, y = equals
their respective events. but then do i say that a) the event should "set_base_position" of the game_battler to event.x and event.y?
or do I say cool.gif the battler should "set_base_position" to the event.x and event.y? to me they say the same thing, but i don't know
how to address those accessors we defined. here's the way i envision it:

for event in @enemies
x, y = event.x, event.y
event.set_base_position($game_battler.x, $game_battler.y)
event.turn_pos(x,y)
end

even if you guys don't respond and just read, i appreciate the time spent to review these concepts. for me, writing it out here and explaining what is going on helps me identify the problems i am creating and how to solve them. again, I'm not much of a programmer, just someone who has taken an interest in this system and its lack of development. I feel that in time it is a feat I can accomplish if I don't rush things. the biggest challenge is writing clean code, and though gubid does a great job of writing it up on the fly, there are elements that I dont think are necessary, like this difference in assigning location flags. in his video he creates the position class and then removes its method implementation, leaving that class useless in the script. It is my feeling that if these game_battler methods can achieve the same goal as the
move_to/turn_to methods then I dont need them either, i merely need to say, set_base_positions to the event, turn to those and then turn to your enemy. again, any suggestions, comments or input is appreciated.
Go to the top of the page
 
+Quote Post
   
mr_melee
post Apr 14 2012, 04:45 PM
Post #3


Level 1
Group Icon

Group: Member
Posts: 10
Type: Developer
RM Skill: Undisclosed




alright, so instead of tackling that problem I decided to take on a different one today; that was, to make the battle process only pull in events labeled in our event list that were within a certain distance of the event or player. I decided that ultimately the distance from the player and the battle event were/are the same x,y value at the initialization of the battle process. so, i outlined this method which i believe will achieve that result.

this method rests inside the class Scene_map > Scene Base.

check_player_distance method
def check_player_distance
@distance_from_player = nil
for event in $game_map.events.values
x, y = event.x, event.y
if (x - $game_player.x) >= 5
distance_from_player = false
else if (x - $game_player.x) <= 5
@distance_from_player = true

end

end

if (y - $game_player.y) >= 5
@distance_from_player = false
else if (y - $game_player.y) <= 5
@distance_from_player = true

end

end

end



so, at the point of sorting the events for battle, i would insert the "check_player_distance" method for each instance that it
checks the $game_map.events.values for events with the listed prefixes we defined. so, it would call the method which
checks all events that are within a range of 5 to it's x or y value and return a boolean stating, yes these events are in range.
then it takes all events in range and asks, "is there a listed prefix in the event name?" and any that are in range and that
listed prefix are assigned to their respective indexes.

i am running a syntax error which leades me to the class Game_Player, which i think is telling me that it is not able to access those
values? or perhaps that i have incorrectly referenced them?


if anyone knows a more direct method of doing this, I'd appreciate the help.


This post has been edited by mr_melee: Apr 14 2012, 04:55 PM
Go to the top of the page
 
+Quote Post
   
mr_melee
post Apr 16 2012, 12:04 AM
Post #4


Level 1
Group Icon

Group: Member
Posts: 10
Type: Developer
RM Skill: Undisclosed




this is solved! here is the code i used to process only events within a distance of the player.


for event in $game_map.events.values
x, y = event.x, event.y
dist = 5
case
when (x - $game_player.x).abs - (y - $game_player.y).abs < dist

im thinking that this equation could be reversed to turn the actor events towards the enemy, and instead of before
where i was invoking a method within the setup method to determine it, which i think may have worked if i knew what i was
doing but was still wrong. you guys are too nice to call me a noob. thank you.



and if anyone wants to see the script and where it's at now, let me know and I'll update it.


This post has been edited by mr_melee: Apr 16 2012, 12:16 AM
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 24th May 2013 - 10:22 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker