Guest User

Untitled

a guest
May 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 KB | None | 0 0
  1. function TrainStuff(npc, who)
  2. var mt_elem := CPM_GetTrainCfgElem(CPM_GetMerchantType(npc));
  3. var skill_array := GetConfigStringArray( mt_elem, "Skill");
  4.  
  5. if(!skill_array || len(skill_array) == 0)
  6. PrintTextAbove(npc, "I have no skills that you can train");
  7. endif
  8.  
  9. var background := GFGetCfgConst("Defaults", "BackGround");
  10. var foreground := GFGetCfgConst("BackGrounds", "WHITE_PAPER");
  11. var X := 50;
  12. var Y := 50;
  13. var page := 1;
  14. var count := 0;
  15.  
  16. var gump := GFCreateGump(GCGUMP_X, GCGUMP_Y);
  17.  
  18. GFResizePic(gump, 0, 0, background, 300, 300);
  19. GFResizePic(gump, 25, 20, foreground, 250, 25);
  20.  
  21. GFTextLine(gump, 100, 22, TXT_CLR_FG, "Train skill");
  22. GFPage(gump, page);
  23. foreach skill in skill_array
  24. var cost := GetTrainingCost(who, skill);
  25. if(cost)
  26. GFAddButton(gump, X-10, Y, 2440, 2440, GF_CLOSE_BTN, AP_AttributeNameToSkillId(skill));
  27.  
  28. GFTextLine(gump, X, Y, TXT_CLR_BG+1, skill);
  29. GFTextLine(gump, X+165, Y, TXT_CLR_BG+1, cost + " gp");
  30. count += 1;
  31. Y += 30;
  32.  
  33. if ( count > 7 )
  34. GFAddButton(gump, 270, 260, 2706, 2707, GF_PAGE_BTN, page+1);
  35. page += 1;
  36. GFPage(gump, page);
  37. GFAddButton(gump, 270, 50, 2704, 2705, GF_PAGE_BTN, page-1);
  38. count := 0;
  39. Y := 50;
  40. endif
  41. endif
  42. endforeach
  43.  
  44. var result := GFSendGump(who, gump);
  45. if(result[0])
  46. var skill_name := AP_SkillIdToAttributeName(result[0]);
  47. var cost := GetTrainingCost(who, skill_name);
  48. //var skill_to_train := GetSkillToTraining(who, skill_name);
  49.  
  50. var newcost := CInt(RequestGump(who, "Enter the amount of gold you want to spend.", "Maximum of " + cost + " gp", "", CANCEL_BTN_ON));
  51. if(!newcost)
  52. return 0;
  53. endif
  54. if(newcost > cost)
  55. newcost := cost;
  56. endif
  57. if(who.SpendGold(newcost))
  58. SendSysMessage(who, "upgrading your skill with: " + CDbl(CDbl(newcost)/10));
  59. AP_SetTrueSkill(who, skill_name, (CDbl(AP_GetTrueSkill(who, skill_name)) + CDbl(CDbl(newcost)/10)));
  60. else
  61. PrintTextAbove(npc, "You do not have enough gold");
  62. endif
  63.  
  64.  
  65. endif
  66. endfunction
  67.  
  68.  
  69.  
  70. function SellStuff(npc, mobile, forsale, buyable, shopping_cart)
  71.  
  72. var merchant_type := CPM_GetMerchantType(npc);
  73.  
  74. AI_Turn(npc, mobile, NETURN_TOWARD);
  75. if ( !HasSellableItems(merchant_type, mobile.backpack) )
  76. AI_Speak(npc, "You don't have anything that I am interested in buying.");
  77. return 1;
  78. endif
  79.  
  80. var result := SendSellWindow(mobile, npc, forsale, shopping_cart, buyable);
  81. if ( result.errortext )
  82. PrintTextAbove(npc, "SendSellWindow() error - "+result.errortext);
  83. endif
  84.  
  85. return 1;
  86. endfunction
  87.  
  88. function SellBag(npc, who)
  89. PrintTextAbovePrivate( npc,"Which bag do you want to sell.",who);
  90. var tgt := Target(who);
  91. if (tgt.container.container.serial != who.serial)
  92. PrintTextAbovePrivate( npc,"That doust not belong to you.",who);
  93. return;
  94. endif
  95. var items := EnumerateItemsInContainer(tgt);
  96. if (len(items) < 1)
  97. PrintTextAbovePrivate( npc,"That is not a bag or it's an empty bag.",who);
  98. return;
  99. endif
  100. var iFound := 0;
  101. var item_cfg := ReadConfigFile("::itemdesc");
  102. var TotalSell := 0;
  103. var iFull := 0;
  104. var reserved := 0;
  105. //hmmm I wonder if not Sell Bag doesn't create to much lag.
  106. foreach item in items
  107. var item_elm := FindConfigElem(item_cfg,item.objtype);
  108. var iSellPricePerPiece := GetConfigInt(item_elm,"VendorBuysFor");
  109. if(!ReserveItem(item))
  110. reserved:= 1;
  111. else
  112. ReleaseItem(item);
  113. endif
  114. if ((iSellPricePerPiece) and (tgt.serial == item.container.serial)
  115. and (Len(EnumerateItemsInContainer(item)) < 1) and (!item.newbie) and (reserved != 1))
  116. ReleaseItem(item);
  117. iFound := 1;
  118. if (item.buyprice)
  119. if (item.amount)
  120. TotalSell := TotalSell + (item.buyprice * item.amount);
  121. else
  122. TotalSell := TotalSell + item.buyprice;
  123. endif
  124. else
  125. if (item.amount)
  126. TotalSell := TotalSell + (iSellPricePerPiece * item.amount);
  127. else
  128. TotalSell := TotalSell + iSellPricePerPiece;
  129. endif
  130. endif
  131. DestroyItem(item);
  132. endif
  133. endforeach
  134. if (iFound)
  135. PrintTextAbovePrivate( npc,"The total of thy sale is " + TotalSell,who);
  136. if (TotalSell > 60000)
  137. var iLeft := TotalSell;
  138. while (iLeft > 0)
  139. if (iLeft > 60000)
  140. if (!CreateItemInContainer(who.backpack,0xEED,60000))
  141. CreateItemAtLocation(who.x,who.y,who.z,0xEED,60000);
  142. iFull := 1;
  143. endif
  144. iLeft := iLeft - 60000;
  145. else
  146. if (!CreateItemInContainer(who.backpack,0xEED,iLeft))
  147. CreateItemAtLocation(who.x,who.y,who.z,0xEED,iLeft);
  148. iFull := 1;
  149. endif
  150. iLeft := 0;
  151. endif
  152. endwhile
  153. else
  154. if (!CreateItemInContainer(who.backpack,0xEED,TotalSell))
  155. CreateItemAtLocation(who.x,who.y,who.z,0xEED,TotalSell);
  156. iFull := 1;
  157. endif
  158. endif
  159. if (iFull)
  160. SendSysMessage(who,"Your backpack is full, placing gold on ground");
  161. endif
  162. else
  163. PrintTextAbovePrivate( npc,"Your bag got nothing that interests me.",who);
  164. endif
  165.  
  166. endfunction
  167.  
  168. function SellAll(npc, who)
  169. PrintTextAbovePrivate( npc, "Which kind of item would you like to sell?", who );
  170. var tgt := Target(who);
  171. if (tgt)
  172. var item_cfg := ReadConfigFile("::itemdesc");
  173. var item_elm := FindConfigElem(item_cfg,tgt.objtype);
  174. var iSellPricePerPiece := GetConfigInt(item_elm,"VendorBuysFor");
  175. var TotalSell := 0;
  176. var iFound := 0;
  177. var iObjType := tgt.objtype;
  178. var iFull := 0;
  179. var reserved := 0;
  180. if (iSellPricePerPiece)
  181. var items := EnumerateItemsInContainer(who.backpack);
  182. foreach item in items
  183. if(!ReserveItem(item))
  184. reserved:= 1;
  185. else
  186. ReleaseItem(item);
  187. endif
  188. if (item.container.serial == who.backpack.serial)
  189. if (item.objtype == iObjType)
  190. if ((Len(EnumerateItemsInContainer(item)) < 1) and (!item.newbie) and reserved != 1)
  191. ReleaseItem(item);
  192. iFound := 1;
  193. if (item.buyprice)
  194. if (item.amount)
  195. TotalSell := TotalSell + (item.buyprice * item.amount);
  196. else
  197. TotalSell := TotalSell + item.buyprice;
  198. endif
  199. else
  200. if (item.amount)
  201. TotalSell := TotalSell + (iSellPricePerPiece * item.amount);
  202. else
  203. TotalSell := TotalSell + iSellPricePerPiece;
  204. endif
  205. endif
  206. DestroyItem(item);
  207. endif
  208. endif
  209. endif
  210. endforeach
  211. if (iFound)
  212. PrintTextAbovePrivate( npc,"The total of thy sale is " + TotalSell,who);
  213. if (TotalSell > 60000)
  214. var iLeft := TotalSell;
  215. while (iLeft > 0)
  216. if (iLeft > 60000)
  217. if (!CreateItemInContainer(who.backpack,0xEED,60000))
  218. CreateItemAtLocation(who.x,who.y,who.z,0xEED,60000);
  219. iFull := 1;
  220. endif
  221. iLeft := iLeft - 60000;
  222. else
  223. if (!CreateItemInContainer(who.backpack,0xEED,iLeft))
  224. CreateItemAtLocation(who.x,who.y,who.z,0xEED,iLeft);
  225. iFull := 1;
  226. endif
  227. iLeft := 0;
  228. endif
  229. endwhile
  230. else
  231. if (!CreateItemInContainer(who.backpack,0xEED,TotalSell))
  232. CreateItemAtLocation(who.x,who.y,who.z,0xEED,TotalSell);
  233. iFull := 1;
  234. endif
  235. endif
  236. if (iFull)
  237. SendSysMessage(who,"Your backpack is full, placing gold on ground");
  238. endif
  239. else
  240. PrintTextAbovePrivate( npc,"You don't have any of that item.",who);
  241. endif
  242. else
  243. PrintTextAbovePrivate( npc,"Bah, I have no use for this. Be off with ye.",who);
  244. endif
  245. else
  246. SendSysMessage(who,"Canceled");
  247. endif
  248. endfunction
Add Comment
Please, Sign In to add comment