Jump to content

Question about GiveVehicle


isa_Khamdan

Recommended Posts

There is, the thing you have to do is as following;

-- get the player's location 
-- create the vehicle on the location and rotation (would be nice) 
-- warpPedIntoVehicle 

Thats all. :) Oh and you mind want to change the command to accept another argument; a vehicle ID.

Link to comment

is this code correct?

function createMyVehicle(vehicleid,x,y,z) 
  
    -- check all the arguments exist 
  
    if vehicleid and x and y and z then 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        warpPedIntoVehicle ( source, Vehicle ) 
  
    end 
  
end 

Link to comment
function createMyVehicle(thePlayer,vehicleid,x,y,z) 
  
    -- check all the arguments exist 
  
    if vehicleid and x and y and z then 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        warpPedIntoVehicle ( thePlayer, Vehicle ) 
  
    end 
  
end 

Link to comment
function createMyVehicle(thePlayer,vehicleid,x,y,z) 
  
    -- check all the arguments exist 
  
    if vehicleid and x and y and z then 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        warpPedIntoVehicle ( thePlayer, Vehicle ) 
  
    end 
  
end 

Pointless what you did there. Since its a command its suppose have;

function (player, command, vehicleId, x, y, z) 

Link to comment
function createMyVehicle(thePlayer,vehicleid,x,y,z) 
  
    -- check all the arguments exist 
  
    if vehicleid and x and y and z then 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        warpPedIntoVehicle ( thePlayer, Vehicle ) 
  
    end 
  
end 

Pointless what you did there. Since its a command its suppose have;

function (player, command, vehicleId, x, y, z) 

I tested it but it didn't work

Client side

function createVehicleHandler(button,state) 
  
    if button == "left" and state == "up" then 
  
  
        local row,col = guiGridListGetSelectedItem(PCSgridlist) 
  
  
  
  
        if row and col and row ~= -1 and col ~= -1 then 
  
  
            local selected = guiGridListGetItemData(PCSgridlist,row,col) 
  
  
  
  
            selected = tonumber(selected) 
  
  
  
  
            local rotz = getPedRotation(getLocalPlayer()) 
  
            local x,y,z = getElementPosition(getLocalPlayer()) 
  
            x = x 
  
            y = y  
  
  
  
            if selected and x and y and z then 
  
  
                triggerServerEvent("createVehicleFromGUI",getRootElement(),selected,x,y,z) 
  
  
  
                guiSetVisible(windowPCS,false) 
  
                showCursor(false,false) 
  
            else 
  
                outputChatBox("Invalid arguments.") 
  
            end 
  
        else 
  
  
            outputChatBox("Please select a vehicle.") 
  
        end 
  
    end 
  
end 

Server side

function createMyVehicle(thePlayer,vehicleid,x,y,z) 
  
    -- check all the arguments exist 
  
    if vehicleid and x and y and z then 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        warpPedIntoVehicle ( thePlayer, Vehicle ) 
  
    end 
  
end 
  
  
  
addEvent("createVehicleFromGUI",true) 
  
addEventHandler("createVehicleFromGUI",root,createMyVehicle) 

Link to comment

If it's attached to a command handler then it should be as you said.

But if it's a function to be called, my code is correct.

Edit:

Client:

function createVehicleHandler(button,state) 
  
    if button == "left" and state == "up" then 
  
  
        local row,col = guiGridListGetSelectedItem(PCSgridlist) 
  
  
  
  
        if row and col and row ~= -1 and col ~= -1 then 
  
            local selected = tonumber(guiGridListGetItemText(PCSgridlist, row, col)) 
  
  
  
            local rotz = getPedRotation(getLocalPlayer()) 
  
            local x,y,z = getElementPosition(getLocalPlayer()) 
  
            x = x 
  
            y = y 
  
  
  
            if selected and x and y and z then 
  
  
                triggerServerEvent("createVehicleFromGUI",localPlayer,selected,x,y,z) 
  
  
  
                guiSetVisible(windowPCS,false) 
  
                showCursor(false,false) 
  
            else 
  
                outputChatBox("Invalid arguments.") 
  
            end 
  
        else 
  
  
            outputChatBox("Please select a vehicle.") 
  
        end 
  
    end 
  
end 

Server:

function createMyVehicle(vehicleid,x,y,z) 
  
    -- check all the arguments exist 
  
    if vehicleid and x and y and z then 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        warpPedIntoVehicle ( source, Vehicle ) 
  
    end 
  
end 
  
  
  
addEvent("createVehicleFromGUI",true) 
  
addEventHandler("createVehicleFromGUI",root,createMyVehicle) 

Edited by Guest
Link to comment

See if 'selected' will return the vehicle ID on the chatbox.

function createVehicleHandler(button,state) 
  
    if button == "left" and state == "up" then 
  
  
        local row,col = guiGridListGetSelectedItem(PCSgridlist) 
  
  
  
  
        if row and col and row ~= -1 and col ~= -1 then 
  
            local selected = tonumber(guiGridListGetItemText(PCSgridlist, row, col)) 
            outputChatBox(selected) 
  
  
  
            local rotz = getPedRotation(getLocalPlayer()) 
  
            local x,y,z = getElementPosition(getLocalPlayer()) 
  
            x = x 
  
            y = y 
  
  
  
            if selected and x and y and z then 
  
  
                triggerServerEvent("createVehicleFromGUI",localPlayer,selected,x,y,z) 
  
  
  
                guiSetVisible(windowPCS,false) 
  
                showCursor(false,false) 
  
            else 
  
                outputChatBox("Invalid arguments.") 
  
            end 
  
        else 
  
  
            outputChatBox("Please select a vehicle.") 
  
        end 
  
    end 
  
end 

Link to comment
See if 'selected' will return the vehicle ID on the chatbox.
function createVehicleHandler(button,state) 
  
    if button == "left" and state == "up" then 
  
  
        local row,col = guiGridListGetSelectedItem(PCSgridlist) 
  
  
  
  
        if row and col and row ~= -1 and col ~= -1 then 
  
            local selected = tonumber(guiGridListGetItemText(PCSgridlist, row, col)) 
            outputChatBox(selected) 
  
  
  
            local rotz = getPedRotation(getLocalPlayer()) 
  
            local x,y,z = getElementPosition(getLocalPlayer()) 
  
            x = x 
  
            y = y 
  
  
  
            if selected and x and y and z then 
  
  
                triggerServerEvent("createVehicleFromGUI",localPlayer,selected,x,y,z) 
  
  
  
                guiSetVisible(windowPCS,false) 
  
                showCursor(false,false) 
  
            else 
  
                outputChatBox("Invalid arguments.") 
  
            end 
  
        else 
  
  
            outputChatBox("Please select a vehicle.") 
  
        end 
  
    end 
  
end 

Now it say nill and invalid argument :/

Link to comment
        PCSgridlist = guiCreateGridList(10, 54, 197, 238, false, windowPCS) 
  
        guiGridListAddColumn(PCSgridlist,"Vehicle",0.2) 
  
        guiGridListAddColumn(PCSgridlist,"Type",0.2) 
  
        guiGridListSetColumnWidth(PCSgridlist,1,0.4,true) 
  
        guiGridListSetColumnWidth(PCSgridlist,2,0.5,true) 
        populateGridlist() 

function populateGridlist() 
  
    for name,vehicle in pairs(PCSTable) do 
  
        local row = guiGridListAddRow(PCSgridlist) 
  
        guiGridListSetItemText(PCSgridlist,row,1,name,false,false) 
  
        guiGridListSetItemText(PCSgridlist,row,2,getVehicleType(vehicle),false,false) 
  
  
        guiGridListSetItemData(PCSgridlist,row,1,tostring(vehicle)) 
    end 
end 

Link to comment

I fixed it thanks for everyone who helped me :)

Edit : how can I replace the player vehicle with the new created vehicle just like the givevehicle on admin panel?

function createMyVehicle(vehicleid,x,y,z,thePlayer) 
  
    if vehicleid and x and y and z then 
  
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        if thePlayer and Vehicle then   
         warpPedIntoVehicle ( thePlayer, Vehicle ) 
  
  
       end 
    end 
  
end 
  
  
addEvent("createVehicleFromGUI",true) 
addEventHandler("createVehicleFromGUI",root,createMyVehicle) 

Link to comment

Try this:

function createMyVehicle(vehicleid,x,y,z,thePlayer) 
  
    if vehicleid and x and y and z then 
  
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        if (vehicle) then 
            destroyElement(vehicle) 
        end 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        if thePlayer and Vehicle then   
         warpPedIntoVehicle ( thePlayer, Vehicle ) 
  
  
       end 
    end 
  
end 
  
  
addEvent("createVehicleFromGUI",true) 
addEventHandler("createVehicleFromGUI",root,createMyVehicle) 

Link to comment
Try this:
function createMyVehicle(vehicleid,x,y,z,thePlayer) 
  
    if vehicleid and x and y and z then 
  
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        if (vehicle) then 
            destroyElement(vehicle) 
        end 
  
        local Vehicle = createVehicle(vehicleid,x,y,z) 
        if thePlayer and Vehicle then   
         warpPedIntoVehicle ( thePlayer, Vehicle ) 
  
  
       end 
    end 
  
end 
  
  
addEvent("createVehicleFromGUI",true) 
addEventHandler("createVehicleFromGUI",root,createMyVehicle) 

I don't want to destroy the element just replace it like how the admin givevehicle option works

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