Advertisement
Guest User

restock npc

a guest
Apr 24th, 2015
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.13 KB | None | 0 0
  1. /*CREATE TABLE IF NOT EXISTS `restock` (
  2.   `slotname` VARCHAR(10) NOT NULL DEFAULT '',
  3.   `charid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  4.   `itemid` INT(10) NOT NULL DEFAULT '0',
  5.   `amount` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
  6.   `zeny` INT(40) UNSIGNED NOT NULL DEFAULT '0',
  7.   PRIMARY KEY (`slotname`)
  8. ) ENGINE=MYISAM;
  9.  
  10. */
  11. -   script  RestockNPC  -1,{
  12.     end;
  13.     function ClearVars;
  14. OnSaveID:
  15. if(.@atcmd_parameters$[0] == "new") {
  16.     for(set .@i,0; .@i < 3; set .@i, .@i +1){
  17.         if(.CanRestock[.@i] != 0) {
  18.             set .@menu$, .@menu$ + "> ^0000FF "+getitemname(.CanRestock[.@i])+" ^000000 ="+.CanRestockZ[.@i]+"z";
  19.             set .@menu$, .@menu$ + ":";
  20.         }
  21.     }      
  22.     set @Restock,select(.@menu$)-1;
  23.    
  24.     mes "Введите кол-во";
  25.     input @amount;
  26.     switch(select("Слот 1:Слот 2:Слот 3")){
  27.         case 1:
  28.         query_sql("SELECT itemid FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '1'", @checkID);
  29.         if(@checkID > 0) {
  30.             query_sql("UPDATE `restock` SET `itemid` = '"+.CanRestock[@Restock]+"', `amount` = '"+@amount+"', `zeny` = '"+.CanRestockZ[@Restock]*@amount+"' WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '1'");
  31.             break;
  32.         }
  33.         query_sql("INSERT INTO `restock` (`slotname`,`charid`,`itemid`,`amount`,`zeny`) VALUES ('1','"+getcharid(0)+"','"+.CanRestock[@Restock]+"','"+@amount+"','"+.CanRestockZ[@Restock]*@amount+"')");
  34.         break;
  35.        
  36.         case 2:
  37.         query_sql("SELECT itemid FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '2'", @checkID2);
  38.         if(@checkID2 > 0) {
  39.             query_sql("UPDATE `restock` SET `itemid` = '"+.CanRestock[@Restock]+"', `amount` = '"+@amount+"', `zeny` = '"+.CanRestockZ[@Restock]*@amount+"' WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '2'");
  40.             break;
  41.         }
  42.         query_sql("INSERT INTO `restock` (`slotname`,`charid`,`itemid`,`amount`,`zeny`) VALUES ('2','"+getcharid(0)+"','"+.CanRestock[@Restock]+"','"+@amount+"','"+.CanRestockZ[@Restock]*@amount+"')");
  43.         break;
  44.        
  45.         case 3:
  46.         query_sql("SELECT itemid FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '3'", @checkID3);
  47.         if(@checkID3 > 0) {
  48.             query_sql("UPDATE `restock` SET `itemid` = '"+.CanRestock[@Restock]+"', `amount` = '"+@amount+"', `zeny` = '"+.CanRestockZ[@Restock]*@amount+"' WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '3'");
  49.             break;
  50.         }
  51.         query_sql("INSERT INTO `restock` (`slotname`,`charid`,`itemid`,`amount`,`zeny`) VALUES ('3','"+getcharid(0)+"','"+.CanRestock[@Restock]+"','"+@amount+"','"+.CanRestockZ[@Restock]*@amount+"')");
  52.         break;
  53.     }
  54.    
  55.     dispbottom "Готово.";
  56.     end;
  57.    
  58. } else if(.@atcmd_parameters$[0] == "1") {
  59.     query_sql("SELECT itemid,amount,zeny FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '1'", @itemID, @amountID, @zenyID);
  60.     if(checkweight(@itemID, @amountID) == 0) {
  61.         message strcharinfo(0), "@restock failed. У Вас не хватает веса.";
  62.         end;
  63.     }
  64.     if(zeny < @zenyID) {
  65.         message strcharinfo(0), "@restock failed. У Вас не хватает зени. Нужно: "+@zenyID;
  66.         end;
  67.     }
  68.     zeny -= @zenyID;
  69.     getitem @itemID, @amountID;
  70.     end;
  71. } else if(.@atcmd_parameters$[0] == "2") {
  72.     query_sql("SELECT itemid,amount,zeny FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '2'", @itemID, @amountID, @zenyID);
  73.     if(checkweight(@itemID, @amountID) == 0) {
  74.         message strcharinfo(0), "@restock failed. У Вас не хватает веса.";
  75.         end;
  76.     }
  77.     if(zeny < @zenyID) {
  78.         message strcharinfo(0), "@restock failed. У Вас не хватает зени. Нужно: "+@zenyID;
  79.         end;
  80.     }
  81.     zeny -= @zenyID;
  82.     getitem @itemID, @amountID;
  83.     end;
  84. } else if(.@atcmd_parameters$[0] == "3") {
  85.     query_sql("SELECT itemid,amount,zeny FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '3'", @itemID, @amountID, @zenyID);
  86.     if(checkweight(@itemID, @amountID) == 0) {
  87.         message strcharinfo(0), "@restock failed. У Вас не хватает веса.";
  88.         end;
  89.     }
  90.     if(zeny < @zenyID) {
  91.         message strcharinfo(0), "@restock failed. У Вас не хватает зени. Нужно: "+@zenyID;
  92.         end;
  93.     }
  94.     zeny -= @zenyID;
  95.     getitem @itemID, @amountID;
  96.     end;
  97. } else if(.@atcmd_parameters$[0] == "info") {
  98.     ClearVars;
  99.     query_sql("SELECT itemid,amount,zeny FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '1'", @itm1, @amt1, @zny1);
  100.     query_sql("SELECT itemid,amount,zeny FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '2'", @itm2, @amt2, @zny2);
  101.     query_sql("SELECT itemid,amount,zeny FROM `restock` WHERE `charid` = '"+getcharid(0)+"' and `slotname` = '3'", @itm3, @amt3, @zny3);
  102.     dispbottom "[ Restock Info ] :::: [ Restock Info ]";
  103.     dispbottom "~ Slot 1 - ["+getitemname(@itm1)+"/"+@amt1+"/"+@zny1+"z] ~";
  104.     dispbottom "~ Slot 2 - ["+getitemname(@itm2)+"/"+@amt2+"/"+@zny2+"z] ~";
  105.     dispbottom "~ Slot 3 - ["+getitemname(@itm3)+"/"+@amt3+"/"+@zny3+"z] ~";
  106.     end;
  107. }
  108.  
  109. function    ClearVars   {
  110.     @itm1 = 0;
  111.     @amt1 = 0;
  112.     @zny1 = 0;
  113.     @itm2 = 0;
  114.     @amt2 = 0;
  115.     @zny2 = 0;
  116.     @itm3 = 0;
  117.     @amt3 = 0;
  118.     @zny3 = 0;
  119.     return;
  120. }
  121. OnInit:
  122. setarray .CanRestock[0], 607, 502, 503;
  123. setarray .CanRestockZ[0], 10000, 500, 500;
  124. bindatcmd "restock",strnpcinfo(0)+"::OnSaveID";
  125. end;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement