This is a very old thread, and I don't know if for
@_Soysauce_ this is still relevant, but while I was just searching to a solution of sorting items by myself, I landet here.
Reading all your answers and suggestions, I believe the answer was already here - or at least you were all close to it.
So I managed to do that task with very few lines of code and I would like to share this. I would like to hear if I have forgotten something at last?
My addition to this task is to just add one property to the "item" objects:
item._lastGainedDate which is set exactly in the function mentioned by
@Maliki79 and set it to "Date()".
Hit me, but I believe this is the only function that covers all the possibilities that
@Andar was concerned about. (I tried it and even if you stripp off a weapon that had been on the actor at game start, this function is called to put it to the menu!).
So the code is looking like that:
JavaScript:
former_Game_Party_gainItem = Game_Party.prototype.gainItem;
Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
// only when gaining item not by loosing
if (amount > 0) {
if (item) {
if (!item._lastGainedDate) {
item._firstGainedDate = Date();
}
item._lastGainedDate = Date();
}
}
former_Game_Party_gainItem.call(this, item, amount, includeEquip);
};
The function to sort by last acquired Item would look like this:
JavaScript:
//sort Items by last gained Date (last will be first)
Window_ItemList.prototype.makeItemList = function() {
this._data = $gameParty.allItems().filter(item => this.includes(item));
this._data.sort(function(a,b){
if(a._lastGainedDate < b._lastGainedDate) return 1;
if(a._lastGainedDate > b._lastGainedDate) return -1;
return 0;
});
if (this.includes(null)) {
this._data.push(null);
}
};
I put everything in a plugin and it works quite decent!
(You may have noticed that I added another timestamp called item._firstGainedDate, so you could also sort by first acquisition of this item type)
So for me the answer is to note everything to the item id and to not try to think about single item "instances". That gives a simple solution that should also be fast in excecution.
Please comment, if you still see any issues.
My question would be how to make it possible to the user to choose a sorting option from the menu itself (how to add a kind of sorting option subwindow). If anybody has an idea on that, I'd be glad to hear about it
🙂