Jump to content

Question

Posted (edited)

May I ask how to attach a player who talks to the NPC to be able to receive the message only?

 

I am trying to create an NPC that I can start the time when I talk to it, 

When I logout, the timer pause if ever i had started it,

The timer will resume if I login and if I started it before logging out.

 

 

prontera,154,181,3	script	testnpc::npctimerX0000	876,{
	mes "Timer value" + getnpctimer(0);
	mes "State timer" + getnpctimer(1,"npctimerX0000");
	mes "Number of events" + getnpctimer(2);
	switch(select("Initialization:Stop:Start:Settings")) {
	case 1:
		//initnpctimer;
		close;
	case 2:
		stopnpctimer;
		close;
	case 3:
		startnpctimer;
		close;
	case 4:
		input .@temp;
		setnpctimer .@temp;
		close;
	}

OnTimer1000:
	dispbottom "After a second...";
	end;

OnTimer5000:
	dispbottom "After 5 seconds...";
	end;

OnTimer10000:
	dispbottom "Times up! ";
	stopnpctimer;
	setnpctimer 0;
	end;

OnPCLogoutEvent:
//ops attached player logout. pausing timer.
stopnpctimer;
end;

OnPCLoginEvent:
if ( getnpctimer(0) == 0 ){
 dispbottom "no start countdown since it didn't start yet";
	end;
}else{
//resume timer
startnpctimer;
}
end;


}

 

Edited by glemor123

9 answers to this question

Recommended Posts

  • 0
Posted (edited)

thanks!, However when I logout. the timer gets going. It should stop and will continue once I login again.

prontera,154,181,3	script	testnpc::npctimerX0000	876,{
	mes "Timer value" + getnpctimer(0);
	mes "State timer" + getnpctimer(1,"npctimerX0000");
	mes "Number of events" + getnpctimer(2);
	switch(select("Initialization:Stop:Start:Settings")) {
	case 1:
		//initnpctimer;
		close;
	case 2:
		stopnpctimer;
		close;
	case 3:
		attachnpctimer strcharinfo(0);
		startnpctimer;
		end;
	case 4:
		input .@temp;
		setnpctimer .@temp;
		close;
	}

OnTimer1000:
	dispbottom "After a second...";
	message strcharinfo(0),"You have "+((getnpctimer(0))/1000)+" Seconds.";
	end;

OnTimer5000:
	dispbottom "After 5 seconds...";
	end;

OnTimer10000:
	dispbottom "Times up! warping you to your home town";
	stopnpctimer;
	end;

OnPCLogoutEvent:
if ( getnpctimer(0) == 0 ){
	dispbottom " Why stop timer if it did not start yet";
	end; 
} else {
stopnpctimer;
end;

}

OnPCLoginEvent:
if ( getnpctimer(0) == 0 ){
 dispbottom "no start countdown since it didn't start yet";
	end;
} else {
startnpctimer;
end;
}



}

 

2 hours ago, Patskie said:

You need to include attachnpctimer before initnpctimer to apply it only on players who talk to your npc.

 

 

 

 

 

Edited by glemor123
  • 0
Posted

Try the end;s after the condition..

prontera,154,181,3	script	testnpc::npctimerX0000	876,{
	mes "Timer value" + getnpctimer(0);
	mes "State timer" + getnpctimer(1,"npctimerX0000");
	mes "Number of events" + getnpctimer(2);
	switch(select("Initialization:Stop:Start:Settings")) {
	case 1:
		//initnpctimer;
		close;
	case 2:
		stopnpctimer;
		close;
	case 3:
		attachnpctimer strcharinfo(0);
		startnpctimer;
		end;
	case 4:
		input .@temp;
		setnpctimer .@temp;
		close;
	}

OnTimer1000:
	dispbottom "After a second...";
	message strcharinfo(0),"You have "+((getnpctimer(0))/1000)+" Seconds.";
	end;

OnTimer5000:
	dispbottom "After 5 seconds...";
	end;

OnTimer10000:
	dispbottom "Times up! warping you to your home town";
	stopnpctimer;
	end;

	OnPCLogoutEvent:
if ( getnpctimer(0) == 0 ){
	dispbottom " Why stop timer if it did not start yet";
} else {
	stopnpctimer;
}
end;

	OnPCLoginEvent:
if ( getnpctimer(0) == 0 ){
	dispbottom "no start countdown since it didn't start yet";
} else {
	startnpctimer;
}
end;

}

 

  • 0
Posted

Tried the end; from the conditions. It didn't work. hmm. What else can we do.

 

prontera,154,181,3	script	testnpc::npctimerX0000	876,{
	mes "Timer value" + getnpctimer(0);
	mes "State timer" + getnpctimer(1,"npctimerX0000");
	mes "Number of events" + getnpctimer(2);
	switch(select("Initialization:Stop:Start:Settings")) {
	case 1:
		//initnpctimer;
		end;
	case 2:
		stopnpctimer;
		end;
	case 3:
		attachnpctimer strcharinfo(0);
		startnpctimer;
		end;
	case 4:
		input .@temp;
		setnpctimer .@temp;
		end;
	}

OnTimer1000:
	dispbottom "After a second...";
	message strcharinfo(0),"You have "+((getnpctimer(0))/1000)+" Seconds.";
	end;

OnTimer5000:
	dispbottom "After 5 seconds...";
	end;

OnTimer10000:
	dispbottom "Times up! warping you to your home town";
	stopnpctimer;
	end;

OnPCLogoutEvent:
if ( getnpctimer(0) == 0 ){
	dispbottom " Why stop timer if it did not start yet";
	end; 
} else {
stopnpctimer;
end;

}

OnPCLoginEvent:
if ( getnpctimer(0) == 0 ){
 dispbottom "no start countdown since it didn't start yet";
	end;
} else {
startnpctimer;
end;
}



}

 

1 hour ago, -Chuck- said:

Try the end;s after the condition..


prontera,154,181,3	script	testnpc::npctimerX0000	876,{
	mes "Timer value" + getnpctimer(0);
	mes "State timer" + getnpctimer(1,"npctimerX0000");
	mes "Number of events" + getnpctimer(2);
	switch(select("Initialization:Stop:Start:Settings")) {
	case 1:
		//initnpctimer;
		close;
	case 2:
		stopnpctimer;
		close;
	case 3:
		attachnpctimer strcharinfo(0);
		startnpctimer;
		end;
	case 4:
		input .@temp;
		setnpctimer .@temp;
		close;
	}

OnTimer1000:
	dispbottom "After a second...";
	message strcharinfo(0),"You have "+((getnpctimer(0))/1000)+" Seconds.";
	end;

OnTimer5000:
	dispbottom "After 5 seconds...";
	end;

OnTimer10000:
	dispbottom "Times up! warping you to your home town";
	stopnpctimer;
	end;

	OnPCLogoutEvent:
if ( getnpctimer(0) == 0 ){
	dispbottom " Why stop timer if it did not start yet";
} else {
	stopnpctimer;
}
end;

	OnPCLoginEvent:
if ( getnpctimer(0) == 0 ){
	dispbottom "no start countdown since it didn't start yet";
} else {
	startnpctimer;
}
end;

}

 

 

  • 0
Posted
Quote

By default timers do not have a RID attached, which lets them continue even
if the player that started them logs off. To attach a RID to a timer, you can
either use the optional "attach flag" when using 'initnpctimer/startnpctimer',
or do it manually by using 'attachnpctimer'. Likewise, the optional flag of
stopnpctimer lets you detach any RID after stopping the timer, and by using
'detachnpctimer' you can detach a RID at any time.

You will need to save the npctimer into a variable when logginout...

  • 0
Posted (edited)

I think your request will not work as getnpctimer(0) and setnpctimer only works as NPC timer. Sure you can attach the timer on multiple players but you cannot get the current tick attached to each players.

You can use the gettimetick/addtimer/deltimer for this perhaps? You can try below

prontera,150,150,6	script	Timer	876,{
	function Time_Left;
	
	mes "Hi Pogi";
	switch(select("Initialization:Stop:Start:Settings")) {
		case 1:
			a = gettimetick(2); // start time
			addtimer (Time_Left() * 1000), strnpcinfo(0) + "::OnTimeUp";
			break;
		case 2:
			b = gettimetick(2); // stop time
			deltimer strnpcinfo(0) + "::OnTimeUp";
			break;
		case 3:
			.@diff = gettimetick(2) - (b - a);
			a = b;
			b = gettimetick(2);
			addtimer Time_Left(.@diff, b) * 1000, strnpcinfo(0) + "::OnTimeUp";
			break;
		case 4:
		default: break;
	}
	close;
		
	OnTimeUp:
		dispbottom "Done!";
		a = 0;
		b = 0;
		end;
		
	OnPCLogoutEvent:
		if (!a) end;
		b = gettimetick(2);
		end;
		
	OnPCLoginEvent:
		if (!a) end;
		.@diff = gettimetick(2) - (b - a);
		a = b;
		b = gettimetick(2);
		addtimer Time_Left(.@diff, b) * 1000, strnpcinfo(0) + "::OnTimeUp";
		end;
		
	function Time_Left {
		.@start = getarg(0, 0);
		.@end = getarg(1, gettimetick(2));
		return !.@start ? .time_in_seconds : (.time_in_seconds - (.@end - .@start));
	}
	
	OnInit:
		.time_limit = 3; // 3 minutes
		.time_in_seconds = .time_limit * 60;
		//uncomment below if you want timers to reset upon server restart / npc reload
		//addrid(0);
		//a = 0;
		//b = 0;
		end;
}

PS : I'm not good at timers also ?

 

Edited by Patskie
Edit links
  • 0
Posted

It appears to be working, However just want to confirm how can I print or show the time left via dispbottom before it displays the "done!". maybe a countdown? ? thanks in advance master

8 hours ago, Patskie said:

I think your request will not work as getnpctimer(0) and setnpctimer only works as NPC timer. Sure you can attach the timer on multiple players but you cannot get the current tick attached to each players.

You can use the gettimetick/addtimer/deltimer for this perhaps? You can try below


prontera,150,150,6	script	Timer	876,{
	function Time_Left;
	
	mes "Hi Pogi";
	switch(select("Initialization:Stop:Start:Settings")) {
		case 1:
			a = gettimetick(2); // start time
			addtimer (Time_Left() * 1000), strnpcinfo(0) + "::OnTimeUp";
			break;
		case 2:
			b = gettimetick(2); // stop time
			deltimer strnpcinfo(0) + "::OnTimeUp";
			break;
		case 3:
			.@diff = gettimetick(2) - (b - a);
			a = b;
			b = gettimetick(2);
			addtimer Time_Left(.@diff, b) * 1000, strnpcinfo(0) + "::OnTimeUp";
			break;
		case 4:
		default: break;
	}
	close;
		
	OnTimeUp:
		dispbottom "Done!";
		a = 0;
		b = 0;
		end;
		
	OnPCLogoutEvent:
		if (!a) end;
		b = gettimetick(2);
		end;
		
	OnPCLoginEvent:
		if (!a) end;
		.@diff = gettimetick(2) - (b - a);
		a = b;
		b = gettimetick(2);
		addtimer Time_Left(.@diff, b) * 1000, strnpcinfo(0) + "::OnTimeUp";
		end;
		
	function Time_Left {
		.@start = getarg(0, 0);
		.@end = getarg(1, gettimetick(2));
		return !.@start ? .time_in_seconds : (.time_in_seconds - (.@end - .@start));
	}
	
	OnInit:
		.time_limit = 3; // 3 minutes
		.time_in_seconds = .time_limit * 60;
		//uncomment below if you want timers to reset upon server restart / npc reload
		//addrid(0);
		//a = 0;
		//b = 0;
		end;
}

PS : I'm not good at timers also ?

 

 

  • 0
Posted

You can try 

prontera,150,150,6	script	Timer	876,{
	function Time_Left;
	
	mes "Hi Pogi";
	switch(select((a?"":"Initialization")+":"+(!a||b?"":"Stop")+":"+(!a||!b?"":"Start")+":Settings")) {
		case 1:
			a = gettimetick(2); // start time
			addtimer (Time_Left() * 1000), strnpcinfo(0) + "::OnTimeUp";
			c = Time_Left();
			break;
		case 2:
			b = gettimetick(2); // stop time
			deltimer strnpcinfo(0) + "::OnTimeUp";
			break;
		case 3:
			c -= b - a;
			addtimer Time_Left((gettimetick(2) - (b - a)), gettimetick(2), c) * 1000, strnpcinfo(0) + "::OnTimeUp";
			a = gettimetick(2);
			b = 0;
			break;
		case 4:
		default: break;
	}
	close;
		
	OnTimeUp:
		dispbottom "Done!";
		a = 0;
		b = 0;
		c = 0;
		end;
		
	OnPCLogoutEvent:
		if (!a || b) end;
		b = gettimetick(2);
		end;
		
	OnPCLoginEvent:
		if (!a || !b) end;
		c -= b - a;
		addtimer Time_Left((gettimetick(2) - (b - a)), gettimetick(2), c) * 1000, strnpcinfo(0) + "::OnTimeUp";
		a = gettimetick(2);
		b = 0;
		end;
		
	OnCmd:
		if (!a)
			dispbottom "No timer set";
		else 
			dispbottom "Timer Left : " + Time_Left(a, (!b?gettimetick(2):b), (!c?.time_in_seconds:c));
		end;
		
		
	// start = start time 
	// end = end time
	// time limit = remaining time
	function Time_Left {
		.@start = getarg(0, 0);
		.@end = getarg(1, gettimetick(2));
		.@time_limit = getarg(2, .time_in_seconds);
		return !.@start ? .time_in_seconds : (.@time_limit - (.@end - .@start));
	}
	
	OnInit:
		.time_limit = 1; // 3 minutes
		.time_in_seconds = .time_limit * 60;
		bindatcmd "timer", strnpcinfo(0) + "::OnCmd";
		//uncomment below if you want timers to reset upon server restart / npc reload
		/*addrid(0);
		a = 0;
		b = 0;
		c = 0;
		deltimer strnpcinfo(0) + "::OnTimeUp";*/
		end;
}

Tho i haven't tested them fully like combination (stop -> logout -> login -> start). Up to you how to debug

Use @timer

  • 0
Posted
On 4/16/2020 at 9:56 AM, Patskie said:

You can try 

prontera,150,150,6	script	Timer	876,{
	function Time_Left;
	
	mes "Hi Pogi";
	switch(select((a?"":"Initialization")+":"+(!a||b?"":"Stop")+":"+(!a||!b?"":"Start")+":Settings")) {
		case 1:
			a = gettimetick(2); // start time
			addtimer (Time_Left() * 1000), strnpcinfo(0) + "::OnTimeUp";
			c = Time_Left();
			break;
		case 2:
			b = gettimetick(2); // stop time
			deltimer strnpcinfo(0) + "::OnTimeUp";
			break;
		case 3:
			c -= b - a;
			addtimer Time_Left((gettimetick(2) - (b - a)), gettimetick(2), c) * 1000, strnpcinfo(0) + "::OnTimeUp";
			a = gettimetick(2);
			b = 0;
			break;
		case 4:
		default: break;
	}
	close;
		
	OnTimeUp:
		dispbottom "Done!";
		a = 0;
		b = 0;
		c = 0;
		end;
		
	OnPCLogoutEvent:
		if (!a || b) end;
		b = gettimetick(2);
		end;
		
	OnPCLoginEvent:
		if (!a || !b) end;
		c -= b - a;
		addtimer Time_Left((gettimetick(2) - (b - a)), gettimetick(2), c) * 1000, strnpcinfo(0) + "::OnTimeUp";
		a = gettimetick(2);
		b = 0;
		end;
		
	OnCmd:
		if (!a)
			dispbottom "No timer set";
		else 
			dispbottom "Timer Left : " + Time_Left(a, (!b?gettimetick(2):b), (!c?.time_in_seconds:c));
		end;
		
		
	// start = start time 
	// end = end time
	// time limit = remaining time
	function Time_Left {
		.@start = getarg(0, 0);
		.@end = getarg(1, gettimetick(2));
		.@time_limit = getarg(2, .time_in_seconds);
		return !.@start ? .time_in_seconds : (.@time_limit - (.@end - .@start));
	}
	
	OnInit:
		.time_limit = 1; // 3 minutes
		.time_in_seconds = .time_limit * 60;
		bindatcmd "timer", strnpcinfo(0) + "::OnCmd";
		//uncomment below if you want timers to reset upon server restart / npc reload
		/*addrid(0);
		a = 0;
		b = 0;
		c = 0;
		deltimer strnpcinfo(0) + "::OnTimeUp";*/
		end;
}

Tho i haven't tested them fully 

Hello, could I sent you a request on discord Santana#5322 I have a few questions about this script please.

 

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...