Jump to content

Help with CreateVehicle please


Guest NLkillya

Recommended Posts

I tried to understand Example 3 (Here) because I want to know how to script something like this. I don't understand how the name recognition works. What does "..." do and is "thePlayer" the same as "sourcePlayer" ?

I also got cunfused at the "Scripting Introduction" because when you look up CreateVehicle you see:

vehicle createVehicle ( int model, float x, float y, float z, [float rx, float ry, float rz, string numberplate] ) 

But when they are explaining it you see:

createVehicle(tonumber(vehicleModel),x,y,z) 

Wich doesn't look very similar.

Kind regards,

NLkillya

Link to comment

Try this.

function createVehicleForPlayer(thePlayer, command, vehicleModel) 
  
        local x,y,z = getElementPosition(thePlayer) -- get the position of the player 
        x = x + 2 -- add 2 units to the x position 
        local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) 
        -- check if the return value was ''false'' 
        if (createdVehicle == false) then 
                -- if so, output a message to the chatbox, but only to this player. 
                outputChatBox("Vehicle created!.",thePlayer) 
        end 
end 
addCommandHandler("spawn", createVehicleForPlayer) 

Then write in the console "spawn 522" (522 = NRG ID number)

You can try with other Vehicle ID.

Link to comment

I'm not entirely sure, but I *think* judging by the comment lines, the dots ... are telling it to recognise vehicles with more than one word in the name.

Eg.

If a vehicle were called 'My Tank', without the ...'s it wouldn't get the name right, and would try creating a vehicle based on the name 'My' which of course doesn't exsist.

With the ...'s it sees the full name, and would create 'My Tank'.

That's how I read it, but tbh I'm not entirely sure either from reading it.

(I also don't see the line createVehicle(tonumber(vehicleModel),x,y,z) mentioned anywhere on the wiki.)

Edited by Guest
Link to comment
I think you mis understood me. The script works perfectly well I just don't get what "..." is and why there's "tonumber" all of a sudden.

tonumber, no idea

the ... I can explain.

you see, most vehicles have a 1 word name such as Sultan or Trashmaster, but some have 2 words, such as the News Chopper,

but if you put the function like consoleCreateVehicle (player, vname) it only catches the first word, so if you were going to spawn a Police Maverick it would spawn a Police instead. So that's when the ... comes into work.

now you have a function like

  
function consoleCreatevehicle (player, ...) 
local vehicleName = table.concat({...}, " ") 
  

what this does is that it will catch all the paramters, and not just the first one. so now it wont only see the Police value, but also Maverick, so when you do the getVehuckeIDFromname function it will get the id of the "Police Maverick"

got it?

Link to comment

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...