Danz Posted December 30, 2014 Share Posted December 30, 2014 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
ViRuZGamiing Posted December 30, 2014 Share Posted December 30, 2014 Where's the origin of carModel? Link to comment
Danz Posted December 30, 2014 Author Share Posted December 30, 2014 Oh snap, i didn't know it didn't have an Origin, can you please, post a "fix"? Link to comment
ViRuZGamiing Posted December 30, 2014 Share Posted December 30, 2014 I see you are working with GUI's so your input/origin would be something as a combobox or an editfield. Link to comment
Danz Posted December 30, 2014 Author Share Posted December 30, 2014 Actually let me post you a ScreenShot of the GUI. http://postimg.org/image/w9a9q21tn/ Yea, i need a way to detect if a Element in the Combobox is selected, and to check if that element is a vehicle, that would solve it probably. Link to comment
ViRuZGamiing Posted December 31, 2014 Share Posted December 31, 2014 Take a look at; https://wiki.multitheftauto.com/wiki/Gu ... etSelected Link to comment
Danz Posted December 31, 2014 Author Share Posted December 31, 2014 (edited) 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 December 31, 2014 by Guest Link to comment
ViRuZGamiing Posted December 31, 2014 Share Posted December 31, 2014 (edited) - Removed - My bad didn't read the above. Edited December 31, 2014 by Guest Link to comment
n3wage Posted December 31, 2014 Share Posted December 31, 2014 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
Danz Posted December 31, 2014 Author Share Posted December 31, 2014 Ugh, didn't work... why? idk. I inserted what you posted, it didn't have any errors in the debug, nor did it do anything so... Link to comment
ViRuZGamiing Posted December 31, 2014 Share Posted December 31, 2014 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
Danz Posted December 31, 2014 Author Share Posted December 31, 2014 (edited) -Deleted Post- Edited December 31, 2014 by Guest Link to comment
Mizudori Posted December 31, 2014 Share Posted December 31, 2014 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
Danz Posted December 31, 2014 Author Share Posted December 31, 2014 This worked ^^ but i cannot enter the vehicle which is kinda a problem Link to comment
Mizudori Posted December 31, 2014 Share Posted December 31, 2014 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
Danz Posted January 1, 2015 Author Share Posted January 1, 2015 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
n3wage Posted January 1, 2015 Share Posted January 1, 2015 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
Castillo Posted January 1, 2015 Share Posted January 1, 2015 "carModel" is nil, you forgot to define it on your function arguments. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now