Help me adding delay in this command.

Amalgam

New member
Messages
42
Points
0
Can anybody help me add a delay of 60 seconds before using the command again. Thanks!

Code:
/*========================================== * @storeall by [MouseJstr] * Put everything into storage *------------------------------------------*/ACMD_FUNC(storeall){	int i;	nullpo_retr(-1, sd);	if (sd->state.storage_flag != 1)  	{	//Open storage.		if( storage_storageopen(sd) == 1 ) {			clif_displaymessage(fd, "You can't open the storage currently.");			return -1;		}	}	for (i = 0; i < MAX_INVENTORY; i++) {		if (sd->status.inventory[i].amount && sd->status.inventory[i].equip == 0) {			if(sd->status.inventory[i].equip != 0)				pc_unequipitem(sd, i, 3);			storage_storageadd(sd,  i, sd->status.inventory[i].amount);		}	}	storage_storageclose(sd);	clif_displaymessage(fd, "It is done");	return 0;} 
 
 
- script storeall_atcommand -1,{OnInit: bindatcmd "storeall",strnpcinfo(3)+"::OnDo"; end;OnDo: if(gettimetick(2) - #storeall < 30) {dispbottom "Please wait 30 seconds before using this command again.";end;} atcommand "@storeall"; set #storeall,gettimetick(2); end;}
You could do it like this

 
I'm not sure if that's the best approach to this problem but you could try using this snippet:

int storeall_timer(int tid, int64 tick, int id, intptr_t data){ struct map_session_data *sd; if( (sd=(struct map_session_data *)map->id2sd(id)) == NULL ) return 1; //ShowDebug("storeall_timer: bl.id = %d, sd->storeall_tid = %dn", sd->bl.id, sd->storeall_tid); if(sd->storeall_tid != tid) { ShowError("storeall_timer %d != %dn",sd->storeall_tid,tid); return 0; } sd->storeall_tid = INVALID_TIMER; // Player can use the command once again c: //ShowDebug("storeall_timer: done! sd->storeall_tid = %d n",sd->storeall_tid); return 0;}/*========================================== * @storeall by [MouseJstr] * Put everything into storage *------------------------------------------*/ACMD(storeall){ int i; nullpo_retr(false, sd); if (sd->storeall_tid != INVALID_TIMER && sd->storeall_tid) { clif->message(fd, "You need to wait for a while to use this function."); return false; } if (sd->state.storage_flag != 1) { //Open storage. if( storage->open(sd) == 1 ) { clif->message(fd, "You can't open the storage currently."); return false; } } for (i = 0; i < MAX_INVENTORY; i++) { if (sd->status.inventory.amount && sd->status.inventory.equip == 0) { if(sd->status.inventory.equip != 0) pc->unequipitem(sd, i, 3); storage->add(sd, i, sd->status.inventory.amount); } } // Starts the timer, note that it's in ms sd->storeall_tid = timer->add( (timer->gettick()+60000), storeall_timer, sd->bl.id, 0); //ShowDebug("storeall: bl.id = %d, storeall_tid = %dn", sd->bl.id,sd->storeall_tid); storage->close(sd); clif->message(fd, "It is done"); return true;}I haven't tested this mod in-game, but my modifications in your snippet built just fine.Regards.

@EDIT:

Tested the code and made minor changes c:

 
Last edited by a moderator:
I recommend you to try PokemonRO suggestion first. Thats why we have bindatcmd script
default_smile.png


 
Back
Top