DelItemFromSlot Function: Removing Items from Game Inventory Slots
function DelItemFromSlot(argument0, argument1, argument2, argument3, argument4) { var bag = argument0; var page = argument1; var row = argument2; var col = argument3; var num = argument4;
var curItm = GetSlotItemByPos(bag,page,row,col);
var left = 0;
if( num>0 && curItm[ia_.type]!=ITEM_TYPE.NONE ){
var curNum = curItm[ia_.num];
if( curNum > num ){
left = curNum - num;
curItm[ia_.num] =left;
SetSlotItem(bag,page,row,col,curItm);
}else{
SetSlotEmpty(bag,page,row,col);
}
}
return left;
}This function, DelItemFromSlot, handles the removal of items from a game inventory slot. It takes five arguments: 'bag', 'page', 'row', 'column', and 'num', representing the inventory bag, the page within the bag, the row and column of the slot, and the number of items to delete, respectively.
First, the function retrieves the item currently in the specified slot using GetSlotItemByPos. Then, it checks if the number of items to be deleted ('num') is greater than 0 and if the retrieved item is not empty (ITEM_TYPE.NONE).
If both conditions are met, it compares the current number of items in the slot ('curNum') with the number of items to be deleted. If 'curNum' is greater than 'num', the function subtracts 'num' from 'curNum', updates the item in the slot with the remaining quantity, and sets the updated item back into the slot using SetSlotItem.
However, if 'num' is greater than or equal to 'curNum', the function clears the slot by calling SetSlotEmpty, effectively removing all the items from that slot.
Finally, the function returns the number of items that were not deleted ('left'). If all items were successfully deleted, 'left' will be 0.
原文地址: https://www.cveoy.top/t/topic/nxPy 著作权归作者所有。请勿转载和采集!