Jump to content

I need help... again


Danz

Recommended Posts

Ok, so let me get into this straight away.

addEventHandler("onClientGUIClick", createVeh, cVeh) 

So here is the function:

  
function cVeh ( localPlayer, carModel ) 
    local carName = getVehicleNameFromModel ( tonumber ( carModel ) ) 
    if not carName then 
        outputChatBox ( "That is not a valid car model ID", thePlayer ) 
    else 
        createVehicle ( tonumber ( carModel ), x, y + 2, z ) 
        outputChatBox ( "A " .. carName .. " was created!" ) 
    end 
end 
  

If you understood anything, would you mind telling me what the F is wrong if i keep getting this;

WARNING: veh/client.lua:72: Bad argument @ 'getVehicleNameFromModel' [Expected number at argument 1, got nil]

Thank you.

Link to comment

EDIT AGAIN: I tried this.

function createTheVehicle (veh) 
    local x, y, z = getElementPosition (localPlayer) 
    carModel = guiComboBoxGetSelected(combo, tonumber, carName) 
    carName = getVehicleNameFromModel( carModel ) 
        if getElementType (carModel) == "vehicle" then 
            createVehicle(carModel, x, y + 2, z) 
        end 
en 

I got this: Bad argument @ 'getElementType' [Expected element at argument 1, got number '1'

Edited by Guest
Link to comment

guiComboBoxGetSelected returns the index of the selected combobox item, then you use guiComboBoxGetItemText to get the selected item text and getVehicleModelFromName to get vehicle ID from the name (obvious '-')

This should work:

function createTheVehicle (veh) 
    local x, y, z = getElementPosition (localPlayer) 
    carModel = guiComboBoxGetItemText ( combo, guiComboBoxGetSelected ( combo ) ) 
    carName = getVehicleModelFromName( carModel ) 
    createVehicle(carModel, x, y + 2, z) 
end 

Link to comment
guiComboBoxGetSelected returns the index of the selected combobox item, then you use guiComboBoxGetItemText to get the selected item text and getVehicleModelFromName to get vehicle ID from the name (obvious '-')

This should work:

function createTheVehicle (veh) 
    local x, y, z = getElementPosition (localPlayer) 
    carModel = guiComboBoxGetItemText ( combo, guiComboBoxGetSelected ( combo ) ) 
    carName = getVehicleModelFromName( carModel ) 
    createVehicle(carModel, x, y + 2, z) 
end 

Should work but add an if (carName) then should be added if the carModel isn't a vehicle carName returns false.

Removed my previous post as I didn't read what stood above it.

Regards Viruz

Link to comment

Hey man, maybe check what is in the carName var by

  
function cVeh () 
    local x, y, z = getElementPosition (localPlayer) 
    carModel = guiComboBoxGetItemText ( combo, guiComboBoxGetSelected ( combo ) ) 
    carName = getVehicleModelFromName( carModel ) 
    if (carName) then 
        outputChatBox("name: "..CarName.."Mode: "..carModel) <-- and check if this is model of vehicle which you choose on wiki site. 
        createVehicle(carModel, x, y + 2, z) 
    end 
end 
  

Link to comment

What do you mean by enter the vehicle? I think the reason of this is creating vehicle on client side.

  
If(carName) then 
 local y = y+2 
triggerServerEvent("somename",getRootElement(),carModel,x,y,z) 
end 
  
  

and creave vehicle server side with carModel var.

server side

  
function create(CarModel,x,y,z) 
  
createVehicle(CarModel,x,y,z) 
  
end 
addEvent("somename",true) 
addEventHandler("somename",getRootElement(),create) 
  

https://wiki.multitheftauto.com/wiki/CreateVehicle here is the reason why.

Note: Vehicles (and other elements) created client-side are only seen by the client that created them, aren't synced and players cannot enter them. They are essentially for display only.

Link to comment

client:

function cVeh () 
    local x, y, z = getElementPosition (source) 
    carModel = guiComboBoxGetItemText ( combo, guiComboBoxGetSelected ( combo ) ) 
    carName = getVehicleModelFromName( carModel ) 
    if (carName) then 
        triggerServerEvent("spawnvehicle", root, carModel, x, y, z) 
    end 
end 

server:

function create() 
    createVehicle(carModel, x, y, z) 
end 
addEvent("spawnvehicle", true) 
addEventHandler("spawnvehicle", root, create) 

Bad argument @ createVehicle [Expected number at argument 1, got nil]

Link to comment

Client:

function cVeh () 
    local x, y, z = getElementPosition (source) 
    carModel = guiComboBoxGetItemText ( combo, guiComboBoxGetSelected ( combo ) ) 
    carName = getVehicleModelFromName( carModel ) 
    if (carName) then 
        triggerServerEvent("spawnvehicle", root, carName, x, y, z) 
    end 
end 

server:

function create(id,x,y,z) 
    createVehicle(id, x, y, z) 
end 
addEvent("spawnvehicle", true) 
addEventHandler("spawnvehicle", root, create) 

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