Jump to content

Spawn Custom Cars?


diaverso

Recommended Posts

Hi, I'm trying to create a script to spawn custom vehicles with a command.
I have this script: 
[Command("car")]
        public void CreateCar(Client player, string name)
        {
            try
            {
                Vector3 position = player.Position;
                Vector3 rotation = player.Rotation;
                uint veh = NAPI.Util.GetHashKey(name);
                VehicleHash veh = NAPI.Util.VehicleNameToModel(name);
                Vehicle vehicle = NAPI.Vehicle.CreateVehicle(veh, position, rotation.Z, 0, 0, "Om4n3k");
                player.SetIntoVehicle(vehicle, (int)VehicleSeat.Driver);
            }
            catch(Exception e)
            {
                player.SendNotification(e.Message);
            }
        }
 
I have the file saved as index.js

But when launching it to the server, I get this error.

K2F8Eba.png

 
Can somebody help me?
Thank you
Link to comment
Share on other sites

I don't understand, you write that you saved that code into the index.js, but the code is written on C#, then you have to choose one of the languages...

In that code you have made a mistake here:

uint veh = NAPI.Util.GetHashKey(name);
VehicleHash veh = NAPI.Util.VehicleNameToModel(name);

Two variables have the same name.

Edited by Evgeniy_Moguchiy
Link to comment
Share on other sites

6 minutes ago, Evgeniy_Moguchiy said:

uint veh = NAPI.Util.GetHashKey(name);
VehicleHash veh = NAPI.Util.VehicleNameToModel(name);

You have two variables with the same name.
Try to delete one of them.

Remove, 

Same mistake

VehicleHash veh = NAPI.Util.VehicleNameToModel(name);
Edited by diaverso
Link to comment
Share on other sites

5 hours ago, Evgeniy_Moguchiy said:

I don't understand, you write that you saved that code into the index.js, but the code is written on C#, then you have to choose one of the languages...

In that code you have made a mistake here:


uint veh = NAPI.Util.GetHashKey(name);
VehicleHash veh = NAPI.Util.VehicleNameToModel(name);

Two variables have the same name.

 
I got confused.
But also in C # it keeps giving me errors.
Would it be easier to get it to work in js or C #?
Link to comment
Share on other sites

3 hours ago, diaverso said:
 

I got confused.
But also in C # it keeps giving me errors.
Would it be easier to get it to work in js or C #?

That question has no sense. The syntax is more or less the same (talking about the API), so it's up to the developer.

You should know which language is the one you know better.

Link to comment
Share on other sites

8 hours ago, Xabi said:

That question has no sense. The syntax is more or less the same (talking about the API), so it's up to the developer.

You should know which language is the one you know better.

 
I am new to these languages.
I wanted to make a Drift server, with custom vehicles.
To play some friends.
I found the code searching the forum, but I don't know how to make it work.
Link to comment
Share on other sites

  • 4 weeks later...

I think thats Because the "void".I am not a Programmer but as far as I know, you can only use the "void", when there ware no values you are giving the function. But you are giving the function some values. (You can try it, but I am  not sure, because I cant really Program by myself) P.S Sorry for my bad Englisch.

Link to comment
Share on other sites

You should get your hands off here and first learn JS or C# (I prefer C# over JS).

What u're trying is literally not how programming works.
Else by that C# is a language that needs to be compiled before getting executed.
You are writing C# in JS. First time I see someone trying that xd

Go watch some tutorials and try understanding.

 

Link to comment
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.
×
×
  • Create New...