Пример #1
0
        public async Task ClaimVehicle <T>(T vehicle) where T : Vehicle
        {
            //T vehicle = JsonConvert.DeserializeObject<T>(vehJson);

            Client.Log($"Claiming vehicle with netId: {vehicle.NetId}");

            var vehHandle = API.NetToVeh(vehicle.NetId ?? 0);

            if (vehHandle == 0)
            {
                return;
            }

            Client.Log($"Handle found for net id: {vehHandle}");

            CitizenFX.Core.Vehicle citizenVehicle = new CitizenFX.Core.Vehicle(vehHandle);
            API.VehToNet(citizenVehicle.Handle);
            API.NetworkRegisterEntityAsNetworked(citizenVehicle.Handle);
            var netId = API.NetworkGetNetworkIdFromEntity(citizenVehicle.Handle);

            Client.Log($"Sending {vehicle.Id}");

            Server.Event(RpcEvents.CarClaim)
            .Attach(vehicle.Id)
            .Trigger();

            Client.Instance.Services.First <VehicleService>().Tracked.Add(new VehicleService.TrackedVehicle
            {
                Id    = vehicle.Id,
                Type  = typeof(T),
                NetId = vehicle.NetId ?? 0
            });

            Client.Log($"Tracked vehicle count in claim: {string.Join(", ", Client.Instance.Services.First<VehicleService>().Tracked)}");
        }
Пример #2
0
        public async Task <T> Spawn <T>(T vehToSpawn) where T : Vehicle
        {
            Client.Log($"Spawning {vehToSpawn.Id}");

            CitizenFX.Core.Vehicle spawnedVehicle = await vehToSpawn.ToCitizenVehicle();

            API.VehToNet(spawnedVehicle.Handle);
            API.NetworkRegisterEntityAsNetworked(spawnedVehicle.Handle);
            var netId = API.NetworkGetNetworkIdFromEntity(spawnedVehicle.Handle);

            //SetNetworkIdExistsOnAllMachines(netId, true);

            Client.Log($"Spawned {spawnedVehicle.Handle} with netId {netId}");

            Vehicle vehicle = spawnedVehicle;

            vehicle.Id             = vehToSpawn.Id;
            vehicle.TrackingUserId = Client.Instance.Controllers.First <UserController>().User.Id;
            vehicle.Handle         = spawnedVehicle.Handle;
            vehicle.NetId          = netId;

            Client.Log($"Sending {vehicle.Id} with event \"igi:{typeof(T).VehicleType().Name}:save\"");

            Server.Event($"igi:{typeof(T).VehicleType().Name}:save")
            .Attach(vehicle)
            .Trigger();
            //TriggerServerEvent($"igi:{typeof(T).VehicleType().Name}:save", JsonConvert.SerializeObject(vehicle, typeof(T), new JsonSerializerSettings()));

            Client.Instance.Services.First <VehicleService>().Tracked.Add(new Tuple <Type, int>(typeof(T), netId));

            return(JsonConvert.DeserializeObject <T>(JsonConvert.SerializeObject(vehicle)));
        }