Yanfly's Steal Item - success check?

I am using Yanfly's Steal Item script for RPG Maker VX Ace.

I'd like to create a scenario where my player thief can stop an enemy from using skills by stealing from them.
Such examples would include:
- Stopping an enemy from using potions to heal themselves by stealing their stash of potions.
- Lowering the attack/stopping a certain skill of a bull by stealing its horns.
- Instant killing a machine enemy by stealing their core.

I'm wondering if there's a way for me to check if a steal attempt is successful?
Bump!
You can check if the steal was successful within the Game_Battler class by calling:
Code:
@result.success
and the stolen item by calling:
Code:
@result.stolen_item # see class RPG::Enemy::StealItem in Yanfly's script
You can check if the steal was successful within the Game_Battler class by calling:
Code:
@result.success
That;s the general success flag, it is true if ANY effect is applied on the target (including damage, added states, other effects and stealing).
I haven't checked the steal script much, but this specific variable won't help in this case.

Checking for the stolen item won't help either, because that only stores the last stolen item, and not the amount of items the enemy still has.

Getting all the items the enemy has can be done with this line:
Code:
enemy.stealable_items
You must replace the enemy here with a valid Game_Enemy object, such as:
Code:
$game_troop[index] # Gets the enemy at the index from the current troop
So, the variable mentioned returns an array of RPG::Enemy::StealItem objects, which are simple objects with 3 variables, from which you only need 2 for checking their item type (weapon, armor, item or gold) and item ID.

Without adding more boring details, here is a shortcut method you can use to check if an enemy has the specified item or not:
Spoiler
Code:
class Game_BattlerBase

  def check_pocket(type,id,amount=1)
    itms = stealable_items.select {|it| it.kind == type && it.data_id == id }
    return itms.size >= amount
  end

end
Put this snippet anywhere below the default scripts.
You would use it like this:
Code:
enemy.check_pocket(type,id,amount)
The type must be any of the following:
1 = Item
2 = Weapon
3 = Armor
4 = Gold
The id must be the database ID of the item you check for.
And the amount must be the amount of items you want to check for. You can also omit this argument, in which case 1 is used for this by default.
For example:
Code:
enemy.check_pocket(1,34,2)
This would return true if the enemy has at least 2 from Item 34 in their "pockets".

Now for actual usage...
For your first scenario, you would need an enemy AI script, I guess.
I saw some good ones which let you use scripted conditions for enemy skill usage in the enemy note-box. Get one of these (I think Tsukihime made one), and you should be able to use this code part in the note-tag:
Code:
check_pocket(type,id,amount)
Simply as that, since I guess, this piece of code will be executed on the enemy object itself, so no need to specify the enemy in this case.

For the second scenario, you can use this in the damage formula:
Code:
a.check_pocket(type,id,amount) ? formula1 : formula2
This checks if the attacker (so, the enemy) has the specified item or not.
If it has, execute formula1, otherwise execute formula2.
The formulas here are your own damage formulas, so enter whatever you want there, just like you do with your other damage formulas.
Using this means that the skill with these type of damage formulas must only be used by enemies!
Well, technically, you can use these skills even for actors, but the item check will always return false for them.

For the third scenario...
This can get complicated, since you can't use the damage formula for this one, because the stealing happens only after the damage is executed.
I don't have time to get this done, but with a little research, adding a little code here and there might make the trick.
You could try using common events, but I don't remember how to get the last target of the actors for the item check, so this requires some research too.

Anyway, coffee disappeared, so my break is over. 😀
Ohh, and as a final note, I did not test anything I wrote, so in case it doesn't work, don't punch me! 😛
That;s the general success flag, it is true if ANY effect is applied on the target (including damage, added states, other effects and stealing).
I haven't checked the steal script much, but this specific variable won't help in this case.

Checking for the stolen item won't help either, because that only stores the last stolen item, and not the amount of items the enemy still has.

Getting all the items the enemy has can be done with this line:
Code:
enemy.stealable_items
You must replace the enemy here with a valid Game_Enemy object, such as:
Code:
$game_troop[index] # Gets the enemy at the index from the current troop
So, the variable mentioned returns an array of RPG::Enemy::StealItem objects, which are simple objects with 3 variables, from which you only need 2 for checking their item type (weapon, armor, item or gold) and item ID.

Without adding more boring details, here is a shortcut method you can use to check if an enemy has the specified item or not:
Spoiler
Code:
class Game_BattlerBase

  def check_pocket(type,id,amount=1)
    itms = stealable_items.select {|it| it.kind == type && it.data_id == id }
    return itms.size >= amount
  end

end
Put this snippet anywhere below the default scripts.
You would use it like this:
Code:
enemy.check_pocket(type,id,amount)
The type must be any of the following:
1 = Item
2 = Weapon
3 = Armor
4 = Gold
The id must be the database ID of the item you check for.
And the amount must be the amount of items you want to check for. You can also omit this argument, in which case 1 is used for this by default.
For example:
Code:
enemy.check_pocket(1,34,2)
This would return true if the enemy has at least 2 from Item 34 in their "pockets".

Now for actual usage...
For your first scenario, you would need an enemy AI script, I guess.
I saw some good ones which let you use scripted conditions for enemy skill usage in the enemy note-box. Get one of these (I think Tsukihime made one), and you should be able to use this code part in the note-tag:
Code:
check_pocket(type,id,amount)
Simply as that, since I guess, this piece of code will be executed on the enemy object itself, so no need to specify the enemy in this case.

For the second scenario, you can use this in the damage formula:
Code:
a.check_pocket(type,id,amount) ? formula1 : formula2
This checks if the attacker (so, the enemy) has the specified item or not.
If it has, execute formula1, otherwise execute formula2.
The formulas here are your own damage formulas, so enter whatever you want there, just like you do with your other damage formulas.
Using this means that the skill with these type of damage formulas must only be used by enemies!
Well, technically, you can use these skills even for actors, but the item check will always return false for them.

For the third scenario...
This can get complicated, since you can't use the damage formula for this one, because the stealing happens only after the damage is executed.
I don't have time to get this done, but with a little research, adding a little code here and there might make the trick.
You could try using common events, but I don't remember how to get the last target of the actors for the item check, so this requires some research too.

Anyway, coffee disappeared, so my break is over. 😀
Ohh, and as a final note, I did not test anything I wrote, so in case it doesn't work, don't punch me! 😛

By checking both, the @result.success and @result.stolen_item, you can check if the steal was successful (if it is true and the stolen item is not nil).
My answer was more in case an add-on/edit script was needed. If he wants to get the success outside of scripts (script call events or something) of course it won't be that simple (your suggestion will be enough).

The third case scenario is simpler that it seems. Just by checking if the core (or a specific item) is stolen you can add the death state to the target (in Game_Enemy.refresh function), the same way it checks if the target's hp is 0.
Now for actual usage...
For your first scenario, you would need an enemy AI script, I guess.
I saw some good ones which let you use scripted conditions for enemy skill usage in the enemy note-box. Get one of these (I think Tsukihime made one), and you should be able to use this code part in the note-tag:
Code:
check_pocket(type,id,amount)
Simply as that, since I guess, this piece of code will be executed on the enemy object itself, so no need to specify the enemy in this case.

This works with Hime's AI script (only if I put "a." prior), but it I don't think it works with much else as I tried using it with Victor's Passive State script (the only one I've seen that utilises script conditions), but it ends up applying the state regardless of what I put in. Not sure if that's Victor's script being weird or the code snippet. Wanted to utilise this for the third scenario by adding a passive death state if the check_pocket amount was 0.

By checking both, the @result.success and @result.stolen_item, you can check if the steal was successful (if it is true and the stolen item is not nil).
My answer was more in case an add-on/edit script was needed. If he wants to get the success outside of scripts (script call events or something) of course it won't be that simple (your suggestion will be enough).

The third case scenario is simpler that it seems. Just by checking if the core (or a specific item) is stolen you can add the death state to the target (in Game_Enemy.refresh function), the same way it checks if the target's hp is 0.

I tried putting the following in my Steal skill's formula bar just to test the call you gave me (mind, I don't have the foggiest clue about Ruby).

Code:
@result.success && @result.stolen_item ? 500 : 100

But that returned null, so I'm not sure if I've written that wrong or not?
In the formula box, "a." is the user of the skill and "b." is the target, so using
Code:
a.check_pocket
will check the user's pocket for the item.

What I suggested will not work inside the formula as is and will have to be inside the Game_Enemy class, BUT it seems that the result of the steal and the item stolen are assigned (to the @result) AFTER the formula calculation (and also removed from the @stealable_items), which means that it is not possible to check it inside the formula (neither my approach nor @Sixth 's will work this way).

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-steal-item-success-check.83710/