Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TrainStuff(npc, who)
- var mt_elem := CPM_GetTrainCfgElem(CPM_GetMerchantType(npc));
- var skill_array := GetConfigStringArray( mt_elem, "Skill");
- if(!skill_array || len(skill_array) == 0)
- PrintTextAbove(npc, "I have no skills that you can train");
- endif
- var background := GFGetCfgConst("Defaults", "BackGround");
- var foreground := GFGetCfgConst("BackGrounds", "WHITE_PAPER");
- var X := 50;
- var Y := 50;
- var page := 1;
- var count := 0;
- var gump := GFCreateGump(GCGUMP_X, GCGUMP_Y);
- GFResizePic(gump, 0, 0, background, 300, 300);
- GFResizePic(gump, 25, 20, foreground, 250, 25);
- GFTextLine(gump, 100, 22, TXT_CLR_FG, "Train skill");
- GFPage(gump, page);
- foreach skill in skill_array
- var cost := GetTrainingCost(who, skill);
- if(cost)
- GFAddButton(gump, X-10, Y, 2440, 2440, GF_CLOSE_BTN, AP_AttributeNameToSkillId(skill));
- GFTextLine(gump, X, Y, TXT_CLR_BG+1, skill);
- GFTextLine(gump, X+165, Y, TXT_CLR_BG+1, cost + " gp");
- count += 1;
- Y += 30;
- if ( count > 7 )
- GFAddButton(gump, 270, 260, 2706, 2707, GF_PAGE_BTN, page+1);
- page += 1;
- GFPage(gump, page);
- GFAddButton(gump, 270, 50, 2704, 2705, GF_PAGE_BTN, page-1);
- count := 0;
- Y := 50;
- endif
- endif
- endforeach
- var result := GFSendGump(who, gump);
- if(result[0])
- var skill_name := AP_SkillIdToAttributeName(result[0]);
- var cost := GetTrainingCost(who, skill_name);
- //var skill_to_train := GetSkillToTraining(who, skill_name);
- var newcost := CInt(RequestGump(who, "Enter the amount of gold you want to spend.", "Maximum of " + cost + " gp", "", CANCEL_BTN_ON));
- if(!newcost)
- return 0;
- endif
- if(newcost > cost)
- newcost := cost;
- endif
- if(who.SpendGold(newcost))
- SendSysMessage(who, "upgrading your skill with: " + CDbl(CDbl(newcost)/10));
- AP_SetTrueSkill(who, skill_name, (CDbl(AP_GetTrueSkill(who, skill_name)) + CDbl(CDbl(newcost)/10)));
- else
- PrintTextAbove(npc, "You do not have enough gold");
- endif
- endif
- endfunction
- function SellStuff(npc, mobile, forsale, buyable, shopping_cart)
- var merchant_type := CPM_GetMerchantType(npc);
- AI_Turn(npc, mobile, NETURN_TOWARD);
- if ( !HasSellableItems(merchant_type, mobile.backpack) )
- AI_Speak(npc, "You don't have anything that I am interested in buying.");
- return 1;
- endif
- var result := SendSellWindow(mobile, npc, forsale, shopping_cart, buyable);
- if ( result.errortext )
- PrintTextAbove(npc, "SendSellWindow() error - "+result.errortext);
- endif
- return 1;
- endfunction
- function SellBag(npc, who)
- PrintTextAbovePrivate( npc,"Which bag do you want to sell.",who);
- var tgt := Target(who);
- if (tgt.container.container.serial != who.serial)
- PrintTextAbovePrivate( npc,"That doust not belong to you.",who);
- return;
- endif
- var items := EnumerateItemsInContainer(tgt);
- if (len(items) < 1)
- PrintTextAbovePrivate( npc,"That is not a bag or it's an empty bag.",who);
- return;
- endif
- var iFound := 0;
- var item_cfg := ReadConfigFile("::itemdesc");
- var TotalSell := 0;
- var iFull := 0;
- var reserved := 0;
- //hmmm I wonder if not Sell Bag doesn't create to much lag.
- foreach item in items
- var item_elm := FindConfigElem(item_cfg,item.objtype);
- var iSellPricePerPiece := GetConfigInt(item_elm,"VendorBuysFor");
- if(!ReserveItem(item))
- reserved:= 1;
- else
- ReleaseItem(item);
- endif
- if ((iSellPricePerPiece) and (tgt.serial == item.container.serial)
- and (Len(EnumerateItemsInContainer(item)) < 1) and (!item.newbie) and (reserved != 1))
- ReleaseItem(item);
- iFound := 1;
- if (item.buyprice)
- if (item.amount)
- TotalSell := TotalSell + (item.buyprice * item.amount);
- else
- TotalSell := TotalSell + item.buyprice;
- endif
- else
- if (item.amount)
- TotalSell := TotalSell + (iSellPricePerPiece * item.amount);
- else
- TotalSell := TotalSell + iSellPricePerPiece;
- endif
- endif
- DestroyItem(item);
- endif
- endforeach
- if (iFound)
- PrintTextAbovePrivate( npc,"The total of thy sale is " + TotalSell,who);
- if (TotalSell > 60000)
- var iLeft := TotalSell;
- while (iLeft > 0)
- if (iLeft > 60000)
- if (!CreateItemInContainer(who.backpack,0xEED,60000))
- CreateItemAtLocation(who.x,who.y,who.z,0xEED,60000);
- iFull := 1;
- endif
- iLeft := iLeft - 60000;
- else
- if (!CreateItemInContainer(who.backpack,0xEED,iLeft))
- CreateItemAtLocation(who.x,who.y,who.z,0xEED,iLeft);
- iFull := 1;
- endif
- iLeft := 0;
- endif
- endwhile
- else
- if (!CreateItemInContainer(who.backpack,0xEED,TotalSell))
- CreateItemAtLocation(who.x,who.y,who.z,0xEED,TotalSell);
- iFull := 1;
- endif
- endif
- if (iFull)
- SendSysMessage(who,"Your backpack is full, placing gold on ground");
- endif
- else
- PrintTextAbovePrivate( npc,"Your bag got nothing that interests me.",who);
- endif
- endfunction
- function SellAll(npc, who)
- PrintTextAbovePrivate( npc, "Which kind of item would you like to sell?", who );
- var tgt := Target(who);
- if (tgt)
- var item_cfg := ReadConfigFile("::itemdesc");
- var item_elm := FindConfigElem(item_cfg,tgt.objtype);
- var iSellPricePerPiece := GetConfigInt(item_elm,"VendorBuysFor");
- var TotalSell := 0;
- var iFound := 0;
- var iObjType := tgt.objtype;
- var iFull := 0;
- var reserved := 0;
- if (iSellPricePerPiece)
- var items := EnumerateItemsInContainer(who.backpack);
- foreach item in items
- if(!ReserveItem(item))
- reserved:= 1;
- else
- ReleaseItem(item);
- endif
- if (item.container.serial == who.backpack.serial)
- if (item.objtype == iObjType)
- if ((Len(EnumerateItemsInContainer(item)) < 1) and (!item.newbie) and reserved != 1)
- ReleaseItem(item);
- iFound := 1;
- if (item.buyprice)
- if (item.amount)
- TotalSell := TotalSell + (item.buyprice * item.amount);
- else
- TotalSell := TotalSell + item.buyprice;
- endif
- else
- if (item.amount)
- TotalSell := TotalSell + (iSellPricePerPiece * item.amount);
- else
- TotalSell := TotalSell + iSellPricePerPiece;
- endif
- endif
- DestroyItem(item);
- endif
- endif
- endif
- endforeach
- if (iFound)
- PrintTextAbovePrivate( npc,"The total of thy sale is " + TotalSell,who);
- if (TotalSell > 60000)
- var iLeft := TotalSell;
- while (iLeft > 0)
- if (iLeft > 60000)
- if (!CreateItemInContainer(who.backpack,0xEED,60000))
- CreateItemAtLocation(who.x,who.y,who.z,0xEED,60000);
- iFull := 1;
- endif
- iLeft := iLeft - 60000;
- else
- if (!CreateItemInContainer(who.backpack,0xEED,iLeft))
- CreateItemAtLocation(who.x,who.y,who.z,0xEED,iLeft);
- iFull := 1;
- endif
- iLeft := 0;
- endif
- endwhile
- else
- if (!CreateItemInContainer(who.backpack,0xEED,TotalSell))
- CreateItemAtLocation(who.x,who.y,who.z,0xEED,TotalSell);
- iFull := 1;
- endif
- endif
- if (iFull)
- SendSysMessage(who,"Your backpack is full, placing gold on ground");
- endif
- else
- PrintTextAbovePrivate( npc,"You don't have any of that item.",who);
- endif
- else
- PrintTextAbovePrivate( npc,"Bah, I have no use for this. Be off with ye.",who);
- endif
- else
- SendSysMessage(who,"Canceled");
- endif
- endfunction
Add Comment
Please, Sign In to add comment