Thank you for your help.
Actually I didn't understand what you mean with "add a variable on sd", but after hours of trouble I came to a solution that works:
if( sd->inventory_data[n]->delay > 0 ) {
ARR_FIND(0, MAX_ITEMDELAYS, i, sd->item_delay[i].nameid == nameid );
if( nameid == ITEMID_RED_POTION || nameid == ITEMID_YELLOW_POTION || nameid == ITEMID_WHITE_POTION ) {
sd->item_delay[1].nameid = ITEMID_RED_POTION;
sd->item_delay[2].nameid = ITEMID_YELLOW_POTION;
sd->item_delay[3].nameid = ITEMID_WHITE_POTION;
}
if( i == MAX_ITEMDELAYS ) /* item not found. try first empty now */
ARR_FIND(0, MAX_ITEMDELAYS, i, !sd->item_delay[i].nameid );
if( i < MAX_ITEMDELAYS ) {
if( sd->item_delay[i].nameid ) {// found
if( DIFF_TICK(sd->item_delay[i].tick, tick) > 0 ) {
int e_tick = (int)(DIFF_TICK(sd->item_delay[i].tick, tick)/1000);
// clif->msgtable_num(sd, MSG_SECONDS_UNTIL_USE, e_tick + 1); // [%d] seconds left until you can use
return 0; // Delay has not expired yet
}
} else {// not yet used item (all slots are initially empty)
sd->item_delay[i].nameid = nameid;
}
if( sd->item_delay[1].nameid == ITEMID_RED_POTION || sd->item_delay[2].nameid == ITEMID_YELLOW_POTION || sd->item_delay[3].nameid == ITEMID_WHITE_POTION ){
sd->item_delay[1].tick = tick + 5000;
sd->item_delay[2].tick = tick + 5000;
sd->item_delay[3].tick = tick + 5000;
goto limpartudo;
}
if (!(nameid == ITEMID_BOARDING_HALTER && pc_hasmount(sd))) {
sd->item_delay[i].tick = tick + sd->inventory_data[n]->delay;
}
} else {// should not happen
ShowError("pc_useitem: Exceeded item delay array capacity! (nameid=%d, char_id=%d)\n", nameid, sd->status.char_id);
}
//clean up used delays so we can give room for more
limpartudo:
for(i = 0; i < MAX_ITEMDELAYS; i++) {
if( DIFF_TICK(sd->item_delay[i].tick, tick) <= 0 ) {
sd->item_delay[i].tick = 0;
sd->item_delay[i].nameid = 0;
}
}
}
I wonder if you could help me with a better solution, because my code is an outrage to the community. hahahahahah
I thank you all for the good cooperation!