yuhsing

Untitled

Feb 14th, 2013
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1.  
  2. /*------------------------------------------
  3. * Usage :
  4. * consumeitem 607,1;
  5. *
  6. * delete 1 Yggdrasilberry + Run Yggdrasilberry's Script ( from item_db )
  7. *
  8. * return 1 on Succes / 0 on failed.
  9. *------------------------------------------*/
  10. BUILDIN_FUNC(consumeitem)
  11. {
  12. TBL_PC *sd = script_rid2sd( st );
  13.  
  14. struct item_data *i_data;
  15.  
  16. int i,index,count=0;
  17. struct item it;
  18.  
  19. it.nameid = script_getnum( st,2 );
  20.  
  21. i_data = itemdb_exists(it.nameid);
  22.  
  23. // check for item exist or not
  24. if( !itemdb_exists( it.nameid ) ){
  25. ShowError( "script:consumeitem: unknown item \"%d\".\n", it.nameid );
  26. st->state = END;
  27. return 1;
  28. }
  29. if( pc_isdead(sd) ){
  30. return 0;
  31. }
  32. it.amount = script_getnum( st,3 );
  33. // Set amount to 1 if it's below 0. ( Enable 0 to not consume item )
  34. if( it.amount <= 0 ) it.amount = 1;
  35.  
  36. // loop through the inventory and return the amount of item available.
  37. for( i = 0; i < MAX_INVENTORY; i++ )
  38. if( sd->status.inventory[i].nameid == it.nameid ){
  39. count += sd->status.inventory[i].amount;
  40. index = i;
  41. break;
  42. }
  43.  
  44. // if amount available and >= required amount :
  45. // delete the item + run the item script
  46. if( count && count >= it.amount ){
  47. if (!pc_useitem(sd,index))
  48. clif_useitemack(sd,it.amount,0,false);
  49. script_pushint( st, 1 );
  50. }
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment