例子3------ void batch_buy(string type, string item, int num,int var1,int var2);
按照sas提供的,我修改了下,大家可以参照下
//void batch_buy(string type, string item, int num,int var1,int var2);
//type 购买类型 item 物品名字 num 购买的数量 var1 购买类型在批量购买菜单的行数 var2 购买类型在批量购买菜单的列数
//例如:我要购买回城,属于杂货类,购买10个,杂货类在批量购买菜单的第1行,第2列
//则这样调用 batch_buy("@杂货类+","回城卷",10,1,2)
//批量购买菜单如下:
//------------------------------------------------
//1. 购买药水类 | <购买杂货类/@杂货类+> | <购买首饰类/@首饰类+> //| (@药水类+)
//|---------------|----------------|---------------|
//2. 购买武器类 | <购买护具类/@护具类+> | <购买书籍类/@书籍类+> //| (@武器类+)
// ------------------------------------------------
//代码从这里开始
mapping npc;
void batch_buy(string type, string item, int num,int var1,int var2);
void batch_buy(string type, string item, int num,int var1,int var2)
{
int n;
if ((n = get_item_amount(item) - atoi(num)) > 0)
{
sell(item, n, npc);
}
if ((n = atoi(num) - get_item_amount(item)) > 0)
{
talk_to(npc);
talk_to(npc, "批量购买");
//talk_to(npc, type);
current_menu[var2]["action"]= (type);
talk_to(npc,var1);
talk_to(npc, item,(string)n);
}
}
//回城准备
int on_prepare_for_quest()
{
if (! close_to_npc("item", &npc))
{
tell_user("TIP: 无法找到杂货店,采用缺省流程");
return 0;
}
//购买1个回城卷,10个随机传送卷
batch_buy("@杂货类+","回城卷",1,1,2);
batch_buy("@杂货类+", "随机传送卷",10,1,2);
if (! close_to_npc("potion", &npc))
{
tell_user("TIP: 无法找到药店,采用缺省流程");
return 0;
}
//购买400个金创药(中),购买100个魔法药(中)
batch_buy("@药水类+", "金创药(中)",400,1,1);
batch_buy("@药水类+", "魔法药(中)",100,1,1);
return 1;
}
//当中蓝和中红小于5个的时候,回城
void on_applied_item(mapping ob)
{
if ((get_item_amount("魔法药(中)")<5)||(get_item_amount("金创药(中)")<5))
back(5);
}