![]() |
Posessed DBNPC - Please help
Okay I got a DBNPC. I noticed something that I canno't explain. I did not know it was possible and have no idea how to fix this.
I used the following: PHP Code:
PHP Code:
Also, PHP Code:
PHP Code:
|
this.option.(@ player.account) will access a variable within the "option" var, but this.("option." @ player.account) treats "option.<account>" as a variable name itself. That is how you can have two separate data points with similar paths. It also can make the latter unwanted path impossible to access by makevar.
|
Thanks. That helped alot.
Now the only problem I am having with it is the getstringkeys not getting all the flags. Any idea why it might not? I made sure they are all added using the same method. PHP Code:
|
The function getstringkeys will not find a var path if it does not exist. If you are setting your vars to 0, "", {}, or null, the var name and path will not be created because it is equal to null. Try this.option.(@player.account) = 1; or any value not null.
|
Quote:
|
Have you considered simply using TStaticVars? It will likely simplify what you're trying to do.
You create a TStaticVar as follows: PHP Code:
PHP Code:
PHP Code:
You could pass it from clientside to serverside via something like: PHP Code:
PHP Code:
|
Kinda what I'm already doing. There's a problem tho. DBNPC seems to not always save flags and they dissapear. Not entirely sure under which circumstances tho. But occasionally I notice some just vanishing. Some people said it happens sometimes when restarting npc server even with the rc save npcs command
|
TStaticVar is normally not used for database flag storage. It is the same as a TGraalVar (every base data type) except as a global reference. This means that the data would not be stored on the database npc, but actually on a global object, which may be deleted after time or server restart. A common technique for storing persistent dynamic vars to a database npc is using a prefix like this.("option_" @ player.account) . You can then find the full list of accounts by doing getstringkeys("this.option_") .
|
I would have to check my script but about the TStaticVar.. but I was meaning I'm using the save art array and loading also the same way. It shows in the flags. Also saves some flags but not every one. I would say I counted 77 saved strings and sadly no way to know for sure how many did not save. Not sure why it would work sometimes... but not all the times..
|
Quote:
We also noticed that savenpcs seems not effective; we wrote our own that we called before restarting the NPC-server that just called trigger('update') on every DBNPC with much better results -shrug- Maybe it's just a placebo but I kind of doubt it. I don't know why it works or if it has to be update. |
Quote:
|
Quote:
You can do what you're saying via: this.options.(@player.account) The advantages of a TStaticVar instead of that are: 1. Easier to send between server and client via savevarstoarray() 2. Easier to write to a file via savevars() 3. Easier to access with smaller variable names and thus cleaner 4?. I would imagine a guess that .getDynamicVarNames() is an O(c) operation, while .getStringKeys() is an O(n) operation. Also, you claim it's a "global" reference but no more than a DB NPC's variables are. The advantages outweigh the disadvantages. However, I am well aware that TStaticVars do not persist for long periods of time. They seem to have some time limit until they are garbage collected. If you're creating a static variable, you can reload it whenever it's garbage collected. If this is a variable that changes rarely but needs to maintain long-term data, saving it to a file is more persistent than BOTH methods described (And a TStaticVar is ideal for that, via .saveVars()). As Scriptless has stated, even this.'s can have troubles persisting in DB NPCs. If you want true persistence for long-term database usage, I would suggest either: 1. File I/O. This is best method if the files will not change often (since I/O can be laggy). The easiest method for this is, you guessed it, TStaticVars and .savevars 2. SQL DB. This is the best method if the options will be changing frequently, as reading/writing to SQL is less intense than files. |
Quote:
|
hello!
tStaticVars should never be garbage collected for as long as they have an active reference, ive seen them remain for several months and only be destroyed whenever the npc-server is restarted personally i prefer to store data within an sqlite database, however load the sql data into a tStaticVar cache upon database npc initialization for easier access |
I definately want to move the system to sqlite. But it's currently live on the server and only going to be active another half a week. So it's kinda a bandaid to help make sure it works better till then. I'll try the trigger for now hopefully it buys me time to finish the sql part.
Thanks everyone for the info. |
| All times are GMT +2. The time now is 08:05 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.