ncps Table from npcs.db

A new update (0.9.3) is available now!
  • Hi


    I see in table npcs data about a particular npc spawn in game. I tried to use information from fields lastXXX (like lastinteraction,lasfeeding,lasteating,lasttamed,etc.), but so far i can't interpret correctly the result.

    So far i don't find exposed this data via API (or maybe i miss something). So i select them directly from table. But now come difficult part because i can't correlate the respective value with actual current time (aka how many seconds ago that happen?) or a relation with spawndate (witch is stored as epoch time in miliseconds). From what i see fields lastXXX are stored as miliseconds after some time reference. Any clue how to find that time reference to can actual compare this numbers with to can get actual date or how many seconds elapsed from last changed value?


    Thx. in advance for any hints!


    Bamse

  • EN Hi, I'd guess these time values are based on server ticks (i.e., elapsed ticks since the server started).

    So the "time reference" is simply the server start time.


    DE Hi, ich tippe mal darauf, dass diese Zeitwerte auf Server-Ticks basieren (also verstrichene Ticks seit Serverstart).

    Der "Zeitreferenzpunkt" wäre dann einfach der Serverstart.

  • EN Hi, I'd guess these time values are based on server ticks (i.e., elapsed ticks since the server started).

    So the "time reference" is simply the server start time.



    It can't be server ticks (time when server start) because server can be online/offline during some intervals.
    If we talk about world tick (time from creating of world, and server was online) it can be!
    Now question how i can read this world tick from API?

  • most times in the game are stored as epoch second. Epoch time (commonly called Unix time) is a system for tracking time in computers by counting the total number of seconds that have passed since January 1, 1970, at 00:00:00 UTC

    i guessing your wanting something like this.

    Java
    //replace with whatever npc time stat
    long start = Instant.now().getEpochSecond();
    // ... run code ...
    long end = Instant.now().getEpochSecond();
    long secondsElapsed = end - start;
  • It's not case of values from fields lastXXX from table npcs. They are not epoch time. Value from them sure are some milisseconds. On new world start from 0 and keep increasing when touch respective actions (interact,feed, etc.). On old world this values are much bigger.

    I suppose value from this field are just world tick (in miliseonds) from creation of world and server was online. To calculate how many ago event happen (relative to server online) just need how to read current world tick and substract this values.

    So to resolve my problem i need to know if my supposition is accurate and need a method to read current world tick. To place on realtime scale event, i suppose this will be accurate just for current running session of server by calculating from current real time minus seconds in the past. But if go back earlier than server start this will not be accurate.

  • In older versions some of the npc "lastxxx" columns indeed stored a unix timestamp, but this was changed with the last update. These npc columns now rely on a special ingame timestamp: basically it tracks the running time of the server (across all sessions). Unfortunately it's not exposed to the API yet... and there is no clean way to reconstruct the timestamp... but I will add a new Server.getIngameTimestamp() method with the next hotfix :)

  • Maybe add a method to just get raw value too not just as timestamp. This for example can be used to calculate quick how many seconds (in server online time) elapsed from last action.

    something like:


    long Server.getIngameTick()

  • Maybe add a method to just get raw value too not just as timestamp. This for example can be used to calculate quick how many seconds (in server online time) elapsed from last action.

    Hmm... can you elaborate on that? Basically the ingame timestamp has nothing to do with a classic unix timestamp... it just counts the total amount of milliseconds the server was active (unlike a unix timestamp, the count doesn't start from a fixed date)^^ If you create a new server and let it run for 10 seconds, for example, the ingame timestamp would be 10,000 (miliseconds). If you shut it down and restart it after a month and let it run for another 10 seconds, the ingame timestamp would be 20,000 etc.


    Under the hood it consists of three components: the total running time of the server (during this session) in millis, minus the world idle time (i.e the amount of time the world was "paused" this session), plus the timestamp when the server was started (basically the ingame timestamp from the previous session).


    The total running time is basically already exposed as Server.getRunningTime(). But it returns a float (representing seconds) instead of milliseconds (but I could add another Server.getRunningTimeMillis() method which returns milliseconds instead).

  • Hmm... can you elaborate on that?

    From my understanding, more or less, time model for game start when world is created and increased with a tick (millisecond) continuously just while server is online. So analog with epoch time, instead of January 1, 1970, at 00:00:00 UTC we have basically reference date as real date when world was created and fundamental difference beside real time is fact game time is composed by summing all time of sessions of running of server.

    Take following scenario:
    Create a new world and start a new game. For a npc lastXXX field start with 0 that mean respective action never happen yet (interacting,feeding,etc.). From this point game time start to tick permanent.

    At second 30 we feed a npc. That mean lastFeed field from npcs table will be update with 30000 miliseconds because so far game tick time reached this value.

    If first session of server run time is 60 seconds, before server stop Server.getRunningTime() will return 60.


    After some time we run another session of game.

    At second 30 from second running session i want to know how many seconds passed from last feeding NPC. For this need current game tick. This, in that moment must be 90000 (60000 from first session of server run + 30000 from current session). With current API we can get easy with Server.getRunningTime() current time from current session (30000 - less ignore for moment when server was "paused"). So we need API (as proposed in earlier post) to get accumulated game ticks from previously sessions, let say (random name) Server.getAcumulatedTimeAtServerStart() wich must return in this case 60000. From sum of this value we get current game tick.


    Java
    long currentGammeTick=Server.getRunningTime()*1000+Server.getAcumulatedTimeAtServerStart()*1000 ;   <-- this must be 90000 milliseconds
    long lastFeedFromDB= get value from db npcs field lastfeed                                          <-- this must be 30000 milliseconds
    long npcFeedSecondsAgo=(currentGammeTick-lastFeedFromDB)/1000                                      <-- result must be 60 seconds

    But this game tick is cumulative over multiple sessions so i think is more coupled with World class (all time model over existence of world) than Server class (time model based on running server)

    So my proposal is to keep Server class (getRunningTime()) specific to session and create truly world tick timer coupled to world class (World.getCurrentGameTick()) witch will return game tick keeping accumulated time from previously running sessions of server. In fact this will return same value who is update in fieldsXXX if method was called same time with fedding a npc for example.

    With that example will be (run at second 30 from second run session):


    Code
    long currentGammeTick=World.getCurrentGameTick() ;                   <-- this must be 90000 milliseconds
    long lastFeedFromDB= get value from db npcs field lastfeed          <-- this must be 30000 milliseconds
    long npcFeedSecondsAgo=(currentGammeTick-lastFeedFromDB)/1000        <-- result must be 60 seconds


    I hope is more clear what i mean.


    Thx.

    Bamse

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!