-.Paradox.- Posted April 2, 2014 Share Posted April 2, 2014 Hello, guys is it possible to spawn a vehicle by getting the vehicle Id from an edit box? Link to comment
WhoAmI Posted April 2, 2014 Share Posted April 2, 2014 But remember to create vehicles only serverside. Link to comment
Saml1er Posted April 2, 2014 Share Posted April 2, 2014 _yoBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "10", true ) local VehID = tonumber ( guiGetText ( _yoBox ) ) -- <-- < -- tonumber () will try to convert the string into a number if type (VehID) == "number" then outputChatBox ( VehID ) --<--<--< This will output the vehicle ID end Link to comment
WhoAmI Posted April 2, 2014 Share Posted April 2, 2014 It's pointless to check if the variable is number, when you converted it to number before. Link to comment
Saml1er Posted April 2, 2014 Share Posted April 2, 2014 It's pointless to check if the variable is number, when you converted it to number before. And what if someone writes "HelloWorld!10" then tonumber won't work in such case so it will give him error when he is using createVehicle. Link to comment
WhoAmI Posted April 2, 2014 Share Posted April 2, 2014 So add if: if ( VehID ) then Then it would return int, or false. Link to comment
Saml1er Posted April 2, 2014 Share Posted April 2, 2014 So add if: if ( VehID ) then Then it would return int, or false. But its not a requirement. Link to comment
cheez3d Posted April 2, 2014 Share Posted April 2, 2014 CLIENT local gui = {edit = guiCreateEdit(200,200,150,30,"",false),button = guiCreateButton(200,250,150,30,"Spawn",false)} addEventHandler("onClientGUIClick",gui.button,function() triggerServerEvent("onPlayerRequestCar",localPlayer,string.match(guiGetText(gui.edit),"[0-9]") and tonumber(guiGetText(gui.edit)) or 497) end,false) SERVER addEvent("onPlayerRequestCar",true) addEventHandler("onPlayerRequestCar",root,function(id) if id then local x,y,z = getElementPosition(client) local rx,ry,rz = getElementRotation(client) createVehicle(id,x,y,z,rx,ry,rz) end end) Link to comment
-.Paradox.- Posted April 2, 2014 Author Share Posted April 2, 2014 Thank you Cheez3D i will try it 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