Sending informations from client.lua to react

Viewed 26

so recently I was using jQuery,due the old DOM , I switched to React and now I'm struggling a bit with transferring all data from jQuery to React. The problem is : I'm using LUA , and I'm making a hud for my server where when the player holds let's say a pistol the image will be displayed for a pistol , when he is unarmed the image will be a fist. Now I don't know how exactly to recreate that on React, the code is down below.

LUA CODE

SetInterval("run",150, function()
local ped = PlayerPedId()
local oldWeaponHash = nil
local currentWeaponHash = nil
local oldWeaponAmmo = nil
local oldClipAmmo = nil
    currentWeaponHash = GetSelectedPedWeapon(ped)
    oldWeaponHash = currentWeaponHash

    local weaponName = nil
    local _, maxAmmo = GetMaxAmmo(ped, currentWeaponHash)

    for _k, value in pairs(weapons) do
        if currentWeaponHash == GetHashKey(value) then
            weaponName = value
        end
    end

    if currentWeaponHash == -1569615261 or currentWeaponHash == nil  then
        SendReactMessage('pesnica') 
        SendNUIMessage({
            show2 = true, --This sends that it needs to show the fist image
            show3 = false, --Hides the weapon images.
        })
    else
        if weaponName ~= nil then
          
            local maxClipAmmo = GetMaxAmmoInClip(ped, currentWeaponHash, 1)
            local _, clipAmmo = GetAmmoInClip(ped, currentWeaponHash)
            local weaponAmmo = GetAmmoInPedWeapon(ped, currentWeaponHash)
    
            oldWeaponAmmo = weaponAmmo
            oldClipAmmo = clipAmmo
            SendNUIMessage({
                updateWeapon = true,
                show2 = false, -- hides fist
                show3 = true, -- shows the current weapon as an image thru jQuery
                weaponName = weaponName,
                maxAmmo = maxAmmo,
                maxClipAmmo = maxClipAmmo,
                clipAmmo = clipAmmo,
                weaponAmmo = weaponAmmo,
            })
            SetNuiFocus(false, false)
        end
    end

end)

jQuery code down bellow

    if (data.show2 == true) {
    var Url = `<img class="stoljpi mt-1" id ="weapon_image" src="./assets/imgs/weapons/unarmed.png" alt="">`
    $("#slike").html(Url)
    $("#slike").fadeIn("100")
} 
if (data.show2 == false) {
    var Url = `<img class="stoljpi mt-1" id ="weapon_image" src="./assets/imgs/weapons/${data.weaponName}.png" alt="">`
    $("#slike").html(Url)
}
0 Answers
Related