[How-to] vRP Vehicle control with GUI (Example)

Let’s start :snail:

Everything what you need is:
vRP

Step 1.
Open vrp/modules/basic_garage.lua
To the bottom of file add this:

local veh_doors = {}

and

veh_doors["Open all doors"] = {function(user_id,player,vtype,name)
	vRPclient.vc_openDoor(player, {vtype,5}) 
	vRPclient.vc_openDoor(player, {vtype,4})
	vRPclient.vc_openDoor(player, {vtype,3})
	vRPclient.vc_openDoor(player, {vtype,2})
	vRPclient.vc_openDoor(player, {vtype,1})
	vRPclient.vc_openDoor(player, {vtype,0})
end, "All doors are open, including hood and trunk"}

veh_doors["Close all doors"] = {function(user_id,player,vtype,name)
	vRPclient.vc_closeDoor(player, {vtype,5})     
	vRPclient.vc_closeDoor(player, {vtype,4})  
	vRPclient.vc_closeDoor(player, {vtype,3})  
	vRPclient.vc_closeDoor(player, {vtype,2})  
	vRPclient.vc_closeDoor(player, {vtype,1})  
	vRPclient.vc_closeDoor(player, {vtype,0})  
end, "All doors are closed, including the hood and trunk"}

Now you can open and close all vehicle doors, but how open single door?

Look at this:

veh_doors["Open hood"] = {function(user_id,player,vtype,name)
	vRPclient.vc_openDoor(player, {vtype,4})
end, "Only the hood opens"}

veh_doors["Close hood"] = {function(user_id,player,vtype,name)
	vRPclient.vc_closeDoor(player, {vtype,4})   
end, "Only the hood closes"}

Now you now how to control single door.
This is the numbering of doors:
0 - Front left
1 - Front right
2 - Rear left
3 - Rear right
4 - Hood
5 - Trunk

Step 2.
Now you need to make a button in the menu.

Add local function

local function ch_vehdoors(player,choice)
	local user_id = vRP.getUserId(player)
	if user_id ~= nil then
		-- check vehicle
		vRPclient.getNearestOwnedVehicle(player,{7},function(ok,vtype,name)
			if ok then
				-- build vehicle menu
				local menu = {name="Vehicle: Doors", css={top="75px",header_color="rgba(255,125,0,0.75)"}}
				
				for k,v in pairs(veh_doors) do 
					menu[k] = {function(player,choice) v[1](user_id,player,vtype,name) end, v[2]}
				end
				
				vRP.openMenu(player,menu)
				else
				vRPclient.notify(player,{lang.vehicle.no_owned_near()}) 
			end
		end)
	end
end

Step 3.
After you adding local function, add choices in a Menu Builder.

choices["Vehicle: Doors"] = {ch_vehdoors}

You should get something like this:

vRP.registerMenuBuilder("main", function(add, data)
	local user_id = vRP.getUserId(data.player)
	if user_id ~= nil then
		
		local choices = {}
		choices[lang.vehicle.title()] = {ch_vehicle}
		
        choices["Vehicle: Doors"] = {ch_vehdoors}

		choices[lang.vehicle.asktrunk.title()] = {ch_asktrunk}
		
		add(choices)
	end
end)

That’s all! Easily, right?

I hope this is useful to someone.
Many thanks to ImagicTheCat and other vRP developers!

Check my other tutorial:
[How-to] vRP teleport with GUI (Example)

4 Likes

Nice Tutorial!

I am currently trying to implement a vehicle extra and vehicle livery changer into the menu, it is giving me such a headache haha

Good job contaminating the only intact category with the vrp bullshit!

Besides the one made literally yesterday linked in this topic?

1 Like

have you got a download as i have tried to do all the above but cant get it to work

How can I make this a toggle rather than open all close all just trigger to open the trigger again to close