coolnickname

Untitled

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