vRP-framework / vRP

FiveM (http://fivem.net) RP addon/framework
https://vrp-framework.github.io/vRP
MIT License
294 stars 191 forks source link

Migration Question. #678

Closed SuelTheDev closed 1 year ago

SuelTheDev commented 1 year ago

I have some questions.

I'm migrating my scripts to vRP 2, however, researching I saw that I need to load the script in the vRP context to give access to the API, on the server side it's not a problem, but on the client side, a doubt arose, since my script will have a NUI, how do I redirect the requests, should I set the url to https://vrp/... ? But other scripts will also have UI, and is it possible to access the client side API without the vRP.loadScript?

My code.

vrp_client.lua

local Proxy = module("vrp", "lib/Proxy")
local vRP = Proxy.getInterface("vRP")
async(function ()    
    vRP.loadScript(GetCurrentResourceName(), "client/client", true)
end)

client.lua

local RESOURCE_NAME = "vrp_multichar"

local Luang = module("lib/Luang")

local Multichar = class("Multichar", vRP.Extension)

function Multichar:__construct()
    vRP.Extension.__construct(self)     
    self.luang = Luang()
    self.luang:loadLocale(vRP.cfg.lang, module(RESOURCE_NAME, "lang/" .. vRP.cfg.lang) or {})
    self.lang = self.luang.lang[vRP.cfg.lang]      
end

if vRP:isExtensionRegistered(Multichar) then
    vRP:unregisterExtension(Multichar)
end

vRP:registerExtension(Multichar)

and my fxmanifest.lua

fx_version "cerulean"
game "gta5"
shared_scripts {
   "@vrp/lib/utils.lua",
   "shared.lua",
}
client_scripts {
   "client/vrp_client.lua"
}

server_scripts {
   "server/vrp_server.lua"
}

files {
   "lang/*.lua",   
   "client/client.lua"
}

lua54 'yes'
Boss-Man-Dev commented 1 year ago

From the information I understand you can access the client side API in the normal way with SendNUIMessage, to give the server the information from a NUICallback you just need to use the tunnel functionality.

As for the loading client side the vrp_client.lua is not needed and instead inside at the top of the client.lua paste the following information.

-- init vRP server context top of client.lua Tunnel = module("vrp", "lib/Tunnel") Proxy = module("vrp", "lib/Proxy")

local cvRP = module("vrp", "client/vRP") vRP = cvRP()

local pvRP = {} -- load script in vRP context pvRP.loadScript = module Proxy.addInterface("vRP", pvRP)

if any additional information is required feel free to dm me on discord in the vrp channel