コード例 #1
0
        private static async void BuyCardealerVehicle(dynamic _data, CallbackDelegate _callback)
        {
            Utils.WriteLine("Buying cardealer!");

            MainClient.TriggerServerEvent("Laced:BuyCardealerVehicle", PlayerSession.getSessionKey(), (string)_data.CarModel, new Action <bool, string>(async(_bought, _garageItem) => {
                if (_bought)
                {
                    Character playerCharacter = PlayerSession.getSelectedCharacter();
                    GarageItem garageItem     = JsonConvert.DeserializeObject <GarageItem>(_garageItem);
                    Utils.WriteLine("Bought item!");
                    //Loop through all the garage items to get how many of these cars the character already has
                    int vehGarageId = 0;
                    foreach (GarageItem gI in playerCharacter.Garage.garageItems)
                    {
                        if (gI.vehicleModel == garageItem.vehicleModel)
                        {
                            vehGarageId++;
                        }
                    }
                    string vehGarageIdString = "";
                    if (vehGarageId > 0)
                    {
                        vehGarageIdString = vehGarageId.ToString();
                    }
                    //After the car is added into the garage, spawn it
                    uint vehicleHash = Helpers.GetVehicleHashFromString(garageItem.vehicleModel);

                    int vehicleID = await Helpers.SpawnVehicle(vehicleHash, garageItem.vehicleNumberPlate);
                    Utils.WriteLine($"Vehicle created ID:[{vehicleID}], Vehicle networkID: [{API.NetworkGetNetworkIdFromEntity(vehicleID)}]");
                    //Create the new garage item and add it into the character garage
                    garageItem.setNetworkID(API.NetworkGetNetworkIdFromEntity(vehicleID));
                    playerCharacter.Garage.garageItems.Add(garageItem);

                    if (vehicleID != -1)
                    {
                        _ = _callback(new { ok = true });
                    }
                    else
                    {
                        _ = _callback(new { ok = false });
                    }
                }
            }));

            MainClient.GetInstance().SetNUIFocus(false, false);

            await Task.FromResult(0);
        }
コード例 #2
0
        public async static void GarageStoring(Marker _marker)
        {
            if (_marker == null)
            {
                return;
            }

            if (!Game.PlayerPed.IsInVehicle() || !Game.Player.IsAlive)
            {
                Utils.WriteLine("Not in a vehicle or dead!"); return;
            }
            await Task.FromResult(0);

            //Get the current vehicle of the character
            Vehicle plyVeh = Game.Player.Character.CurrentVehicle;

            Utils.WriteLine($"Vehicle handle:[{plyVeh.Handle}], Vehicle ID:[{plyVeh.NetworkId}]");
            //Loop through all of the characters garage items to check if the current vehicle is inside their garage
            foreach (GarageItem gI in SessionManager.PlayerSession.getSelectedCharacter().Garage.garageItems)
            {
                Utils.WriteLine($"Garage network id:[{gI.vehicleNetworkID}]");
                //If the network ID is the same between both items then we know the character has their own car
                if (gI.vehicleNetworkID == plyVeh.NetworkId)
                {
                    //Send the
                    MainClient.TriggerServerEvent("Laced:GarageStoreVehicle", SessionManager.PlayerSession.getSessionKey(), JsonConvert.SerializeObject(gI), new Action <bool>((_stored) => {
                        //Networkcallback, if the server returned with true then we can set if the car is stored and impounded
                        if (_stored)
                        {
                            GarageItem updatedItem = SessionManager.PlayerSession.getSelectedCharacter().Garage.garageItems.Find(GI => GI.garageID == gI.garageID);
                            updatedItem.setImpounded(false);
                            updatedItem.setStored(true);
                            updatedItem.setNetworkID(0);
                            plyVeh.Delete();
                        }
                        else
                        {
                            Utils.WriteLine("Something went wrong when storing the vehicle!");
                        }
                    }));
                }
            }
        }