coolnickname

Untitled

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