Originally posted by [b]VoidLess[/b]
http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=2994
implemented checkweight TODO.
full checks for stackable/unstackable, empty slots, adding on the slot with same stackable item not over max_amount
code with tabs
_http://www.paste-it.net/public/o41ed08/
CODE
BUILDIN_FUNC(checkweight)
{
int nameid=0,amount,i,count=0;
unsigned long weight;
TBL_PC *sd;
struct script_data *data;
sd = script_rid2sd(st);
if( sd == NULL )
return 0;
data=script_getdata(st,2);
get_val(st,data);
if( data_isstring(data) ){
const char *name=conv_str(st,data);
struct item_data *item_data = itemdb_searchname(name);
if( item_data )
nameid=item_data->nameid;
}else
nameid=conv_num(st,data);
amount=script_getnum(st,3);
if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
script_pushint(st,0);
ShowError("buildin_checkweight: Wrong item ID or amount.\n");
return 1;
}
weight = itemdb_weight(nameid)*amount;
if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
script_pushint(st,0);
} else {
//Check if the inventory ain't full.
//[VoidLess] implemented full checks
if(itemdb_isstackable(nameid)){
i = pc_search_inventory(sd,nameid); //Look for same items
if(i >= 0)
if(sd->status.inventory[i].amount + amount > MAX_AMOUNT)
script_pushint(st,0); //Can't take, total will be more than max
else
script_pushint(st,1);
else { //There is no same items, look for spaces
i = pc_search_inventory(sd,0);
if(i >= 0)
script_pushint(st,1);
else //Inventory full
script_pushint(st,0);
}
} else { //Not stackable
for(i = 0; i < MAX_INVENTORY; i++)
if(sd->status.inventory[i].nameid == 0)
count++; //Counting empty slots
if (count >= amount)
script_pushint(st,1);
else //Not enough slots
script_pushint(st,0);
}
}
return 0;
}
This post has been edited by Brute_Force: Apr 20 2009, 01:17 PM