SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 06/01/2018, 03:59 PM   #1
dicknyson
Banned
 
Join Date: Feb 2016
Location: 𝕪𝕠𝕦𝕥𝕦𝕓𝕖
Posts: 56
Reputation: 5
Default Saving online time with a MySQL event

I was just about to create a timer to update all online players' online time in a MySQL table every 5 minutes, but then I thought... would a MySQL event be better? Something like:

Code:
CREATE EVENT update_time ON SCHEDULE EVERY 1 SECOND DO
  UPDATE users SET onlinetime = onlinetime + 1 WHERE online = 1;
Or to decrease the amount of load, even:
Code:
CREATE EVENT update_time ON SCHEDULE EVERY 60 SECOND DO
  UPDATE users SET onlinetime = onlinetime + 60 WHERE online = 1;
Would it be slow/inefficient for MySQL to search through potentially thousands of rows for online players?

Or perhaps I could have a separate table that adds a row for users when they come online in-game, and deletes the row when they disconnect, and have the event update if their ID exists in that table? What do you think?

Edit: obviously, when a player disconnects their online time will be saved from the gamemode.
dicknyson is offline   Reply With Quote
Old 06/01/2018, 04:30 PM   #2
iLearner
Gangsta
 
iLearner's Avatar
 
Join Date: Apr 2017
Posts: 631
Reputation: 124
Default Re: Saving online time with a MySQL event

Do it within pawn, and save it when player leaves the server.
iLearner is offline   Reply With Quote
Old 07/01/2018, 12:56 AM   #3
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,499
Reputation: 439
Default Re: Saving online time with a MySQL event

Do you need the amount of time through MySQL, out of the game server?
Abagail is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
A little help in saving and loading time with MySQL. AroseKhanNiazi Scripting Help 10 25/06/2016 03:15 PM
Saving Date & Time MYSQL aa Scripting Help 2 16/02/2015 01:43 AM
Problem with saving the players total online time! sniperwars Scripting Help 4 20/08/2012 12:54 AM
[Help] Saving Character online time. Mowgli Help Archive 5 01/09/2009 07:21 AM


All times are GMT. The time now is 12:20 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.