As the title says, is it possible to use vRP/ESX functions in C#? I know vRP is written in lua, so can I use them in C#?
You can get the ESX object like normal as it’s just an event with a callback. Use the dynamic
type for the value of the callback value.
vRP won’t work.
I recall seeing someone reimplement the tunnel
stuff in C# or so though.
1 Like
There’s a hacky fix by using an export made in lua that can then be called from your C#
exports("CallVRP", function(method_name, params)
return vRP[method_name](params)
end)
for future references it is totally possibly to do GetSharedObject like esx does
first in vrp/base.lua under: vRP.user_sources = {} – user sources
Add:
AddEventHandler('vrp:getSharedVRP', function(cb)
cb(vRP)
end)
function getSharedVRP()
return vRP
end
now in vrp/client/base.lua under: Proxy.addInterface(“vRP”,tvRP)
Add:
AddEventHandler('vrp:getSharedVRP', function(cb)
cb(tvRP)
end)
function getSharedVRP()
return tvRP
end
then in c# (Example of Server sided plugin)
using System;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
namespace Server
{
public class Gta5Plugin_s : BaseScript
{
dynamic vRP;
public Gta5Plugin_s()
{
TriggerEvent("vrp:getSharedVRP", new object[] { new Action<dynamic>(vrp => { vRP = vrp; })});
EventHandlers["chatMessage"] += new Action<int, string, string>(OnChatMessage);
}
private void OnChatMessage(int src, string colour, string msg)
{
string[] args = msg.Split(' ');
if (args[0].StartsWith("/"))
{
Player player = Players[src];
CancelEvent();
switch (args[0])
{
case "/info":
var user_id = vRP.getUserId(src);
var BankDolla = vRP.getBankMoney(user_id);
player.TriggerEvent("Gta5Plugin:Client:Info", BankDolla);
break;
}
}
}
}
}
Example of C# Client sided:
using System;
using CitizenFX.Core;
using CitizenFX.Core.UI;
using static CitizenFX.Core.Native.API;
namespace Client
{
public class Gta5Plugin_c : BaseScript
{
public Gta5Plugin_c()
{
EventHandlers["Gta5Plugin:Client:Info"] += new Action<int>(Info);
}
private void Info(int Money)
{
Screen.ShowNotification($"~b~this is a test!!!~s~ {Game.Player.Name} : {Money}");
}
}
}
credits:
Me
2 Likes
Wow, thanks