[Request] Player's online time.

08/18/2014 04:21 Penchod-Shaiya#1
Is there any possible way to read how long a player has been online in total?
Or if it is possible to read how long a player was online at a specific day.

Thanks in advance! :)
08/18/2014 05:27 nubness#2
Yes, you gotta start a counter since the server's first day.
08/18/2014 07:53 Penchod-Shaiya#3
Quote:
Originally Posted by nubness View Post
Yes, you gotta start a counter since the server's first day.
Not for yourself... as a owner of a server, is there a way to create a script to read how long a player has been online in total ?
08/18/2014 16:53 nubness#4
Not for a server that is already online for some time, no.
08/19/2014 13:33 Penchod-Shaiya#5
Quote:
Originally Posted by nubness View Post
Not for a server that is already online for some time, no.
I was checking the database tables and found PS_GameLog.dbo.Userlog where is shows every time a player logs in + how long he was online (if I am not wrong) itīs pasted as time such as: 2014-19-08 07:10 03:20 (where I think itīs for the Date - Clock - Online Time (3 minutes and 20 seconds) I donīt know I think it is wrong tho but there is a table for when a character logs on and when it logs out is the "LeaveDate" but that one gets updated every time a player re-logs...
08/19/2014 14:04 nubness#6
That table doesn't store the log out time from what I see in my database, which makes it useless for what you need.
08/19/2014 16:34 Penchod-Shaiya#7
Quote:
Originally Posted by nubness View Post
That table doesn't store the log out time from what I see in my database, which makes it useless for what you need.
Thank you Sir.

A small beside-request from me personally to you, could you make a tutorial on how to make a trigger for something?
Examples:
Trigger to hand out kills per Rank level and not per Kills.
Trigger to hand out DP once a player logs in once a day (daily login reward)

or something random, just the way of basics of a trigger ? - Tried google'ing but all I found was basic SQL useless stuff x.x

Thanks again :)
08/19/2014 18:01 nubness#8
A trigger is basically a query executed when something happens to a table.
There are 3 trigger types - INSERT, UPDATE, DELETE.

It looks something like this:
Code:
CREATE TRIGGER LeTrigger
ON Chars
AFTER UPDATE
AS IF UPDATE(K1)
BEGIN
-- the SQL code to execute
END
This will create a trigger which executes when the a cell of the K1 column from the Chars table is modified.

The easier way to create a trigger is by using the SQL Server Management Studio interface. Expand a table's options by clicking the + sign -> right click on Triggers -> New Trigger.

There are 2 important terms for triggers to keep in mind - inserted and deleted.

deleted represents the row before it was changed, whereas inserted represents the new row.

For example, for an UPDATE(K1) trigger:
Code:
DECLARE @OldK1 INT = (SELECT K1 FROM deleted) -- old value
DECLARE @NewK1 INT = (SELECT K1 FROM inserted) -- new value
That's pretty much the basics.

There's also some other aspects, such as INSTEAD OF, which are rather interesting. For example, INSTEAD OF INSERT will mean that the code in the BEGIN/END block will be executed INSTEAD OF an insert, rather than AFTER the insert.