Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   GS2 'cron jobs' (https://forums.graalonline.com/forums/showthread.php?t=85543)

LoneAngelIbesu 05-11-2009 09:41 PM

GS2 'cron jobs'
 
For the shop system on Valikorlia, I'm wanting to implement a cron job-like scenario for updating item stock in certain shops. I'm assuming that scheduleEvent() would be used here. I've never used scheduleEvent() a day in my life, though.

Is there a way to update item stock every 24 hours, indefinitely using scheduleEvent()?

Tigairius 05-11-2009 09:45 PM

There is, but scheduled events are cancelled when the npcserver restarts, so it would be better to use a sleep or a timeout which is not interrupted by the npcserver.

Loriel 05-11-2009 09:51 PM

This is retarded, just do nothing until a player actually enters the shop and then calculate how much restocking you have to do.

LoneAngelIbesu 05-11-2009 09:57 PM

Quote:

Originally Posted by Tigairius (Post 1490943)
There is, but scheduled events are cancelled when the npcserver restarts, so it would be better to use a sleep or a timeout which is not interrupted by the npcserver.

Timeouts are reset each time the weapon is updated, right? Is there any way to prevent this, or would I have to create a separate weapon for the timeout?
Quote:

Originally Posted by Loriel (Post 1490948)
This is retarded, just do nothing until a player actually enters the shop and then calculate how much restocking you have to do.

That would defeat the purpose. I don't want the shops to have an endless stock of items at all times. I want a static amount of items each 24 hours; more specific, I want to make sure that there's nothing out of stock after 24 hours. Calculating when 24 hours has passed based on players entering the level seems overly complicated, especially since no facet of the system is used in level NPCs.

Tigairius 05-11-2009 10:17 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1490951)
Timeouts are reset each time the weapon is updated, right? Is there any way to prevent this, or would I have to create a separate weapon for the timeout?

There's not really a way to prevent that, but loriel gives a good suggestion.

Quote:

Originally Posted by LoneAngelIbesu (Post 1490951)
That would defeat the purpose. I don't want the shops to have an endless stock of items at all times.

I think what Loriel means is, save a timevar2 each time the shop is restocked, then each time someone enters the shop, subtract the saved timevar2 from the current timevar2, if it's > 86400 (24 hours), then divide the result by 86400 and it will give you how many days have passed since the last restock. Then you can stock based on that data. It's probably the best way to approach it.

Inverness 05-11-2009 10:34 PM

Quote:

Originally Posted by Tigairius (Post 1490956)
I think what Loriel means is, save a timevar2 each time the shop is restocked, then each time someone enters the shop, subtract the saved timevar2 from the current timevar2, if it's > 86400 (24 hours), then divide the result by 86400 and it will give you how many days have passed since the last restock. Then you can stock based on that data. It's probably the best way to approach it.

Or you can just do serverr.restocktime = timevar2 + 86400 then if (timevar2 >= serverr.restocktime) restock().

cbk1994 05-11-2009 11:07 PM

Quote:

Originally Posted by Inverness (Post 1490962)
Or you can just do serverr.restocktime = timevar2 + 86400 then if (timevar2 >= serverr.restocktime) restock().

That's what I'd do, but I'd save it in a 'server.' var; no need to send it to all the players (not a big deal here, but it's a good idea to encourage people not to use serverr when not needed).

EDIT: To be honest, I'd probably use a database NPC.

DarkReaper0 05-12-2009 12:46 AM

Quote:

Originally Posted by cbk1994 (Post 1490971)
EDIT: To be honest, I'd probably use a database NPC.

This.

But I'd use the database NPC for a variety of different shop functions like keeping inventory or whatever.

Because if you just use it to time it's a waste of resources, and that makes Scripters want to beat you upside the head with a Pipe Wrench.

Tigairius 05-12-2009 01:26 AM

Quote:

Originally Posted by Inverness (Post 1490962)
Or you can just do serverr.restocktime = timevar2 + 86400 then if (timevar2 >= serverr.restocktime) restock().

Yeah, that's basically just a different way to do what I just said.

[email protected] 05-12-2009 06:45 PM

Why use a server flag... I'd go with Loriel and the timevar2

LoneAngelIbesu 05-12-2009 09:00 PM

Quote:

Originally Posted by [email protected] (Post 1491108)
Why use a server flag... I'd go with Loriel and the timevar2

Server flag would allow all shops to be updated at the same time, which is what I want to do. Loriel's way is just complicating things by updating on a shop-by-shop basis. Having all shops update at the same time is required, anyways, for the global managing GUI that I've made.

Loriel 05-12-2009 10:44 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1491134)
Server flag would allow all shops to be updated at the same time, which is what I want to do. Loriel's way is just complicating things by updating on a shop-by-shop basis.

I did not say anything about doing it on a shop-by-shop basis.

Tigairius 05-12-2009 10:58 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1491134)
Server flag would allow all shops to be updated at the same time, which is what I want to do. Loriel's way is just complicating things by updating on a shop-by-shop basis. Having all shops update at the same time is required, anyways, for the global managing GUI that I've made.

We're all saying that you should keep a database and only update the shops every time someone enters the level to prevent the use of a timeout/sleep. It's really the best way to go about it, if you wanted to restock all shops just add a DBNPC.restockall = true boolean and check it when a player enters a shop.

LoneAngelIbesu 05-14-2009 08:32 PM

Quote:

Originally Posted by Tigairius (Post 1491158)
We're all saying that you should keep a database and only update the shops every time someone enters the level to prevent the use of a timeout/sleep. It's really the best way to go about it, if you wanted to restock all shops just add a DBNPC.restockall = true boolean and check it when a player enters a shop.

I've already finished the system. Auto-updating was a last-minute addition that I had accidentally overlooked. When a player enters a level with a shop in it, the serverr.restocktime check that Inverness suggested is used.


All times are GMT +2. The time now is 01:22 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.