[HELP] npctimer

schan

New member
Messages
60
Points
0
Github
xschan
Emulator
Hi,

I need help with this. I want the npc to start a counter on server start up and attach to players who activated it.

The counter will continue even if the player logged out of the game.

OnTimer60000: //1 minute set minute, minute + 1; stopnpctimer; initnpctimer; end;OnPCLoginEvent: attachnpctimer strcharinfo(0); initnpctimer; end;OnInit: attachnpctimer strcharinfo(0); initnpctimer; end; 
My script works fine but the counter stops when player logs out of the game and gives me this error on server start up:

Code:
script_rid2sd: fatal error! player not attached!
 
Last edited by a moderator:
I have never write a script that needs the timer to attach to the player and yet continue after logout

what kind of script are you writing ?

although this is do-able

Code:
prontera,155,186,5	script	kjfhksdjf	100,{	dispbottom "current timer is "+( gettimetick(2) - .timer[ getcharid(0) ] )+" seconds";	end;OnPCLoginEvent:	.@cid = getcharid(0);	if ( .timer[.@cid] ) {		dispbottom "continue the timer from "+( gettimetick(2) - .timer[.@cid] );		end;	}	.timer[.@cid] = gettimetick(2);	end;}
honestly ... tell me what you are writing ...
 
Last edited by a moderator:
I have never write a script that needs the timer to attach to the player and yet continue after logout

what kind of script are you writing ?

although this is do-able

prontera,155,186,5 script kjfhksdjf 100,{ dispbottom "current timer is "+( gettimetick(2) - .timer[ getcharid(0) ] )+" seconds"; end;OnPCLoginEvent: .@cid = getcharid(0); if ( .timer[.@cid] ) { dispbottom "continue the timer from "+( gettimetick(2) - .timer[.@cid] ); end; } .timer[.@cid] = gettimetick(2); end;}honestly ... tell me what you are writing ...

Hi Annie,

I'm trying to make a script that would give experience to players every minute/hour continuously even if they log out of the game. 

 
I think it's easier for your server's processing capabilities just calculating the time difference from when the user logged out by using the OnPCLogoutEvent to when he logs in back when he uses OnPCLoginEvent. You can use gettimetick(2) for this.

Once you know the time the user went out and the time it's logged back in, and since gettimetick(2) is a measure of seconds from January 1 1970, you'll only need to subtract the logout time to the login time (now you have the difference) and then give according exp.

This will reduce your processing time burden, because it's way too heavy for a processor to host, say, 5000 timers at once*?

*one per character be it online or not, based on a small-sized server of mine that was run alive for some more than a year.

 
Last edited by a moderator:
Back
Top