Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var tier = 0;
- var msgArray = [];
- //lib.Reputation.addReputationAndNotify(chatter, "Elpida", int);
- var allowedItems = {"mf:pickaxeiron":2,"mf:oreiron":50,"mf:oregold":50,"mf:emeraldrough":50}
- var demosellmargin = 1.45
- var buymargin = 0.8
- var currentlyLooking = undefined;
- function openAdvancedShop(chatter, msg){
- currentlyLooking = chatter.getUniqueId();
- tier = lib.Reputation.getReputationTier(chatter, "Elpida");
- var data = lib.shop.gui.SimpleShopData.of(
- lib.shop.provider.DBNPCBalance,
- makeSellPrice,
- makeBuyPrice,
- lib.shop.provider.defaultOnMoneyAction,
- npc);
- lib.shop.gui.openShopGUI(chatter, data, traits.mfplayerinventorytrait);
- }
- function getText(a){
- return a[Math.floor(Math.random()*a.length)];
- }
- function onoff(chatter){
- if (chatter.getUniqueId() == currentlyLooking)
- currentlyLooking = undefined;
- }
- function makeSellPrice(npc, itemstack){
- if (!(itemstack.getItem().getName() in allowedItems))
- return -1;
- return ( getPrice(itemstack)*makeSellMargin()).intValue();
- }
- function makeBuyPrice(npc, itemstack){
- if (!(itemstack.getItem().getName() in allowedItems))
- return -1;
- var inv = npc.getTrait(Java.type("com.minecraftfrontiers.mfnpc.traits.inventory.MFPlayerInventoryTrait").class);
- if (inv.getAmount(itemstack.getItem().getName())+itemstack.getAmount() >= allowedItems[itemstack.getItem().getName()])
- return -1;
- return (getPrice(itemstack)*buymargin).intValue();
- }
- function getPrice(itemstack){
- var r = lib.meta.getValue(itemstack.getItem().getName());
- return r <= 0?-1 : r;
- }
- function makeSellMargin(){
- var marg_output = demosellmargin - 0.05 * tier;
- say(npc, "Your sellmargin is ", marg_output);
- return marg_output;
- }
- function onchat(chatter, msg) {
- tier = lib.Reputation.getReputationTier(chatter, "Elpida");
- msgArray = msg.split(" ");
- if(msgArray[0].indexOf("rawr") > -1 ){
- say(npc, "Your rep level is ", tier);
- say(npc, "Your sell margin is ", makeSellMargin());
- openAdvancedShop(chatter);
- }else if(msgArray[0].indexOf("upgrade") > -1 ){
- lib.Reputation.addReputationAndNotify(chatter, "Elpida", msgArray[1]);
- say(npc, "Added ", msgArray[1], " rep points");
- }else if(msgArray[0].indexOf("downgrade") > -1 ){
- lib.Reputation.addReputationAndNotify(chatter, "Elpida", msgArray[1]);
- say(npc, "Removed " + msgArray[1] + " rep points");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment