Jump to content
  • 0

NPC timer unaffected by server reset


Question

Posted (edited)

hi,

how do i make an npc continue doing a certain event even server is being reset?

to further explain:

<code>

npc x = trigger an event where event will last for 1 hr.

after an hour, event will end.

 

if server is being reset or shutdown while event is being triggered, the NPC timer will pause and will resume after server is up again

<code>

i already tried OnTimerXXXX codes but it terminates the event after server is reset.

any other available options for me? tia

 

im on mobile, dont know how to make codebox x.x

 

update: 

i added initnpctimer at OnInit label. however, it restarts the timer to 0.

Edited by pajodex

5 answers to this question

Recommended Posts

  • 1
Posted

Pseudocode, but I think you can get what I want to show here

- script secret -1,{

OnFoo:
  $evt_tick = gettimetick(2);
  addtimer "somenpc::someevent",.delay_tick;
  end;

OnInit:
  .delay_tick = youreventdelay;
  .@difftick = gettimetick(2) - $evt_tick;
  if(.@difftick < 0) {
    // timer still not elapsed
    addtimer "somenpc::someevent",.@difftick;
  } else {
    donpcevent "somenpc::someevent";
  }

 

  • MVP 1
  • 0
Posted (edited)
8 hours ago, pajodex said:

i added initnpctimer at OnInit label. however, it restarts the timer to 0

I don't think there is a way to continue npc timer after a reload.

Maby OnClock event or other workaround ?

-	script	DayNight	-1,{
OnClock0600:
	day;
	end;
OnInit:
	// setting correct mode upon server start-up
	if (gettime(DT_HOUR)>=6 && gettime(DT_HOUR)<18) end;
OnClock1800:
	night;
	end;
}

 

Edited by Sehrentos
Fix
  • Upvote 1
  • 0
Posted
12 hours ago, Sehrentos said:

I don't think there is a way to continue npc timer after a reload.

Maby OnClock event or other workaround ?


-	script	DayNight	-1,{
OnClock0600:
	day;
	end;
OnInit:
	// setting correct mode upon server start-up
	if (gettime(DT_HOUR)>=6 && gettime(DT_HOUR)<18) end;
OnClock1800:
	night;
	end;
}

 

i have thought of this already. it doesn't really fit the need of the script i'm currently working on with. maybe i should just work around with my idea and use OnClock. thanks anyways

  • 0
Posted
9 hours ago, Secrets said:

Pseudocode, but I think you can get what I want to show here


- script secret -1,{

OnFoo:
  $evt_tick = gettimetick(2);
  addtimer "somenpc::someevent",.delay_tick;
  end;

OnInit:
  .delay_tick = youreventdelay;
  .@difftick = gettimetick(2) - $evt_tick;
  if(.@difftick < 0) {
    // timer still not elapsed
    addtimer "somenpc::someevent",.@difftick;
  } else {
    donpcevent "somenpc::someevent";
  }

 

i will try my best to comprehend thanks ????

  • 0
Posted

have you tried putting checkpoints on your script?

*pseudocode*

script{

#checkpoint =0;

if (checkpoint==0)

{

//do something

//since this part of the script is done,

checkpoint+=;

}

if(checkpoint==1)

{

//do something

//since this part of the script is done,

checkpoint+=;

}

}

this way, if your server is done with a part of the script, after you reset your server, the script will resume to the last part it has completed.

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