coolnickname

Untitled

Jul 13th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. var tier = 0;
  2. var msgArray = [];
  3.  
  4. //lib.Reputation.addReputationAndNotify(chatter, "Elpida", int);
  5.  
  6. var allowedItems = {"mf:pickaxeiron":2,"mf:oreiron":50,"mf:oregold":50,"mf:emeraldrough":50}
  7. var demosellmargin = 1.45
  8. var buymargin = 0.8
  9. var currentlyLooking = undefined;
  10.  
  11. function openAdvancedShop(chatter, msg){
  12. currentlyLooking = chatter.getUniqueId();
  13. tier = lib.Reputation.getReputationTier(chatter, "Elpida");
  14.  
  15.  
  16. var data = lib.shop.gui.SimpleShopData.of(
  17. lib.shop.provider.DBNPCBalance,
  18. makeSellPrice,
  19. makeBuyPrice,
  20. lib.shop.provider.defaultOnMoneyAction,
  21. npc);
  22.  
  23. lib.shop.gui.openShopGUI(chatter, data, traits.mfplayerinventorytrait);
  24. }
  25.  
  26.  
  27.  
  28. function getText(a){
  29. return a[Math.floor(Math.random()*a.length)];
  30. }
  31.  
  32. function onoff(chatter){
  33. if (chatter.getUniqueId() == currentlyLooking)
  34. currentlyLooking = undefined;
  35. }
  36.  
  37. function makeSellPrice(npc, itemstack){
  38. if (!(itemstack.getItem().getName() in allowedItems))
  39. return -1;
  40. return ( getPrice(itemstack)*makeSellMargin()).intValue();
  41. }
  42.  
  43. function makeBuyPrice(npc, itemstack){
  44. if (!(itemstack.getItem().getName() in allowedItems))
  45. return -1;
  46. var inv = npc.getTrait(Java.type("com.minecraftfrontiers.mfnpc.traits.inventory.MFPlayerInventoryTrait").class);
  47. if (inv.getAmount(itemstack.getItem().getName())+itemstack.getAmount() >= allowedItems[itemstack.getItem().getName()])
  48. return -1;
  49.  
  50. return (getPrice(itemstack)*buymargin).intValue();
  51. }
  52.  
  53. function getPrice(itemstack){
  54. var r = lib.meta.getValue(itemstack.getItem().getName());
  55. return r <= 0?-1 : r;
  56. }
  57.  
  58. function makeSellMargin(){
  59. var marg_output = demosellmargin - 0.05 * tier;
  60. say(npc, "Your sellmargin is ", marg_output);
  61. return marg_output;
  62. }
  63.  
  64. function onchat(chatter, msg) {
  65. tier = lib.Reputation.getReputationTier(chatter, "Elpida");
  66. msgArray = msg.split(" ");
  67. if(msgArray[0].indexOf("rawr") > -1 ){
  68. say(npc, "Your rep level is ", tier);
  69. say(npc, "Your sell margin is ", makeSellMargin());
  70. openAdvancedShop(chatter);
  71. }else if(msgArray[0].indexOf("upgrade") > -1 ){
  72. lib.Reputation.addReputationAndNotify(chatter, "Elpida", msgArray[1]);
  73. say(npc, "Added ", msgArray[1], " rep points");
  74. }else if(msgArray[0].indexOf("downgrade") > -1 ){
  75. lib.Reputation.addReputationAndNotify(chatter, "Elpida", msgArray[1]);
  76. say(npc, "Removed " + msgArray[1] + " rep points");
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment