Jump to content

Question about GiveVehicle


isa_Khamdan

Recommended Posts

Posted

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.

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

Posted
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 

Thanks I will test it now

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

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 

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted
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 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
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) 

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

Posted
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) 

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted (edited)

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

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
It is but why do you want to type the coordinates. Just use;
local x,y,z = getElementPosition( source ) 

I don't type them on the client side there is a code that get them onguiclock

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

Where debugscript shows that error?

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

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 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
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 :/

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

Show how you created the grid list and how you used the guiGridListSetItemText function.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
        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 

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

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) 

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

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) 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
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

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

Replace:

destroyElement(vehicle) 

With:

removePedFromVehicle(thePlayer) 

Please do not PM me with scripting related question nor support, use the forums instead.

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