Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------------------------
- * Usage :
- * consumeitem 607,1;
- *
- * delete 1 Yggdrasilberry + Run Yggdrasilberry's Script ( from item_db )
- *
- * return 1 on Succes / 0 on failed.
- *------------------------------------------*/
- BUILDIN_FUNC(consumeitem)
- {
- TBL_PC *sd = script_rid2sd( st );
- struct item_data *i_data;
- int i,index,count=0;
- struct item it;
- it.nameid = script_getnum( st,2 );
- i_data = itemdb_exists(it.nameid);
- // check for item exist or not
- if( !itemdb_exists( it.nameid ) ){
- ShowError( "script:consumeitem: unknown item \"%d\".\n", it.nameid );
- st->state = END;
- return 1;
- }
- if( pc_isdead(sd) ){
- return 0;
- }
- it.amount = script_getnum( st,3 );
- // Set amount to 1 if it's below 0. ( Enable 0 to not consume item )
- if( it.amount <= 0 ) it.amount = 1;
- // loop through the inventory and return the amount of item available.
- for( i = 0; i < MAX_INVENTORY; i++ )
- if( sd->status.inventory[i].nameid == it.nameid ){
- count += sd->status.inventory[i].amount;
- index = i;
- break;
- }
- // if amount available and >= required amount :
- // delete the item + run the item script
- if( count && count >= it.amount ){
- if (!pc_useitem(sd,index))
- clif_useitemack(sd,it.amount,0,false);
- script_pushint( st, 1 );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment