Checking in a script if a given state is in effect.

I'm working on a mini script and I've hit something I don't know how to do. I'm looking for a conditional that checks if the target of an action has a specific state and effects the hit rate. I'll write what I have so far. The underlined part is just pseudocode, since that's what I don't know. I'm pretty sure the rest should work fine.

class Game_Battler < Game_BattlerBase
def item_hit(user, item)
rate = 1.0
rate = 0.5 if target.has_state[5]? # Lower hit rate to 50% if target has specific state.
return rate
end
end

So, yeah. I just need to know what to replace the underlined part with.
You can use:
Ruby:
state?(5)
You can use:
Ruby:
state?(5)

Thank you. It's working perfectly.
You can also write it like this:

class Game_Battler < Game_BattlerBase
def item_hit(user, item)
rate = target.state?(5)? 0.5 : 1.0 # Lower hit rate to 50% if target has specific state.
end
end

return is unnecessary since rate is the last value read or calculated in that method of yours. It's only convenient if you just need to check 2 different possibilities. You can also include a third by inserting a secondary ternary condition (it's what I've posted above) but usually you wouldn't need to do that.

Just in case I'd like to remind you that you can also rely on alias to keep the method's original code working while you can still add new functionality like that rate.
class Game_Battler < Game_BattlerBase
def item_hit(user, item)
rate = target.state?(5)? 0.5 : 1.0 # Lower hit rate to 50% if target has specific state.
end
end
"target" does not exist in this context, and assigning to "rate" is not even necessary either. It can be simplified as state?(5) ? 0.5 : 1.0
Let's say rate could have been left untouched just to let the user recall what it is all about. Concerning target... yeah, that would throw a NoMethodError message at once. Only if you need to make it afflict an enemy or any other actor, you would need to specify target, probably by adding a third argument to the method definition and making it option to keep it compatible with any previous definition, if there was any...

Original thread: https://forums.rpgmakerweb.com/threads/checking-in-a-script-if-a-given-state-is-in-effect.117390/