Ejemplo n.º 1
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            Console.WriteLine("The game mode has loaded.");
            AddPlayerClass(0, Vector3.Zero, 0);

            var sampleVehicle = BaseVehicle.Create(VehicleModelType.Alpha, Vector3.One * 10, 0, -1, -1);

            Console.WriteLine("Spawned sample vehicle " + sampleVehicle.Model);

            var cfg = new ServerConfig(Path.Combine(Client.ServerPath, "server.cfg"));

            foreach (var kv in cfg)
            {
                Console.WriteLine(kv.Key + " " + kv.Value);
            }

            var values = Enum.GetValues(typeof(Weapon)).OfType <Weapon>().ToList();

            foreach (Weapon weapon in values.TakeLast(10))
            {
                Console.WriteLine($"{weapon}({(int)weapon}) :: {Server.GetWeaponName(weapon)}");
            }
        }
Ejemplo n.º 2
0
        private void RunPerformanceBenchmark()
        {
            var v = BaseVehicle.Create(VehicleModelType.BMX, Vector3.One, 0, 0, 0);

            var native = Interop.FastNativeFind("GetVehicleParamsEx");

            Timer x = new Timer(2000, true, true);

            var id = v.Id;

            void PerfTest()
            {
                Stopwatch sw = new Stopwatch();

                sw.Start();
                for (int i = 0; i < 400000; i++)
                {
                    CallThat(native, id);
                }
                sw.Stop();
                Console.WriteLine("TestMultiple={0}", sw.Elapsed.TotalMilliseconds);
            }

            PerfTest();

            x.Tick += (sender, args) =>
            {
                PerfTest();
            };
        }
Ejemplo n.º 3
0
        private void SpawnVehicleCommand(VehicleModelType model)
        {
            Random      rndColor = new Random();
            BaseVehicle v        = BaseVehicle.Create(model, new Vector3(this.Position.X + 5.0, this.Position.Y, this.Position.Z), 0.0f, rndColor.Next(0, 255), rndColor.Next(0, 255));

            this.PutInVehicle(v, 0);
        }
Ejemplo n.º 4
0
        private void RunPerformanceBenchmark()
        {
            var vehicle = BaseVehicle.Create(VehicleModelType.BMX, Vector3.One, 0, 0, 0);

            var native = Interop.FastNativeFind("GetVehicleParamsEx");

            var timer = new Timer(2000, true, true);

            var id = vehicle.Id;

            void PerfTest()
            {
                var sw = new Stopwatch();

                sw.Start();
                for (int i = 0; i < 400000; i++)
                {
                    CallThat(native, id);
                }
                sw.Stop();
                Console.WriteLine("BestPossible={0}", sw.Elapsed.TotalMilliseconds);
                sw.Reset();
                sw.Start();
                for (var i = 0; i < 400000; i++)
                {
                    vehicle.GetParameters(out VehicleParameterValue a, out _, out _, out _, out _, out _, out _);
                }

                sw.Stop();
                Console.WriteLine("ViaOOWrapper={0}", sw.Elapsed.TotalMilliseconds);
                sw.Reset();

                var proxy = BaseVehicle.VehicleInternal.Instance;

                sw.Start();
                for (var i = 0; i < 400000; i++)
                {
                    proxy.GetVehicleParamsEx(id, out _, out _, out _, out _, out _, out _, out _);
                }

                sw.Stop();
                Console.WriteLine("ViaDirectProxy={0}", sw.Elapsed.TotalMilliseconds);
                sw.Reset();
            }

            PerfTest();

            var benchRuns = 50;

            timer.Tick += (sender, args) =>
            {
                PerfTest();

                if (--benchRuns == 0)
                {
                    timer.IsRunning = false;
                }
            };
        }
Ejemplo n.º 5
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            Console.WriteLine("The game mode has loaded.");
            AddPlayerClass(0, Vector3.Zero, 0);

            var sampleVehicle = BaseVehicle.Create(VehicleModelType.Alpha, Vector3.One * 10, 0, -1, -1);

            Console.WriteLine("Spawned sample vehicle " + sampleVehicle.Model);
        }
Ejemplo n.º 6
0
        public static void SpawnCommand(BasePlayer player, VehicleModelType type)
        {
            var vehicle = BaseVehicle.Create(type, player.Position + Vector3.Up, player.Angle, -1, -1);

            player.PutInVehicle(vehicle);
            vehicle.GetDamageStatus(out var panels, out var doors, out var lights, out var tires);
            Console.WriteLine(panels.ToString());
            Console.WriteLine(doors.ToString());
            Console.WriteLine(lights.ToString());
            Console.WriteLine(tires.ToString());
        }
Ejemplo n.º 7
0
        public static void SpawnCommand(BasePlayer player, VehicleModelType?type)
        {
            if (type == null)
            {
                player.SendClientMessage("That's not a valid vehicle model");
                return;
            }

            var vehicle = BaseVehicle.Create(type.Value, player.Position + Vector3.Up, player.Angle, -1, -1);

            player.PutInVehicle(vehicle);
        }
Ejemplo n.º 8
0
        public void Connect(Player player)
        {
            bot = SampSharp.GameMode.SAMP.Server.ConnectNPC("testman", "npctest2");
            bot.SetSpawnInfo(0, 0, new SampSharp.GameMode.Vector3(1431.6393f, 1519.5398f, 10.5988f), 0.0f);
            bot.Spawn();

            player.SendClientMessage("bot id = " + bot.Id);
            player.SendClientMessage("bot is npc = " + bot.IsNPC.ToString()); // False

            BaseVehicle vehicle = BaseVehicle.Create(SampSharp.GameMode.Definitions.VehicleModelType.Buccaneer, new SampSharp.GameMode.Vector3(1431.6393f, 1519.5398f, 10.5988f), 0.0f, 1, 1);

            bot.PutInVehicle(vehicle, 0);
        }
Ejemplo n.º 9
0
        public static void OnSpawnVehicleCommand(BasePlayer sender, VehicleModelType model)
        {
            if (sender.Vehicle != null)
            {
                sender.SendClientMessage(Color.IndianRed, Messages.AlreadyInAVehicle);
                return;
            }

            var car = (Vehicle)BaseVehicle.Create(model, sender.Position + Vector3.One, sender.Angle, -1, -1, 600);

            car.Engine         = true;
            car.IsAdminSpawned = true;
            sender.PutInVehicle(car, 0);
        }
Ejemplo n.º 10
0
        protected override void OnInitialized(EventArgs e)
        {
            RakNet = Services.GetService <IRakNet>();
            RakNet.SetLogging(false, false, false, false, true, true);
            RakNet.IncomingRpc     += (sender, args) => OnIncomingRpc(args);
            RakNet.OutcomingRpc    += (sender, args) => OnOutcomingRpc(args);
            RakNet.IncomingPacket  += (sender, args) => OnIncomingPacket(args);
            RakNet.OutcomingPacket += (sender, args) => OnOutcomingPacket(args);

            BaseVehicle.Create((VehicleModelType)429, new Vector3(5, 0, 5), 0, 0, 0);
            BaseVehicle.Create((VehicleModelType)461, new Vector3(10, 0, 5), 0, 0, 0);
            BaseVehicle.Create((VehicleModelType)488, new Vector3(15, 0, 5), 0, 0, 0);

            BaseVehicle.Create((VehicleModelType)403, new Vector3(25, 0, 5), 0, 0, 0);
            BaseVehicle.Create((VehicleModelType)435, new Vector3(30, 0, 5), 0, 0, 0);
            base.OnInitialized(e);
        }
Ejemplo n.º 11
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            Console.WriteLine("The game mode has loaded.");
            AddPlayerClass(0, Vector3.Zero, 0);

            var sampleVehicle = BaseVehicle.Create(VehicleModelType.Alpha, Vector3.One * 10, 0, -1, -1);

            Console.WriteLine("Spawned sample vehicle " + sampleVehicle.Model);

            var cfg = new ServerConfig(Path.Combine(Client.ServerPath, "server.cfg"));

            foreach (var kv in cfg)
            {
                Console.WriteLine(kv.Key + " " + kv.Value);
            }
        }
Ejemplo n.º 12
0
        private static void CloneCarCommand(BasePlayer player)
        {
            if (clone == null)
            {
                player.SendClientMessage("You don't have a clone! Type /clone to spawn it.");
                return;
            }

            if (clone.IsAiming)
            {
                clone.StopAim();
            }

            player.SendClientMessage("Your clone will now enter a car.");

            var pos = GetPositionInFront(clone.Position, clone.Angle - 90, 5f);
            var v   = BaseVehicle.Create(VehicleModelType.Rancher, pos, clone.Angle, 0, 0);

            clone.EnterVehicle(v, 0, MoveType.Walk);
        }
Ejemplo n.º 13
0
        public RaceCreator(Player _player)
        {
            player = _player;
            player.KeyStateChanged     += Player_KeyStateChanged;
            player.EnterCheckpoint     += Player_EnterCheckpoint;
            player.EnterRaceCheckpoint += Player_EnterRaceCheckpoint;

            if (!player.InAnyVehicle)
            {
                BaseVehicle veh = BaseVehicle.Create(VehicleModelType.Infernus, player.Position + new Vector3(0.0, 5.0, 0.0), 0.0f, 1, 1);
                player.PutInVehicle(veh);
            }

            hud = new HUD(_player);

            editingRace     = null;
            isEditing       = false;
            editingMode     = EditingMode.Checkpoints;
            checkpointIndex = 0;

            spawnVehicles = new BaseVehicle[Race.MAX_PLAYERS_IN_RACE];
        }
Ejemplo n.º 14
0
        public void SpawnVehicle(VehicleModelType model)
        {
            var v = BaseVehicle.Create(model, Position + new Vector3(0, 0.5f, 0), 0, -1, -1);

            PutInVehicle(v);
        }
        public void Start(GameMode gameMode)
        {
            var veh = BaseVehicle.Create(VehicleModelType.Burrito, new Vector3(5), 0, -1, -1, -1, true);

            Console.WriteLine("Vehiclesize of {1}: {0}", veh.ModelInfo[VehicleModelInfoType.Size], veh.ModelInfo.Name);
        }
Ejemplo n.º 16
0
        private void RaceDialog_Response(object sender, SampSharp.GameMode.Events.DialogResponseEventArgs e)
        {
            if (e.Player.Equals(player))
            {
                if (e.DialogButton == DialogButton.Left)
                {
                    Checkpoint cp = editingRace.checkpoints[checkpointIndex];
                    switch (e.ListItem)
                    {
                    case 0:     // Select starting vehicle
                    {
                        InputDialog cpStartCarNameDialog = new InputDialog("Vehicle name", "Enter the vehicle name:", false, "Find", "Cancel");
                        cpStartCarNameDialog.Show(player);
                        cpStartCarNameDialog.Response += (sender, eventArgs) =>
                        {
                            if (eventArgs.DialogButton == DialogButton.Left)
                            {
                                editingRace.StartingVehicle = Utils.GetVehicleModelType(eventArgs.InputText);
                                player.Notificate("Updated");
                                ShowRaceDialog();
                            }
                            else
                            {
                                player.Notificate("Cancelled");
                                ShowRaceDialog();
                            }
                        };
                        break;
                    }

                    case 1:     // Edit race name
                    {
                        InputDialog cpRaceNameDialog = new InputDialog("Race name", "Enter the race name:", false, "Edit", "Cancel");
                        cpRaceNameDialog.Show(player);
                        cpRaceNameDialog.Response += (sender, eventArgs) =>
                        {
                            if (eventArgs.DialogButton == DialogButton.Left)
                            {
                                editingRace.Name = eventArgs.InputText;
                                player.Notificate("Updated");
                                ShowRaceDialog();
                            }
                            else
                            {
                                player.Notificate("Cancelled");
                                ShowRaceDialog();
                            }
                        };
                        break;
                    }

                    case 2:     // Set/Edit spawn position
                    {
                        checkpointIndex = 0;
                        UpdatePlayerCheckpoint();
                        editingMode = EditingMode.SpawnPos;
                        hud.SetEditingMode(editingMode);

                        player.DisableRemoteVehicleCollisions(true);
                        foreach (BaseVehicle veh in spawnVehicles)
                        {
                            if (veh != null)
                            {
                                veh.Dispose();
                            }
                        }
                        if (editingRace.startingSpawn[0].Position == Vector3.Zero)
                        {
                            spawnVehicles[0] = BaseVehicle.Create(editingRace.StartingVehicle.GetValueOrDefault(VehicleModelType.Infernus), editingRace.checkpoints[editingRace.checkpoints.Count - 1].Position, 0.0f, 0, 0);
                        }
                        else
                        {
                            int idx = 0;
                            foreach (Vector3R spawn in editingRace.startingSpawn)
                            {
                                if (spawn.Position != Vector3.Zero)
                                {
                                    spawnVehicles[idx++] = BaseVehicle.Create(editingRace.StartingVehicle.GetValueOrDefault(VehicleModelType.Infernus), spawn.Position, spawn.Rotation, 0, 0);
                                }
                            }
                        }
                        //TODO: canceledit
                        UpdatePlayerSpawnMover();
                        moverObject.Edit();
                        break;
                    }

                    case 3:     // Laps
                    {
                        InputDialog cpRaceLapsDialog = new InputDialog("Race laps", "Enter the number of laps the race have:", false, "Set", "Cancel");
                        cpRaceLapsDialog.Show(player);
                        cpRaceLapsDialog.Response += (sender, eventArgs) =>
                        {
                            if (eventArgs.DialogButton == DialogButton.Left)
                            {
                                try
                                {
                                    editingRace.Laps = Convert.ToInt32(eventArgs.InputText);
                                    player.Notificate("Updated");
                                }
                                catch (Exception e)
                                {
                                    player.SendClientMessage(Color.Red, "There was an error trying to set this value.");
                                    player.Notificate("Error");
                                }
                                ShowRaceDialog();
                            }
                            else
                            {
                                player.Notificate("Cancelled");
                                ShowRaceDialog();
                            }
                        };
                        break;
                    }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     Raises the <see cref="E:SampSharp.GameMode.BaseMode.Initialized" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param>
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            var vehicle = BaseVehicle.Create(VehicleModelType.Alpha, Vector3.Up * 15, 0, -1, -1);

            vehicle.GetDamageStatus(out var panels, out var doors, out var lights, out var tires);
            Console.WriteLine(panels.ToString());
            Console.WriteLine(doors.ToString());
            Console.WriteLine(lights.ToString());
            Console.WriteLine(tires.ToString());

            var streamer = Services.GetService <IStreamer>();

            Console.WriteLine("Service: " + streamer);

            var area =
                DynamicArea.CreatePolygon(new[]
            {
                Vector3.One + new Vector3(-10, -10),
                Vector3.One + new Vector3(10, -10),
                Vector3.One + new Vector3(10, 10),
                Vector3.One + new Vector3(-10, 10)
            }, -100.0f, 100.0f);

            Console.WriteLine("Area handle: " + area.Id);

            area.Enter += (sender, args) => args.Player.SendClientMessage("Entered polygon");
            area.Leave += (sender, args) => args.Player.SendClientMessage("Left polygon");

            var isValid  = area.IsValid;
            var position = area.Position;
            var points   = area.GetPoints().ToArray();

            Console.WriteLine($"area.IsValid = {isValid}, area.Position = {position}, Points = {string.Join(", ", points)}");

            var area2 = DynamicArea.CreateRectangle(0, 0, 20, 20);

            area2.Enter += (sender, args) => args.Player.SendClientMessage("Entered Rectangle");
            area2.Leave += (sender, args) => args.Player.SendClientMessage("Left Rectangle");

            var icon = new DynamicMapIcon(new Vector3(1500, -1500, 0), Color.Blue, MapIconType.Global, -1, -1, null, 300);

            Console.WriteLine(icon.Position);
            icon.Position = new Vector3(50, 50, 5);
            Console.WriteLine(icon.Position);

            var pickup = new DynamicPickup(1274, 23, new Vector3(0, 0, 3), 100f,
                                           new[] { 11, 22, 33, 44, 0, 55, 66, 77, 88, 99 }); //Dollar icon

            pickup.PickedUp += (sender, args) => args.Player.SendClientMessage(Color.White, "Picked Up");

            var pickup2 = new DynamicPickup(1274, 23, Vector3.One, 42);

            Console.WriteLine("World: {0}", string.Join(",", pickup.Worlds));
            Console.WriteLine("World: {0}", string.Join(",", pickup2.Worlds));

            var checkpoint = new DynamicCheckpoint(new Vector3(10, 10, 3));

            checkpoint.Enter += (sender, args) => args.Player.SendClientMessage(Color.White, "Entered CP");
            checkpoint.Leave += (sender, args) => args.Player.SendClientMessage(Color.White, "Left CP");

            var actor = new DynamicActor(100, new Vector3(20, 10, 5), 0);



            var racecheckpoint = new DynamicRaceCheckpoint(CheckpointType.Normal, new Vector3(-10, -10, 3), new Vector3());

            racecheckpoint.Enter += (sender, args) => args.Player.SendClientMessage(Color.White, "Entered RCP");
            racecheckpoint.Leave += (sender, args) => args.Player.SendClientMessage(Color.White, "Left RCP");

            new DynamicTextLabel("[I am maroon]", Color.Maroon, pickup.Position + new Vector3(0, 0, 1), 100.0f);

            var obj = new DynamicObject(12991, new Vector3(10, 10, 3));

            Console.WriteLine("obj position after spawn " + obj.Position);
            var offset = Vector3.One;

            obj.SetMaterialText(1, "Test", ObjectMaterialSize.X512X512, "Arial", 30, false, Color.Black, Color.White);
            obj.Move(obj.Position + -offset, 0.6f, obj.Rotation + new Vector3(0, 0, 25));
            obj.Moved += (sender, args) =>
            {
                Console.WriteLine("moved");
                obj.Move(obj.Position + (offset = -offset), 0.6f, obj.Rotation + new Vector3(0, 0, 25));
            };


            Console.WriteLine("Test error handling...");
            streamer.IsErrorCallbackEnabled = true;
            streamer.Error += (sender, args) => { Console.WriteLine("Error CB: " + args.Error); };
            streamer.PrintStackTraceOnError = true;
            streamer.ItemType[StreamType.MapIcon].GetArray(9999, StreamerDataType.Color, 1);
            Console.WriteLine("Messages should have appeared above.");
        }
Ejemplo n.º 18
0
        public static void SpawnCommand(BasePlayer player, VehicleModelType type)
        {
            var vehicle = BaseVehicle.Create(type, player.Position + Vector3.Up, player.Angle, -1, -1);

            player.PutInVehicle(vehicle);
        }
Ejemplo n.º 19
0
 public static void SpawnCommand(BasePlayer player, VehicleModelType type, float x, float y, float z, float a)
 {
     BaseVehicle.Create(type, new Vector3(x, y, z), a, -1, -1);
 }