RedM Honor Notification System: Display Good/Bad Honor with Sound

Published on
2 mins read
--- views
RedM RDR2 Honor Notification

This snippet provides a way to display honor notifications in RedM.

Requirements

  • RedM server
  • LIB.DataView (A Dataview can be found in github)
  • Basic understanding of RedM natives

Implementation

function PlayLowHonor()
    -- Play the honor level animation effect
    AnimpostfxPlay("PlayerHonorLevelBad") -- Use "PlayerHonorLevelGood" for positive honor

    -- Create notification strings
    local str1 = Citizen.InvokeNative(0xFA925AC00EB830B9, 2, "PLAYER_HONOR_CHANGE_NEG", Citizen.ResultAsLong()) 
    local str2 = Citizen.InvokeNative(0xFA925AC00EB830B9, 10, "LITERAL_STRING", "ITEMTYPE_TEXTURES", Citizen.ResultAsLong())
    local str3 = Citizen.InvokeNative(0xFA925AC00EB830B9, 10, "LITERAL_STRING", "Honor_Display_Sounds", Citizen.ResultAsLong())
    local str4 = Citizen.InvokeNative(0xFA925AC00EB830B9, 10, "LITERAL_STRING", "Honor_Decrease_Small", Citizen.ResultAsLong())

    -- Initialize data buffers
    local charPtr0 = LIB.DataView.ArrayBuffer(16)
    charPtr0:SetInt64(0, str1)
    local charPtr1 = LIB.DataView.ArrayBuffer(16)
    charPtr1:SetInt64(0, str2)
    local charPtr2 = LIB.DataView.ArrayBuffer(16)
    charPtr2:SetInt64(0, str3)
    local charPtr3 = LIB.DataView.ArrayBuffer(16)
    charPtr3:SetInt64(0, str4)

    -- Configure notification structure
    local struct1 = LIB.DataView.ArrayBuffer(128)
    struct1:SetInt32(8 * 0, 1000)                 -- Duration
    struct1:SetInt64(8 * 1, charPtr2:GetInt64(0)) -- Sound category
    struct1:SetInt64(8 * 2, charPtr3:GetInt64(0)) -- Sound name
    struct1:SetInt32(8 * 3, 0)                    -- Additional parameters
    struct1:SetInt32(8 * 4, 0)
    struct1:SetInt32(8 * 5, 0)
    struct1:SetInt64(8 * 6, 0)                    -- Secondary subtitle
    struct1:SetInt32(8 * 7, 0)
    struct1:SetInt32(8 * 8, 0)
    struct1:SetInt32(8 * 9, 0)
    struct1:SetInt32(8 * 10, 0)
    struct1:SetInt32(8 * 11, 0)
    struct1:SetInt32(8 * 12, 0)

    -- Configure display structure
    local struct2 = LIB.DataView.ArrayBuffer(128)
    struct2:SetInt32(8 * 0, 0)                    -- Initialize
    struct2:SetInt64(8 * 1, charPtr0:GetInt64(0)) -- Title text
    struct2:SetInt64(8 * 2, charPtr1:GetInt64(0)) -- Subtitle text
    struct2:SetInt32(8 * 3, `TRANSACTION_HONOR_BAD`) -- Transaction type
    struct2:SetInt32(8 * 4, 0)                    -- Sound flag
    struct2:SetInt32(8 * 5, `COLOR_PURE_WHITE`)   -- Text color
    struct2:SetInt32(8 * 6, 0)
    struct2:SetInt32(8 * 7, 0)

    -- Display the notification
    Citizen.InvokeNative(0xB249EBCB30DD88E0, struct1:Buffer(), struct2:Buffer(), 1)
end

-- Test command
RegisterCommand("testlowhonor", function()
    PlayLowHonor()
end, false)

Join Our Community!

Get help, share ideas, get free scripts, and connect with other RedM enthusiasts in our Discord server.

Join Discord