genxx

Help deleting a vehicle!

Recommended Posts

Hey there,

I'm working in a job base. In that base I create a vehicle, but I don't know how to delete that vehicle!

Here is the code:

using GTANetworkAPI;
using System;
namespace TestCamionero
{
    public class Class1 : Script
    {
     
        [Command("camionero")]
        public void jobcamionero(Client player, string job)
        {
            

            switch (job)
            {
                case "empezar": //if write /camionero empezar | It's where the job starts
                    {
                        if (NAPI.Data.GetEntityData(player,"trabajocamion") == true)
                        {
                            NAPI.Chat.SendChatMessageToPlayer(player, "Ya estás trabajando"); //you're alredy working
                        }
                        else
                        {

                            NAPI.Data.SetEntityData(player,"trabajocamion", true);
                            Vehicle truck = NAPI.Vehicle.CreateVehicle(NAPI.Util.GetHashKey("terbyte"), NAPI.Entity.GetEntityPosition(player).Around(2f), 0, 0, 0, "JOB", 0, false, true);
                            NAPI.Chat.SendChatMessageToPlayer(player, "¿Ves ese camión? Bien, pues ahora mismo no te va a servir para una puta mierda porque todavía no sirve para nada");
                            
                        }
                        break;



                    }
                case "acabar": //write /camionero acabar | here is where you finish the job
                    {
                        if (NAPI.Data.GetEntityData(player, "trabajocamion") == false) 
                        {
                            NAPI.Chat.SendChatMessageToPlayer(player, "No estás trabajando"); //it says that you are not working
                        }
                        else if (NAPI.Data.GetEntityData(player,"trabajocamion") == true)
                        {
                            NAPI.Data.SetEntityData(player, "trabajocamion", false); 
                            NAPI.Chat.SendChatMessageToPlayer(player, "Has terminado tu jornada laboral") //you finished your task
							//here it was suppoused to delete te vehicle!
                        }
                        else
                        {
                           
                        }
   
                        break;
                       
                    }
                default:
                    {
                        NAPI.Chat.SendChatMessageToPlayer(player, "Introduce un valor válido (empezar, acabar)");
                        
                        break;
                    }
                 
        }
            


        }
        
    }
}

 

Share this post


Link to post
Share on other sites

I recommend that you start using an IDE like Visual Studio, at first glance I highlight an error and a suggestion, first, under the switch, the syntax is: 'case "example": break;', it doesn't have keys as you put them in your code, on the other hand, I am looking forward to if any library is missing that does not matter with the 'using' of the beginning of your code.

With regard to your doubt, you can create a dictionary with the trucks created so far and as a value the client of the player, or the other way around, in order to be able to relate them and to the player to start or finish the work, you check if it is in the dictionary or not, and if you own the truck or not, if you own it, delete it, if it is not in that dictionary, create it, greetings.

Edited by santoridev
The translate of the message was cut.

Share this post


Link to post
Share on other sites

You could either give the Vehicle a Data and then check all vehicles on the server with that data, or check if the vehicle is within a specific range.. something like:
foreach(Vehicle veh in NAPI.Pools.GetAllVehicles()){

if(veh.HasData("TEST")){

veh.Delete();

}

if(veh.Position.DistanceTo(player.Position) <= 1.0f){

veh.Delete();

}

}

Edited by bettercallpaul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.