Need help working lua into a C# resource

Hi there everyone!

To explain my needs, I’m using this resource for missions in game but instead of it’s own money and payment system, I would like the payment to go into the ESX money system. I have been asking for help in each resource topic but although Scammer has been very helpful, it’s clear that each resource is unable to help me work with the other resource so I need some help combining the two.

In the ESX thread, It was explained to me that this is what I needed to add to the missions resource to enable payments:

Client side:



    ESX = nil

    Citizen.CreateThread(function()
    while ESX == nil do
    TriggerEvent(‘esx:getSharedObject’, function(obj) ESX = obj end)
    Citizen.Wait(0)
    end
    end)

Server side:

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

Then at the payment command,

xPlayer.addMoney(vehPrice)

And when I asked the missions author how to do that, he explained:

Which is where I’m stuck. I added this part to the top of /server/main.lua:

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

Which is where it was explained that it should go but when I try to trigger a payment in the C# program with the code that normally goes in lua:

xPlayer.addMoney(vehPrice)

I get:

If I understand it right, I need to place that part in a lua file and call it from the C# code but I don’t know how to do that.

Could someone explain to me what I might need to do to be able to execute that lua code in the C# code?

Thanks for your time!

Hi,

I’m currently facing this problem as well. Is there any way to receive back the Shared ESX Object when using C#?

Any help is much appreciated :slight_smile:

Edit: Huh, seems like it isn’t that hard after all. If anybody cares, this is how I got the ESX shared object in my C# class:

public class Solution : BaseScript
{
    dynamic ESX;
    public Solution()
    {
        TriggerEvent("esx:getSharedObject", new object[] { new Action<dynamic>(esx => {
            ESX = esx;
        })});
    }
}

The resulting ESX object looks like this.

Thanks!

3 Likes