Ejemplo n.º 1
0
        public static void DestroyPed(ulong Id)
        {
            Ped?Ped = Ped.GetByID(Id);

            if (Ped == null)
            {
                return;
            }

            Ped.Destroy();
        }
Ejemplo n.º 2
0
        public static void SetPedData(ulong Id, string Key, object Value)
        {
            Ped?Ped = Ped.GetByID(Id);

            if (Ped == null || Ped.GetType().GetProperty(Key) == null)
            {
                return;
            }

            Ped.GetType().GetProperty(Key).SetValue(Ped, Value);
        }
Ejemplo n.º 3
0
        public static object?GetPedData(ulong Id, string Key)
        {
            Ped?Ped = Ped.GetByID(Id);

            if (Ped == null || Ped.GetType().GetProperty(Key) == null)
            {
                return(null);
            }

            return(Ped.GetType().GetProperty(Key).GetValue(Ped));
        }
Ejemplo n.º 4
0
        public static void ContinueWandering(ulong Id)
        {
            Ped?Ped = Ped.GetByID(Id);

            if (Ped == null)
            {
                return;
            }

            Ped.ContinueWandering();
        }
Ejemplo n.º 5
0
        public static void StartWandering(ulong Id)
        {
            Ped?Ped = Ped.GetByID(Id);

            if (Ped == null)
            {
                return;
            }

            Ped.Wandering = true;
        }
Ejemplo n.º 6
0
        /**
         * Event which is fired on the time the first netOwner of a ped created the ped and decided
         * the 'look' of the ped.
         */
        public static void OnFirstSpawn(IPlayer Player, Dictionary <string, string> PedClient)
        {
            if (!PedClient.TryGetValue("id", out string?idStr))
            {
                return;
            }

            ulong id = (ulong)int.Parse(idStr);

            Ped?ped = Ped.GetByID(id);

            if (ped == null)
            {
                return;
            }

            //Alt.EmitAllClients("pedSyncer:server:update", ped);
        }
Ejemplo n.º 7
0
        /**
         * Event which fires if a ped was streamed out of a player
         *
         * Determine the new netOwner or start the serverside ped movement calculcation
         */
        public static void OnEntityRemove(IClient client, AltV.Net.EntitySync.IEntity entity)
        {
            if (entity.Type != Ped.PED_TYPE)
            {
                return;
            }

            Ped?ped = Ped.GetByID(entity.Id);

            if (ped == null)
            {
                return;
            }

            HashSet <IClient> PedStreamedToClients = ped.GetClients();

            //No other players got the ped streamed in: Start serverside ped movement calculation
            if (PedStreamedToClients.Count == 1)
            {
                ped.NetOwner = null;
                PedMovement.GetInstance().AddPedMovementCalculcation(ped);
            }
            //An other player got the ped streamed in, set him as the new netOwner
            else
            {
                IClient[] pNewClients = PedStreamedToClients.ToArray <IClient>();

                //Determine the first valid player
                foreach (IClient pNewClient in pNewClients)
                {
                    IPlayer pNewPlayer = ((PlayerClient)pNewClient).GetPlayer();

                    if (pNewPlayer.Exists && (ped.NetOwner == null || pNewPlayer.Id != ((PlayerClient)ped.NetOwner).GetPlayer().Id))
                    {
                        ped.NetOwner = pNewClient;
                        return;
                    }
                }

                //No valid player found, start serverside ped movement calculation
                ped.NetOwner = null;
                PedMovement.GetInstance().AddPedMovementCalculcation(ped);
            }
        }
Ejemplo n.º 8
0
        public static void OnTaskUpdate(IPlayer Player, ulong PedId, string TaskString, string[] TaskParams)
        {
            Ped?Ped = Ped.GetByID(PedId);

            if (Ped == null)
            {
                return;
            }

            if (Ped.NetOwner != null && ((PlayerClient)Ped.NetOwner).GetPlayer().Id != Player.Id)
            {
                return;
            }

            bool ParamCheck = false;

            if (TaskParams.Length != Ped.TaskParams.Count)
            {
                ParamCheck = true;
            }
            else
            {
                for (int i = 0; i < TaskParams.Length; i++)
                {
                    if (TaskParams[i] != Ped.TaskParams[i])
                    {
                        ParamCheck = true;
                        break;
                    }
                }
            }


            if (Ped.Task != TaskString || ParamCheck)
            {
                Ped.TaskParams = TaskParams.ToList <string>();
                Ped.Task       = TaskString;
            }
        }
Ejemplo n.º 9
0
        public static bool IsPedIdExisting(ulong Id)
        {
            Ped?Ped = Ped.GetByID(Id);

            return(Ped != null);
        }
Ejemplo n.º 10
0
        /**
         * Event which is fired on the sending of the current positions and other states of
         * the peds by their netOwner. This event will be fired very, very often.
         */
        public static void OnPositionUpdate(IPlayer Player, string PedClientArrayJSON)
        {
            List <Dictionary <string, object> > PedClientArray = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(PedClientArrayJSON);

            if (PedClientArray.Count == 0)
            {
                return;
            }

            //Process all sended peds
            foreach (Dictionary <string, object> PedClient in PedClientArray)
            {
                if (!PedClient.TryGetValue("id", out object?idStr))
                {
                    continue;
                }

                ulong Id = (ulong)IntegerType.FromObject(idStr);

                //Get the ped which should be updated
                Ped?ped = Ped.GetByID(Id);

                if (ped == null)
                {
                    return;
                }

                //Update position
                if (PedClient.TryGetValue("pos", out object?posObj) && (string)posObj != "{null}")
                {
                    try
                    {
                        ped.Position = JsonConvert.DeserializeObject <Vector3>((string)posObj);
                    } catch (Exception ex)
                    {
                        Console.WriteLine("Wrong JSON: " + (string)posObj);
                    }
                }

                //Update heading
                if (PedClient.TryGetValue("heading", out object?headingObj))
                {
                    ped.Heading = Convert.ToDouble(headingObj);
                }

                //Update nearFinalPosition state
                if (PedClient.TryGetValue("nearFinalPosition", out object?nearFinalObject))
                {
                    bool nearFinal = (bool)nearFinalObject;
                    if (nearFinal && !ped.NearFinalPosition)
                    {
                        ped.NearFinalPosition = true;
                        ped.ContinueWandering();
                    }
                }

                //Update armour
                if (PedClient.TryGetValue("armour", out object?armourObj))
                {
                    ped.Armour = Convert.ToInt32(armourObj);
                }

                //Update health
                if (PedClient.TryGetValue("health", out object?healthObj))
                {
                    ped.Health = Convert.ToInt32(healthObj);
                }

                //Update dead
                if (PedClient.TryGetValue("dead", out object?deadObj))
                {
                    ped.Dead = Convert.ToBoolean(deadObj);
                }

                //Set Ped flags

                /*if (PedClient.TryGetValue("flags", out object[] flagsObj))
                 * {
                 *  List<bool> flagsBool = new List<bool>();
                 *  foreach(object flag in flagsObj)
                 *  {
                 *      flagsBool.Add(Convert.ToBoolean(flag));
                 *  }
                 *  ped.SetFlags(flagsBool.ToArray());
                 * }*/
            }
        }