llllll 发表于 2015-10-27 15:40:39

装备合成 NPC脚本

新建一个NPC脚本,NPC的代码为2048,然后复制如下脚本自行修改

function ontalk2048(npc,event,player)
zqitem={
{150005,160005,170005,180005,"战"};
{150006,160006,170006,180006,"法"};
{150007,160007,170007,180007,"道"}
}
zqitem2={
{150101,160101,170101,180101,"战"};
{150102,160102,170102,180102,"法"};
{150103,160103,170103,180103,"道"}
}
player:echo(0,npc:GetLowGUID(),[[
在我这可合成最强王者内四格装备
合成最强王者·首饰(]]..zqitem2..[[).
         主宰头巾(]]..zqitem2..[[)*2+烈焰石*2+永恒玫瑰*2
#&item]]..zqitem2..[[#&               <u><a href='event:M2402,1'>锻造</a></u>
         主宰吊坠(]]..zqitem2..[[)*2+烈焰石*2+永恒玫瑰*2
#&item]]..zqitem2..[[#&               <u><a href='event:M2402,2'>锻造</a></u>
         主宰护肩(]]..zqitem2..[[)*2+烈焰石*2+永恒玫瑰*2
#&item]]..zqitem2..[[#&               <u><a href='event:M2402,3'>锻造</a></u>
         主宰护膝(]]..zqitem2..[[)*2+烈焰石*2+永恒玫瑰*2
#&item]]..zqitem2..[[#&               <u><a href='event:M2402,4'>锻造</a></u>
]]);
player:echo(0,npc:GetLowGUID(),[[
合成烈焰锻造石

#&item18100#&需要烈焰锻造石碎片x3   <u><a href='event:M2402,5'>合成</a></u>
]]);
end



function ontalk2048_1(npc,event,player)
      if player:num_item_level(zqitem,1) >= 2 and player:num_item(18100) >= 2 and player:num_item(10198)>=2 then
             player:remove_item(zqitem,2);
               player:remove_item(18100,2);
                player:remove_item(10198,2);
               player:add_item(zqitem2,1,0);
               player:alert(110,0,0,"锻造成功");
                else
                        player:alert(10,0,0,"材料不足,请确认后再来找我");
                end
      ontalk2048(npc,0,player,0);
end

function ontalk2048_2(npc,event,player)
      if player:num_item_level(zqitem,1) >= 2 and player:num_item(18100) >= 2 and player:num_item(10198)>=2 then
             player:remove_item(zqitem,2);
               player:remove_item(18100,2);
                player:remove_item(10198,2);
               player:add_item(zqitem2,1,0);
               player:alert(110,0,0,"锻造成功");
                else
                        player:alert(10,0,0,"材料不足,请确认后再来找我");
                end
      ontalk2048(npc,0,player,0);
end

function ontalk2048_3(npc,event,player)
      if player:num_item_level(zqitem,1) >= 2 and player:num_item(18100) >= 2 and player:num_item(10198)>=2 then
             player:remove_item(zqitem,2);
               player:remove_item(18100,2);
                player:remove_item(10198,2);
               player:add_item(zqitem2,1,0);
               player:alert(110,0,0,"锻造成功");
                else
                        player:alert(10,0,0,"材料不足,请确认后再来找我");
                end
      ontalk2048(npc,0,player,0);
end

function ontalk2048_4(npc,event,player)
      if player:num_item_level(zqitem,1) >= 2 and player:num_item(18100) >= 2 and player:num_item(10198)>=2 then
             player:remove_item(zqitem,2);
               player:remove_item(18100,2);
                player:remove_item(10198,2);
               player:add_item(zqitem2,1,0);
               player:alert(110,0,0,"锻造成功");
                else
                        player:alert(10,0,0,"材料不足,请确认后再来找我");
                end
      ontalk2048(npc,0,player,0);
end

function ontalk2048_5(npc,event,player)
      ifplayer:num_item(18101) >= 3 then      
               player:remove_item(18101,3);               
               player:add_item(18100,1,0);
               player:alert(110,0,0,"锻造成功");
                else
                        player:alert(10,0,0,"材料不足,请确认后再来找我");
                end
      ontalk2048(npc,0,player,0);
end      


Npc2048Funid =
{
= ontalk2048;
= ontalk2048_3;
= ontalk2048_4;
= ontalk2048_1;
= ontalk2048_2;
= ontalk2048_5;
}

function CreatureNpcFun(npc,event,player,funid)
      if Npc2048Funid ~= nil then
                Npc2048Funid(npc,event,player);
      end
end

RegisterUnitEvent(2048,20,"ontalk2048")
RegisterUnitEvent(2048,29,"CreatureNpcFun")

这里合成脚本使用了lua自带功能的数组功能这样写的好处就是可以减少代码的编写量.
而且易于修改和更新.
520页游论坛www.ye520.com 欢迎您的到来,本论坛需要您的多多支持,有空常来逛逛!

页: [1]
查看完整版本: 装备合成 NPC脚本