Esempio n. 1
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!");
                        }
                    }));
                }
            }
        }
Esempio n. 2
0
        private void BuyCardealerVehicle([FromSource] Player _player, string _seshKey, string _vehicleModel, NetworkCallbackDelegate _networkCallback)
        {
            Utils.WriteLine("Buying Cardealer vehicle!");
            if (_seshKey == null)
            {
                Utils.WriteLine("Session key is missing!");
                return;
            }

            Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle);

            if (foundSesh == null || foundSesh.SessionKey != _seshKey)
            {
                Utils.WriteLine("Session either doesn't exist or the session key doesn't match up");
                return;
            }

            Utils.WriteLine("Searching markers");
            foreach (string key in ConfigManager.MarkerConfig.Keys)
            {
                //Find the cardealers within the markers
                if (key.ToLower().Contains("dealer"))
                {
                    foreach (string dataKey in ConfigManager.MarkerConfig[key].MarkerData.Keys)
                    {
                        if (dataKey.ToLower().Contains("vehicles"))
                        {
                            string markerDataString = JsonConvert.SerializeObject(ConfigManager.MarkerConfig[key].MarkerData[dataKey]);
                            Dictionary <string, CardealerItem> markerData = JsonConvert.DeserializeObject <Dictionary <string, CardealerItem> >(markerDataString);

                            foreach (string dataKey2 in markerData.Keys)
                            {
                                if (dataKey2.ToLower().Contains(_vehicleModel))
                                {
                                    //We have found the vehicle
                                    //We need to save the car to the garage and the garage to the database
                                    string        jsonString    = JsonConvert.SerializeObject(markerData[dataKey2]);
                                    CardealerItem cardealerItem = JsonConvert.DeserializeObject <CardealerItem>(jsonString);
                                    if (!foundSesh.selectedCharacter.BuyItem(cardealerItem.Price))
                                    {
                                        Utils.WriteLine($"Player doesn't have enough money![{foundSesh.Player.Name}]");
                                        _networkCallback(false, null);
                                        return;
                                    }
                                    int        garageID   = foundSesh.selectedCharacter.Garage.garageItems.Count + 1;
                                    GarageItem garageItem = new GarageItem(garageID, foundSesh.selectedCharacter.Id, cardealerItem.CarName, cardealerItem.CarModel, Utils.CreateVehicleNumberPlate(), false, false, new Dictionary <string, int>());
                                    if (ConfigManager.ServerConfig.RPImpound)
                                    {
                                        garageItem.setImpounded(false);
                                    }
                                    else
                                    {
                                        garageItem.setImpounded(true);
                                    }
                                    garageItem.setStored(false);
                                    foundSesh.selectedCharacter.Garage.garageItems.Add(garageItem);
                                    foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id));

                                    _networkCallback(true, JsonConvert.SerializeObject(garageItem));
                                }
                            }
                        }
                    }
                }
            }
        }