Jump to content

Looking to use this, but need Playtime Rewards instead of Playtime Tracker

Pending 2.2.6

Jackelmyer
Jackelmyer

Posted

Playtime Tracker hasn't seemed to have been updated for a while.  Playtime Rewards is the same thing, but a bit easier to use (no extra permissions and such).  However Playtime Rewards needed a fix for API calls when other plugins referenced it.

 

I've informed Playtime Rewards the change that's required.  However for the time being, support for Playtime Rewards could be reached with a minor tweak to PlayTimeRewards,.cs and it's all the exact same API as Playtime Tracker.  Hoping the plugin author will fix it but for the time being, if you could include support for Playtime Rewards, making the slight tweak to the plugin as noted below it'd be a big help!  

Playtime Rewards fix noted on the UMod help page below.

API Methods Not Working

Jackelmyer

Posted

I've gone ahead and edited version 2.2.6 on my own and made the following changes to make it all work.  Note the API methods Not Working link in my OP is needed to be changed as well.

Note:  There seems to be an older issue in code where the latest amount of time played is only refreshed when player data is saved or player is connecting.  Does not refresh when the Player Ranks UI is displayed.  Minor issue, thought I'd note it though.  For what I have currently edited, I just added a call to "UpdatePlayer(player);" in the CmtTarget after the "HasPerm(player)" check succeeds and before the if statement to load which UI.  Showing the code change below as well.

 

  • Added plugin reference
    • Plugin Clans, Friends, EventManager, PlaytimeTracker, PlayTimeRewards, Economics, ServerRewards;
  • Added Lang for PlayTimeRewards not being installed.
    • {"noPTW", "PlayTime Rewards is not installed and will not be used." },
  • Updated "UpdateOfflinePlayer" and "UpdatePlayer" methods to what's shown below.

        public void UpdateOfflinePlayer(ulong userID)
        {
            var path = data.PlayerRankData[userID];
            bool gotClan = (Clans?.CallHook("GetClanOf", userID) != null);
            double time = 0;
            if (PlayTimeRewards)
            {
                time = Convert.ToDouble(PlayTimeRewards?.Call("FetchPlayTime", userID.ToString()));
            }
            else if (PlaytimeTracker)
            {
                time = Convert.ToDouble(PlaytimeTracker?.Call("GetPlayTime", userID.ToString()));
            }
            path["Status"] = "offline";
            path["Economics"] = Economics ? Economics?.Call("Balance", userID) : path["Economics"];
            path["ServerRewards"] = ServerRewards ? ServerRewards?.Call("CheckPoints", userID) : path["ServerRewards"];
            path["Clan"] = gotClan ? (string)Clans?.CallHook("GetClanOf", userID) : "None";
            path["TimePlayed"] = (time == null) ? "0" : time.ToString();
        }

        public void UpdatePlayer(BasePlayer player)
        {
            var path = data.PlayerRankData[player.userID];
            var clan = Clans?.CallHook("GetClanOf", player.userID);
            double time = 0;
            if (PlayTimeRewards)
            {
                time = Convert.ToDouble(PlayTimeRewards.Call("FetchPlayTime", player.UserIDString));
            }
            else if (PlaytimeTracker)
            {
                time = Convert.ToDouble(PlaytimeTracker?.Call("GetPlayTime", player.UserIDString));
            }
            path["UserID"] = player.userID;
            path["Admin"] = IsAuth(player);
            path["Changed"] = true;
            path["Name"] = CleanString(player.displayName, "");
            path["Status"] = "online";
            path["ActiveDate"] = DateTime.UtcNow;
            path["Economics"] = Economics ? Economics?.Call("Balance", player.userID) : path["Economics"];
            path["ServerRewards"] = ServerRewards ? ServerRewards?.Call("CheckPoints", player.userID) : path["ServerRewards"];
            path["Clan"] = clan != null ? (string)clan : "None";
            path["TimePlayed"] = (time == null) ? "0" : time.ToString();
            path["OptOut"] = HasPermission(player.UserIDString, permOptOut);
        }

 

 

 

 

Extra Code Change to refresh Time Played when UI is displayed, change in bold.:

        [ChatCommand("pr")]
        void CmdTarget(BasePlayer player, string command, string[] args)
        {
            if (player == null)
                return;

            if (args == null || args.Length == 0)
            {
                if (HasPerm(player))
                {
                    UpdatePlayer(player);
                    if (conf.Options.CommandOpensTop30)
                        CallTopThirty(player, "false", false, 1, "false", true, "false");
                    else if (conf.Options.CommandOpensTop1)
                        CallTopOne(player, "false", false);
                    else
                        CallPersonalStatsUI(player, "true", false);
                }
                return;
            }

guvk

Posted

Although you're right in that Playtime Tracker hasn't been updated in quite some time, with v0.2.2 over 2 years old, I did notice several reports in the support threads that a complete unload/uninstall/thorough deletion if associated files/configs/directories followed by a proper re-compile did work for several. Trying it myself soon and will report findings.

 

1.4m

Downloads

Total number of downloads.

6.9k

Customers

Total customers served.

102.2k

Files Sold

Total number of files sold.

2m

Payments Processed

Total payments processed.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.