Reason for the "bug" looks simple enough (in ScoreBoardSB.uc):
Code: Select all
PlayerInfos.Columns[CColTime].Value = string(int((Level.TimeSeconds - PRI.StartTime) / Level.TimeDilation) + PlayerReplicationInfoSB(PRI).PreviousPlayedSeconds);
This part in particular (abbreviated for easier reading):
Level.TimeSeconds, which one would think this property would hold the total time the match has been running, is actually a property which appears to be variable across clients and server, it can contain different values so is not a good variable to use for calculating total playing time that will synchronize properly across clients.
StartTime on the other hand is a value that is assigned when client first connects to a map but for some reason stays the same even if they reconnect an hour later (as long as the map/match is still running). This creates an issue where the calculation would incorrectly show a player's time. Let's take an example of a player connecting to a match, they play for 5 seconds, then disconnect because they forgot to do something. And then an hour later...this player returns (3600 seconds later) and the same map is still running.
The formula would work as follows:
"Okay let's figure out how long this player has played for. First off, what's the current play time at right this second? 3625 seconds. (1h 25s). Okay Got it."
"And at what 'second time value' did that player join? At 5 seconds of map elapsed time? Oh okay then we just take the difference between now (3625 seconds) and the time they joined at (5 seconds). So this player has been playing for 3620 seconds easy!"
Except that would be wrong. The player has not even played a minute.
The following is a way to fix this issue, We simply need 1 variable to store the current elapsed time when the player first joins and then the elapsed time will increment with their played time. If the player reconnects then the variable is updated and the elapsed time continues to increment as normal from that new point. Now Barbie would also like the previous amount of time played to be added, this is doable but for now I wanted to get this negative time issue fixed if possible.
So, 3 files need to be updated:
1. MonsterHuntSB:
Code: Select all
//Using the PostLogin event in this file, when a player first joins, we are going to call an event we need to create called PlayerJoined in PlayerReplicationInfoSB UC file
if (PlayerReplicationInfoSB(NewPlayer.PlayerReplicationInfo) != None) {
PlayerReplicationInfoSB(NewPlayer.PlayerReplicationInfo).PlayerJoined();
}
2. PlayerReplicationInfoSB
Code: Select all
//Assign the current ElapsedTime to a variable which will update each time the player connects/reconnects, and we can now use it for calculating their total played time by referencing the current elapsed time of the match.
event PlayerJoined() {
LastConnectedTime=Level.Game.GameReplicationInfo.ElapsedTime;
}
3. ScoreBoardSB
Code: Select all
//Use the map's current elapsed time and subtract the value of time in seconds of when the player joined (LastConnectedTime). That variable, again, will be updated when player reconnects.
PlayerInfos.Columns[CColTime].Value = string(GRI_SB.ElapsedTime - PlayerReplicationInfoSB(PRI).LastConnectedTime + PlayerReplicationInfoSB(PRI).PreviousPlayedSeconds);
There are of course a few extra declarations that need to be included in 2 of the files so I'm attaching the 3 files I mentioned and I've marked the lines I added and "commented out" using the following.
and...
Now, the only drawback with using ElapsedTime that I can see is that ElapsedTime begins as soon as the map is loaded but if no one clicks in to start the match then TECHNICALLY I imagine that running time should NOT count towards the player's total play time.
So you could have a scenario where the map changes, a player is reconnected to the new map and then they don't click in for a few minutes. So now the player's play time will still be calculated since the map first loaded not when the actual match started (which is actually a variable called PlayedTime, but it resets upon reconnect!). Anyway, I think this isn't that big of a deal since most maps are started within a few seconds of being able to click in, a few seconds or even a minute or two shouldn't make much of a difference. But there is a way to fix this I think if Barbie really wanted it to be more accurate.
I'm QUITE new to UScript coding so there may be some slight change that could be made of course. Long post, lol!