/// <summary>
        /// Tell the plugin we have a new call partner
        /// </summary>
        /// <param name="args">args[0] - handle | args[1] - bool | args[2] - string[]</param>
        private static void OnEstablishCallRelayed(object[] args)
        {
            ushort handle = Convert.ToUInt16(args[0]);
            bool   direct = (bool)args[1];

            string[] relays = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>((string)args[2]);

            Player player = Entities.Players.GetAtRemote(handle);

            if (player == null || !VoiceManager.TryGetVoiceClient(handle, out VoiceClient voiceClient))
            {
                return;
            }

            RAGE.Vector3 ownPosition    = RAGE.Elements.Player.LocalPlayer.Position;
            RAGE.Vector3 playerPosition = player.Position;

            VoiceManager.ExecuteCommand(
                new PluginCommand(
                    Command.PhoneCommunicationUpdate,
                    VoiceManager.ServerUniqueIdentifier,
                    new PhoneCommunication(
                        voiceClient.TeamSpeakName,
                        RAGE.Game.Zone.GetZoneScumminess(RAGE.Game.Zone.GetZoneAtCoords(ownPosition.X, ownPosition.Y, ownPosition.Z)) +
                        RAGE.Game.Zone.GetZoneScumminess(RAGE.Game.Zone.GetZoneAtCoords(playerPosition.X, playerPosition.Y, playerPosition.Z)),
                        direct,
                        relays
                        )
                    )
                );
        }
        /// <summary>
        /// Sends the plugin an update on all players
        /// </summary>
        private static void PlayerStateUpdate()
        {
            RAGE.Vector3 playerPosition = Player.LocalPlayer.Position;

            foreach (var voiceClient in VoiceManager.VoiceClients)
            {
                RAGE.Vector3 nPlayerPosition = voiceClient.Player.Position;

                VoiceManager.ExecuteCommand(
                    new PluginCommand(
                        Command.PlayerStateUpdate,
                        VoiceManager.ServerUniqueIdentifier,
                        new PlayerState(
                            voiceClient.TeamSpeakName,
                            nPlayerPosition,
                            voiceClient.VoiceRange,
                            voiceClient.IsAlive
                            )
                        )
                    );
            }

            VoiceManager.ExecuteCommand(
                new PluginCommand(
                    Command.SelfStateUpdate,
                    VoiceManager.ServerUniqueIdentifier,
                    new PlayerState(
                        playerPosition,
                        RAGE.Game.Cam.GetGameplayCamRot(0).Z
                        )
                    )
                );
        }
Example #3
0
 /// <summary>
 /// Used for <see cref="Command.PlayerStateUpdate"/>
 /// </summary>
 /// <param name="name"></param>
 /// <param name="position"></param>
 /// <param name="voiceRange"></param>
 /// <param name="isAlive"></param>
 public PlayerState(string name, RAGE.Vector3 position, float voiceRange, bool isAlive)
 {
     this.Name       = name;
     this.Position   = new TSVector(position); // Needs to be converted to "SaltyChat.TSVector" due to a bug - client will crash if "RAGE.Vector3" will be serialized with "Newtonsoft.Json.Linq.JObject.FromObject()"
     this.VoiceRange = voiceRange;
     this.IsAlive    = isAlive;
 }
Example #4
0
        public static Vector3 GetPosInFrontOfPlayer(Player myPlayer, float range)
        {
            var forwardX = myPlayer.Position.X + myPlayer.GetForwardX() * range;
            var forwardY = myPlayer.Position.Y + myPlayer.GetForwardY() * range;
            var pos      = new Vector3(forwardX, forwardY, myPlayer.Position.Z + 0.5f);

            return(pos);
        }
Example #5
0
        public static Vector3 GetPosInFrontOfVector3(Vector3 pos, float heading, float range)
        {
            var newPos = new Vector3(pos.X, pos.Y, pos.Z);

            newPos.X += range * (float)Math.Sin(-heading * Math.PI / 180.0);
            newPos.Y += range * (float)Math.Cos(-heading * Math.PI / 180.0);
            return(newPos);
        }
Example #6
0
 public void SetPos(Vector3 pos, Vector3 lookAt, bool setActive = false)
 {
     RAGE.Game.Cam.SetCamCoord(CameraID, pos.X, pos.Y, pos.Z);
     RAGE.Game.Cam.PointCamAtCoord(CameraID, lookAt.X, lookAt.Y, lookAt.Z);
     if (setActive)
     {
         SetActive(true);
     }
 }
Example #7
0
        private static void CalculateProximityVoice()
        {
            RAGE.Vector3 lPlayerPosition    = RAGE.Elements.Player.LocalPlayer.Position;
            RAGE.Vector3 lPlayerCamPosition = RAGE.Game.Cam.GetGameplayCamRot(0);
            double       camRotation        = Math.PI / 180 * (lPlayerCamPosition.Z * -1);

            Voice.ExecuteCommand("keepalive");

            foreach (var nPlayer in RAGE.Elements.Entities.Players.All)
            {
                if (nPlayer == RAGE.Elements.Player.LocalPlayer ||
                    !nPlayer.TryGetSharedData(SaltyShared.SharedData.Voice_TeamSpeakName, out string nPlayerName))
                {
                    continue;
                }

                if (!nPlayer.TryGetSharedData(SaltyShared.SharedData.Voice_VoiceRange, out float nPlayerVoiceRange))
                {
                    nPlayerVoiceRange = Voice.VolumeLevels[2];
                }

                RAGE.Vector3 nPlayerPosition  = nPlayer.Position;
                float        distanceToPlayer = RAGE.Game.Utils.Vdist(lPlayerPosition.X, lPlayerPosition.Y, lPlayerPosition.Z, nPlayerPosition.X, nPlayerPosition.Y, nPlayerPosition.Z);

                if (distanceToPlayer <= nPlayerVoiceRange)
                {
                    if (!Voice._playersInRange.Contains(nPlayerName))
                    {
                        Voice._playersInRange.Add(nPlayerName);
                        Voice.ExecuteCommand("inRange", nPlayerName);
                    }

                    RAGE.Vector3 subtractedPosition = new RAGE.Vector3(nPlayerPosition.X - lPlayerPosition.X, nPlayerPosition.Y - lPlayerPosition.Y, nPlayerPosition.Z - lPlayerPosition.Z);

                    double x = (subtractedPosition.X * Math.Cos(camRotation) - subtractedPosition.Y * Math.Sin(camRotation)) * 10 / nPlayerVoiceRange;
                    double y = (subtractedPosition.X * Math.Sin(camRotation) + subtractedPosition.Y * Math.Cos(camRotation)) * 10 / nPlayerVoiceRange;

                    Voice.ExecuteCommand("updatePosition", nPlayerName, Math.Round(x * 1000) / 1000, Math.Round(y * 1000) / 1000, 0);
                }
                else if (_playersInRange.Contains(nPlayerName))
                {
                    Voice._playersInRange.Remove(nPlayerName);
                    Voice.ExecuteCommand("outRange", nPlayerName);
                }
            }
        }
Example #8
0
 public TSVector(RAGE.Vector3 position)
 {
     this.X = position.X;
     this.Y = position.Y;
     this.Z = position.Z;
 }
Example #9
0
 /// <summary>
 /// Used for <see cref="Command.SelfStateUpdate"/>
 /// </summary>
 /// <param name="position"></param>
 /// <param name="rotation"></param>
 public PlayerState(RAGE.Vector3 position, float rotation)
 {
     this.Position = new TSVector(position); // Needs to be converted to "SaltyChat.TSVector" due to a bug - client will crash if "RAGE.Vector3" will be serialized with "Newtonsoft.Json.Linq.JObject.FromObject()"
     this.Rotation = rotation;
 }