Update: Sorry, just realized this was in the wrong forum. Is there any way for me to delete or move this post? Thanks!
What I'm Trying to Accomplish:
I'm creating a system that simulates ranges. Bows fire from long-range, spears attack at mid-range, and other melee at short. This distinction opens up a lot of strategic possibilities, such as having melee attackers block opponents so they cannot reach vulnerable archers. In game terms, a swordsman cannot attack an archer if there are other melee characters between them.
I'm approaching this through states, so that characters with states 38, 40, and 41 cannot be attack by characters with states 36, 38, or 41. They can, however, be attacked by characters with states 37, 39, and 40. Characters with state 41 cannot attack anyone. I've already managed to alter the enemy AI so that it follows these rules. I'm having a harder time with player controlled characters.
I'm attempting to do so through the class Arrow_Enemy by altering which enemies can be selected. I'm using the following code based on Atoa's battle system:
Normally this script works fine.
What I've Added:
I've added four things. The first is the method 'actor_cannot_select,' and the other three are calls of my new method next to 'break if self.enemy.exist?'
The Error:
The game still starts normally. However, when I move the arrow beyond the last enemy in the index, I get the error:
My Uneducated Guess:
I suspect this is because the class Arrow_Enemy does not have access to the states index and so is responding with nil. If so, how do I call the states index so that it can be used within this class?
Any help would be appreciated! I just started teaching myself Ruby last week and my understanding is far from complete.
-Tuatha
What I'm Trying to Accomplish:
I'm creating a system that simulates ranges. Bows fire from long-range, spears attack at mid-range, and other melee at short. This distinction opens up a lot of strategic possibilities, such as having melee attackers block opponents so they cannot reach vulnerable archers. In game terms, a swordsman cannot attack an archer if there are other melee characters between them.
I'm approaching this through states, so that characters with states 38, 40, and 41 cannot be attack by characters with states 36, 38, or 41. They can, however, be attacked by characters with states 37, 39, and 40. Characters with state 41 cannot attack anyone. I've already managed to alter the enemy AI so that it follows these rules. I'm having a harder time with player controlled characters.
I'm attempting to do so through the class Arrow_Enemy by altering which enemies can be selected. I'm using the following code based on Atoa's battle system:
Code:
#==============================================================================
# ■ Arrow_Enemy
#==============================================================================
class Arrow_Enemy < Arrow_Base
#--------------------------------------------------------------------------
def update
super
$game_troop.enemies.size.times do
break if self.enemy.exist? or actor_cannot_select(enemy)
@index += 1
@index %= $game_troop.enemies.size
end
cursor_down if Input.repeat?(Input::RIGHT)
cursor_down if Input.repeat?(Input::UP)
cursor_up if Input.repeat?(Input::LEFT)
cursor_up if Input.repeat?(Input::DOWN)
if self.enemy != nil
self.x = self.enemy.actual_x
self.y = self.enemy.actual_y
end
end
#--------------------------------------------------------------------------
def actor_cannot_select(target)
battler = $game_party.actors[@index]
return true if battler.states.include?(41)
return false if battler.states.include?(37) or battler.states.include?(39) or battler.states.include?(40)
return true if target.states.include?(38) or target.states.include?(40)
end
#--------------------------------------------------------------------------
def cursor_up
$game_system.se_play($data_system.cursor_se)
$game_troop.enemies.size.times do
@index += $game_troop.enemies.size - 1
@index %= $game_troop.enemies.size
break if self.enemy.exist? or actor_cannot_select(enemy)
end
end
#--------------------------------------------------------------------------
def cursor_down
$game_system.se_play($data_system.cursor_se)
$game_troop.enemies.size.times do
@index += 1
@index %= $game_troop.enemies.size
break if self.enemy.exist? or actor_cannot_select(enemy)
end
end
end
Normally this script works fine.
What I've Added:
I've added four things. The first is the method 'actor_cannot_select,' and the other three are calls of my new method next to 'break if self.enemy.exist?'
The Error:
The game still starts normally. However, when I move the arrow beyond the last enemy in the index, I get the error:
Script 'ACBS | Battle Main Code' line 3697: NoMethodError occured.
undefined method 'states' for nil:NilClass
My Uneducated Guess:
I suspect this is because the class Arrow_Enemy does not have access to the states index and so is responding with nil. If so, how do I call the states index so that it can be used within this class?
Any help would be appreciated! I just started teaching myself Ruby last week and my understanding is far from complete.
-Tuatha