Log in to reply
 

How can I delete a player's car when I reach the marker?



  • I have a code:
    if (World.GetDistance(Game.Player.Character.Position, BuyCarTaxi) < 2f && arendTaxi == false)
    {
    toolTip("Нажмите Е, чтобы арендовать такси.");

                if (e.KeyCode == Keys.E && arendTaxi == false && Game.Player.Money > 249)
                {
                    //Game.Player.Money = Game.Player.Money - 250;
                    Class1.arendTaxi = true;
                    Vehicle PlayerTaxi = World.CreateVehicle(new Model(-956048545), new Vector3(916.272f, -188.624f, 73.024f));
                    GTA.Native.Function.Call(GTA.Native.Hash.SET_PED_INTO_VEHICLE, player, PlayerTaxi, (int)GTA.VehicleSeat.Driver);
                    
    
                    UI.Notify("Вы арендовали машину. Удачной работы! ");
                   
                }
                else if (e.KeyCode==Keys.E && Game.Player.Money<249)
                {
                    UI.Notify("У вас не достаточно средств для аренды машины.");
                }
                else if (e.KeyCode == Keys.E && arendTaxi == true)
                    {
                        UI.Notify("Вы уже арендовали машину.");
                    }
                }  
            else if (World.GetDistance(Game.Player.Character.Position, BuyCarTaxi)< 2f && arendTaxi == true)
            {
                toolTip("Нажмите Е чтобы припарковать машину.");
                if (e.KeyCode == Keys.E)
                {
                   Class1.arendTaxi = false;
                   GTA.Native.Function.Call(GTA.Native.Hash.DELETE_VEHICLE,PlayerTaxi);
                }
                
            }
    

    The game gives an error and closes. What I did wrong? I understand not can..



  • This post is deleted!

  • MODERATOR

    Your indenting is all botched and I have no idea what's going on. Post a better snippet. Enclose it with these things:
    ```cs
    <your code>
    ```

    Also mentioning the error thrown would also help.

    Reformatted:

    if (World.GetDistance(Game.Player.Character.Position, BuyCarTaxi) < 2f && arendTaxi == false)
    {
    	toolTip("Нажмите Е, чтобы арендовать такси.");
    	if (e.KeyCode == Keys.E && arendTaxi == false && Game.Player.Money > 249)
    	{
    		//Game.Player.Money = Game.Player.Money - 250;
    		Class1.arendTaxi = true;
    		Vehicle PlayerTaxi = World.CreateVehicle(new Model(-956048545), new Vector3(916.272f, -188.624f, 73.024f));
    		GTA.Native.Function.Call(GTA.Native.Hash.SET_PED_INTO_VEHICLE, player, PlayerTaxi, (int)GTA.VehicleSeat.Driver);
    		
    
    		UI.Notify("Вы арендовали машину. Удачной работы! ");
    	}
    	else if (e.KeyCode==Keys.E && Game.Player.Money<249)
    	{
    		UI.Notify("У вас не достаточно средств для аренды машины.");
    	}
    	else if (e.KeyCode == Keys.E && arendTaxi == true)
    	{
    		UI.Notify("Вы уже арендовали машину.");
    	}
    }  
    else if (World.GetDistance(Game.Player.Character.Position, BuyCarTaxi)< 2f && arendTaxi == true)
    {
    	toolTip("Нажмите Е чтобы припарковать машину.");
    	if (e.KeyCode == Keys.E)
    	{
    	   Class1.arendTaxi = false;
    	   GTA.Native.Function.Call(GTA.Native.Hash.DELETE_VEHICLE,PlayerTaxi);
    	}
    }
    

    PlayerTaxi seems to be a local variable. You want to make it a class-scoped one. Right now Vehicle PlayerTaxi goes out of scope after spawning it.

    Are you aware that everything is (re)evaluated on each tick?



  • @ikt I'm new to it, and I don't know much about it yet... And I don't know what you mean... Hmm the problem is what?))


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.