Examples
Code Samples
Real-world examples and use cases for IF Subtitle.
Basic Examples
Simple Subtitle
lua
-- Show a basic subtitle
exports['if-subtitle']:ShowSubtitle(
'John',
'Hello! This is a test subtitle message.'
)Subtitle with Custom Color
lua
-- Speaker name in cyan
exports['if-subtitle']:ShowSubtitle(
'Sarah',
'This speaker has a custom color!',
'#00ffff'
)Subtitle with Icon
lua
-- Subtitle with rocket emoji
exports['if-subtitle']:ShowSubtitle(
'Admin',
'This subtitle has a custom icon!',
'#ffff00',
'🚀'
)Framework Integration
ESX Integration
lua
-- Create a wrapper function for dialogue
function ShowDialogue(speaker, text, color)
exports['if-subtitle']:ShowSubtitle(
speaker,
text,
color or '#ffffff',
'',
false,
'',
'fade'
)
end
-- Usage:
ShowDialogue('Shop Owner', 'Welcome to my store! What would you like to buy?', '#10b981')QBCore Integration
lua
-- In your client script
RegisterNetEvent('qb-dialogue:show')
AddEventHandler('qb-dialogue:show', function(speaker, text, avatar)
exports['if-subtitle']:ShowSubtitle(
speaker,
text,
'#ffffff',
'',
false,
avatar or '',
'fade'
)
end)
-- Trigger from anywhere:
TriggerEvent('qb-dialogue:show', 'NPC Name', 'Hello there!', 'https://example.com/npc.png')Standalone Usage
lua
-- No framework needed!
RegisterCommand('dialogue', function()
exports['if-subtitle']:ShowSubtitle(
'Narrator',
'This works without any framework!',
'#c084fc',
'📖'
)
end, false)Avatar Examples
Basic Avatar
lua
exports['if-subtitle']:ShowSubtitle(
'John Marston',
'Hello! This message has an avatar!',
'#EE0000',
'',
false,
'https://example.com/john.png'
)Multi-Character Conversation
lua
-- Create a cinematic dialogue sequence
RegisterCommand('testmulti', function()
exports['if-subtitle']:ShowSubtitle(
'John',
'Hey, how are you doing?',
'#EE0000',
'',
false,
'https://example.com/john.png'
)
Wait(2500)
exports['if-subtitle']:ShowSubtitle(
'Abigail',
'I am doing great, thanks!',
'#ff88ff',
'',
false,
'https://example.com/abigail.png'
)
Wait(2500)
exports['if-subtitle']:ShowSubtitle(
'Jack',
'Nice to see you both!',
'#88ff88',
'',
false,
'https://example.com/jack.png'
)
end, false)Animation Examples
Fade Animation (Default)
lua
exports['if-subtitle']:ShowSubtitle(
'Fade',
'This is a fade animation',
'#ffffff',
'',
false,
'',
'fade'
)Slide Animation
lua
exports['if-subtitle']:ShowSubtitle(
'Slide',
'This is a slide animation',
'#88ffff',
'',
false,
'',
'slide'
)Bounce Animation
lua
exports['if-subtitle']:ShowSubtitle(
'Bounce',
'This is a bounce animation',
'#88ff88',
'',
false,
'',
'bounce'
)Glow Animation
lua
exports['if-subtitle']:ShowSubtitle(
'Glow',
'This is a glow animation',
'#ff8888',
'',
false,
'',
'glow'
)Persistent Subtitles
Mission Objective
lua
-- Show persistent objective
exports['if-subtitle']:ShowSubtitle(
'Mission Objective',
'Find the hidden keycard to access the vault.',
'#2ecc71',
'🎯',
true -- persistent = true
)
-- Later, when objective is complete:
exports['if-subtitle']:ClearSubtitles()Server-Side Examples
Server Announcement
lua
-- Server script
RegisterCommand('announce', function(source, args)
local message = table.concat(args, ' ')
exports['if-subtitle']:ShowSubtitleToAll(
'Server',
message,
'#c084fc',
'📢',
false,
'',
'glow'
)
end, true) -- Restricted to adminsNearby Players Only
lua
-- Show subtitle to players within 50 units
RegisterCommand('shout', function(source)
local playerPed = GetPlayerPed(source)
local coords = GetEntityCoords(playerPed)
local playerName = GetPlayerName(source)
exports['if-subtitle']:ShowSubtitleNearby(
coords,
50.0,
playerName,
'Hey everyone nearby!',
'#f59e0b',
'📣'
)
end, false)Private Subtitle
lua
-- Send subtitle to specific player
RegisterCommand('whisper', function(source, args)
local targetId = tonumber(args[1])
local message = table.concat(args, ' ', 2)
local senderName = GetPlayerName(source)
exports['if-subtitle']:ShowSubtitleToPlayer(
targetId,
senderName .. ' (whispers)',
message,
'#a855f7',
'🤫'
)
end, false)Cutscene Example
Complete Cutscene System
lua
-- Client-side cutscene handler
local cutsceneData = {
{
speaker = 'Detective',
text = 'We need to investigate the crime scene.',
color = '#3b82f6',
avatar = 'https://example.com/detective.png',
delay = 3000
},
{
speaker = 'Partner',
text = 'I found something over here!',
color = '#10b981',
avatar = 'https://example.com/partner.png',
delay = 2500
},
{
speaker = 'Detective',
text = 'Good work. Bag it for evidence.',
color = '#3b82f6',
avatar = 'https://example.com/detective.png',
delay = 3000
}
}
RegisterCommand('playcutscene', function()
for _, dialogue in ipairs(cutsceneData) do
exports['if-subtitle']:ShowSubtitle(
dialogue.speaker,
dialogue.text,
dialogue.color,
'',
false,
dialogue.avatar,
'fade'
)
Wait(dialogue.delay)
end
end, false)Testing Commands
lua
-- Useful for testing all subtitle features
RegisterCommand('testsubtitle', function()
exports['if-subtitle']:ShowSubtitle('John', 'Hello! This is a test subtitle message.')
end, false)
RegisterCommand('testcolor', function()
exports['if-subtitle']:ShowSubtitle('Sarah', 'This speaker has a custom color!', '#00ffff')
end, false)
RegisterCommand('testicon', function()
exports['if-subtitle']:ShowSubtitle('Admin', 'This subtitle has a custom icon!', '#ffff00', '🚀')
end, false)
RegisterCommand('testavatar', function()
exports['if-subtitle']:ShowSubtitle('John Marston', 'Hello! This message has an avatar!', '#EE0000', '', false, 'https://example.com/avatar.png')
end, false)
RegisterCommand('clearsubtitles', function()
exports['if-subtitle']:ClearSubtitles()
end, false)Need More Examples?
Check out our Discord community for more examples shared by other developers!
Remember
Always test your subtitles on a development server first before deploying to production!
