Skip to content

Commit

Permalink
Fixing Flags not updating
Browse files Browse the repository at this point in the history
Adding player:SetSharedVar("Flags", player:GetFlags()); to the end of both functions: 

function Clockwork:PlayerFlagsGiven(player, flags) & function Clockwork:PlayerFlagsTaken(player, flags)

This fixes the issue of flags not updating. Originally, the character would have to be reloaded to see updated flags. This fixes that.
  • Loading branch information
Nightmare-Night authored and sanny committed Jul 12, 2018
1 parent e89e517 commit 2b40cc1
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ function Clockwork:PlayerFlagsGiven(player, flags)
if (string.find(flags, "t") and player:Alive()) then
cwPly:GiveSpawnWeapon(player, "gmod_tool");
end;
player:SetSharedVar("Flags", player:GetFlags());
end;
--[[
Expand All @@ -780,6 +782,8 @@ function Clockwork:PlayerFlagsTaken(player, flags)
cwPly:TakeSpawnWeapon(player, "gmod_tool");
end;
end;
player:SetSharedVar("Flags", player:GetFlags());
end;
--[[
Expand Down

3 comments on commit 2b40cc1

@kurozael
Copy link
Member

@kurozael kurozael commented on 2b40cc1 Jul 13, 2018

Choose a reason for hiding this comment

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

This shouldn't be done in the hook callback, though. It should really be done in the Clockwork.player.GiveFlags and Clockwork.player.TakeFlags methods, but actually SetCharacterData("Flags", ...) in those methods does automatically call SetSharedVar because it's called by SetCharacterData internally as "Flags" is already added with AddCharacterData in sh_boot.lua (and networked that way.)

So this will cause SetSharedVar to be called twice, the actual bug is that SetCharacterData doesn't appear to be calling SetSharedVar...

My other concern is that global flags (GivePlayerFlag) doesn't seem to get networked at all, so there's no way to know client-side what global flags you have?

Can I confirm that prior to this bug fix, you were using and connected to the latest CAX for CW 0.98 as that will contain the latest versions of the Clockwork.player.UpdateCharacterData method.

@sannysc @Nightmare-Night @xRJx

@Nightmare-Night
Copy link

Choose a reason for hiding this comment

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

As far as I was concerned at the time, and as I've explained before, the only issue I ran into was that the character data would only update upon reloading the character. (Switching my character then going back to the previous character) Whatever is the issue, or whatever is missing, it was causing it not to update in-real-time.

I edited as per each time either a character is given or gets a flag taken from them, it refreshes and grabs the flags for that player. After I added the two lines, I haven't had any issue of flags becoming corrupt, or any sort of loop, or the flags being carried over globally as I never checked plygiveflags function.

And I can confirm that prior to this bug fix, I was using the most recent CAX and have been connected. Basically, took whatever was available a few days before I made this pull request, and threw in this fix and it fixed the problem I was having with flags updating.

Bare with me if I misinterpreted anything you may of said, as this is my first pull request for clockwork.

@kurozael

@kurozael
Copy link
Member

@kurozael kurozael commented on 2b40cc1 Jul 17, 2018

Choose a reason for hiding this comment

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

If you're able to move to these calls into the actual Clockwork.player.GiveFlags and Clockwork.player.TakeFlags methods instead of the hooks that'd be okay for now until I can investigate why UpdateCharacterData isn't automatically setting the shareds vars itself.

Another thing you could investigate is whether or not "Player Flags". which are the global equivalent of "Character Flags", are ever networked.

I can merge in any additional pull-requests when that's resolved. I'd simply go ahead and make the setting of the shared vars happen at the end of the GiveFlags/TakeFlags methods because the gamemode hooks may never be called if a plugin returns out a value before it reaches them.

@sannysc @Nightmare-Night @xRJx

Please sign in to comment.