- 19
- Posts
- 2
- Years
- Age 22
- He/Him
- Seen yesterday
So I'm trying to create this new ability called Celestial Guard, where basically it's Magic Bounce but it reflects projectile or bomb type moves back at the opponent. I tried to copy the code for Magic Bounce, but this error message keeps popping up.
Here's the code if you need to see it.
I had trouble with this ability and also a new move for a while now, and I just wanted to get past it so I could play the game, but there was so much code that I didn't want to delete it all. I just now backed all the code up, but there's still a lot to delete. I just want to fix it now so I can move on.
Exception `SyntaxError' at -e - 166:Battler_UseMove:509: dynamic constant assignment
CelestialGuarder = -1
^~~~~~~~~~~~~~~~
-e:in `eval': 166:Battler_UseMove:509: dynamic constant assignment
CelestialGuarder = -1
^~~~~~~~~~~~~~~~
(SyntaxError)
Here's the code if you need to see it.
Code:
magicCoater = -1
magicBouncer = -1
if targets.length == 0 && move.pbTarget(user).num_targets > 0 && !move.worksWithNoTargets?
# def pbFindTargets should have found a target(s), but it didn't because
# they were all fainted
# All target types except: None, User, UserSide, FoeSide, BothSides
@battle.pbDisplay(_INTL("But there was no target..."))
user.lastMoveFailed = true
else # We have targets, or move doesn't use targets
# Reset whole damage state, perform various success checks (not accuracy)
@battle.allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
targets.each do |b|
b.damageState.reset
next if pbSuccessCheckAgainstTarget(move, user, b, targets)
b.damageState.unaffected = true
end
# Magic Coat/Magic Bounce checks (for moves which don't target Pokémon)
if targets.length == 0 && move.statusMove? && move.canMagicCoat?
@battle.pbPriority(true).each do |b|
next if b.fainted? || !b.opposes?(user)
next if b.semiInvulnerable?
if b.effects[PBEffects::MagicCoat]
magicCoater = b.index
b.effects[PBEffects::MagicCoat] = false
break
elsif b.hasActiveAbility?(:MAGICBOUNCE) && [email protected] &&
!b.effects[PBEffects::MagicBounce]
magicBouncer = b.index
b.effects[PBEffects::MagicBounce] = true
break
end
end
end
# Get the number of hits
numHits = move.pbNumHits(user, targets)
# Process each hit in turn
realNumHits = 0
numHits.times do |i|
break if magicCoater >= 0 || magicBouncer >= 0
success = pbProcessMoveHit(move, user, targets, i, skipAccuracyCheck)
if !success
if i == 0 && targets.length > 0
hasFailed = false
targets.each do |t|
next if t.damageState.protected
hasFailed = t.damageState.unaffected
break if !t.damageState.unaffected
end
user.lastMoveFailed = hasFailed
end
break
end
realNumHits += 1
break if user.fainted?
break if [:SLEEP, :FROZEN].include?(user.status)
# NOTE: If a multi-hit move becomes disabled partway through doing those
# hits (e.g. by Cursed Body), the rest of the hits continue as
# normal.
break if targets.none? { |t| !t.fainted? } # All targets are fainted
end
# Battle Arena only - attack is successful
@battle.successStates[user.index].useState = 2
if targets.length > 0
@battle.successStates[user.index].typeMod = 0
targets.each do |b|
next if b.damageState.unaffected
@battle.successStates[user.index].typeMod += b.damageState.typeMod
end
end
# Effectiveness message for multi-hit moves
# NOTE: No move is both multi-hit and multi-target, and the messages below
# aren't quite right for such a hypothetical move.
if numHits > 1
if move.damagingMove?
targets.each do |b|
next if b.damageState.unaffected || b.damageState.substitute
move.pbEffectivenessMessage(user, b, targets.length)
end
end
if realNumHits == 1
@battle.pbDisplay(_INTL("Hit 1 time!"))
elsif realNumHits > 1
@battle.pbDisplay(_INTL("Hit {1} times!", realNumHits))
end
end
# Magic Coat's bouncing back (move has targets)
targets.each do |b|
next if b.fainted?
next if !b.damageState.magicCoat && !b.damageState.magicBounce
@battle.pbShowAbilitySplash(b) if b.damageState.magicBounce
@battle.pbDisplay(_INTL("{1} bounced the {2} back!", b.pbThis, move.name))
@battle.pbHideAbilitySplash(b) if b.damageState.magicBounce
newChoice = choice.clone
newChoice[3] = user.index
newTargets = pbFindTargets(newChoice, move, b)
newTargets = pbChangeTargets(move, b, newTargets)
success = false
if !move.pbMoveFailed?(b, newTargets)
newTargets.each_with_index do |newTarget, idx|
if pbSuccessCheckAgainstTarget(move, b, newTarget, newTargets)
success = true
next
end
newTargets[idx] = nil
end
newTargets.compact!
end
pbProcessMoveHit(move, b, newTargets, 0, false) if success
b.lastMoveFailed = true if !success
targets.each { |otherB| otherB.pbFaint if otherB&.fainted? }
user.pbFaint if user.fainted?
end
# Magic Coat's bouncing back (move has no targets)
if magicCoater >= 0 || magicBouncer >= 0
mc = @battle.battlers[(magicCoater >= 0) ? magicCoater : magicBouncer]
if !mc.fainted?
user.lastMoveFailed = true
@battle.pbShowAbilitySplash(mc) if magicBouncer >= 0
@battle.pbDisplay(_INTL("{1} bounced the {2} back!", mc.pbThis, move.name))
@battle.pbHideAbilitySplash(mc) if magicBouncer >= 0
success = false
if !move.pbMoveFailed?(mc, [])
success = pbProcessMoveHit(move, mc, [], 0, false)
end
mc.lastMoveFailed = true if !success
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
end
end
# Move-specific effects after all hits
targets.each { |b| move.pbEffectAfterAllHits(user, b) }
# Faint if 0 HP
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
# External/general effects after all hits. Eject Button, Shell Bell, etc.
pbEffectsAfterMove(user, targets, move, realNumHits)
@battle.allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
end
CelestialGuarder = -1
if targets.length == 0 && move.pbTarget(user).num_targets > 0 && !move.worksWithNoTargets?
# def pbFindTargets should have found a target(s), but it didn't because
# they were all fainted
# All target types except: None, User, UserSide, FoeSide, BothSides
@battle.pbDisplay(_INTL("But there was no target..."))
user.lastMoveFailed = true
else # We have targets, or move doesn't use targets
# Reset whole damage state, perform various success checks (not accuracy)
@battle.allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
targets.each do |b|
b.damageState.reset
next if pbSuccessCheckAgainstTarget(move, user, b, targets)
b.damageState.unaffected = true
end
# Magic Coat/Magic Bounce checks (for moves which don't target Pokémon)
if targets.length == 0 && move.bombMove?
@battle.pbPriority(true).each do |b|
next if b.fainted? || !b.opposes?(user)
next if b.semiInvulnerable?
if b.hasActiveAbility?(:CELESTIALGUARD) && [email protected] &&
!b.effects[PBEffects::CelestialGuard]
magicBouncer = b.index
b.effects[PBEffects::CelestialGuard] = true
break
end
end
end
# Get the number of hits
numHits = move.pbNumHits(user, targets)
# Process each hit in turn
realNumHits = 0
numHits.times do |i|
break if CelestialGuarder >= 0
success = pbProcessMoveHit(move, user, targets, i, skipAccuracyCheck)
if !success
if i == 0 && targets.length > 0
hasFailed = false
targets.each do |t|
next if t.damageState.protected
hasFailed = t.damageState.unaffected
break if !t.damageState.unaffected
end
user.lastMoveFailed = hasFailed
end
break
end
realNumHits += 1
break if user.fainted?
break if [:SLEEP, :FROZEN].include?(user.status)
# NOTE: If a multi-hit move becomes disabled partway through doing those
# hits (e.g. by Cursed Body), the rest of the hits continue as
# normal.
break if targets.none? { |t| !t.fainted? } # All targets are fainted
end
# Battle Arena only - attack is successful
@battle.successStates[user.index].useState = 2
if targets.length > 0
@battle.successStates[user.index].typeMod = 0
targets.each do |b|
next if b.damageState.unaffected
@battle.successStates[user.index].typeMod += b.damageState.typeMod
end
end
# Effectiveness message for multi-hit moves
# NOTE: No move is both multi-hit and multi-target, and the messages below
# aren't quite right for such a hypothetical move.
if numHits > 1
if move.damagingMove?
targets.each do |b|
next if b.damageState.unaffected || b.damageState.substitute
move.pbEffectivenessMessage(user, b, targets.length)
end
end
if realNumHits == 1
@battle.pbDisplay(_INTL("Hit 1 time!"))
elsif realNumHits > 1
@battle.pbDisplay(_INTL("Hit {1} times!", realNumHits))
end
end
# Magic Coat's bouncing back (move has targets)
targets.each do |b|
next if b.fainted?
next if !b.damageState.magicCoat && !b.damageState.celestialGuard
@battle.pbShowAbilitySplash(b) if b.damageState.celestialGuard
@battle.pbDisplay(_INTL("{1} bounced the {2} back!", b.pbThis, move.name))
@battle.pbHideAbilitySplash(b) if b.damageState.celestialGuard
newChoice = choice.clone
newChoice[3] = user.index
newTargets = pbFindTargets(newChoice, move, b)
newTargets = pbChangeTargets(move, b, newTargets)
success = false
if !move.pbMoveFailed?(b, newTargets)
newTargets.each_with_index do |newTarget, idx|
if pbSuccessCheckAgainstTarget(move, b, newTarget, newTargets)
success = true
next
end
newTargets[idx] = nil
end
newTargets.compact!
end
pbProcessMoveHit(move, b, newTargets, 0, false) if success
b.lastMoveFailed = true if !success
targets.each { |otherB| otherB.pbFaint if otherB&.fainted? }
user.pbFaint if user.fainted?
end
# Magic Coat's bouncing back (move has no targets)
if CelestialGuarder >= 0
if !mc.fainted?
user.lastMoveFailed = true
@battle.pbShowAbilitySplash(mc) if CelestialGuarder >= 0
@battle.pbDisplay(_INTL("{1} bounced the {2} back!", mc.pbThis, move.name))
@battle.pbHideAbilitySplash(mc) if CelestialGuarder >= 0
success = false
if !move.pbMoveFailed?(mc, [])
success = pbProcessMoveHit(move, mc, [], 0, false)
end
mc.lastMoveFailed = true if !success
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
end
end
# Move-specific effects after all hits
targets.each { |b| move.pbEffectAfterAllHits(user, b) }
# Faint if 0 HP
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
# External/general effects after all hits. Eject Button, Shell Bell, etc.
pbEffectsAfterMove(user, targets, move, realNumHits)
@battle.allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
end
I had trouble with this ability and also a new move for a while now, and I just wanted to get past it so I could play the game, but there was so much code that I didn't want to delete it all. I just now backed all the code up, but there's still a lot to delete. I just want to fix it now so I can move on.