Need help with Yanfly's Enemy Thieves Tips and Tricks code.

After Eval>


if (user.isEnemy(1)) {


var successRate = 0.5;


if (Math.random(1) < successRate) {


var items = [1];


var total = $gameParty.items(1).length;


for (var i = 0; i < total; ++i) {


var item = $gameParty.items(1);


if (item.itypeId !== 2) items.push(item);


}


var random = Math.floor(Math.random() * items.length);


var item = items[random];


$gameParty.loseItem(item, 1);


var text = user.name(1) + ' stole ' + item.name + ' from the party!';


SoundManager.playEquip(1);


} else {


var text = user.name(1) + ' failed to steal an item!';


SoundManager.playBuzzer(1);


}


var window = SceneManager._scene._logWindow;


window._lines.push(text + '<CENTER>');


window.refresh(1);


}


</After Eval>

Okay, I must be doing something wrong here. I just tried to do the Enemy Thieves thing with my Steal Item (partially to see if it was successfully working and partially because I'm trying to still do the "Enemies Steal Weapons thing") skill. At first I copy pasted the code exactly as you put it in the video. That got me this. I tried again, adding in numbers to any paratheses I found. Same result when the Slime went up to perform the Pilfer action.


 


For what it's worth, here's the code for the regular action:

<Steal Item>


 


<setup action>


display action


immortal: targets, true


</setup action>


 


<target action>


move user: targets, front, 20


motion standby: user


wait for movement


face user: target


action animation: target


move user: targets, base, 10


motion thrust: user, no weapon


wait: 15


action effect


jump user: 50, 10


move user: targets, front, 10


face user: forward


wait: 60


</target action>

Does anybody know what I'm doing wrong?


Screenshot 2016-04-04 01.27.02.png






 

I decided to fiddle with the Enemy Thieves notetags a bit and managed to make enemies steal actor's weapons. It works... sort of.


<After Eval>
if (user.isEnemy()) {
var successRate = 0.5;
if (Math.random() < successRate) {
var weapons = [];
var total = target.weapons().length;
for (var i = 0; i < total; ++i) {
var weapon = target.weapons();
}
if (weapon === "null") {
var text = user.name() + ' found nothing to steal!';
} else {
target.discardEquip(weapon);
var text = user.name() + ' stole ' + weapon.name + '!';
SoundManager.playEquip();
}
} else {
var text = user.name() + ' failed to steal a weapon!';
SoundManager.playBuzzer();
}
var window = SceneManager._scene._logWindow;
window._lines.push(text + '<CENTER>');
window.refresh();
}
</After Eval>


There's just one major downside: I haven't managed to figure out how to get the code check if the target has no weapon (i.e. the part with if (weapon === "null") doesn't work). Currently, the game crashes if the enemy tries to steal weapon from a target which doesn't have one equipped because it can't read the 'name' value of 'weapon'.


I can try to find a solution later on, but it might take a couple of days because I am busy with work. I decided to post the code nevertheless in case you or someone else managed to point out where I went wrong. 🙂
I decided to fiddle with the Enemy Thieves notetags a bit and managed to make enemies steal actor's weapons. It works... sort of.


There's just one major downside: I haven't managed to figure out how to get the code check if the target has no weapon (i.e. the part with if (weapon === "null") doesn't work). Currently, the game crashes if the enemy tries to steal weapon from a target which doesn't have one equipped because it can't read the 'name' value of 'weapon'.


I can try to find a solution later on, but it might take a couple of days because I am busy with work. I decided to post the code nevertheless in case you or someone else managed to point out where I went wrong. 🙂



Try either


if (weapon === null) // without quotes


or

Code:
if (!weapon)
Try either



if (weapon === null) // without quotes


or



if (!weapon)

The latter one seemed to do the trick, thanks! At least on my quick test run everything worked as intended.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-yanflys-enemy-thieves-tips-and-tricks-code.59971/