Advertiser Content

# Scripting Question Function Code Help

Started by clawort 4 Weeks Ago 9:52 PM
• 1137 views
• 9 replies
Okay I am making a Function Code for a new move. It is called Sky Lunge and the move fails if the target is heavier than the user.

Idk how to make a Function Code that does it so would someone please help?
Burn your neurons and edit Sucker Punch for what you want:

```################################################################################
# Fails if the target didn't chose a damaging move to use this round, or has
# already moved. (Sucker Punch)
################################################################################
class PokeBattle_Move_116 < PokeBattle_Move
def pbMoveFailed(attacker,opponent)
return true if @battle.choices[opponent.index][0]!=1 # Didn't choose a move
oppmove=@battle.choices[opponent.index][2]
return true if !oppmove || oppmove.id<=0 || oppmove.pbIsStatus?
return true if opponent.hasMovedThisRound? && oppmove.function!=0xB0 # Me First
return false
end
end```
Check Heavy Slam's code to recognize the weight:
```################################################################################
# Power increases the heavier the user is than the target. (Heat Crash, Heavy Slam)
################################################################################
class PokeBattle_Move_09B < PokeBattle_Move
def pbBaseDamage(basedmg,attacker,opponent)
n=(attacker.weight/opponent.weight(attacker)).floor
ret=40
ret=60 if n>=2
ret=80 if n>=3
ret=100 if n>=4
ret=120 if n>=5
return ret
end
end```
Good luck.
Also, this might go without saying, but make sure to assign a unique code to it as well. In the scripts where move functions are defined, you'll see this pattern at the start:
`class PokeBattle_Move_### < PokeBattle_Move`
where ### is the actual function code - the one that you would assign to the move in the PBS. It's a three digit hexadecimal number. Base essentials goes up to 158 with function codes, so the next available would be 159, then 15A, up to 15F, then 160. But they don't have to be sequential. You could just start up at 500 and guarantee that you're not overriding another code.

And sorry if this is all stuff you're aware of - just trying to provide a thorough answer and maybe help out someone else who comes across this post in the future.
Burn your neurons and edit Sucker Punch for what you want:

```################################################################################
# Fails if the target didn't chose a damaging move to use this round, or has
# already moved. (Sucker Punch)
################################################################################
class PokeBattle_Move_116 < PokeBattle_Move
def pbMoveFailed(attacker,opponent)
return true if @battle.choices[opponent.index][0]!=1 # Didn't choose a move
oppmove=@battle.choices[opponent.index][2]
return true if !oppmove || oppmove.id<=0 || oppmove.pbIsStatus?
return true if opponent.hasMovedThisRound? && oppmove.function!=0xB0 # Me First
return false
end
end```
Check Heavy Slam's code to recognize the weight:
```################################################################################
# Power increases the heavier the user is than the target. (Heat Crash, Heavy Slam)
################################################################################
class PokeBattle_Move_09B < PokeBattle_Move
def pbBaseDamage(basedmg,attacker,opponent)
n=(attacker.weight/opponent.weight(attacker)).floor
ret=40
ret=60 if n>=2
ret=80 if n>=3
ret=100 if n>=4
ret=120 if n>=5
return ret
end
end```
Good luck.
Yeah but...

How do I do that?

Also, I think I already started so, is this correct?
################################################################################
# Fails if the target is heavier than the user. (Sky Lunge)
################################################################################
class PokeBattle_Move_15A < PokeBattle_Move
def pbMoveFailed(attacker,opponent)
return (attacker.weight<opponent.weight)
end
Also, this might go without saying, but make sure to assign a unique code to it as well. In the scripts where move functions are defined, you'll see this pattern at the start:
`class PokeBattle_Move_### < PokeBattle_Move`
where ### is the actual function code - the one that you would assign to the move in the PBS. It's a three digit hexadecimal number. Base essentials goes up to 158 with function codes, so the next available would be 159, then 15A, up to 15F, then 160. But they don't have to be sequential. You could just start up at 500 and guarantee that you're not overriding another code.

And sorry if this is all stuff you're aware of - just trying to provide a thorough answer and maybe help out someone else who comes across this post in the future.
Already got that! :D
################################################################################
# Fails if the target is heavier than the user. (Sky Lunge)
################################################################################
class PokeBattle_Move_15A < PokeBattle_Move
def pbMoveFailed(attacker,opponent)
return (attacker.weight<opponent.weight)
end
Pay attention, you need to put 'return true if' and then 'return false', like you saw in Sucker Punch. Also, you don't need '()' between code.
Pay attention, you need to put 'return true if' and then 'return false', like you saw in Sucker Punch. Also, you don't need '()' between code.
Actually, I think that syntax is fine since (attacker.weight<opponent.weight) will already be a boolean value. The only change I might add is
```class PokeBattle_Move_15A < PokeBattle_Move
def pbMoveFailed(attacker,opponent)
return ((attacker.weight<opponent.weight) rescue false)
end```
just to catch any errors.
Pay attention, you need to put 'return true if' and then 'return false', like you saw in Sucker Punch. Also, you don't need '()' between code.
I'm confused...!
Actually, I think that syntax is fine since (attacker.weight<opponent.weight) will already be a boolean value. The only change I might add is
```class PokeBattle_Move_15A < PokeBattle_Move
def pbMoveFailed(attacker,opponent)
return ((attacker.weight<opponent.weight) rescue false)
end```
just to catch any errors.
Okay! Thanks!
Okay so it works!

Everything functions correctly. The move works on Pokemon that are lighter than the user but not heavier than the user!

This is the function code I used:
################################################################################
# Fails if the target is heavier than the user. (Sky Lunge)
################################################################################
class PokeBattle_Move_15A < PokeBattle_Move
def pbMoveFailed(attacker,opponent)
return true if ((attacker.weight<opponent.weight) rescue false)
return false
end
end
Advertiser Content