Esempio n. 1
0
        private async Task OnConsoleCommand(string name, string[] args)
        {
            // destroy all objects
            if (name == "dao")
            {
                ObjectStreamer.DestroyAllDynamicObjects( );
                Console.WriteLine($"all objects destroyed.");
            }

            // create all objects
            if (name == "cao")
            {
                ObjectStreamer.DestroyAllDynamicObjects( );
                CreateObjects( );
            }

            // destroy object
            if (name == "do")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                if (ObjectStreamer.DestroyDynamicObject(objId))
                {
                    Console.WriteLine($"Object with ID { objId } deleted!");
                }
            }

            // change rotation
            if (name == "cr")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    Vector3 rot = obj.Rotation;
                    obj.Rotation = new Vector3(rot.X, rot.Y, rot.Z + 5f);
                    Console.WriteLine($"Object rotation increased on Z with +5f");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change visible
            if (name == "cv")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    obj.Visible = !obj.Visible;
                    Console.WriteLine($"Object visibility set to { obj.Visible }");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change lod distance
            if (name == "cld")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    obj.LodDistance += 100;
                    Console.WriteLine($"Object LOD Dist increased by 100");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change texture variation
            if (name == "ctv")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    var variations = Enum.GetValues(typeof(TextureVariation));

                    obj.TextureVariation = ( TextureVariation )variations.GetValue(new Random( ).Next(variations.Length));
                    Console.WriteLine($"Object texture variation changed to a random variation");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change dynamic
            if (name == "cd")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    obj.Dynamic = !obj.Dynamic;
                    Console.WriteLine($"Object dynamic changed to: { obj.Dynamic }");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change on fire(EXPERIMENTAL, DOESNT WORK VERY WELL AS OF RIGHT NOW!)
            if (name == "cof")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    obj.OnFire = !obj.OnFire;
                    Console.WriteLine($"Object on fire changed to: { obj.OnFire }");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change frozen
            if (name == "cf")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    obj.Frozen = !obj.Frozen;
                    Console.WriteLine($"Object frozen changed to: { obj.Frozen }");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change light color
            if (name == "clc")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    Random r = new Random( );
                    obj.LightColor = new Rgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
                    Console.WriteLine($"Object lightcolor changed to random value");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change model
            if (name == "cm")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    // change object into a house
                    obj.Model = "lf_house_17_";
                    Console.WriteLine($"Object changed into a house.");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // change pos
            if (name == "cp")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    Console.WriteLine($"obj pos: { obj.Position.Z }");

                    obj.Position += new Vector3(0, 0, 5);
                    Console.WriteLine($"Object position increased on Z with +5f { obj.Position.Z }");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // get object by ID
            if (name == "go")
            {
                if (args.Length == 0)
                {
                    return;
                }

                ulong objId = Convert.ToUInt64(args[0]);
                var   obj   = ObjectStreamer.GetDynamicObject(objId);
                if (obj != null)
                {
                    Console.WriteLine($"Object found, data: { obj.Model }, { obj.Rotation.X }, { obj.Rotation.Y }, { obj.Rotation.Z }, { obj.Frozen }, ...!");
                }
                else
                {
                    Console.WriteLine($"Couldnt find object with ID { objId }");
                }
            }

            // get closest object
            if (name == "gc")
            {
                IPlayer player = Alt.GetAllPlayers( ).First( );

                if (player != null)
                {
                    (DynamicObject obj, float distance) = ObjectStreamer.GetClosestDynamicObject(player.Position);

                    if (obj == null)
                    {
                        Console.WriteLine("Couldn't find any object near player.");
                        return;
                    }

                    Console.WriteLine($"Closest object ID is { obj.Id } at a distance of { distance }.");
                }
                else
                {
                    Console.WriteLine($"Couldnt find any players.");
                }
            }

            // count objects
            if (name == "countobj")
            {
                Console.WriteLine($"total objects created: { ObjectStreamer.GetAllDynamicObjects( ).Count }");
            }
        }
Esempio n. 2
0
 public override void OnStop( )
 {
     ObjectStreamer.DestroyAllDynamicObjects( );
     Console.WriteLine($"Server stopped.");
 }