#Capture the flag

1 messages · Page 1 of 1 (latest)

celest veldt
#

For this case you would probably have a game manager keep track of things rather than the flag or the player. That way you make a global notice that the flag has been taken or dropped. The trigger can fire an event that the manager is listening for. Triggers fire for both clients and server so you don't really need to send any messages over the network.

neat stratus
#

hm I see. so the game manager would keep track of the flags' booleans?

celest veldt
#

That's the way I would do it. You do have to take care that the game manager class doesn't get too bloated. You might want to split it off into its own ctf manager

neat stratus
#

I did just that, yeah

#

that being said I am quite dense when it comes to events and triggering them

#

should I just do CTFManager.Instance.Whatever() when inside OnTriggerEnter?

#

and then, in CTFManager, I do everything player-related?

celest veldt
#

I don't use singletons. The flag itself would have a static event like FlagTaken<Player>. Then on trigger would called FlagTaken.Invoke("Player that took the flag"). Ctf manager would be listening for all flag taken events then update UI and what not accordingly

neat stratus
#

I rearranged things, but the problem remains visually

#

everything is being detected just fine, but the client isn't seeing the flag on their backs as they should. one second

#

if blue touches his base flag the points get calculated as expected

#

in the CTFManager I'm doing

        player.hasFlag.Value = false;
        player.FlagUpdate();

which calls the player stats

public void FlagUpdate()
    {
        if(flagCarryObject != null) flagCarryObject.SetActive(hasFlag.Value);
        if(flagCarryEffects != null) flagCarryEffects.SetActive(hasFlag.Value);
    }
#

hasFlag is a network variable

public NetworkVariable<bool> hasFlag = new NetworkVariable<bool>();
#

with default permissions

#

hm actually scratch that, the points only update for the server as well

#

so it's the same problem in two places, basically

celest veldt
#

Are the points in a network variable?

neat stratus
#

will that help with only the server being able to track changes?

#

they are in the regular game manager, yeah

    NetworkVariable<int> T1Points = new NetworkVariable<int>
        (5, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
    NetworkVariable<int> T2Points = new NetworkVariable<int>
        (0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
#

don't mind that 5, it's for testing purposes

celest veldt
neat stratus
#

the UI changes just fine...server-side

#

seems like a sync issue

#

you can see the right window, the host, updates blue's points just fine

#

are you sure I'm not just missing a sync command of sorts that should be called when I want to update things network-wide?

neat stratus
#

could this be related?

celest veldt
# neat stratus could this be related?

Network Variables get updated automatically so no other commands are needed.
That is usually when you are updating a network variable in start or awake before the object has been spawned

neat stratus
#

it's getting called because of this line

if (joinTeam) { JoinPlayerTeam(tnum).Value += 1; }

which is triggered by the player spawning via OnNetworkSpawn

#

unfortunately commenting the code doesn't really fix anything so I guess that's not where the issue lies

#

here's the full OnTriggerEnter after changing things to CTFManager

    void OnTriggerEnter(Collider other)
    {
        PlayerStats player = other.GetComponent<PlayerStats>();
        if (player == null) return;
        if (IsServer)
        {
            if (!string.Equals(player.tag, tag) && !CTFManager.instance.IsFlagTaken(team.teamID) )
            {
                CTFManager.instance.TakeFlag(player);
            }
            else if(string.Equals(player.tag, tag) && CTFManager.instance.flagCarriers[team.teamID] == player)
            {
                CTFManager.instance.ReturnFlagFromPlayer(player);
                GameManager.instance.AddTeamPoints(team, 1);
            }
        }
    }
#

I'm still using singletons for now since they aren't the source of my problem

#

I think the problem stems from if (IsServer), but without that the game complains that the player doesn't have access to the variables trying to be changed

#

or at least something like that

#

any ideas? I'm drawing a complete blank

#

the project's pretty small if you want to take a look at it

celest veldt
#

Yea your network variables are server write only. I think probably is the Singleton. When the player connects it spawns any in scene network objects. This can cause duplicate Singletons and cause it to destroy the original and then you lose connection to the network variables

neat stratus
#

anything short of constantly updating the characters' meshes on FixedUpdate is coming up short

neat stratus
celest veldt
#

That or you can grab a reference of the Manager with FindObjectByType

neat stratus
#

nope

#

made the manager a regular game object, found by type on awake, tested

#

same error

#

so it's not a singleton issue

celest veldt
neat stratus
#

made sure it had the component

celest veldt
#

make sure the game manger is still getting the reference to the score roller masks. usually when they spawn in it can lose those scene references.

neat stratus
#

doesn't seem to be the case

celest veldt
neat stratus
#

client. also tested on the host