搜索
开启左侧

更改提示频率

[复制链接]
赴爱 发表于 7 天前 | 显示全部楼层 |阅读模式

RegisterNetEvent('hud:server:GainStress', function(amount)
   
        local src = source
        local identifier = GetIdentifier(src)
        local newStress
        if IsWhitelisted(src) then
            return
        end
        if stressData[identifier] == nil then
            stressData[identifier] = 0
        end
        newStress = tonumber(stressData[identifier]) + amount
        if newStress <= 0 then newStress = 0 end
   
        if newStress > 100 then
            newStress = 100
        end
        stressData[identifier] = newStress
        -- ExecuteSql("UPDATE `"..Config.StressMysqlTable.."` SET stress = '"..newStress.."' WHERE identifier = '"..identifier.."'")
        TriggerClientEvent('hud:client:UpdateStress', src, newStress)
        if newStress > 0 then
            Config.Notification(Config.Notifications["GETTING_STRESSED"].message, Config.Notifications["GETTING_STRESSED"].type, true, src)
        end
    end)


回复 论坛版权

使用道具 举报

ChatGPT 发表于 7 天前 | 显示全部楼层
您提供的代码是一个用于处理压力值增加的事件,以下是带有注释的代码,并且我将会在最后指出该代码应该放置的位置。
-- 注册一个新的网络事件 'hud:server:GainStress'
RegisterNetEvent('hud:server:GainStress', function(amount)
    
    local src = source  -- 获取触发事件的玩家ID
    local identifier = GetIdentifier(src)  -- 获取玩家的唯一标识符
    local newStress  -- 声明一个变量用来存储新的压力值

    -- 如果玩家在白名单中,则不执行后续操作
    if IsWhitelisted(src) then
        return
    end
    
    -- 如果该标识符的压力值不存在,则初始化为0
    if stressData[identifier] == nil then
        stressData[identifier] = 0
    end

    -- 计算新的压力值
    newStress = tonumber(stressData[identifier]) + amount

    -- 如果新的压力值超过100,则将其限制为100
    if newStress > 100 then
        newStress = 100
    end

    -- 更新压力值数据
    stressData[identifier] = newStress

    -- 更新数据库中的压力值(当前被注释掉,可以根据需要启用)
    -- ExecuteSql("UPDATE `"..Config.StressMysqlTable.."` SET stress = '"..newStress.."' WHERE identifier = '"..identifier.."'")

    -- 触发客户端事件以更新玩家的压力值
    TriggerClientEvent('hud:client:UpdateStress', src, newStress)

    -- 如果新的压力值大于0,则发送通知给玩家
    if newStress > 0 then
        Config.Notification(Config.Notifications["GETTING_STRESSED"].message, Config.Notifications["GETTING_STRESSED"].type, true, src)
    end
end)

### 运行环境
这个代码应该放在 `server.lua` 文件中,因为它是服务器端的逻辑,处理与玩家状态相关的计算和数据库更新。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-27 21:30 , Processed in 0.292580 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

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

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