Help with some code

Basically i am trying to implement lockpicks, i have added them to the store and menu however i cant get this bit of code right, i have used a part of the repair vehicle function and tried to adapt it for lockpicks but keep getting errors in the console, could anyone point me in the right direction please

I havent posted in the vrp section as theres hundreds of unanswered questions there already

The code im trying

local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")

vRP = Proxy.getInterface("vRP")
vRPclient = Tunnel.getInterface("vRP","vRP_static_menus")

local Lang = module("vrp", "lib/Lang")
local cfg = module("vrp", "cfg/base")
local lang = Lang.new(module("vrp", "cfg/lang/"..cfg.lang) or {})




--unlock vehicle
local choice_lockpick = {function(player,choice)
  local user_id = vRP.getUserId({player})
  if user_id ~= nil then
     if vRP.tryGetInventoryItem(user_id,"lockpick",1,true) then
      vRPclient.playAnim(player,{false,{task="WORLD_HUMAN_WELDING"},false})
      SetTimeout(15000, function()
        vRPclient.SetVehicleDoorsLocked(player,{7})
        vRPclient.stopAnim(player,{false})
    end
  end
end}



-- REGISTER MAIN MENU CHOICES
vRP.registerMenuBuilder({"main", function(add, data)
  local user_id = vRP.getUserId({data.player})
  if user_id ~= nil then
    local choices = {}
	
    if vRP.hasPermission({user_id,"player.lockpick"}) then
      choices["lockpick"] = choice_lockpick
    end
	
    add(choices)
  end
end})

The error

) expected to close ( at line 20

Yes im not quite sure what that means to be honest im still very much learning

I tried adding ) at end of line 20 but still the same

You need a parenthesis after end.

Can you put the code in a Pastebin and post the link here?

1 Like

https://pastebin.com/TKydnYH5

You need a parenthesis to close this:

SetTimeout(15000, function()
vRPclient.SetVehicleDoorsLocked(player,{7})
vRPclient.stopAnim(player,{false})

Thanks for the help but its still throwing the same error

What about this? I had to go through and reformat the text because it wasn’t properly indented. I think this should work, if not I’m missing something extremely obvious…

local choice_lockpick = {function(player,choice)
	local user_id = vRP.getUserId({player})

	if user_id ~= nil then
		if vRP.tryGetInventoryItem(user_id,"lockpick",1,true) then
			vRPclient.playAnim(player,{false,{task="WORLD_HUMAN_WELDING"},false})

			SetTimeout(15000, function()
				vRPclient.SetVehicleDoorsLocked(player,{7})
				vRPclient.stopAnim(player,{false})
			)
		end
	end
end}

Pretty sure you don’t need the { and } for that choice_lockpick function.

That function works fine for my loot script

I have no clue what I’m missing that’s causing the error then, sorry.

No problem thanks for the trying

Why is the function wrapped in braces? Someone correct me if wrong but, doesn’t that make “choice_lockpick” an array with one element in it (the function)?

Is where the error is at. You don’t “end” the function or close the SetTimeout call.

Yes im still getting my ahead around it to be honest but appreciate the reply could you possibly show me how it should look so then i will no for next time

Well, there’s two ways it can be done.

function someFunc()
   -- Do something
end

SetTimeout(NUMBER_HERE, someFunc)

Or

SetTimeout(NUMBER_HERE, function()
    -- Do something
end)

They both do the same thing, executing the function after the time has elapsed.

1 Like

Excuse my noobness but this still gives errors>

https://pastebin.com/pZ9k5dt9

And the errors are…?

Also, don’t use screenshots. You can just paste the errors or code right into your post. Just use the </> thingy in your posting tools.