So, I want to do something kinda interesting and have collectors in my game that are shop keepers. However, when you have a certain item that they want really bad, they buy it from you for more than what you bought it for from another vendor. So say I buy a bat wing from one vendor for 200 gold and another vendor happens to be a collector of bat wings and allows me to sell it for 300 gold instead of 100. How would I do something like that? Also I feel like this is something that is from a game I played, but don't remember what games had this feature. Any help is appreciated.
Collectors in game
RPG Maker MV SupportI think without a Plugin, you can only customize the overall price of an item per shop - which means if the collector sells the item they want to buy, they would sell it for the same modified price you provide.
You could ensure that the collector doesn't sell the thing they want really bad, which would make sense, since presumably they wouldn't have any if they're willing to pay a lot, so that you could set a custom price:
When you add items to the shop processing item list in the event editor, you can specify that the price is either "standard" or "specify", so you could, for a given shop, just specify double the value you want the collector to buy it for.
If you want the collector to sell the item they're willing to buy, but purchase it for something other than 50% its buy price, then I believe you'll need a Plugin, in which case:
Try saving this file in your plugins folder, or copy/paste the following into a .js file in your plugins folder:
I called the file CustomSellModifier.js, but it doesn't have any parameters, so it doesn't matter what you call it.
You can add comments before any shop processing command to specify that a particular item, weapon, or armor should have a different price modifier than the standard 50% one. Comments should be in the format "customSellModifier: itemType, itemId, modifier", where the itemType is either "weapon", "item", or "armor", the itemId is the Id of the item within that itemType, and modifier is a decimal that will be multiplied by the original price of the item to get the sell price.
I tested with the following setup in a default project:
Which means the weapon with Id 2 (Sword) should sell for 1.5x its original price, the item with Id 1 (Potion) should sell for 2x its original price, and the armor with Id 4 (Ring) should sell for 0.1x its original price. Everything else should sell at 0.5x its original price.
The custom sell prices of items should reset after the shop is closed, so when I open the shop the second time, the armor with Id 4 (Ring) will sell for 0.75x of its original price and everything else will sell for the default 0.5x original price value.
I'm not sure if there's a better way to figure out if a shop's item is a weapon, armor, or item, but since the same itemId can point to three different items, it's important to distinguish what set of items you're referring to before providing an Id, which is why you need to specify "weapon", "item", or "armor" as the first value.
I didn't build in case-insensitive checks, so it's important that the comments are in exactly that format: "customSellModifier: itemType, itemId, modifier".
You could ensure that the collector doesn't sell the thing they want really bad, which would make sense, since presumably they wouldn't have any if they're willing to pay a lot, so that you could set a custom price:
When you add items to the shop processing item list in the event editor, you can specify that the price is either "standard" or "specify", so you could, for a given shop, just specify double the value you want the collector to buy it for.
If you want the collector to sell the item they're willing to buy, but purchase it for something other than 50% its buy price, then I believe you'll need a Plugin, in which case:
Try saving this file in your plugins folder, or copy/paste the following into a .js file in your plugins folder:
Code:
/*:
* @plugindesc Allows specifying a custom modifier to the price
* of an item for a given shop via comments
* @author Zevia
*
* @help Before a shop processing command in a window, add comments in the
* format "customSellModifier: itemCategory, itemId, modifier".
* For example:
* customSellModifier: item, 1, 2
* customSellModifier: weapon, 3, 1.5
* customSellModifier: armor, 4, 0.1
* itemCategory MUST be either item, weapon, or armor.
* The default modifier for selling items is 0.5, meaning an item
* sells for half its purchase price. So with the above examples,
* in a default project, Potion would sell for double its buy
* price, Sword would sell for 50% over its buy price, and
* Ring would sell for 10% of its buy price.
*
* All customSellModifiers should be entered as separate comments,
* but as many as desired can be added in as many comments before
* the shop processing command as desired. Comments after
* the shop processing command won't be recognized.
*
* customSellModifiers are cleared after a shop interaction
* completes / when the Scene_Shop is popped.
*/
(function(module) {
'use strict';
var Zevia = module.Zevia || {};
var itemTypeByProperty = {
atypeId: 'armor',
itypeId: 'item',
wtypeId: 'weapon'
};
Zevia.commentCommand = Game_Interpreter.prototype.command108;
Game_Interpreter.prototype.command108 = function() {
var parts = this._params[0].split('customSellModifier:')[1];
if (!parts) { return Zevia.commentCommand.call(this); }
var parameters = parts.split(',');
if (parameters.length !== 3) { return Zevia.commentCommand.call(this); }
var itemType = parameters[0].replace(/[^a-zA-Z]/g, '');
var data = ({
armor: $dataArmors,
item: $dataItems,
weapon: $dataWeapons
})[itemType];
if (!data) { return Zevia.commentCommand.call(this); }
var itemId = parameters[1].replace(/\D/g, '');
var item = data[itemId];
if (!item) { return Zevia.commentCommand.call(this); }
var modifier = Number(parameters[2].replace(/[^\d.]/g, ''));
if (isNaN(modifier)) { return Zevia.commentCommand.call(this); }
$gameParty.sellModifierByItemIdByItemType = Object.assign(
$gameParty.sellModifierByItemIdByItemType || {},
{
[itemType]: {
[itemId]: modifier
}
}
)
return Zevia.commentCommand.call(this);
};
Zevia.sellingPrice = Scene_Shop.prototype.sellingPrice;
Scene_Shop.prototype.sellingPrice = function() {
var properties = ['atypeId', 'itypeId', 'wtypeId'];
var itemType;
for (let i = 0; i < properties.length; i++) {
var property = properties[i];
if (this._item[property]) {
itemType = itemTypeByProperty[property];
break;
}
}
if (!itemType) { return Zevia.sellingPrice.call(this); }
var modifierByItemId = $gameParty.sellModifierByItemIdByItemType[itemType];
if (!modifierByItemId) { return Zevia.sellingPrice.call(this); }
var modifier = modifierByItemId[this._item.id];
if (!modifier && modifier !== 0) { return Zevia.sellingPrice.call(this); }
return Math.floor(this._item.price * modifier);
};
Zevia.popScene = SceneManager.pop;
SceneManager.pop = function() {
if (this._scene instanceof Scene_Shop) {
$gameParty.sellModifierByItemIdByItemType = {};
}
Zevia.popScene.call(this);
};
})(window);
I called the file CustomSellModifier.js, but it doesn't have any parameters, so it doesn't matter what you call it.
You can add comments before any shop processing command to specify that a particular item, weapon, or armor should have a different price modifier than the standard 50% one. Comments should be in the format "customSellModifier: itemType, itemId, modifier", where the itemType is either "weapon", "item", or "armor", the itemId is the Id of the item within that itemType, and modifier is a decimal that will be multiplied by the original price of the item to get the sell price.
I tested with the following setup in a default project:
Which means the weapon with Id 2 (Sword) should sell for 1.5x its original price, the item with Id 1 (Potion) should sell for 2x its original price, and the armor with Id 4 (Ring) should sell for 0.1x its original price. Everything else should sell at 0.5x its original price.
The custom sell prices of items should reset after the shop is closed, so when I open the shop the second time, the armor with Id 4 (Ring) will sell for 0.75x of its original price and everything else will sell for the default 0.5x original price value.
I'm not sure if there's a better way to figure out if a shop's item is a weapon, armor, or item, but since the same itemId can point to three different items, it's important to distinguish what set of items you're referring to before providing an Id, which is why you need to specify "weapon", "item", or "armor" as the first value.
I didn't build in case-insensitive checks, so it's important that the comments are in exactly that format: "customSellModifier: itemType, itemId, modifier".
Unless I am misunderstanding, you could also do this with simple Eventing.
When you first interact with the shop keeper, you can do a simple check to see if the party has the type of item that they collect. If so, before you trigger normal shop processing, you could do Dialog for the shop keeper to offer to buy the item at a higher price. If you say no, then you enter normal shop processing. If yes, you code the Event to handle it outside of shop processing.
You could actually do quite a bit of immersive NPC interaction with this using Eventing.
But a plugin might be easier for you and might meet your needs.
When you first interact with the shop keeper, you can do a simple check to see if the party has the type of item that they collect. If so, before you trigger normal shop processing, you could do Dialog for the shop keeper to offer to buy the item at a higher price. If you say no, then you enter normal shop processing. If yes, you code the Event to handle it outside of shop processing.
You could actually do quite a bit of immersive NPC interaction with this using Eventing.
But a plugin might be easier for you and might meet your needs.
I'd still opt for the plugin solution, since if you want to buy something from the vendor as well as sell your item, you'd have to go into normal shop processing after selling the item, which is an extra step for no real reason.
It gets extra odd if you're selling something else too, which means you're going through two separate processes to sell items instead of one.
You are absolutely amazing! Thanks for that. It worked out perfectly.
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!
Original thread: https://forums.rpgmakerweb.com/threads/collectors-in-game.167313/