private async Task OnEntityRemove(IEntity entity)
        {
            Position entityPosition = await entity.GetPositionAsync();

            switch (entity.Type)
            {
            case EntityType.Player:
                AltAsync.Log("A player has been removed, at position "
                             + entityPosition + ".");
                break;

            case EntityType.Vehicle:
                AltAsync.Log("A vehicle has been removed, at position "
                             + entityPosition + ".");
                break;

            case EntityType.Blip:
                AltAsync.Log("A blip has been removed, at position "
                             + entityPosition + ".");
                break;

            case EntityType.Checkpoint:
                AltAsync.Log("A checkpoint has been removed, at position "
                             + entityPosition + ".");
                break;

            default:
                AltAsync.Log("A entity has been removed, at position "
                             + entityPosition + ".");
                break;
            }
        }
Ejemplo n.º 2
0
        public async Task OnEnterColshape(IColShape colShape, IEntity targetEntity, bool state) => await AltAsync.Do(() =>
        {
            if (!state)
            {
                return;
            }
            if (colShape == null || !colShape.Exists)
            {
                return;
            }
            if (targetEntity.Type != BaseObjectType.Player)
            {
                return;
            }

            AltAsync.Log("Shop");

            ShopEntity shopEntity = colShape.GetShopEntity();

            if (shopEntity == null || shopEntity.ColShape != colShape)
            {
                return;
            }

            IPlayer player = targetEntity as IPlayer;

            if (player.IsInVehicle)
            {
                return;
            }

            player.SetData("current:shop", shopEntity);
            new Interaction(player, "shop:openWindow", "aby otworzyć ~g~sklep");
        });
        private async Task OnPlayerDead(IPlayer player, IEntity killer, uint weapon)
        {
            string playerName = await player.GetNameAsync();

            switch (killer.Type)
            {
            case EntityType.Player:
                IPlayer playerKiller     = (IPlayer)killer;
                string  playerKillerName = await playerKiller.GetNameAsync();

                AltAsync.Log(playerName + " has been killed by " + playerKillerName
                             + " with weapon " + weapon + ".");
                break;

            case EntityType.Vehicle:
                IVehicle vehicleKiller = (IVehicle)killer;
                IPlayer  driver        = await vehicleKiller.GetDriverAsync();

                string driverName = await driver.GetNameAsync();

                AltAsync.Log(playerName + " has been killed by a vehicle (Driver: "
                             + driverName + ").");
                break;

            default:

                AltAsync.Log(playerName + " has been killed by an Entity.");
                break;
            }
        }
Ejemplo n.º 4
0
        /*
         *  Add your Server Commands here
         */
        internal static async Task ManageCommands(string command, string[] arguments)
        {
            switch (command)
            {
                #region SpecialCommands
            case "client":
            {
                await Client(arguments);

                break;
            }

                #endregion
                #region ServerCommands
            case "HelloServer":
            {
                HelloServer(arguments);
                break;
            }

                #endregion
            default:
            {
                AltAsync.Log("Command `" + command + "` not found.");
                break;
            }
            }
        }
        // Can been triggered from a Client Event
        private async Task OnPlayerEvent(IPlayer player, string eventName, object[] args)
        {
            string playerName = await player.GetNameAsync();

            switch (eventName)
            {
            case "playerEventA":
            {
                AltAsync.Log(playerName + " has triggered Event A, "
                             + "with following Args:");
                foreach (var arg in args)
                {
                    AltAsync.Log(arg + " - Type: " + arg.GetType());
                }
                break;
            }

            case "playerEventB":
            {
                AltAsync.Log(playerName + " has triggered Event B, "
                             + "with following Args:");
                foreach (var arg in args)
                {
                    AltAsync.Log(arg + " - Type: " + arg.GetType());
                }
                break;
            }
            }
        }
        private async Task OnPlayerDamage(IPlayer player, IEntity attacker, uint weapon,
                                          byte damage)
        {
            string playerName = await player.GetNameAsync();

            switch (attacker.Type)
            {
            case EntityType.Player:
                var    playerAttacker     = (IPlayer)attacker;
                string playerAttackerName = await playerAttacker.GetNameAsync();

                AltAsync.Log(playerName + " has been damaged by " + playerAttackerName
                             + " with weapon " + weapon + " and suffered " + damage +
                             " HP.");
                break;

            case EntityType.Vehicle:
                var     vehicleAttacker = (IVehicle)attacker;
                IPlayer driver          = await vehicleAttacker.GetDriverAsync();

                string driverName = await driver.GetNameAsync();

                AltAsync.Log(playerName + " has been damaged by a vehicle (Driver: "
                             + driverName + ") and suffered "
                             + damage + " HP.");
                break;

            default:
                AltAsync.Log(playerName + " has been damaged by an Entity and suffered "
                             + damage + ".");
                break;
            }
        }
Ejemplo n.º 7
0
        private static async Task OnPlayerConnect(IPlayer player, string reason)
        {
            var name = await player.GetNameAsync();

            AltAsync.Log(name + " has joined the Server.");

            await Login.Login.OnPlayerConnect(player, reason);
        }
Ejemplo n.º 8
0
        public override void OnStart()
        {
            AltAsync.OnPlayerConnect    += OnPlayerConnect;
            AltAsync.OnPlayerDisconnect += OnPlayerDisconnect;
            AltAsync.OnPlayerDead       += OnPlayerDead;
            AltAsync.OnConsoleCommand   += OnConsoleCommand;
            AltAsync.OnPlayerEvent      += OnPlayerEvent;

            AltAsync.Log("Server initialized.");
        }
        private async Task OnCheckpoint(ICheckpoint checkpoint, IEntity entity, bool state)
        {
            Position entityPosition = await entity.GetPositionAsync();

            Position checkPosition = await checkpoint.GetPositionAsync();

            if (state)
            {
                //Executed if entity enters checkpoint
                switch (entity.Type)
                {
                case EntityType.Player:
                    AltAsync.Log("A player has entered the checkpoint: player-position "
                                 + entityPosition + " - checkpoint-position "
                                 + checkPosition);
                    break;

                case EntityType.Vehicle:
                    AltAsync.Log("A vehicle has entered the checkpoint: vehicle-position "
                                 + entityPosition + " - checkpoint-position "
                                 + checkPosition);
                    break;

                default:
                    AltAsync.Log("A entity has entered the checkpoint: entity-position "
                                 + entityPosition + " - checkpoint-position "
                                 + checkPosition);
                    break;
                }
            }
            else
            {
                //Executed if entity leaves checkpoint
                switch (entity.Type)
                {
                case EntityType.Player:
                    AltAsync.Log("A player has left the checkpoint: player-position "
                                 + entityPosition + " - checkpoint-position "
                                 + checkPosition);
                    break;

                case EntityType.Vehicle:
                    AltAsync.Log("A vehicle has left the checkpoint: vehicle-position "
                                 + entityPosition + " - checkpoint-position "
                                 + checkPosition);
                    break;

                default:
                    AltAsync.Log("A entity has left the checkpoint: entity-position "
                                 + entityPosition + " - checkpoint-position "
                                 + checkPosition);
                    break;
                }
            }
        }
        private async Task OnVehicleLeave(IVehicle vehicle, IPlayer player, sbyte seat)
        {
            IPlayer driver = await vehicle.GetDriverAsync();

            string driverName = await driver.GetNameAsync();

            string playerName = await player.GetNameAsync();

            AltAsync.Log(playerName + " left vehicle (Driver: " + driverName
                         + ") from seat " + seat + ".");
        }
        public async Task SubtractHungerAndThirsty(IPlayer player) => await AltAsync.Do(() =>
        {
            CharacterEntity characterEntity = player.GetAccountEntity().characterEntity;
            if (characterEntity.Hunger == 0 || characterEntity.Thirsty == 0)
            {
                return;
            }

            AltAsync.Log("Dotarł event z jedzeniem");

            characterEntity.Hunger  -= 3.0f;
            characterEntity.Thirsty -= 3.0f;
        });
        private async Task OnVehicleChangeSeat(IVehicle vehicle, IPlayer player, sbyte oldSeat,
                                               sbyte newSeat)
        {
            IPlayer driver = await vehicle.GetDriverAsync();

            string driverName = await driver.GetNameAsync();

            string playerName = await player.GetNameAsync();

            AltAsync.Log(playerName + " has changed seat in vehicle (Driver: "
                         + driverName + ") from " + oldSeat
                         + " to " + newSeat + ".");
        }
        public static async Task OnPlayerEvent(IPlayer player, string eventName, object[] args)
        {
            switch (eventName)
            {
            case "COMMAND_CALLBACK_test":
            {
                await Task.Delay(0);     //Suppress Warning

                AltAsync.Log("Test is working");
                break;
            }
            }
        }
        private async Task OnVehicleEnter(IVehicle vehicle, IPlayer player, sbyte seat)
        {
            IPlayer driver = await vehicle.GetDriverAsync();

            string driverName = await driver.GetNameAsync();

            string playerName = await player.GetNameAsync();

            AltAsync.Log(playerName + " entered vehicle (Driver: " + driverName
                         + ") on seat " + seat + ".");

            await Task.Delay(5000);

            AltAsync.Log(playerName + " entered vehicle 5 seconds ago.");
        }
Ejemplo n.º 15
0
        public async Task OnPlayerConnect(IAltPlayer player, string reason)
        {
            await using (var asyncContext = AsyncContext.Create())
            {
                if (!player.TryToAsync(asyncContext, out var asyncPlayer))
                {
                    return;
                }

                if (Misc.BannedPlayers.Contains(new Tuple <ulong, ulong>(asyncPlayer.HardwareIdHash, asyncPlayer.HardwareIdExHash)))
                {
                    asyncPlayer.Kick("You're banned from this server!");
                    AltAsync.Log($"HWID: {asyncPlayer.HardwareIdHash}, SC: {asyncPlayer.SocialClubId}. Tried to join the server with a ban.");
                    return;
                }

                if (Misc.Operators.Contains(new Tuple <ulong, ulong>(asyncPlayer.HardwareIdHash, asyncPlayer.HardwareIdExHash)))
                {
                    asyncPlayer.IsAdmin = true;
                }

                // select random entry from SpawnPoints
                var randomSpawnPoint = Misc.SpawnPositions.ElementAt(_random.Next(0, Misc.SpawnPositions.Length));
                asyncPlayer.Spawn(randomSpawnPoint + new Position(_random.Next(0, 10), _random.Next(0, 10), 0));
                asyncPlayer.Model = (uint)PedModel.FreemodeMale01;
                asyncPlayer.SetDateTime(1, 1, 1, Misc.Hour, 1, 1);
                asyncPlayer.SetWeather(Misc.Weather);

                asyncPlayer.Emit("draw_dmzone", Misc.DMPos.X, Misc.DMPos.Y, Misc.DMRadius, 150);

                if (asyncPlayer.IsAdmin)
                {
                    asyncPlayer.Emit("set_chat_state", true);
                }
            }

            // create async context
            lock (StatsHandler.StatsData)
            {
                StatsHandler.StatsData.PlayerConnections++;
            }

            return;
        }
        public override void OnStart()
        {
            AltAsync.OnCheckpoint        += OnCheckpoint;
            AltAsync.OnEntityRemove      += OnEntityRemove;
            AltAsync.OnPlayerConnect     += OnPlayerConnect;
            AltAsync.OnPlayerDamage      += OnPlayerDamage;
            AltAsync.OnPlayerDead        += OnPlayerDead;
            AltAsync.OnPlayerDisconnect  += OnPlayerDisconnect;
            AltAsync.OnVehicleChangeSeat += OnVehicleChangeSeat;
            AltAsync.OnVehicleEnter      += OnVehicleEnter;
            AltAsync.OnVehicleLeave      += OnVehicleLeave;
            AltAsync.OnPlayerEvent       += OnPlayerEvent;

            // Custom Event Triggers can be found at the bottom
            // Custom Event Type 01
            AltAsync.On("customEvent01", async args =>
            {
                await Task.Delay(1000);
                AltAsync.Log("customEvent01 triggered with following arguments: " + args[0]);
            });

            // Custom Event Type 02 - Fixed Argument Type
            AltAsync.On <string>("customEvent02", async str =>
            {
                await Task.Delay(1000);
                AltAsync.Log("customEvent01 triggered with following argument: " + str);
            });

            // Custom Event Type 03 - Delegate Type
            AltAsync.On("customEvent03", async delegate(string str)
            {
                await Task.Delay(1000);
                AltAsync.Log("customEvent03 triggered with following argument: " + str);
            });

            // Custom Event Type 04 - Method Call
            AltAsync.On <string>("customEvent04", CustomEvent04);

            AltAsync.Log("Resource \"CSharp_Examples\" has been started.");
        }
Ejemplo n.º 17
0
        private static async Task Client(IReadOnlyList <string> args)
        {
            if (args.Count < 2)
            {
                AltAsync.Log("Could too few arguments.");
                return;
            }

            var playerName = args[0];
            var command    = args[1];
            var arguments  = new string[args.Count - 2];

            for (var i = 2; i < args.Count; i++)
            {
                arguments[i - 2] = args[i];
            }

            IPlayer player = null;

            foreach (var client in Alt.GetAllPlayers())
            {
                var name = client.GetNameAsync();
                if (name.Result != playerName)
                {
                    continue;
                }

                player = client;
                break;
            }

            if (player == null)
            {
                AltAsync.Log("Could not find Player `" + playerName + "`.");
                return;
            }

            await ConsoleManager.ParseClientCommands(player, command, arguments, false);
        }
Ejemplo n.º 18
0
 public async void MyServerEventHandlerAsync(IMyVehicle vehicle)
 {
     AltAsync.Log("data-custom-parser: " + vehicle.MyData);
 }
Ejemplo n.º 19
0
        public override void OnStart()
        {
            Alt.On <string>("test", s => { Alt.Log("test=" + s); });
            Alt.OnServer("test", args => { Alt.Log("args=" + args[0]); });
            Alt.Emit("test", "bla");
            Alt.On("bla", bla);
            Alt.On <string>("bla2", bla2);
            Alt.On <string, bool>("bla3", bla3);
            Alt.On <string, string>("bla4", bla4);
            Alt.On <IMyVehicle>("vehicleTest", myVehicle => { Alt.Log("myData: " + myVehicle.MyData); });

            Alt.OnPlayerConnect         += OnPlayerConnect;
            Alt.OnPlayerDisconnect      += OnPlayerDisconnect;
            AltAsync.OnPlayerDisconnect += OnPlayerDisconnectAsync;
            Alt.OnPlayerRemove          += OnPlayerRemove;
            Alt.OnVehicleRemove         += OnVehicleRemove;
            AltAsync.OnPlayerConnect    += OnPlayerConnectAsync;
            Alt.OnConsoleCommand        += (name, args) => { };
            Alt.OnPlayerEvent           += (player, name, args) => { Alt.Log("event:" + name); };
            AltAsync.OnPlayerEvent      += (player, name, args) =>
            {
                AltAsync.Log("event:" + name);
                return(Task.CompletedTask);
            };
            AltAsync.On("bla", async args => { await AltAsync.Do(() => Alt.Log("bla with no args:" + args.Length)); });
            Alt.Emit("bla");

            var vehicle = Alt.CreateVehicle(VehicleModel.Apc, new Position(1, 2, 3), float.MinValue);

            Alt.Log(vehicle.Position.ToString());
            vehicle.PrimaryColor     = 7;
            vehicle.NumberplateText  = "AltV-C#";
            vehicle.NumberplateIndex = 2;
            vehicle.SetMod(0, 0);
            vehicle.GetMod(0);
            vehicle.GetModsCount(0);
            vehicle.Dimension       = 0;
            vehicle.LockState       = VehicleLockState.Locked;
            vehicle.PrimaryColorRgb = new Rgba
            {
                r = 1,
                g = 8,
                b = 7,
                a = 0
            };

            Alt.Log("ptr:" + vehicle.NativePointer);

            Alt.Log("number-plate:" + vehicle.NumberplateText + " " + vehicle.NumberplateIndex);

            Alt.Emit("vehicleTest", vehicle);

            Alt.On("event_name",
                   delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVehicle arg5,
                            Dictionary <string, object> arg6, IMyVehicle[] myVehicles, string probablyNull, string[] nullArray,
                            Dictionary <string, double> bla)
            {
                Alt.Log("param1:" + s);
                Alt.Log("param2:" + s1);
                Alt.Log("bla:" + ((object[])arg4[1])[0]);
                Alt.Log("myData-2: " + arg5.Position.X + " " + arg5.MyData);
                Alt.Log("myData-4-veh-array: " + myVehicles[0].Position.X + " " + myVehicles[0].MyData);
                Alt.Log("myData-3: " + arg6["test"]);
                Alt.Log("null?" + (probablyNull == null ? "y" : "n"));
                Alt.Log("null2?" + (nullArray[0] == null ? "y" : "n"));
                Alt.Log("bla2:" + bla["test"]);
            });

            Alt.On("entity-array-obj",
                   delegate(object[] myVehicles)
            {
                Alt.Log("entity-array-obj: " + ((MyVehicle)myVehicles[0]).Position.X + " " +
                        ((MyVehicle)myVehicles[0]).MyData);
            });

            AltAsync.On("event_name",
                        async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVehicle arg5,
                                       Dictionary <string, object> arg6, IMyVehicle[] myVehicles, string probablyNull, string[] nullArray,
                                       Dictionary <string, double> bla)
            {
                await Task.Delay(500);
                var asyncVehicle = await AltAsync.CreateVehicle(VehicleModel.Apc, Position.Zero, float.MaxValue);

                AltAsync.Log("async-param1:" + s);
                AltAsync.Log("async-param2:" + s1);
                AltAsync.Log("async-bla:" + ((object[])arg4[1])[0]);
                AltAsync.Log("exists:" + arg5.Exists);
                AltAsync.Log("async-myData-2: " + arg5.Position.X + " " + arg5.MyData);
                AltAsync.Log("async-myData-4: " + myVehicles[0].Position.X + " " + myVehicles[0].MyData);
                AltAsync.Log("async-myData-3: " + arg6["test"]);
                AltAsync.Log("async-null?" + (probablyNull == null ? "y" : "n"));
                AltAsync.Log("async-null2?" + (nullArray[0] == null ? "y" : "n"));
                AltAsync.Log("async-bla2:" + bla["test"]);
            });

            Alt.Emit("event_name", "param_string_1", "param_string_2", 1, new[] { "array_1", "array_2" },
                     new object[] { "test", new[] { 1337 } }, vehicle,
                     new Dictionary <string, object>
            {
                ["test"] = "test" //,
                                  //["test2"] = new Dictionary<string, long> {["test"] = 1},
                                  //["test3"] = new Dictionary<string, long> {["test"] = 42}
            },
                     new IMyVehicle[] { (IMyVehicle)vehicle }, null, new string[] { null },
                     new Dictionary <string, object>
            {
                ["test"] = null
            });

            Alt.On <string[]>("test_string_array", s => { Alt.Log("string-array-entry-0:" + s[0]); });

            Alt.Emit("test_string_array", new object[] { new string[] { "bla" } });

            Alt.On("function_event", delegate(Function.Func func)
            {
                var result = func("parameter1");
                Alt.Log("result:" + result);
            });

            Alt.Emit("function_event", Function.Create(delegate(string bla)
            {
                Alt.Log("parameter=" + bla);
                return(42);
            }));

            foreach (var player in Alt.GetAllPlayers())
            {
            }

            foreach (var veh in Alt.GetAllVehicles())
            {
                Alt.Log("vehicle:" + veh.Position.X + " " + veh.Position.Y + " " + veh.Position.Z);
            }

            Alt.On("1337", delegate(int int1) { Alt.Log("int1:" + int1); });

            AltAsync.On("1337", delegate(int int1) { Alt.Log("int1:" + int1); });

            Alt.Emit("1337", 1);

            Alt.On <IMyVehicle>("MyServerEvent3", MyServerEventHandler2, MyServerEventParser3);

            Alt.On <IMyVehicle>("MyServerEvent3", MyServerEventHandlerAsync, MyServerEventParserAsync);

            Alt.Emit("MyServerEvent3", vehicle);

            Alt.Emit("entity-array-obj", new[] { new[] { vehicle } });

            vehicle.Remove();

            Bla();

            Alt.On <IPlayer, string>("MyEvent", MyEventHandler, MyParser);

            Alt.On <string>("MyServerEvent", MyServerEventHandler, MyServerEventParser);

            Alt.On <string>("MyServerEvent2", MyServerEventHandler, MyServerEventParser2);

            Alt.Emit("MyServerEvent", "test-custom-parser");

            Alt.Emit("MyServerEvent2", new object[] { new string[] { "test-custom-parser-array" } });

            dynamic dynamic = new ExpandoObject();

            Alt.Emit("dynamic_test", dynamic);

            Alt.Export("GetBla", () => { Alt.Log("GetBla called"); });

            /*if (Alt.Import("Bla", "GetBla", out Action value))
             * {
             *  value();
             * }*/

            Alt.Emit("none-existing-event", new WritableObject());

            Alt.Emit("none-existing-event", new ConvertibleObject());
        }
Ejemplo n.º 20
0
        private static void HelloServer(string[] arguments)
        {
            var printString = arguments.Aggregate("", (current, arg) => current + (" " + arg)); // Arguments to one String

            AltAsync.Log("Hello Server!" + printString);
        }
Ejemplo n.º 21
0
        public async void MyServerEventHandlerAsync(IMyVehicle vehicle)
        {
            await Task.Delay(100);

            AltAsync.Log("data-custom-parser: " + vehicle.MyData);
        }
Ejemplo n.º 22
0
        public override void OnStart()
        {
            MValueAdapters.Register(new ConvertibleObject.ConvertibleObjectAdapter());
            Alt.On("convertible_test", delegate(ConvertibleObject convertible)
            {
                Console.WriteLine("convertible_test received");
                Console.WriteLine(convertible.Test);
                foreach (var t in convertible.List)
                {
                    Console.WriteLine("-" + t.Test);
                }
            });
            var convertibleObject = new ConvertibleObject();

            Alt.Emit("convertible_test", convertibleObject);

            Alt.On <string>("test", s => { Alt.Log("test=" + s); });
            Alt.OnServer("test", args => { Alt.Log("args=" + args[0]); });
            Alt.Emit("test", "bla");
            Alt.On("bla", bla);
            Alt.On <string>("bla2", bla2);
            Alt.On <string, bool>("bla3", bla3);
            Alt.On <string, string>("bla4", bla4);
            Alt.On <IMyVehicle>("vehicleTest", myVehicle => { Alt.Log("myData: " + myVehicle.MyData); });

            Alt.OnPlayerConnect         += OnPlayerConnect;
            Alt.OnPlayerDisconnect      += OnPlayerDisconnect;
            AltAsync.OnPlayerDisconnect += OnPlayerDisconnectAsync;
            Alt.OnPlayerRemove          += OnPlayerRemove;
            Alt.OnVehicleRemove         += OnVehicleRemove;
            AltAsync.OnPlayerConnect    += OnPlayerConnectAsync;
            Alt.OnConsoleCommand        += (name, args) => { };
            Alt.OnPlayerEvent           += (player, name, args) => { Alt.Log("event:" + name); };
            AltAsync.OnPlayerEvent      += (player, name, args) =>
            {
                AltAsync.Log("event:" + name);
                return(Task.CompletedTask);
            };
            AltAsync.OnServer("bla",
                              async args => { await AltAsync.Do(() => Alt.Log("bla with no args:" + args.Length)); });
            Alt.Emit("bla");

            var blip = Alt.CreateBlip(BlipType.Area, Position.Zero);

            blip.Color = 1;

            var checkpoint = Alt.CreateCheckpoint(CheckpointType.Cyclinder, Position.Zero, 1f, 1f, Rgba.Zero);

            Alt.Log(checkpoint.Color.ToString());

            var voiceChannel = Alt.CreateVoiceChannel(true, 10f);

            Alt.Log(voiceChannel.MaxDistance.ToString());

            var vehicle = Alt.CreateVehicle(VehicleModel.Apc, new Position(1, 2, 3), new Rotation(1, 2, 3));

            Alt.Log(vehicle.Position.ToString());
            vehicle.PrimaryColor     = 7;
            vehicle.NumberplateText  = "AltV-C#";
            vehicle.NumberplateIndex = 2;
            vehicle.SetMod(0, 0);
            vehicle.GetMod(0);
            vehicle.GetModsCount(0);
            vehicle.Dimension       = 0;
            vehicle.LockState       = VehicleLockState.Locked;
            vehicle.PrimaryColorRgb = new Rgba
            {
                R = 1,
                G = 8,
                B = 7,
                A = 0
            };

            var(x, y, z) = vehicle.GetPosition();
            vehicle.SetPosition(1, 1, 1);
            vehicle.SetPosition((x, y, z));
            var tuple = vehicle.GetPosition();

            vehicle.SetPosition(tuple);


            Task.Factory.StartNew(() =>
                                  AltAsync.CreateVehicleBuilder(VehicleModel.Apc, new Position(1, 2, 3), new Rotation(1, 2, 3))
                                  .PrimaryColorRgb(Color.GreenYellow)
                                  .SecondaryColor(24)
                                  .NumberplateText("C#")
                                  .LockState(VehicleLockState.Locked)
                                  .Build()
                                  );

            Alt.Log("ptr:" + vehicle.NativePointer);

            Alt.Log("number-plate:" + vehicle.NumberplateText + " " + vehicle.NumberplateIndex);

            Alt.Emit("vehicleTest", vehicle);

            Alt.On("event_name",
                   delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVehicle arg5,
                            Dictionary <string, object> arg6, IMyVehicle[] myVehicles, string probablyNull, string[] nullArray,
                            Dictionary <string, double> bla)
            {
                Alt.Log("param1:" + s);
                Alt.Log("param2:" + s1);
                Alt.Log("bla:" + ((object[])arg4[1])[0]);
                Alt.Log("myData-2: " + arg5.Position.X + " " + arg5.MyData);
                Alt.Log("myData-4-veh-array: " + myVehicles[0].Position.X + " " + myVehicles[0].MyData);
                Alt.Log("myData-3: " + arg6["test"]);
                Alt.Log("null?" + (probablyNull == null ? "y" : "n"));
                Alt.Log("null2?" + (nullArray[0] == null ? "y" : "n"));
                Alt.Log("bla2:" + bla["test"]);
            });

            Alt.On("entity-array-obj",
                   delegate(object[] myVehicles)
            {
                Alt.Log("entity-array-obj: " + ((MyVehicle)myVehicles[0]).Position.X + " " +
                        ((MyVehicle)myVehicles[0]).MyData);
            });

            AltAsync.On("event_name",
                        async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVehicle arg5,
                                       Dictionary <string, object> arg6, IMyVehicle[] myVehicles, string probablyNull, string[] nullArray,
                                       Dictionary <string, double> bla)
            {
                await Task.Delay(500);
                var asyncVehicle =
                    await AltAsync.CreateVehicle(VehicleModel.Apc, Position.Zero, new Rotation(1, 2, 3));

                AltAsync.Log("async-param1:" + s);
                AltAsync.Log("async-param2:" + s1);
                AltAsync.Log("async-bla:" + ((object[])arg4[1])[0]);
                AltAsync.Log("exists:" + arg5.Exists);
                AltAsync.Log("async-myData-2: " + arg5.Position.X + " " + arg5.MyData);
                AltAsync.Log("async-myData-4: " + myVehicles[0].Position.X + " " + myVehicles[0].MyData);
                AltAsync.Log("async-myData-3: " + arg6["test"]);
                AltAsync.Log("async-null?" + (probablyNull == null ? "y" : "n"));
                AltAsync.Log("async-null2?" + (nullArray[0] == null ? "y" : "n"));
                AltAsync.Log("async-bla2:" + bla["test"]);
            });

            Alt.Emit("event_name", "param_string_1", "param_string_2", 1, new[] { "array_1", "array_2" },
                     new object[] { "test", new[] { 1337 } }, vehicle,
                     new Dictionary <string, object>
            {
                ["test"] = "test" //,
                                  //["test2"] = new Dictionary<string, long> {["test"] = 1},
                                  //["test3"] = new Dictionary<string, long> {["test"] = 42}
            },
                     new IMyVehicle[] { (IMyVehicle)vehicle }, null, new string[] { null },
                     new Dictionary <string, object>
            {
                ["test"] = null
            });

            Alt.On <string[]>("test_string_array", s => { Alt.Log("string-array-entry-0:" + s[0]); });

            Alt.Emit("test_string_array", new object[] { new string[] { "bla" } });

            Alt.On("function_event", delegate(Function.Func func)
            {
                var result = func("parameter1");
                Alt.Log("result:" + result);
            });

            Alt.Emit("function_event", Function.Create(delegate(string bla)
            {
                Alt.Log("parameter=" + bla);
                return(42);
            }));

            foreach (var player in Alt.GetAllPlayers())
            {
            }

            foreach (var veh in Alt.GetAllVehicles())
            {
                Alt.Log("vehicle:" + veh.Position.X + " " + veh.Position.Y + " " + veh.Position.Z);
            }

            Alt.On("1337", delegate(int int1) { Alt.Log("int1:" + int1); });

            AltAsync.On("1337", delegate(int int1) { Alt.Log("int1:" + int1); });

            Alt.Emit("1337", 1);

            Alt.On <IMyVehicle>("MyServerEvent3", MyServerEventHandler2, MyServerEventParser3);

            Alt.On <IMyVehicle>("MyServerEvent3", MyServerEventHandlerAsync, MyServerEventParserAsync);

            Alt.Emit("MyServerEvent3", vehicle);

            Alt.Emit("entity-array-obj", new[] { new[] { vehicle } });

            vehicle.Remove();

            Bla();

            Alt.On <IPlayer, string>("MyEvent", MyEventHandler, MyParser);

            Alt.On <string>("MyServerEvent", MyServerEventHandler, MyServerEventParser);

            Alt.On <string>("MyServerEvent2", MyServerEventHandler, MyServerEventParser2);

            Alt.Emit("MyServerEvent", "test-custom-parser");

            Alt.Emit("MyServerEvent2", new object[] { new string[] { "test-custom-parser-array" } });

            //dynamic dynamic = new ExpandoObject();

            //Alt.Emit("dynamic_test", dynamic);

            Alt.Export("GetBla", () => { Alt.Log("GetBla called"); });

            Action action;

            Alt.Import("example", "GetBla", out action);

            action();

            Alt.Export("functionExport", delegate(string name) { Alt.Log("called with:" + name); });

            Action <string> action2;

            Alt.Import("example", "functionExport", out action2);

            action2("123");

            /*if (Alt.Import("Bla", "GetBla", out Action value))
             * {
             *  value();
             * }*/

            Alt.Emit("none-existing-event", new WritableObject());

            Alt.Emit("none-existing-event", new ConvertibleObject());

            // You need to catch this with a exception because its not possible to construct a invalid entity
            // Remember not all vehicles you receive from events has to be constructored by this constructor when there got created from different resources ect.
            // But when you don't use a entity factory you can validate that by checking if the ivehicle is a imyvehicle
            try
            {
                IMyVehicle myConstructedVehicle =
                    new MyVehicle((uint)VehicleModel.Apc, new Position(1, 1, 1), new Rotation(1, 1, 1));
            }
            catch (BaseObjectRemovedException baseObjectRemovedException)
            {
            }

            Alt.RegisterEvents(this);

            Alt.Emit("bla2", "bla");

            AltAsync.RegisterEvents(this);

            Alt.Emit("asyncBla3", "bla");

            Alt.OnColShape += (shape, entity, state) =>
            {
                Console.WriteLine("collision shape test:" + shape + " " + shape.GetData("bla", out int id1) + " " + id1);
                Console.WriteLine(" " + shape + " " + shape.GetMetaData("bla", out long id2) + " " + id2 + " " + entity + " " + state);
            };

            var colShapeCylinder = Alt.CreateColShapeCylinder(new Position(1337, 1337, 1337), 10, 10);

            colShapeCylinder.SetMetaData("bla", 1);
            colShapeCylinder.SetData("bla", (int)2);

            var colShapeCircle = Alt.CreateColShapeCircle(new Position(1337, 1337, 1337), 10);

            colShapeCircle.SetMetaData("bla", 3);
            colShapeCircle.SetData("bla", (int)4);

            AltChat.SendBroadcast("Test");

            var vehicle2 = Alt.CreateVehicle(VehicleModel.Adder, new Position(1337, 1337, 1337), Rotation.Zero);

            Alt.On <IVehicle, VehicleModel>("onEnum", OnEnum);
            Alt.Emit("onEnum", vehicle2, VehicleModel.Adder.ToString());
        }
Ejemplo n.º 23
0
 public void asyncBla3(string myString)
 {
     AltAsync.Log(myString);
 }
Ejemplo n.º 24
0
        public async Task OnConsoleCommand(string name, string[] args)
        {
            var playerPool = Alt.GetAllPlayers();

            switch (name)
            {
            case "op":
                if (args.Length is > 1 or 0)
                {
                    Alt.Log("Usage: op <ID>");
                    break;
                }

                var playerOp = playerPool.FirstOrDefault(x => x.Id == int.Parse(args[0]));
                if (playerOp is not IAltPlayer playerOpAlt)
                {
                    return;
                }

                await using (var asyncContext = AsyncContext.Create())
                {
                    if (!playerOpAlt.TryToAsync(asyncContext, out var asyncPlayer))
                    {
                        return;
                    }
                    if (Misc.Operators.Any(tuple => tuple.Item1 == asyncPlayer.HardwareIdHash && tuple.Item2 == asyncPlayer.HardwareIdExHash))
                    {
                        Alt.Log($"Id {args[0]} already is an operator!");
                        break;
                    }
                    Misc.Operators.Add(new Tuple <ulong, ulong>(asyncPlayer.HardwareIdHash, asyncPlayer.HardwareIdExHash));
                    string json = JsonSerializer.Serialize(Misc.Operators);
                    await File.WriteAllTextAsync(@"Operators.json", json);

                    await asyncPlayer.EmitAsync("set_chat_state", true);

                    asyncPlayer.IsAdmin = true;
                    break;
                }

            case "deop":
                if (args.Length is > 1 or 0)
                {
                    Alt.Log("Usage: deop <ID>");
                    break;
                }
                var playerDeOp = playerPool.FirstOrDefault(x => x.Id == int.Parse(args[0]));
                if (playerDeOp is not IAltPlayer playerDeOpAlt)
                {
                    return;
                }
                await using (var asyncContext = AsyncContext.Create())
                {
                    if (!playerDeOpAlt.TryToAsync(asyncContext, out var asyncPlayer))
                    {
                        return;
                    }

                    if (!Misc.Operators.Any(tuple => tuple.Item1 == asyncPlayer.HardwareIdHash && tuple.Item2 == asyncPlayer.HardwareIdExHash))
                    {
                        AltAsync.Log($"Id {args[0]} is not an operator!");
                        break;
                    }
                    Misc.Operators.Remove(new Tuple <ulong, ulong>(asyncPlayer.HardwareIdHash, asyncPlayer.HardwareIdExHash));
                    await asyncPlayer.EmitAsync("set_chat_state", Misc.ChatState);

                    asyncPlayer.IsAdmin = false;
                    break;
                }
            }
            return;
        }
Ejemplo n.º 25
0
        public override void OnStart()
        {
            //var benchmarkRunner = new BenchmarkRunner();
            //benchmarkRunner.Run();

            long currentTraceSize = 0;

            AltTrace.OnTraceFileSizeChange += size =>
            {
                currentTraceSize = size;
            };

            Alt.OnConsoleCommand += (name, args) =>
            {
                Console.WriteLine("Command name: " + name);
                foreach (var arg in args)
                {
                    Console.WriteLine("arg:" + arg);
                }
                switch (name)
                {
                case "trace_start":
                    if (args.Length != 1)
                    {
                        Console.WriteLine("trace_start {name}");
                        return;
                    }
                    AltTrace.Start(args[0]);
                    break;

                case "trace_stop":
                    AltTrace.Stop();
                    break;

                case "trace_size":
                    Console.WriteLine("trace file size: " + currentTraceSize + " bytes");
                    break;
                }
            };

            Alt.OnServer <object[]>("array_test", objects =>
            {
                Console.WriteLine("count:" + objects.Length);
                Console.WriteLine("1:" + objects[0]);
                Console.WriteLine("3:" + objects[1]);
                Console.WriteLine("2:" + ((object[])objects[2]).Length);
                Console.WriteLine("2:" + string.Join(",", objects[1]));
                Console.WriteLine("2:" + ((object[])objects[2])[0]);
            });
            Alt.Emit("array_test", new object[] { new object[] { "test", "test4", new[] { 1337 } } });
            Alt.OnServer <object[]>("array_test2", objects =>
            {
                Console.WriteLine("count2:" + objects.Length);
                Console.WriteLine("count3:" + ((object[])objects[0])[0]);
            });
            Alt.Emit("array_test2", new object[] { new object[] { new object[] { 1337 } } });


            var mValues      = new MValueConst[1];
            var mInnerValues = new MValueConst[1];

            Alt.Core.CreateMValueInt(out mInnerValues[0], 5);
            Alt.Core.CreateMValueList(out mValues[0], mInnerValues, 1);
            Alt.Core.CreateMValueList(out var mValueList, mValues, 1);
            var mValuesListGet = mValueList.GetList();

            for (var i = 0; i < mValuesListGet.Length; i++)
            {
                Console.WriteLine("val: " + mValuesListGet[i]);
                mValuesListGet[i].Dispose();
            }

            MValueAdapters.Register(new ConvertibleObject.ConvertibleObjectAdapter());
            Alt.OnServer("convertible_test", delegate(ConvertibleObject convertible)
            {
                Console.WriteLine("convertible_test received");
                Console.WriteLine(convertible.Test);
                foreach (var t in convertible.List)
                {
                    Console.WriteLine("-" + t.Test);
                }
            });
            var convertibleObject = new ConvertibleObject();

            /*var writer = new MValueWriter2();
             * convertibleObject.GetAdapter().ToMValue(convertibleObject, writer);
             * writer.ToMValue(out var mValueFromConvertible);
             * foreach (var entry in  mValueFromConvertible.GetDictionary())
             * {
             *  Console.WriteLine("key="+ entry.Key + " =" + entry.Value.type);
             *  entry.Value.Dispose();
             * }*/

            //Console.WriteLine("obj:" + mValueFromConvertible.type + " " + mValueFromConvertible.nativePointer);
            //mValueFromConvertible.Dispose();
            Alt.Emit("convertible_test", convertibleObject);

            Alt.OnServer <string>("test", s => { Alt.Log("test=" + s); });
            //Alt.OnServer<object[]>("test", args => { Alt.Log("args=" + args[0]); });
            Alt.Emit("test", "bla");
            Alt.OnServer("bla", bla);
            Alt.OnServer <string>("bla2", bla2);
            Alt.OnServer <string, bool>("bla3", bla3);
            Alt.OnServer <string, string>("bla4", bla4);
            Alt.OnServer <IMyVehicle>("vehicleTest", myVehicle =>
            {
                Console.WriteLine("inside invoke");
                Alt.Log("myData: " + myVehicle?.MyData);
                Console.WriteLine("inside invoke2");
            });

            Console.WriteLine("vehicleTestDone");

            Alt.OnPlayerConnect         += OnPlayerConnect;
            Alt.OnPlayerDisconnect      += OnPlayerDisconnect;
            AltAsync.OnPlayerDisconnect += OnPlayerDisconnectAsync;
            Alt.OnPlayerRemove          += OnPlayerRemove;
            Alt.OnVehicleRemove         += OnVehicleRemove;
            AltAsync.OnPlayerConnect    += OnPlayerConnectAsync;
            Alt.OnConsoleCommand        += (name, args) => { };
            Alt.OnPlayerEvent           += (player, name, args) => { Alt.Log("event:" + name); };
            AltAsync.OnPlayerEvent      += (player, name, args) =>
            {
                AltAsync.Log("event:" + name);
                return(Task.CompletedTask);
            };
            AltAsync.OnServer <object[]>("bla",
                                         async args => { await AltAsync.Do(() => Alt.Log("bla with no args:" + args.Length)); });
            Alt.Emit("bla");

            var blip = Alt.CreateBlip(BlipType.Area, Position.Zero);

            blip.Color = 1;

            var checkpoint = Alt.CreateCheckpoint(CheckpointType.Cyclinder, Position.Zero, 1f, 1f, Rgba.Zero);

            Alt.Log(checkpoint.Color.ToString());

            var voiceChannel = Alt.CreateVoiceChannel(true, 10f);

            Alt.Log(voiceChannel.MaxDistance.ToString("R"));

            var vehicle = Alt.CreateVehicle(VehicleModel.Apc, new Position(1, 2, 3), new Rotation(1, 2, 3));

            vehicle.SetSyncedMetaData("test", 123);
            Alt.Log(vehicle.Position.ToString());

            /*var watch = System.Diagnostics.Stopwatch.StartNew();
            *  for (int i = 0; i < int.MaxValue; i++)
            *  {
            *   vehicle.PrimaryColor = (i % 2 == 0) ? (byte) 1 : (byte) 0;
            *  }
            *  watch.Stop();
            *  var elapsedMs = watch.Elapsed;
            *  Console.WriteLine("primaryColor took " + elapsedMs);*/
            vehicle.NumberplateText  = "AltV-C#";
            vehicle.NumberplateIndex = 2;
            vehicle.SetMod(0, 0);
            vehicle.GetMod(0);
            vehicle.GetModsCount(0);
            vehicle.Dimension       = 0;
            vehicle.LockState       = VehicleLockState.Locked;
            vehicle.PrimaryColorRgb = new Rgba
            {
                R = 1,
                G = 8,
                B = 7,
                A = 0
            };

            var(x, y, z) = vehicle.GetPosition();
            vehicle.SetPosition(1, 1, 1);
            vehicle.SetPosition((x, y, z));
            var tuple = vehicle.GetPosition();

            vehicle.SetPosition(tuple);


            Task.Factory.StartNew(() =>
                                  AltAsync.CreateVehicleBuilder(VehicleModel.Apc, new Position(1, 2, 3), new Rotation(1, 2, 3))
                                  .PrimaryColorRgb(Color.GreenYellow)
                                  .SecondaryColor(24)
                                  .NumberplateText("C#")
                                  .LockState(VehicleLockState.Locked)
                                  .Build()
                                  );

            Alt.Log("ptr:" + vehicle.NativePointer);

            Alt.Log("number-plate:" + vehicle.NumberplateText + " " + vehicle.NumberplateIndex);

            Alt.Emit("vehicleTest", vehicle);

            Alt.OnServer("event_name",
                         delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVehicle arg5,
                                  Dictionary <string, object> arg6, IMyVehicle[] myVehicles, string probablyNull, string[] nullArray,
                                  Dictionary <string, double> bla)
            {
                Alt.Log("param1:" + s);
                Alt.Log("param2:" + s1);
                Alt.Log("bla:" + ((object[])arg4[1])[0]);
                Alt.Log("myData-2: " + arg5.Position.X + " " + arg5.MyData);
                Alt.Log("myData-4-veh-array: " + myVehicles[0].Position.X + " " + myVehicles[0].MyData);
                Alt.Log("myData-3: " + arg6["test"]);
                Alt.Log("null?" + (probablyNull == null ? "y" : "n"));
                Alt.Log("null2?" + (nullArray[0] == null ? "y" : "n"));
                Alt.Log("bla2:" + bla["test"]);
            });

            Alt.OnServer <object[]>("entity-array-obj",
                                    delegate(object[] myVehicles)
            {
                Alt.Log("entity-array-obj: " + ((MyVehicle)myVehicles[0]).Position.X + " " +
                        ((MyVehicle)myVehicles[0]).MyData);
            });

            AltAsync.OnServer("event_name",
                              async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVehicle arg5,
                                             Dictionary <string, object> arg6, IMyVehicle[] myVehicles, string probablyNull, string[] nullArray,
                                             Dictionary <string, double> bla)
            {
                await Task.Delay(500);
                await AltAsync.CreateVehicle(VehicleModel.Apc, Position.Zero, new Rotation(1, 2, 3));

                AltAsync.Log("async-param1:" + s);
                AltAsync.Log("async-param2:" + s1);
                AltAsync.Log("async-bla:" + ((object[])arg4[1])[0]);
                AltAsync.Log("exists:" + arg5.Exists);
                AltAsync.Log("async-myData-2: " + arg5.Position.X + " " + arg5.MyData);
                AltAsync.Log("async-myData-4: " + myVehicles[0].Position.X + " " + myVehicles[0].MyData);
                AltAsync.Log("async-myData-3: " + arg6["test"]);
                AltAsync.Log("async-null?" + (probablyNull == null ? "y" : "n"));
                AltAsync.Log("async-null2?" + (nullArray[0] == null ? "y" : "n"));
                AltAsync.Log("async-bla2:" + bla["test"]);
            });

            Alt.Emit("event_name", "param_string_1", "param_string_2", 1, new[] { "array_1", "array_2" },
                     new object[] { "test", new[] { 1337 } }, vehicle,
                     new Dictionary <string, object>
            {
                ["test"] = "test" //,
                                  //["test2"] = new Dictionary<string, long> {["test"] = 1},
                                  //["test3"] = new Dictionary<string, long> {["test"] = 42}
            },
                     new[] { (IMyVehicle)vehicle }, null, new string[] { null },
                     new Dictionary <string, object>
            {
                ["test"] = null
            });

            Alt.OnServer <string[]>("test_string_array", s => { Alt.Log("string-array-entry-0:" + s[0]); });

            Alt.Emit("test_string_array", new object[] { new[] { "bla" } });

            Alt.OnServer("function_event", delegate(Function.Func func)
            {
                var result = func("parameter1");
                Alt.Log("result:" + result);
            });

            Alt.Emit("function_event", Function.Create(delegate(string bla)
            {
                Console.WriteLine(bla + " " + (bla == null));
                Alt.Log("parameter=" + bla);
                return(42);
            }));

            Alt.OnServer("function_event_action", delegate(Function.Func func)
            {
                var result = func("parameter1");
                Alt.Log("result:" + result);
            });

            Alt.Emit("function_event_action", Function.Create(delegate(string bla)
            {
                Console.WriteLine(bla + " " + (bla == null));
                Alt.Log("parameter=" + bla);
            }));

            foreach (var pl in Alt.GetAllPlayers())
            {
                Alt.Log("player:" + pl.Position.X + " " + pl.Position.Y + " " + pl.Position.Z);
            }

            foreach (var veh in Alt.GetAllVehicles())
            {
                Alt.Log("vehicle:" + veh.Position.X + " " + veh.Position.Y + " " + veh.Position.Z);
            }

            Alt.OnServer("1337", delegate(int int1) { Alt.Log("int1:" + int1); });

            AltAsync.OnServer("1337", delegate(int int1) { Alt.Log("int1:" + int1); });

            Alt.Emit("1337", 1);

            Alt.OnServer <IMyVehicle>("MyServerEvent3", MyServerEventHandler2, MyServerEventParser3);

            Alt.OnServer <IMyVehicle>("MyServerEvent3", MyServerEventHandlerAsync, MyServerEventParserAsync);

            Alt.Emit("MyServerEvent3", vehicle);

            Alt.Emit("entity-array-obj", new object[] { new[] { vehicle } });

            vehicle.Remove();

            Bla();

            Alt.OnClient <IPlayer, string>("MyEvent", MyEventHandler, MyParser);

            Alt.OnServer <string>("MyServerEvent", MyServerEventHandler, MyServerEventParser);

            Alt.OnServer <string>("MyServerEvent2", MyServerEventHandler, MyServerEventParser2);

            Alt.Emit("MyServerEvent", "test-custom-parser");

            Alt.Emit("MyServerEvent2", new object[] { new[] { "test-custom-parser-array" } });

            //dynamic dynamic = new ExpandoObject();

            //Alt.Emit("dynamic_test", dynamic);

            Alt.Export("GetBla", () => { Alt.Log("GetBla called"); });

            Alt.Import(Alt.Server.Resource.Name, "GetBla", out Action action);

            action();

            Alt.Export("functionExport", delegate(string name) { Alt.Log("called with:" + name); });

            Alt.Import(Alt.Server.Resource.Name, "functionExport", out Action <string> action2);

            action2("123");

            /*if (Alt.Import("Bla", "GetBla", out Action value))
             * {
             *  value();
             * }*/

            Alt.Emit("none-existing-event", new WritableObject());

            Alt.Emit("none-existing-event", new ConvertibleObject());

            // You need to catch this with a exception because its not possible to construct a invalid entity
            // Remember not all vehicles you receive from events has to be constructed by this constructor when there got created from different resources ect.
            // But when you don't use a entity factory you can validate that by checking if the ivehicle is a imyvehicle
            try
            {
                IMyVehicle unused =
                    new MyVehicle((uint)VehicleModel.Apc, new Position(1, 1, 1), new Rotation(1, 1, 1));
            }
            catch (BaseObjectRemovedException)
            {
            }

            Alt.RegisterEvents(this);

            Alt.Emit("bla2", "bla");

            AltAsync.RegisterEvents(this);

            Alt.Emit("asyncBla3", "bla");

            Alt.OnColShape += (shape, entity, state) =>
            {
                Console.WriteLine("collision shape test:" + shape + " " + shape.GetData("bla", out int id1) + " " + id1);
                Console.WriteLine(" " + shape + " " + shape.GetMetaData("bla", out long id2) + " " + id2 + " " + entity + " " + state);
            };

            var colShapeCylinder = Alt.CreateColShapeCylinder(new Position(1337, 1337, 1337), 10, 10);

            colShapeCylinder.SetMetaData("bla", 1);
            colShapeCylinder.SetData("bla", 2);

            var colShapeCircle = Alt.CreateColShapeCircle(new Position(1337, 1337, 1337), 10);

            colShapeCircle.SetMetaData("bla", 3);
            colShapeCircle.SetData("bla", 4);

            AltChat.SendBroadcast("Test");

            var vehicle2 = Alt.CreateVehicle(VehicleModel.Adder, new Position(1337, 1337, 1337), Rotation.Zero);

            Alt.OnServer <IVehicle, VehicleModel>("onEnum", OnEnum);
            Alt.Emit("onEnum", vehicle2, VehicleModel.Adder.ToString());

            Alt.OnServer("EmptyParams", TestEmptyParams);
            Alt.Emit("EmptyParams", 1, 2, 3);

            Alt.Emit("chat:message", "/dynamicArgs2 7");

            Alt.Emit("chat:message", "/dynamicArgs2 7 5 test");

            Alt.Emit("chat:message", "bla");
            Alt.Emit("chat:message", "/bla");
            Alt.Emit("chat:message", "/bla 5");
            Alt.Emit("chat:message", "/bla2 3223");
            Alt.Emit("chat:message", "/bla3 3535");
            Alt.Emit("chat:message", "/invalidCommand");
            Alt.Emit("chat:message", "/invalidCommand 3535");
            Alt.Emit("chat:message", "/defaultParamsCommand test");
            Alt.Emit("chat:message", "/defaultParamsCommand test 5");
            Alt.Emit("chat:message", "/defaultParamsCommand test 6 3");
            Alt.Emit("chat:message", "/defaultParamsCommand2 test 6 3");

            Alt.Emit("chat:message", "/bladyn 6");
            Alt.Emit("chat:message", "/bladyn 6 test");
            Alt.Emit("chat:message", "/bladyn 6 test test2");
            Alt.Emit("chat:message", "/bladyn 6 test test2 test3");

            Alt.OnServer <int, object[]>("onOptionalAndParamArray", OnOptionalAndParamArray);

            Alt.Emit("onOptionalAndParamArray", 5, 42, "test");

            Alt.CreateCheckpoint(CheckpointType.Cyclinder, Position.Zero, 50f, 50f, Rgba.Zero);

            Alt.CreateVehicle(VehicleModel.Adder, Position.Zero, Rotation.Zero);
        }
        private async Task OnPlayerDisconnect(IPlayer player, string reason)
        {
            string playerName = await player.GetNameAsync();

            AltAsync.Log(playerName + "has left the server. (" + reason + ")");
        }
Ejemplo n.º 27
0
 public override void OnStop()
 {
     AltAsync.Log("Server stopped");
 }
Ejemplo n.º 28
0
        private static async Task OnPlayerDisconnect(ReadOnlyPlayer player, IPlayer origin, string reason)
        {
            var name = await player.GetNameAsync();

            AltAsync.Log(name + " has disconnected.");
        }
 public void CustomEvent04(string str)
 {
     AltAsync.Log("customEvent04 triggered with following argument: " + str);
 }
 public override void OnStop()
 {
     AltAsync.Log("Resource \"CSharp_Examples\" has been stopped.");
 }