Jump to content

[Help] give vehicle


Stranger

Recommended Posts

hello,

i have a problem in this code:

addEventHandler ("onClientGUIClick", root, function () 
if source == giv then 
row, co = guiGridListGetSelectedItem(pl) 
row2, co2 = guiGridListGetSelectedItem(ve) 
select = guiGridListGetItemText(pl, row, co) 
selectt = guiGridListGetItemText(ve, row2, co2) 
if select and select ~= "" and selectt ~= "" then 
local pla = getPlayerFromName(select) 
if pla then 
triggerServerEvent ("giveH", getVehicleModelFromName (selectt), pla) 
end 
end 
end 
end) 

server side:

vehh = { } 
addEvent ("giveH", true) 
addEventHandler ("giveH", root, function (vehID, plr) 
if isElement (vehh[plr]) then 
destroyElement (vehh[plr]) 
vehh[plr] = nil 
end 
local x,y,z = getElementPosition (plr) 
vehh[plr] = createVehicle (vehID, x,y,z) 
warpPedIntoVehicle (plr, vehh[plr]) 
end) 

that when i click the button "give" the debug says:

WARNING: test\server.lua:8: Bad argument @ 'createVehicle' [Expected

number at argument 4, got nil]

WARNING: test\server.lua:9: Bad argument @ 'warpPedIntoVehicle'

so, help.

Link to comment

Your code is really messy.. I think you should try again. Well heads up on this line:

  
addEventHandler ("onClientGUIClick", root, function () 
  

root is a global variable, meaning whatever you click the function will be triggered even from another GUI.

Bad Argument at line 9 is because the vehicle wasn't created, the vehicle wasn't created (Line 8 ) because, idk.. Just really tired to focus, it must be your table data, I think.

Link to comment

Server

addEvent("giveH",true) 
addEventHandler("giveH",root, 
function(plr, vehID) 
local player = getPlayerFromName(plr or "") 
local theCurrentVehicle = getPedOccupiedVehicle(player) 
if player and theCurrentVehicle then 
    if vehID then 
    destroyElement(theCurrentVehicle) 
        local x,y,z = getElementPosition(player) 
        local rx,ry,rz = getElementRotation(player) 
        local vehicle = createVehicle(vehID,x,y,z,rx,ry,rz) 
    warpPedIntoVehicle(player, vehicle) 
    end 
end 
end) 

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