Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-11-2009, 09:41 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
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()?
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #2  
Old 05-11-2009, 09:45 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 05-11-2009, 09:51 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
This is retarded, just do nothing until a player actually enters the shop and then calculate how much restocking you have to do.
Reply With Quote
  #4  
Old 05-11-2009, 09:57 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Tigairius View Post
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 View Post
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan

Last edited by LoneAngelIbesu; 05-11-2009 at 10:17 PM..
Reply With Quote
  #5  
Old 05-11-2009, 10:17 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by LoneAngelIbesu View Post
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 View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 05-11-2009, 10:34 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Tigairius View Post
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().
__________________
Reply With Quote
  #7  
Old 05-11-2009, 11:07 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Inverness View Post
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.
__________________
Reply With Quote
  #8  
Old 05-12-2009, 12:46 AM
DarkReaper0 DarkReaper0 is offline
No.
DarkReaper0's Avatar
Join Date: May 2005
Location: Texas,USA
Posts: 344
DarkReaper0 will become famous soon enough
Send a message via MSN to DarkReaper0
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #9  
Old 05-12-2009, 01:26 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Inverness View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #10  
Old 05-12-2009, 06:45 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Why use a server flag... I'd go with Loriel and the timevar2
Reply With Quote
  #11  
Old 05-12-2009, 09:00 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by [email protected] View Post
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #12  
Old 05-12-2009, 10:44 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by LoneAngelIbesu View Post
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.
Reply With Quote
  #13  
Old 05-12-2009, 10:58 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by LoneAngelIbesu View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #14  
Old 05-14-2009, 08:32 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Tigairius View Post
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:43 PM.


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