Jump to content
  • 0
Sign in to follow this  
Amalgam

Help me adding delay in this command.

Question

Can anybody help me add a delay of 60 seconds before using the command again. Thanks!

 

/*========================================== * @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;} 

 

 

 

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 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

Share this post


Link to post
Share on other sites
  • 0

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[i].amount && sd->status.inventory[i].equip == 0) {			if(sd->status.inventory[i].equip != 0)				pc->unequipitem(sd, i, 3);			storage->add(sd,  i, sd->status.inventory[i].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:

Edited by pan

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.