Jump to content

create Vehicle


Recommended Posts

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

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

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