Example #1
0
    private void _cratePlayer(int netId, Team.TeamCode team, String unitName, String displayName)
    {
        String playerId = _agentPlayerPrefix + netId;

        // Already generated
        if (spawnPlayers.ContainsKey(playerId))
        {
            return;
        }

        // If observer is setup, clean it up
        if (HasNode(_agentObserverPrefix + observerCounter))
        {
            GetNode(_agentObserverPrefix + observerCounter).QueueFree();
            observerCounter++;
        }

        // Load the scene and create an instance
        Player agent = (Player)(TeamMapAIs[(int)team].CreateUnit(unitName, displayName, false));

        // If this actor does not belong to the server, change the network master accordingly
        if (netId != 1)
        {
            agent.SetNetworkMaster(netId);
        }



        // If this actor is the current client controlled, add camera and attach HUD
        if (netId == network.gamestateNetworkPlayer.net_id)
        {
            // Attach camera
            agent.SetHUD(_hud, _inventoryManager);
            agent.SetCameraRemotePath(_camera2D);

            // Set player marker
            _miniMap.SetPlayer(agent);
        }
        else
        {
            // Add as normal agent marker
            _miniMap.AddAgent(agent);
        }

        spawnPlayers.Add(playerId, agent);
        EmitSignal(nameof(PlayerCreateSignal));
    }