📝Editable

(SERVER) utils.lua

local Framework, frameworkName = getFramework()

function getPlayer(source)
    if frameworkName == "esx" then
        return Framework.GetPlayerFromId(source)
    else
        return Framework.Functions.GetPlayer(source)
    end
end

function addItem(Player, item, count)
    if frameworkName == "esx" then
        Player.addInventoryItem(item, count)
    else
        Player.Functions.AddItem(item, count)
    end
end

function removeItem(Player, item, count)
    if frameworkName == "esx" then
        Player.removeInventoryItem(item, count)
    else
        Player.Functions.RemoveItem(item, count)
    end
end

function registerUsableItem(itemName, callback)
    if frameworkName == "esx" then
        Framework.RegisterUsableItem(itemName, callback)
    elseif frameworkName == "qb" then
        Framework.Functions.CreateUseableItem(itemName, callback)
    end
end

function getItem(Player, item)
    if frameworkName == "esx" then
        return Player.getInventoryItem(item)
    else
        return Player.Functions.GetItemByName(item)
    end
end

function getMoney(Player, method)
    if frameworkName == "esx" then
        if method == "cash" then
            return Player.getMoney()
        else
            return Player.getAccount('bank').money
        end
    else
        if method == "cash" then
            return Player.PlayerData.money["cash"]
        else
            return Player.PlayerData.money["bank"]
        end
    end
end

function addMoney(Player, method, money)
    if frameworkName == "esx" then
        if method == "cash" then
            Player.addMoney(money)
        else
            Player.AddAccountMoney('bank', money)
        end
    else
        if method == "cash" then
            Player.Functions.AddMoney('cash', money)
        else
            Player.Functions.AddMoney('bank', money)
        end
    end
end

function removeMoney(Player, method, money)
    if frameworkName == "esx" then
        if method == "cash" then
            Player.removeMoney(money)
        else
            Player.removeAccountMoney('bank', money)
        end
    else
        if method == "cash" then
            Player.Functions.RemoveMoney("cash", money)
        else
            Player.Functions.RemoveMoney('bank', money)
        end
    end
end

function getName(identifier, Player)
    if identifier then
        if frameworkName == "esx" then
            local Info = MySQL.Sync.fetchAll("SELECT * FROM users WHERE identifier = @identifier", {["@identifier"] = identifier})
            return Info[1].firstname.." "..Info[1].lastname
        else
            if Player then 
                return Player.PlayerData.charinfo.firstname.." "..Player.PlayerData.charinfo.lastname
            else
                return "Not Found"
            end
        end
    else
        return "Not Found"
    end
end

GetJsonData = function()
    local data = LoadResourceFile(GetCurrentResourceName(), 'data.json')
    if data then
        return json.decode(data)
    else
        return {}
    end
end

(CLIENT) grounds.lua

local surfaceList = {
    -1595148316
}

function GetGroundHash()
    local coords = GetEntityCoords(PlayerPedId())
    local num = StartShapeTestCapsule(coords.x, coords.y, coords.z+4, coords.x, coords.y, coords.z-2.0, 1, 1, PlayerPedId(), 7)
    local a,b,c,d,e = GetShapeTestResultEx(num)
    return e
end

function groundIsOkay()
    local ground = GetGroundHash()
    for k,v in pairs(surfaceList) do
        if v == ground then
            return true
        end
    end
    return false
end

function getRandomGroundCoord(range)
    local ped = PlayerPedId()
    local baseCoords = GetEntityCoords(ped)
    local attempts = 0
    while attempts < 50 do
        attempts = attempts + 1
        local angle = math.random() * 2.0 * math.pi
        local radius = math.random() * range
        local x = baseCoords.x + radius * math.cos(angle)
        local y = baseCoords.y + radius * math.sin(angle)
        local _, foundZ = GetGroundZFor_3dCoord(x, y, baseCoords.z + 500.0, false)
        if foundZ ~= 0 then
            local test = StartShapeTestCapsule(x, y, foundZ+2.0, x, y, foundZ-2.0, 1, 1, ped, 7)
            local r, hit, endCoords, surfaceNormal, materialHash = GetShapeTestResultEx(test)
            for k,v in pairs(surfaceList) do
                if v == materialHash then
                    return vector3(x, y, foundZ)
                end
            end
        end
    end
    return false
end

(CLIENT) notify.lua

local Framework, frameworkName = getFramework()

surfaceList = {
    sand = {
        -1595148316
    },
    dirt = {
        1333033863,
        -1942898710,
        587194674,
        509508168,
        -1286696947,
        510490462,
        1144315879,
        -461750719,
        2128369009,
        951832588,
        -1885547121
    }
}

RegisterNetEvent('risk-metaldetector:notify')
AddEventHandler('risk-metaldetector:notify', function(msg)
    notify(msg)
end)

function notify(message, extra)
    local str = ""

    if extra then
        str = " "..extra
    end

    if frameworkName == "esx" then
        Framework.ShowNotification(getMessage(message)..str)
    else
        Framework.Functions.Notify(getMessage(message)..str)
    end
end

function getMessage(message)
    return Config.Locales[Config.Language][message] or "Message Not Found: "..message
end

function leftNotify(msg, thisFrame, beep, duration)
    AddTextEntry('rs', msg)

	if thisFrame then
		DisplayHelpTextThisFrame('rs', false)
	else
		if beep == nil then beep = true end
		BeginTextCommandDisplayHelp('rs')
		EndTextCommandDisplayHelp(0, false, beep, duration or -1)
	end
end

Last updated