The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NPC Restock
Author Message
escribano
Journeyman
*

Posts: 170
Likes Given: 16
Likes Received: 32 in 23 posts
Joined: Nov 2012
Reputation: 2

Dragon Shard

Post: #1
NPC Restock
Dudes, me again...

Now i am re-scripting the buy/sell packet to improve some features and help players to sell training itens.
I've finished the script and it works very well, but i noticed a strange behavior happening in the layers of all vendors.

This is what my script does:

1) Override the sphere base packets (0x9e and 0x9f) to give me full control of the buy/sell system.
2) When you sell a item to the npc, this item appears to sell (stored on layer 27, vendor extra)
3) If the NPC have no money, he cant buy your itens
4) When you buy a item on the npc, the gold is set on npc's layer 29 (bankbox) increasing the money of the npc so he can buy more itens next time
5) When a player try to sell a item that is not "groupable", for exemple any weapon, it shows to sell in group.

So ok.. all this works very well, but if i leave the NPC in a area with no players, this NPC simply remove all the itens in layers: 26 (stock), layer 27 (vendor extra) and the money from layer 29 (bankbox)... WHY???

And there is nothing that i could made to make it work.

I've opened all this layers and put itens inside to try to force the buy/sell list but immediatly when i close the box, it was erased and all itens is gone....

I've copied the uid from the itens and saved the world to try to find in the save file but no one uid was saved there...

Someone pass through this before?
Thanks!

UltimaPHP - OpenSource Ultima Online Server v0.1-pre-alpha under development, we need help!
07-19-2015 12:51 PM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes escribano's post
azmanomer
Journeyman
*

Posts: 139
Likes Given: 4
Likes Received: 18 in 16 posts
Joined: Nov 2013
Reputation: 1



Post: #2
RE: NPC Restock
maybe sector sleep could make that.i dont know how to disable it but check it if you know Smile
07-19-2015 04:19 PM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes azmanomer's post
Paulo_BR
Apprentice
*

Posts: 30
Likes Given: 14
Likes Received: 1 in 1 posts
Joined: May 2012
Reputation: 0

Ultima Online Brasil

Post: #3
RE: NPC Restock
Someone can help us?
07-20-2015 03:59 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #4
RE: NPC Restock
When restocking all vendor containers are emptied, default ones will be generated again by the system but custom ones will be lost.

// Restock occurs every 10 minutes of inactivity (unless region tag specifies different time)
So, to avoid this you can set region.tag.NoRestock=1.

However this will make npcs to no restock their items and they will eventually lose them ... so you'll have to manually 'regenerate' these items.

Best idea I can give you is to store the amount of each item in a tag after NPCRestock, something like this:

Code:
[function f_stock_tags_set]
ref1=<uid>
forcont layer_stock
ref1.tag.<baseid>=<amount> // a tag with the id of the item will be created with it's amount, ie 'tag.i_deed_vendor=18'.
endfor

So you will be able to periodically call in that region a custom restock at the time you want.

Code:
[function f_stock_regenerate]
if !(<brain>) // no call on players.
return 0
endif
ref1=<uid>
forcont layer_stock
if (<ref1.tag0.<baseid>>) //if we have a tag for this item
  amount = <ref1.tag.<baseid>> // we set the item to the amount stored in the tag
endif
endfor

So now you have a region not restocking the vendors inside and a function to store how much items of each one the vendor will have and another setting it back, you only need something timing from time to time calling region.allchars.f_stock_regenerate and you should have your problem solved.
07-20-2015 05:46 PM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes XuN's post
escribano
Journeyman
*

Posts: 170
Likes Given: 16
Likes Received: 32 in 23 posts
Joined: Nov 2012
Reputation: 2

Dragon Shard

Post: #5
RE: NPC Restock
Thanks so much XuN!!! seriously, you are a genious!

I'll make this and post the results as soon as possible!

Thanks again!

UltimaPHP - OpenSource Ultima Online Server v0.1-pre-alpha under development, we need help!
07-21-2015 08:01 AM
Find all posts by this user Like Post Quote this message in a reply
escribano
Journeyman
*

Posts: 170
Likes Given: 16
Likes Received: 32 in 23 posts
Joined: Nov 2012
Reputation: 2

Dragon Shard

Post: #6
RE: NPC Restock
XuN, i didn't work... The itens are deleted on the "sphere default restock"... see this images:
http://s23.postimg.org/vfzs01zqi/Captura..._10_39.jpg
http://s23.postimg.org/z25lcp63u/Captura..._14_32.jpg

At 23:10 the itens was inside the vendor on layer 26 (buy) and 28 (sell)
At 23:14 all the itens is gone.... no error on console, no save, no resync, no nothing...


With no itens, i can't change the amount.. i even tryied to make this funcion:

Code:
[FUNCTION f_restock_tag_set]
ref1=<uid>
local.sell = 0
local.buy = 0

forcont <findlayer(26).uid>
    if !(<ref1.tag0.sell.<baseid>>)
        ref1.tag0.sell.<eval <local.sell>>.id = <baseid>
        ref1.tag0.sell.<eval <local.sell>>.amount = <eval <ref1.f_count_itens <baseid>,26>>
    else
        ref1.tag0.sell.<eval <local.sell>>.amount += <eval <ref1.f_count_itens <baseid>,26>>
    endif
    local.sell += 1
endfor

forcont <findlayer(27).uid>
    if !(<ref1.tag0.sell.<baseid>>)
        ref1.tag0.sell.<eval <local.sell>>.id = <baseid>
        ref1.tag0.sell.<eval <local.sell>>.amount = <eval <ref1.f_count_itens <baseid>,27>>
    else
        ref1.tag0.sell.<eval <local.sell>>.amount += <eval <ref1.f_count_itens <baseid>,27>>
    endif
    local.sell += 1
endfor

forcont <findlayer(28).uid>
    if !(<ref1.tag0.sell.<baseid>>)
        ref1.tag0.buy.<eval <local.buy>>.id = <baseid>
        ref1.tag0.buy.<eval <local.buy>>.amount = <eval <ref1.f_count_itens <baseid>,28>>
    else
        ref1.tag0.buy.<eval <local.buy>>.amount += <eval <ref1.f_count_itens <baseid>,28>>
    endif
    local.buy += 1
endfor

ref1.tag0.buying = <eval <local.buy>>
ref1.tag0.selling = <eval <local.sell>>

On the restock stone i've made, when i set "restock 1" on the NPC this funcion run, (cuz if i use only "restocl" all itens was deleted too... i don't know why).

When the player goes on the NPC to buy or sell and there is no layer on some layer, i checked the tags, to re-create the missing itens.. but it makes the shard REALLY slow.


I don't know but i guess there is something wrong with restock in sphere... if the base function could run with the "1" argument the restock would be fixed Smile

OBS: I'm using the spehre nightly build 2387 and i notice this behavior abount 1 month ago... buy just declared as "error" this days..

Thanks for helping XuN!

NOTE: With region.tag0.NoRestock=1 items do not disappear.. At least until now!

XuN, yeah...so far, so goo!

But to restock all NPCs the server is overloaded... so thinking better this may be a bad idea.

There is a way to change the restock time?
There is a way to set the "1" argument on default restock sphere code?
There is a way to run "background" functions to sphere?

Sorry for bothering!
Thanks

UltimaPHP - OpenSource Ultima Online Server v0.1-pre-alpha under development, we need help!
(This post was last modified: 07-21-2015 10:04 AM by escribano.)
07-21-2015 09:29 AM
Find all posts by this user Like Post Quote this message in a reply
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #7
RE: NPC Restock
I never told you to use default restock, just that 'restock' custom function, and only region by region ... doing it world-wide is insane for a full spawned shard!

You don't have to restock all npcs in the server, just region by region, create a memory item (or a repeating timerf) forcing ONE REGION to restock its npcs, so you'll end with like 10 timers at max depending on the amount of cities with vendors you have, that will decrease the impact a lot.

Another idea is to do it for each vendor individually, intercept the 'buy' and 'sell' speechs on the vendors and create a memory on them which force restock when timing out and remove it, so it will not regenerate anything until the next time a shop command is being heard by them.
07-22-2015 06:14 PM
Find all posts by this user Like Post Quote this message in a reply
escribano
Journeyman
*

Posts: 170
Likes Given: 16
Likes Received: 32 in 23 posts
Joined: Nov 2012
Reputation: 2

Dragon Shard

Post: #8
RE: NPC Restock
Hummmm nice ideas XuN!

Ill try this ones at night and o post the results later!

And this other questions:

There is a way to change the default restock time?
There is a way to set the "1" argument on default restock sphere code?
There is a way to run "background" functions to sphere?


Thanks

UltimaPHP - OpenSource Ultima Online Server v0.1-pre-alpha under development, we need help!
07-23-2015 12:55 AM
Find all posts by this user Like Post Quote this message in a reply
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #9
RE: NPC Restock
There's no way to change default restock time (actually).
What does that '1' mean for restock?
For background functions I always have the uid of my character in a def (a character that will NEVER be deleted), then in f_onserv_start I call some functions on that UID, that themselves again with a timerf, another way should be using the ini option for that (although is a little more static):

// Amount of minutes to call f_onserver_timer (0 disables this, default)
TimerCall=0
07-24-2015 06:47 PM
Find all posts by this user Like Post Quote this message in a reply
escribano
Journeyman
*

Posts: 170
Likes Given: 16
Likes Received: 32 in 23 posts
Joined: Nov 2012
Reputation: 2

Dragon Shard

Post: #10
RE: NPC Restock
Thank again XuN!

I mean when i use:

".xrestock" the npc wont restock, and all layers was deleted

if i use "restock 1" the npc was restocked with no errors.

UltimaPHP - OpenSource Ultima Online Server v0.1-pre-alpha under development, we need help!
07-25-2015 04:27 PM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)