Make enemy drop Item via script?

Hi everyone 🙂 i wonder is there anyway to make enemy X drop its Items via script call but not by killing it.
I tried: $gameTroop.members()[0].makeDropItems();
but nothing happened :/ please help : (
This seems to work for me~
Code:
BattleManager._rewards.items = $gameTroop.members()[0].makeDropItems();
BattleManager.displayDropItems();
BattleManager.gainDropItems();
This seems to work for me~
Code:
BattleManager._rewards.items = $gameTroop.members()[0].makeDropItems();
BattleManager.displayDropItems();
BattleManager.gainDropItems();
hi @caethyril , these codes does give Player items from Enemy[0] however it doesn't remove those items from the enemy after that.
So after run this code, those items still be dropped from the enemy if player killed it 🙂 does that make sense?
@Isabella Ava the enemy doesn't have an "inventory" the way that the party does. The game just makes items appear when the enemy is killed (and you're mimicking that behavior with the script calls caethyril provided). There's no simple script call way of doing what you want; you'd need a plugin to change the way makeDropItems() and/or gainDropItems() behave. Most likely it would involve setting some sort of switch to determine whether the items had already been "removed" from the enemy prior to the function call.

Have you checked existing plugins, like Yanfly's Steal & Snatch?
Hi @Llareian thank you for your suggestion. By the way i want to ask something.
how can i check Sprite_Enemy's properties of a specified Enemy?
for example i want to check Enemy id 1's Sprite_Enemy's properties, how do i do that?
upload_2018-3-7_0-18-18.png
@Isabella Ava
Why do you want the sprite properties? If it's coordinates you're seeking, it seems that Game_Enemy has screenX() and screenY().

Otherwise, I'm not certain, but I think this will return the nth enemy sprite on Scene_Battle:
Code:
SceneManager._scene._spriteset._enemySprites[n]
Pretty sure that the sprites do not necessarily follow the same order as the troop members, though? It looks to me like it's meant to be a one-way relation from Game_Enemy to Sprite_Enemy. I'm pretty lost here actually...maybe something like this? 😅
Code:
var nmeSprite = null, seekName = $gameTroop.members()[0].name();
for (var n = 0; n < SceneManager._scene._spriteset._enemySprites.length; n++) {
  var thisSprite = SceneManager._scene._spriteset._enemySprites[n];
  if (thisSprite._battlerName = seekName) {
    nmeSprite = thisSprite;
    break;
  }
};
hi @caethyril
To tell you my problem in detail, i am using MogHunter's Treasure Popup in Battle plugin: https://atelierrgss.wordpress.com/rmv-treasure-popup-battle/
I really want to make enemy drop items when a certain condition has met instead of that they got killed.
After looking into the plugin codes, i guess this is the code to make Items Pop up:
SpriteEnemyTrP.prototype.initialize = function(sprite) {

Sprite.prototype.initialize.call(this);

this._sprite = sprite;

this._mode = Moghunter.trPopup_animation;

this.visible = false;

this._enemy = this._sprite._enemy;

this.createIcon();

if ($gameTemp._trBatRealTimeDrop) {

$gameTemp._trBatDropLock = true;

this.gainDropItems();

};

};

I am trying to find a way to invoke this function in battle via script to see if it is the code to "Pop Up Item" or not
SpriteEnemyTrP.prototype.initialize(argument)
but i am not sure how to do it properly, look like it will need sprite as its argument.
And this sprite is Sprite_Enemy object i showed in the picture at my previous post.
That why i want to access Sprite_Enemy property of a specified Enemy :|
But it doesn't work, those codes doesn't make Item Pop Up :|
hi @caethyril
can i ask how did you know that SceneManager will hold enemySprites?
I search for "enemySprites" however only Rpg_sprites does have some matches.
But none of them could tell that SceneManager hold this property.
How could you know that this will work:
SceneManager._scene._spriteset._enemySprites[n]
Hi @Isabella Ava
The sprites are organised in spritesets, which are a member of the appropriate scene: Scene_Map for Spriteset_Map, Scene_Battle for Spriteset_Battle. Try searching up the createEnemies() method of Spriteset_Battle to see the link. So then I just searched the base script files for Spriteset_Battle, noticed it was used in rpg_scenes.js, and checked it out. It turns out that the spriteset is assigned to the _spriteset property via the scene's createSpriteset() method. SceneManager._scene just retrieves the current scene instance. ^_^

I'm not familiar with that plugin, though, so not sure how much help I can be. Perhaps this would be better posted in Plugin Support? 😅
🙂 thanks @caethyril , you helped me a lots . Knew how to check Sprite_Enemy is a great help already
Oh, I've just discovered that Yanfly's Battle Engine Core plugin defines a battler() function on Game_Battler (thus also available on Game_Actor & Game_Enemy) that returns the battler's sprite! I don't know whether you're using that plugin, but if you are:
Code:
$gameTroop.members()[n].battler()
Thought it was worth mentioning. (I should have checked earlier...) =P
Oh, I've just discovered that Yanfly's Battle Engine Core plugin defines a battler() function on Game_Battler (thus also available on Game_Actor & Game_Enemy) that returns the battler's sprite! I don't know whether you're using that plugin, but if you are:
Code:
$gameTroop.members()[n].battler()
Thought it was worth mentioning. (I should have checked earlier...) =P
: O that was a nice discover, but - again, how did you find out about it 🙂
Were you checking Yanfly Battle Engine Core and find it out in coincidence or
you able to tell that just by looking at console log?
Even after you told me, looking at the console log, I couldn't able to tell what battler() function return until i tried it
upload_2018-3-7_23-57-19.png
There's no simple script call way of doing what you want; you'd need a plugin to change the way makeDropItems() and/or gainDropItems() behave
all you really need to do is clear enemy._dropItems (syntax?) after you've dropped the lot the fist time.
it's *one* instruction.
: O that was a nice discover, but - again, how did you find out about it 🙂
I just remembered Yanfly's action sequence pack 2 lets you move battlers around. I checked that plugin and saw a battler function, but it wasn't defined in that plugin. So I checked the required one, Battle Engine Core, and there it was! 😂

I don't really use the console for finding out about new functions. I mostly just use it to double-check things and see detailed error messages. The actual code files are a more helpful learning resource for me. That said, something like this should print the function code to the console for easy reading:
Code:
console.log($gameTroop.members()[0].battler);
No brackets tells it to output the function itself rather than the result of the function. =)

@gstv87 I think the dropItems property is defined on $dataEnemies, not the troop instance, but I could be wrong.
@gstv87 I think the dropItems property is defined on $dataEnemies, not the troop instance, but I could be wrong.
To tack on to what @gstv87 said. gstv87 actually correct. Inside makeDropItems() is this.enemy().dropItems. This implies that makeDropItems reads an instance of enemy, which is created at the start of battle by Game_Troop, and not directly from the database. Which means you can, in theory, do something like:
Code:
$gameTroop.members()[0].dropItems[0].kind = 0
So, when makeDropItems() recognized that the item's kind is 0 it'll skip it and emulates an empty inventory.

Note: Be aware that dropItems[0] mean first dropable item and dropItems[1] is second dropped item. Also, I didn't test this. theory theory. theory.
@Adventurer_inc.
Nice theory, but I just tested and it doesn't seem to work as you'd hope. =(

As far as I can tell, the enemy() function returns a pointer to the $dataEnemies array at the index corresponding to the enemy type. You can edit the data, but that changes the record for all enemies of that type. Might cause bugginess with save files as well, I'm not sure what is saved and what isn't. 👋

As Llareian said right at the start, I think Yanfly's Steal & Snatch plugin is probably one of the best ways to go with this...
I stand corrected:
Code:
Game_Enemy.prototype.enemy = function() {
    return $dataEnemies[this._enemyId];
};
Database strikes again.

Original thread: https://forums.rpgmakerweb.com/threads/make-enemy-drop-item-via-script.92280/