搜索
开启左侧

翻译

[复制链接]
猪猪侠 发表于 2024-5-21 07:18:31 | 显示全部楼层 |阅读模式

if Config.EnableTwitchCommand then
    RegisterCommand(Config.TwitchCommand, function(source, args, rawCommand)
        local xPlayer = ESX.GetPlayerFromId(source)
        local length = string.len(Config.TwitchCommand)
        local message = rawCommand:sub(length + 1)
        local time = os.date(Config.DateFormat)
        playerName = xPlayer.getName()
        local twitch = twitchPermission(source)

        if twitch then
            TriggerClientEvent('chat:addMessage', -1, {
                template = '<div class="chat-message twitch"><i class="fab fa-twitch"></i> <b><span style="color: #9c70de">{0}</span>&nbsp;<span style="font-size: 14px; color: #e1e1e1;">{2}</span></b><div style="margin-top: 5px; font-weight: 300;">{1}</div></div>',
                args = { playerName, message, time }
            })
        end
    end)
end

function twitchPermission(id)
    for i, a in ipairs(Config.TwitchList) do
        for x, b in ipairs(GetPlayerIdentifiers(id)) do
            if string.lower(b) == string.lower(a) then
                return true
            end
        end
    end
end

if Config.EnableYoutubeCommand then
    RegisterCommand(Config.YoutubeCommand, function(source, args, rawCommand)
        local xPlayer = ESX.GetPlayerFromId(source)
        local length = string.len(Config.YoutubeCommand)
        local message = rawCommand:sub(length + 1)
        local time = os.date(Config.DateFormat)
        playerName = xPlayer.getName()
        local youtube = youtubePermission(source)

        if youtube then
            TriggerClientEvent('chat:addMessage', -1, {
                template = '<div class="chat-message youtube"><i class="fab fa-youtube"></i> <b><span style="color: #ff0000">{0}</span>&nbsp;<span style="font-size: 14px; color: #e1e1e1;">{2}</span></b><div style="margin-top: 5px; font-weight: 300;">{1}</div></div>',
                args = { playerName, message, time }
            })
        end
    end)
end

function youtubePermission(id)
    for i, a in ipairs(Config.YoutubeList) do
        for x, b in ipairs(GetPlayerIdentifiers(id)) do
            if string.lower(b) == string.lower(a) then
                return true
            end
        end
    end
end

if Config.EnableTwitterCommand then
    RegisterCommand(Config.TwitterCommand, function(source, args, rawCommand)
        local xPlayer = ESX.GetPlayerFromId(source)
        local length = string.len(Config.TwitterCommand)
        local message = rawCommand:sub(length + 1)
        local time = os.date(Config.DateFormat)
        playerName = xPlayer.getName()

        TriggerClientEvent('chat:addMessage', -1, {
            template = '<div class="chat-message twitter"><i class="fab fa-twitter"></i> <b><span style="color: #2aa9e0">{0}</span>&nbsp;<span style="font-size: 14px; color: #e1e1e1;">{2}</span></b><div style="margin-top: 5px; font-weight: 300;">{1}</div></div>',
            args = { playerName, message, time }
        })
    end)
end

if Config.EnablePoliceCommand then
    RegisterCommand(Config.PoliceCommand, function(source, args, rawCommand)
        local xPlayer = ESX.GetPlayerFromId(source)
        local length = string.len(Config.PoliceCommand)
        local message = rawCommand:sub(length + 1)
        local time = os.date(Config.DateFormat)
        playerName = xPlayer.getName()
        local job = xPlayer.job.name

        if job == Config.PoliceJobName then
            TriggerClientEvent('chat:addMessage', -1, {
                template = '<div class="chat-message police"><i class="fas fa-bullhorn"></i> <b><span style="color: #4a6cfd">{0}</span>&nbsp;<span style="font-size: 14px; color: #e1e1e1;">{2}</span></b><div style="margin-top: 5px; font-weight: 300;">{1}</div></div>',
                args = { playerName, message, time }
            })
        end
    end)
end

if Config.EnableAmbulanceCommand then
    RegisterCommand(Config.AmbulanceCommand, function(source, args, rawCommand)
        local xPlayer = ESX.GetPlayerFromId(source)
        local length = string.len(Config.AmbulanceCommand)
        local message = rawCommand:sub(length + 1)
        local time = os.date(Config.DateFormat)
        playerName = xPlayer.getName()
        local job = xPlayer.job.name

        if job == Config.AmbulanceJobName then
            TriggerClientEvent('chat:addMessage', -1, {
                template = '<div class="chat-message ambulance"><i class="fas fa-ambulance"></i> <b><span style="color: #e3a71b">{0}</span>&nbsp;<span style="font-size: 14px; color: #e1e1e1;">{2}</span></b><div style="margin-top: 5px; font-weight: 300;">{1}</div></div>',
                args = { playerName, message, time }
            })
        end
    end)
end

if Config.EnableOOCCommand then
    RegisterCommand(Config.OOCCommand, function(source, args, rawCommand)
        local xPlayer = ESX.GetPlayerFromId(source)
        local length = string.len(Config.OOCCommand)
        local message = rawCommand:sub(length + 1)
        local time = os.date(Config.DateFormat)
        playerName = xPlayer.getName()
        TriggerClientEvent('chat:ooc', -1, source, playerName, message, time)
    end)
end

function isAdmin(xPlayer)
    for k,v in ipairs(Config.StaffGroups) do
        if xPlayer.getGroup() == v then
            return true
        end
    end
    return false
end

function showOnlyForAdmins(admins)
    for k,v in ipairs(ESX.GetPlayers()) do
        if isAdmin(ESX.GetPlayerFromId(v)) then
            admins(v)
        end
    end
end


回复 论坛版权

使用道具 举报

ChatGPT 发表于 2024-5-21 07:18:38 | 显示全部楼层
这段代码主要是用于处理玩家在聊天中输入特定指令后的操作。根据配置文件中的设置,分别包括启用 Twitch 指令、YouTube 指令、Twitter 指令、警察指令、医疗指令和OOC(跨区域聊天)指令。根据不同的指令和条件,向客户端触发聊天消息事件。

代码中包含一些函数,用于检查玩家的权限和用户组,以确定是否允许执行相应的指令操作。

此代码应该被放置在服务器端脚本文件(server.lua)中。
回复

使用道具 举报

文明发言,和谐互动
文明发言,和谐互动
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|FiveM技术教程分享 ( 冀ICP备2021005225号-1 ) |网站地图

GMT+8, 2025-5-12 05:00 , Processed in 0.097057 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2013 ELITE论坛【技术无价-分享快乐】

快速回复 返回顶部 返回列表