Jump to content
  • 0

About NPC timer Event


Eross

Question


  • Group:  Members
  • Topic Count:  155
  • Topics Per Day:  0.11
  • Content Count:  349
  • Reputation:   12
  • Joined:  04/05/20
  • Last Seen:  

Hi! I just need a small help here guys .. I need some answers for me to finish my npc script ... I have a Donation base Floating Rates npc .. Wherein the players will donate zeny until they reach the target amount .. Like for example the Server need to donate 5,000,000z ... After they reach target donate amount these are how It should work :

 

1. The NPC will Enable the script of "OnMinute00" (Which we all know that'll change rate every hour) ..So while the event is active there will be changes every hour..

2. The said NPC will enable that script immidiately right after they reached 5m donation for only 24hours .. So, whether its Minute00 or not it should start right away.. (Ex. They reach 5m in 10:55pm, It will start right away but will change rates on 11:00pm and 12:00am so on....)

3. The players are able to check the remaining time of the Floating Rate Event ..And there will be an announcement If theres only hour left or minutes

4. After the timer ends , whether the last hour of event is done or not the server rate should return to its normal rate. 

 

I have here a sample of script by @lupus ... I'm trying to modify it a little but im not good in adding timer .. Please help I really need to finish this one ... Or you can suggest or lecture me on my mistakes here ... Heres the script from rathena folder

 

//===== rAthena Script =======================================
//= Floating Server Rates
//===== By: ==================================================
//= Lupus
//===== Current Version: =====================================
//= 1.0
//===== Compatible With: =====================================
//= rAthena Project
//===== Description: =========================================
//= It's a simply example of setbattleflag
//= This script will change your server rates from 1x to 1.5x every 6 hours
//= Note: It doesn't affect Card granted drops, MVP & Treasure Chests drops ^_-
//=       It also doesn't affect CARD drops, because they are just 0.01%
//===== Additional Comments: =================================
//= You can make incredible scripts with 'setbattleflag'!
//============================================================

//-	script	FloatingRates	-1,{
prontera,123,209,6	script	Broker#FloatingRates	84,{
OnInit:
	set .@fr_targetdonation, 5000;
	
	mes "[Broker]";
	mes "Our server's current fund is:";
	mes "" + callfunc("F_InsertComma",$fr_zeny) + " Zeny";
	next;
	mes "[Broker]";
	mes "Would you like to make a donation?";
	next;
	switch(select("Yes:No")) {
		case 1:
		Change_Amount:			
			mes "[Broker]";
			mes "Please input your donation amount.";
			next;
			input .@fr_zeny;
			if (.@fr_zeny < 1){
				mes "[Broker]";
				mes "Input number greater than 0.";
				end;		
			}	
				mes "[Broker]";
				mes "Please confirm Zeny transfer..";
				next;
				switch(select("Cancel:Change Amount:Confirm")) {
					case 1: 
						end;
					
					case 2: 
						set .@fr_zeny,0;
						next;
						goto Change_Amount;
						end;
					case 3:	
						if (Zeny < .@fr_zeny) {
							mes "[Broker]";
							mes "Sorry, but you don't have enough";
							mes "zeny to proceed on payment.";
							end;
						}
							mes "[Broker]";
							mes "Zeny has succesfully transfered.";
								$fr_zeny += .@fr_zeny;
								
								if ($fr_zeny >= .@fr_targetdonation) {
									
									set $fr_zeny,0;
								} 
								Zeny -= .@fr_zeny;
								end;
											
					}
		case 2:
	}



OnMinute00:

	set $@brate,rand(500,800);
	set $@jrate,rand(500,599);
	//set $@drate,rand(100,150);
	//Base exp
	setbattleflag("base_exp_rate",$@brate);
	//Job exp
	setbattleflag("job_exp_rate",$@jrate);
	set $@brateminus, ($@brate/100) * 100;
	set $@jrateminus, ($@jrate/100) * 100;
	announce "Current rates are: "+($@brate/100)+"."+($@brate-$@brateminus)+"x "+($@jrate/100)+"."+($@jrate-$@jrateminus)+"x ",bc_all,0xFF6060;
	end;


}

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  659
  • Reputation:   664
  • Joined:  11/12/12
  • Last Seen:  

Heya,

Well normally you'd just do a initnpctimer, but since your event needs to run for 24 hours, you can't really expect it to work correctly as a lot can happen in those 24 hours. You need a different approach in that case to survive a server restart/crash or a script reload.

//===== rAthena Script =======================================
//= Floating Server Rates
//===== By: ==================================================
//= Lupus
//===== Current Version: =====================================
//= 1.0
//===== Compatible With: =====================================
//= rAthena Project
//===== Description: =========================================
//= It's a simply example of setbattleflag
//= This script will change your server rates from 1x to 1.5x every 6 hours
//= Note: It doesn't affect Card granted drops, MVP & Treasure Chests drops ^_-
//=       It also doesn't affect CARD drops, because they are just 0.01%
//===== Additional Comments: =================================
//= You can make incredible scripts with 'setbattleflag'!
//============================================================

prontera,123,209,6	script	Broker#FloatingRates	84,{
	if ($floating_rates_hours_left > 0) {
		.@seconds_left = 3600 - (gettime(2) * 60 + gettime(1));
		.@hours_left = ($floating_rates_hours_left - 1) * 3600;
		.@time_left = .@seconds_left + .@hours_left;
		
		.@dun_d = .@time_left / 86400;
		.@dun_h = (.@time_left / 3600) % 24;
		.@dun_m = (.@time_left / 60) % 60;
		.@dun_s = .@time_left % 60;
		
		if (.@dun_d > 0) {
			.@remaining$ = .@dun_d + " day" + (.@dun_d > 1 ? "s" : "") + " and ";
		}
		
		.@remaining$ = .@remaining$ + (.@dun_h < 10 ? "0" : "")+.@dun_h+":"+(.@dun_m < 10 ? "0" : "")+.@dun_m+":"+(.@dun_s < 10 ? "0" : "")+.@dun_s;
		
		mes "[Broker]";
		mes "The event will end in";
		mes .@remaining$;
		mes "Current rates are: "+($@brate/100)+"."+($@brate-$@brateminus)+"x "+($@jrate/100)+"."+($@jrate-$@jrateminus)+"x";
		close;
	}
	
	mes "[Broker]";
	mes "Our server's current fund is:";
	mes "" + callfunc("F_InsertComma",$fr_zeny) + " Zeny";
	next;
	mes "[Broker]";
	mes "Would you like to make a donation?";
	next;
	
	switch(select("Yes:No")) {
		case 1:
Change_Amount:			
			mes "[Broker]";
			mes "Please input your donation amount.";
			next;
			input .@fr_zeny;
			
			if (.@fr_zeny < 1) {
				mes "[Broker]";
				mes "Input number greater than 0.";
				end;		
			}
			
			mes "[Broker]";
			mes "Please confirm Zeny transfer..";
			next;
			
			switch(select("Cancel:Change Amount:Confirm")) {
				case 1:
					end;
				case 2:
					.@fr_zeny = 0;
					next;
					goto Change_Amount;
					end;
				case 3:
					if (Zeny < .@fr_zeny) {
						mes "[Broker]";
						mes "Sorry, but you don't have enough";
						mes "zeny to proceed on payment.";
						end;
					}
					
					mes "[Broker]";
					mes "Zeny has succesfully transfered.";
					Zeny -= .@fr_zeny;
					$fr_zeny += .@fr_zeny;
					
					if ($fr_zeny >= .fr_targetdonation) {
						$fr_zeny = 0;
						
						// Up to you whether you want to add an extra hour or not, as otherwise the event will be below 24 hours.
						$floating_rates_hours_left = 25;
						donpcevent strnpcinfo(0) + "::OnMinute00";
					}
					
					end;
			}
			
			break;
		case 2:
			break;
	}
	
	end;
OnInit:
	.fr_targetdonation = 5000;
OnMinute00:
	if (gettime(2) == 0) {
		$floating_rates_hours_left--;
	}
	
	if ($floating_rates_hours_left < 0) {
		end;
	}
	else if ($floating_rates_hours_left == 0) {
		$floating_rates_hours_left = -1;
		.@default_brate = 100;
		.@default_jrate = 100;
		
		if (getbattleflag("base_exp_rate") != .@default_brate) {
			setbattleflag("base_exp_rate", .@default_brate);
		}
		
		if (getbattleflag("job_exp_rate") != .@default_jrate) {
			setbattleflag("job_exp_rate", .@default_jrate);
		}
		
		announce "Event is over, rates were changed back to: "+(.@default_brate/100)+"x "+(.@default_jrate/100)+"x ",bc_all,0xFF6060;
		end;
	}
	
	$@brate = rand(500,800);
	$@jrate = rand(500,599);
	//$@drate = rand(100,150);
	//Base exp
	setbattleflag("base_exp_rate",$@brate);
	//Job exp
	setbattleflag("job_exp_rate",$@jrate);
	$@brateminus = ($@brate/100) * 100;
	$@jrateminus = ($@jrate/100) * 100;
	announce "Current rates are: "+($@brate/100)+"."+($@brate-$@brateminus)+"x "+($@jrate/100)+"."+($@jrate-$@jrateminus)+"x ",bc_all,0xFF6060;
	
	if ($floating_rates_hours_left == 1) {
		announce "There is one hour left!",bc_all,0xFF6060;
	}
	
	end;
}

 

Edited by Tokei
  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  155
  • Topics Per Day:  0.11
  • Content Count:  349
  • Reputation:   12
  • Joined:  04/05/20
  • Last Seen:  

On 5/13/2021 at 12:18 AM, Tokei said:

Heya,

Well normally you'd just do a initnpctimer, but since your event needs to run for 24 hours, you can't really expect it to work correctly as a lot can happen in those 24 hours. You need a different approach in that case to survive a server restart/crash or a script reload.


//===== rAthena Script =======================================
//= Floating Server Rates
//===== By: ==================================================
//= Lupus
//===== Current Version: =====================================
//= 1.0
//===== Compatible With: =====================================
//= rAthena Project
//===== Description: =========================================
//= It's a simply example of setbattleflag
//= This script will change your server rates from 1x to 1.5x every 6 hours
//= Note: It doesn't affect Card granted drops, MVP & Treasure Chests drops ^_-
//=       It also doesn't affect CARD drops, because they are just 0.01%
//===== Additional Comments: =================================
//= You can make incredible scripts with 'setbattleflag'!
//============================================================

prontera,123,209,6	script	Broker#FloatingRates	84,{
	if ($floating_rates_hours_left > 0) {
		.@seconds_left = 3600 - (gettime(2) * 60 + gettime(1));
		.@hours_left = ($floating_rates_hours_left - 1) * 3600;
		.@time_left = .@seconds_left + .@hours_left;
		
		.@dun_d = .@time_left / 86400;
		.@dun_h = (.@time_left / 3600) % 24;
		.@dun_m = (.@time_left / 60) % 60;
		.@dun_s = .@time_left % 60;
		
		if (.@dun_d > 0) {
			.@remaining$ = .@dun_d + " day" + (.@dun_d > 1 ? "s" : "") + " and ";
		}
		
		.@remaining$ = .@remaining$ + (.@dun_h < 10 ? "0" : "")+.@dun_h+":"+(.@dun_m < 10 ? "0" : "")+.@dun_m+":"+(.@dun_s < 10 ? "0" : "")+.@dun_s;
		
		mes "[Broker]";
		mes "The event will end in";
		mes .@remaining$;
		mes "Current rates are: "+($@brate/100)+"."+($@brate-$@brateminus)+"x "+($@jrate/100)+"."+($@jrate-$@jrateminus)+"x";
		close;
	}
	
	mes "[Broker]";
	mes "Our server's current fund is:";
	mes "" + callfunc("F_InsertComma",$fr_zeny) + " Zeny";
	next;
	mes "[Broker]";
	mes "Would you like to make a donation?";
	next;
	
	switch(select("Yes:No")) {
		case 1:
Change_Amount:			
			mes "[Broker]";
			mes "Please input your donation amount.";
			next;
			input .@fr_zeny;
			
			if (.@fr_zeny < 1) {
				mes "[Broker]";
				mes "Input number greater than 0.";
				end;		
			}
			
			mes "[Broker]";
			mes "Please confirm Zeny transfer..";
			next;
			
			switch(select("Cancel:Change Amount:Confirm")) {
				case 1:
					end;
				case 2:
					.@fr_zeny = 0;
					next;
					goto Change_Amount;
					end;
				case 3:
					if (Zeny < .@fr_zeny) {
						mes "[Broker]";
						mes "Sorry, but you don't have enough";
						mes "zeny to proceed on payment.";
						end;
					}
					
					mes "[Broker]";
					mes "Zeny has succesfully transfered.";
					Zeny -= .@fr_zeny;
					$fr_zeny += .@fr_zeny;
					
					if ($fr_zeny >= .fr_targetdonation) {
						$fr_zeny = 0;
						
						// Up to you whether you want to add an extra hour or not, as otherwise the event will be below 24 hours.
						$floating_rates_hours_left = 25;
						donpcevent strnpcinfo(0) + "::OnMinute00";
					}
					
					end;
			}
			
			break;
		case 2:
			break;
	}
	
	end;
OnInit:
	.fr_targetdonation = 5000;
OnMinute00:
	if (gettime(2) == 0) {
		$floating_rates_hours_left--;
	}
	
	if ($floating_rates_hours_left < 0) {
		end;
	}
	else if ($floating_rates_hours_left == 0) {
		$floating_rates_hours_left = -1;
		.@default_brate = 100;
		.@default_jrate = 100;
		
		if (getbattleflag("base_exp_rate") != .@default_brate) {
			setbattleflag("base_exp_rate", .@default_brate);
		}
		
		if (getbattleflag("job_exp_rate") != .@default_jrate) {
			setbattleflag("job_exp_rate", .@default_jrate);
		}
		
		announce "Event is over, rates were changed back to: "+(.@default_brate/100)+"x "+(.@default_jrate/100)+"x ",bc_all,0xFF6060;
		end;
	}
	
	$@brate = rand(500,800);
	$@jrate = rand(500,599);
	//$@drate = rand(100,150);
	//Base exp
	setbattleflag("base_exp_rate",$@brate);
	//Job exp
	setbattleflag("job_exp_rate",$@jrate);
	$@brateminus = ($@brate/100) * 100;
	$@jrateminus = ($@jrate/100) * 100;
	announce "Current rates are: "+($@brate/100)+"."+($@brate-$@brateminus)+"x "+($@jrate/100)+"."+($@jrate-$@jrateminus)+"x ",bc_all,0xFF6060;
	
	if ($floating_rates_hours_left == 1) {
		announce "There is one hour left!",bc_all,0xFF6060;
	}
	
	end;
}

 

Goodmorning (*PH time) .. Yes2 exactly sir ! I need the script continously running for 24hours without any interruptions ,,, Thanks I will try this one sir ! Godbless

 

Hi ! I noticed that the npc has ended the event without event starting it yet .. 

image.png.7c1690b869a385306d3e3a90e902a1ef.png

I will observe it for the next 24hours ... And also the timer left shows like this sir 

 

image.png.3c8a21b8dc97134ffd24fde6d1015123.png

 

I think this is because you added extra hour??  ... // Up to you whether you want to add an extra hour or not, as otherwise the event will be below 24 hours.

I supposed this will show 23hours and 00:55:59 if I set it to '$floating_rates_hours_left = 24;' right ?? 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Oppps ! I tried to make it 24hours and the timer shows like this .. 

image.png.c53df26711a93cca45466327dd981753.png

Why is it only 30minutes sir ?

 

~~~ And also sir, 

How to add restriction/cooldown on time .. Like, After the event ends .. The player will able to donate again after 6days ? 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  659
  • Reputation:   664
  • Joined:  11/12/12
  • Last Seen:  

Well, that's because of how you described your event. You want the rates to change on the hour at 00, but you want the event to start when the goal is reached. Both of these are impossible as the event has to end on the hour as well. So you have to choose, if the event starts at say... 3:44, does it end the next day at 4:00 or 3:00? That's how I understood it.

If... you want the event to run for 24 hours and announce at non-00 intervals from when the goal is first reached, that's a different story entirely.

As for the first time the script is loaded, that's normal. I was too lazy to resolve that point and since it would only happen once, I didn't care much for that.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  155
  • Topics Per Day:  0.11
  • Content Count:  349
  • Reputation:   12
  • Joined:  04/05/20
  • Last Seen:  

5 hours ago, Tokei said:

Well, that's because of how you described your event. You want the rates to change on the hour at 00, but you want the event to start when the goal is reached. Both of these are impossible as the event has to end on the hour as well. So you have to choose, if the event starts at say... 3:44, does it end the next day at 4:00 or 3:00? That's how I understood it.

If... you want the event to run for 24 hours and announce at non-00 intervals from when the goal is first reached, that's a different story entirely.

As for the first time the script is loaded, that's normal. I was too lazy to resolve that point and since it would only happen once, I didn't care much for that.

Ohh Thats why .. I get it sir ... So, the extra minute came from the difference between the trigger time and the 00 of the next hour right ?? ... Hmmm .. How about after reaching the goal , There will be an announcement that "THE FLOATING RATES EVENT WILL START IN THE NEXT 00 OF NEXT HOUR" ?

I apologize for asking too much ,but ... How to add cooldown after the event ends sir ?? Like if the timer reached zero , The NPC will be disabled for the next 6days .. and announce when players can donate again ?

 

Im so noob on this .. Thankyou for assisting me sir @Tokei

 

 

Edited: Sir as ive observed, everytime I reload script the rates are changing ...

 

Okay my bad sir .. I managed to fix the OnInit: by adding this line 

if ($floating_rates_hours_left > 0) { end; }

 

Edited by Origami
Observed Problem:
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...