Skip to content

Conversation

9zku
Copy link

@9zku 9zku commented Jul 13, 2025

Description

This pull request adds a /setplaytime command that allows admins to set a players playtime that's stored.


Motivation

Some of the server's I develop, they have playtime scripts which control what the players can do, Example; You can't use weapons without 24 hours of playtime. And there is times where they need to set a players playtime for whatever reasons.


Implementation Details

This Implements /setplaytime [playerId] [hours] for admins to manually set a player's total playtime. The new value is saved immediately.

Usage Example

local serverId = 1 

local xPlayer = ESX.GetPlayerFromId(serverId)

if xPlayer then
    -- Set the player's playtime to 50 hours (converted to seconds)
    xPlayer.setPlayTime(50 * 3600)
end

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

@github-project-automation github-project-automation bot moved this to 🆕 To be Discussed in ESX Roadmap Jul 13, 2025
@9zku
Copy link
Author

9zku commented Jul 13, 2025

I can understand if this is seemed useless for most server's or not what ESX had intended playtime to be for, so if this PR gets denied thats understandable. Just thought I'd try to contribute something that I use quite often.

@iSentrie
Copy link
Contributor

it would be better to support s, m, h, and d indicators (for seconds, minutes, hours, and days) instead of forcing everything to hours

@9zku
Copy link
Author

9zku commented Jul 18, 2025

I can edit the pr later today for you guy's.

@Kenshiin13
Copy link
Contributor

@rk3gaming any news?

@9zku
Copy link
Author

9zku commented Jul 26, 2025

My fault, have been busy irl. I'll work on it tonight

@9zku
Copy link
Author

9zku commented Jul 26, 2025

Sorry for the wait. Here you go 9zku@b8cdca8

@feelfreetofee
Copy link
Contributor

feelfreetofee commented Jul 27, 2025

[core]/es_extended/locales/en.lua


[core]/es_extended/server/classes/player.lua

  • lastPlaytime stores the player’s playtime before joining the current session.

  • getPlayTime() returns lastPlaytime + GetPlayerTimeOnline(self.source).

For consistency, consider subtracting the current session time:

playtime = ESX.Math.Round(playtime) - GetPlayerTimeOnline(self.source)
if playtime < 0 then
    playtime = 0
end
  • Metadata update is likely redundant since it's already handled periodically by the server.

I’d remove that line altogether. But if kept, use the value returned by getter instead.


[core]/es_extended/server/modules/commands.lua

["day"] = "day",
["days"] = "days",
["number_day"] = "%d day",
["number_days"] = "%d days",
["hour"] = "hour",
["hours"] = "hours",
["number_hour"] = "%d hour",
["number_hours"] = "%d hours",
["minute"] = "minute",
["minutes"] = "minutes",
["number_minute"] = "%d minute",
["number_minutes"] = "%d minutes",
["second"] = "second",
["seconds"] = "seconds",
["number_second"] = "%d second",
["number_seconds"] = "%d seconds",

Localized time string:

local timeString = {}
if days > 0 then
    table.insert(
        timeString,
        TranslateCap(
            days == 1
            and 'number_day'
            or 'number_days',
            days
        )
    )
end
if hours > 0 then
    table.insert(
        timeString,
        TranslateCap(
            hours == 1
            and 'number_hour'
            or 'number_hours',
            hours
        )
    )
end
if minutes > 0 then
    table.insert(
        timeString,
        TranslateCap(
            minutes == 1
            and 'number_minute'
            or 'number_minutes',
            minutes
        )
    )
end
if seconds > 0 then
    table.insert(
        timeString,
        TranslateCap(
            seconds == 1
            and 'number_second'
            or 'number_seconds',
            seconds
        )
    )
end
timeString = table.concat(timeString, ', ')

Localized suggestions:

{name = "days", help = TranslateCap("days"), type = "number"},
{name = "hours", help = TranslateCap("hours"), type = "number"},
{name = "minutes", help = TranslateCap("minutes"), type = "number"},
{name = "seconds", help = TranslateCap("seconds"), type = "number"},

Also consider localizing notifications

@Kenshiin13 Kenshiin13 changed the base branch from main to dev July 27, 2025 16:31
@Kenshiin13
Copy link
Contributor

@9zku

Copy link
Contributor

@Kenshiin13 Kenshiin13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check @feelfreetofee's review

@github-project-automation github-project-automation bot moved this from 🆕 To be Discussed to In-Development in ESX Roadmap Aug 4, 2025
@9zku
Copy link
Author

9zku commented Aug 5, 2025

out traveling.

@Kenshiin13 Kenshiin13 marked this pull request as draft August 11, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In-Development
Development

Successfully merging this pull request may close these issues.

4 participants