Notifications

Two different style notifications. One is displayer on the middle right side and the other is a "toast" style notification displayed on the left side.

--- Displays a RDO style toast alert on the screen
--- @param title string
--- @param msg string
--- @param textureDict string
--- @param texture string
--- @param duration number
function ToastAlert(title, msg, textureDict, texture, duration)
    if not U.LoadTexture(textureDict) then return end
    
    local struct = U.DataView.ArrayBuffer(56)
    struct:SetInt32(0, duration or 4000)

    local structData = U.DataView.ArrayBuffer(64)
    structData:SetInt64(8, U.DataView:BigInt(VarString(10, "LITERAL_STRING", title)))
    structData:SetInt64(16, U.DataView:BigInt(VarString(10, "LITERAL_STRING", msg)))
    structData:SetInt32(24, 0)
    structData:SetInt64(32, U.DataView:BigInt(joaat(textureDict)))
    structData:SetInt64(40, U.DataView:BigInt(joaat(texture)))
    structData:SetInt64(48, U.DataView:BigInt(joaat("COLOR_WHITE")))

    -- _UI_FEED_POST_SAMPLE_TOAST
    Citizen.InvokeNative(0x26E87218390E6729, struct:Buffer(), structData:Buffer(), 1, 1)

    SetStreamedTextureDictAsNoLongerNeeded(textureDict)
end

--- Display a notification on the screen
--- @param msg string
--- @param mType string
function Notify(msg, mType)
    local textureDict = 'BLIPS'
    local texture = 'blip_mission_camp'

    if not U.LoadTexture(textureDict) then return end

    local struct = U.DataView.ArrayBuffer(56)
    struct:SetInt32(0, 3000)
    struct:SetInt64(8, U.DataView:BigInt(VarString(10, "LITERAL_STRING", "Transaction_Feed_Sounds")))
    struct:SetInt64(16, U.DataView:BigInt(VarString(10, "LITERAL_STRING", "Transaction_Positive")))

    local structData = U.DataView.ArrayBuffer(80)
    structData:SetInt64(8, U.DataView:BigInt(VarString(10, "LITERAL_STRING", msg)))
    structData:SetInt64(16, U.DataView:BigInt(VarString(10, "LITERAL_STRING", textureDict)))
    structData:SetInt64(24, U.DataView:BigInt(joaat(texture)))
    structData:SetInt64(40, U.DataView:BigInt(joaat(mType or "COLOR_WHITE")))

    -- _UI_FEED_POST_SAMPLE_TOAST_RIGHT
    Citizen.InvokeNative(0xB249EBCB30DD88E0, struct:Buffer(), structData:Buffer(), 1)

    SetStreamedTextureDictAsNoLongerNeeded(textureDict)
end

Session

This returns whether or not the player is logged into the framework. Can just return true if this doesn't apply to your framework.

--- Checks if a player is logged in
--- @return boolean
function IsLoggedIn()
    return LocalPlayer.state.IsInSession
end

Draw Text

Two different draw text functions. "DrawText3D" is only used when UIPrompts are disabled.

--- Display a timer on the screen (each frame)
--- @param msg string
function ScreenText(msg)
    local aspectRatio = 16/9
    BgSetTextScale(0.2, aspectRatio * 0.3)
    BgDisplayText(VarString(10, 'LITERAL_STRING', msg), 0.4, 0.95)
end

--- Draw 3D text in world if UIPrompts are disabled
--- @param text string
--- @param x number
--- @param y number
--- @param z number
function Draw3DText(text, x, y, z)
    local onScreen, screenX, screenY = GetScreenCoordFromWorldCoord(x, y, z)
    if not onScreen then return end

    SetTextScale(0.35, 0.35)
    SetTextFontForCurrentCommand(9)
    SetTextColor(255, 255, 255, 215)
    SetTextCentre(true)
    DisplayText(VarString(10, "LITERAL_STRING", text), screenX, screenY)
end

War Declared

This function is triggered when a gang declares war on another gang. (Executes on all clients)

--- Triggered when war is declared
--- @param attacker string
--- @param defender string
function WarDeclared(attacker, defender)
    local attackerGang = exports.gs_gangs:GetGangByName(attacker)
    local defenderGang = exports.gs_gangs:GetGangByName(defender)

    if not attackerGang or not defenderGang then return end

    TriggerEvent('chat:addMessage', {
        color = {30, 144, 255},
        multiline = true,
        args = {'SYSTEM', _('war_declared', attackerGang.label, defenderGang.label)}
    })

    -- RDO Style Toast Alert
    --ToastAlert('Arthur', _('war_declared', attackerGang.label, defenderGang.label), 'l_016e22bcpp', 'headshot_arthur')
end

Peace Declared

Similar to "War Declared" this is triggered when peace has been declared. (Executes on all clients)

--- Triggered when peace is declared
--- @param attacker string
--- @param defender string
function PeaceDeclared(attacker, defender)
    local attackerGang = exports.gs_gangs:GetGangByName(attacker)
    local defenderGang = exports.gs_gangs:GetGangByName(defender)

    if not attackerGang or not defenderGang then return end

    -- Global Chat
    TriggerEvent('chat:addMessage', {
        color = {30, 144, 255},
        multiline = true,
        args = {'SYSTEM', _('peace_declared', attackerGang.label, defenderGang.label)}
    })

    -- RDO Style Toast Alert
    --ToastAlert('Arthur', _('peace_declared', attackerGang.label, defenderGang.label), 'l_016e22bcpp', 'headshot_arthur')
end

Zone Attacked

Triggered when a zone is being attacked. (Only executes on players who are in the gang of the zone being attacked)

--- Triggered when a zone is under attack
--- @param zone string
function ZoneUnderAttack(zone)
    
end

Allowed

This checks to see if a player can interact with a zone. You can add additional logic here if you would like to restrict a players ability to interact

--- Check if a player can claim, miantain, interact with zone
--- @param zone string
--- @return boolean
function Allowed(zone)
    return not IsPedDeadOrDying(U.Cache.Ped, false) and LocalPlayer.state.Gang
end

Ped Spawned

This function is triggered when each ped is pawned (if enabled) during the robbery. You can use this to set the health, armor and accuracy.

--- Function triggered when a law man is spawned (attacker)
--- @param entity number
function AttackerPedSpawned(entity)
    SetPedAccuracy(entity, math.random(80, 98)) -- SetPedAccuracy
    SetEntityHealth(entity, math.random(200, 300)) -- SetEntityHealth
    Citizen.InvokeNative(0x4E3A0CC4, entity, math.random(100, 200)) -- SetPedArmour
end

Command

This command can be used to tell a player if they're at war and who they're at war with.

--- Gives a player a "recap" of the current conflicts their gang is involved in
RegisterCommand('wars', function()
    RecapWars(true)
end)

Last updated