Jump to content
  • 0

How to run timer even the char is off?


Meister

Question


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

e.g. example at his first login. I set a timer to the player for 24 hours..

Even if he/she logouts, the timer will still be on going..

I'm lost with the OnTimer part with attachnpctimer "+strcharinfo(1)+";

cause the timer only run if the player is online..

Link to comment
Share on other sites

15 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

You can't trigger events for offline characters. What do you need to execute when a player is offline, anyway? Calculating elapsed time with a permanent variable and gettimetick(2) OnPCLoginEvent should be sufficient.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

I'm trying to make a command in which it'll give daily reward or monthly reward.. using bindatcmd..

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

how you want it to work ?

everytime login...will do the countdown that stopped at his last login ?

after 24 hours countdown finished and he get 1 time ?

then a new countdown is set again ?

some progress continue again and again ?

then what is the usage of command here ?

check time left ? or what ?

elaborate more ?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

how you want it to work ?

everytime login...will do the countdown that stopped at his last login ?

after 24 hours countdown finished and he get 1 time ?

then a new countdown is set again ?

some progress continue again and again ?

then what is the usage of command here ?

check time left ? or what ?

elaborate more ?

sorry if I didin't elaborate it..

well then here's what i'm trying to make..

i'll make a custom command "@dailyreward" wherein it'll give a daily reward ..

and "@monthlyreward" for monthly reward..

and e.g.

if the player uses @dailyreward .. it will give an item but will set a 24 hour cooldown to avoid spamming of reward. the question here how to attach the timer if player is offline? do I need to use command such as OnClock to reset the variable attached on the @dailyreward ? like.. this..

binatcmd("dailyreward",blablah::OnDaily"); - don't mind the correct script for this..
OnDaily:
if(#dreward != 1) {
announce >>>
getitem n,x;
dispbototm >>>>
set #dreward,1;
OnPCLoginEvent:
attachnpctimer "+strcharinfo(2)+"
initnpctimer
and then get time tick?

what I'm freaking out is that don't know how to use the timer when player is offline.. For simplicity, player can only use the command for every 24 hours..

another example.. if e.g. player uses @dailyreward command at 9:59P.M. then he can use the command again next day with the same time or onwards.. and if com tomorrow, he'll use the command @ 10:30 (late for 30 minutes) come tomorrow, he can use the command again @ 10:30..

just like that..

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  17
  • Topics Per Day:  0.00
  • Content Count:  76
  • Reputation:   3
  • Joined:  02/24/12
  • Last Seen:  

binatcmd("dailyreward",blablah::OnDaily"); - don't mind the correct script for this..

binatcmd("monthlyreward",blablah::OnMonthly"); - don't mind too

OnDaily:

if(#dreward < gettimetick(2)) { //You used that variable so I think you mean it for account

//announce >>>

//getitem n,x;

//dispbottom >>>>

set #dreward,gettimetick(2)+(60*60*24);

} else {

//dispbottom >>>>

}

end;

OnMonthly:

if(#mreward < gettimetick(2)) { //You used that variable so I think you mean it for account

//announce >>>

//getitem n,x;

//dispbottom >>>>

set #mreward,gettimetick(2)+(60*60*24*30); // Just 30 days

} else {

//dispbottom >>>>

}

end;

something like this

Edited by SaZzuke
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

binatcmd("dailyreward",blablah::OnDaily"); - don't mind the correct script for this..

binatcmd("monthlyreward",blablah::OnMonthly"); - don't mind too

OnDaily:

if(#dreward < gettimetick(2)) { //You used that variable so I think you mean it for account

//announce >>>

//getitem n,x;

//dispbottom >>>>

set #dreward,gettimetick(2)+(60*60*24);

} else {

//dispbottom >>>>

}

end;

OnMonthly:

if(#mreward < gettimetick(2)) { //You used that variable so I think you mean it for account

//announce >>>

//getitem n,x;

//dispbottom >>>>

set #mreward,gettimetick(2)+(60*60*24*30); // Just 30 days

} else {

//dispbottom >>>>

}

end;

something like this

can you further enlighten me about gettimetick(2)

cause I don't understand this thing written on the script_commands

.. "This function will return the system time in UNIX epoch time (if tick type is 2)

or the time since the start of the current day in seconds if tick type is 1.

Passing 0 will make it return the server's tick, which is a measurement in

milliseconds used by the server's timer system. The server's tick is an

unsigned int which loops every ~50 days."

Does it mean gettimetick(2) - will still process even the player is offline?

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

By using this script and analyzing how it works, i came up to this thought..

If I use this script.. example today.. day = tuesday..

The

OnDaily:

will set the #dailyreward,gettime(8) -- as tuesday @ time Xx:XX am/pm

and if come tomorrow - wednesday.. if I used the command .. player is able to use it? at the same time with tuesday?

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

my script doesnt check the time cooldown for 24 hours...

as long as he log in everyday / every month ...

he will get the item when used these commands

day or month wont repeat twice...

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

my script doesnt check the time cooldown for 24 hours...

as long as he log in everyday / every month ...

he will get the item when used these commands

day or month wont repeat twice...

Thanks for this. I'll serve his as an alternative.. but I'm trying to find a script in which it will count the hours even player is offline. But don't know if it is possible..

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  554
  • Reputation:   70
  • Joined:  04/04/12
  • Last Seen:  

I will go for Euphy's suggestion..the only problem is how you will implement it...

here is a pseudo

onLogin

{

if(has remaining time)

time = original time - remaining time

start timer based time calculated

else

start timer

}

onLogout{

record time elapse/remaining time

}

:meow:

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

There are many examples of how gettimetick(2) works, please try searching first next time.

OnInit: bindatcmd("dailyreward",strnpcinfo(0)+"::OnAtCmd"); end;
OnAtCmd:
   if (#dailyreward > gettimetick(2)) {
    message strcharinfo(0),"You must wait 24 hours before receiving more items.";
    end;
   }
   // getitem x,y;
   set #dailyreward, gettimetick(2)+86400;
   end;

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

I will go for Euphy's suggestion..the only problem is how you will implement it...

here is a pseudo

onLogin

{

if(has remaining time)

time = original time - remaining time

start timer based time calculated

else

start timer

}

onLogout{

record time elapse/remaining time

}

:meow:

my brain is exploding from the suggestions you've made. >,< from this to that. and from that to this.. Well then maybe its not possible to run timer when player is offline. maybe next time I should put a questionable post like..

How to set timer when player is offline?

if possible can you give an example?

if not possible then topic close. LOL.

There are many examples of how gettimetick(2) works, please try searching first next time.

OnInit: bindatcmd("dailyreward",strnpcinfo(0)+"::OnAtCmd"); end;
OnAtCmd:
if (#dailyreward > gettimetick(2)) {
	message strcharinfo(0),"You must wait 24 hours before receiving more items.";
	end;
}
// getitem x,y;
set #dailyreward, gettimetick(2)+86400;
end;

last final question. does gettimetick(2) or anything that involves gettime or gettimetick can start even the player is offline when it is set on a global variable such as # or @?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

last final question. does gettimetick(2) or anything that involves gettime or gettimetick can start even the player is offline when it is set on a global variable such as # or @?

Please... x.x

*gettimetick(<tick type>)

This function will return the system time in UNIX epoch time (if tick type is 2)

or the time since the start of the current day in seconds if tick type is 1.

Passing 0 will make it return the server's tick, which is a measurement in

milliseconds used by the server's timer system. The server's tick is an

unsigned int which loops every ~50 days.

Just in case you don't know, UNIX epoch time is the number of seconds elapsed

since 1st of January 1970, and is useful to see, for example, for how long the

character has been online with OnPCLoginEvent and OnPCLogoutEvent, which could allow

you to make an 'online time counted for conviction only' jail script.

tl;dr it counts time, that's it. No you can't ever use "timers" for offline characters.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

Oks then. topic close. thanks! now i know that timers cant be used. sorry noob here.

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...