You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Lua报错unexpected symbol near ')',求排查esx_society脚本问题

ESX脚本报错:LUA unexpected symbol near ')' 原因分析

错误根源

报错指向的local society = 'society_mechanic', function(society)这一行存在严重问题:

  • 语法规则违反:Lua不允许在赋值语句后直接拼接匿名函数声明,这种混乱写法让解析器无法识别符号,直接抛出unexpected symbol near ')'错误。
  • 冗余代码误插入:行尾的, function(society)属于完全多余的内容,应该是编写或粘贴代码时的失误,把其他逻辑片段误放到此处。
  • 变量重复声明问题:就算去掉多余的function部分,这里用local society重新声明函数参数里的同名变量,会覆盖传入的参数值,逻辑上也不合理。

修正后的代码示例

RegisterServerEvent('esx_society:depositMoney')
AddEventHandler('esx_society:depositMoney', function(society, amount)
  local xPlayer = ESX.GetPlayerFromId(source)
  -- 优先使用传入的协会参数,无参数时默认使用mechanic协会
  local targetSociety = society or 'society_mechanic'

  if amount > 0 and xPlayer.get('money') >= amount then
    TriggerEvent('esx_addonaccount:getSharedAccount', targetSociety, function(account)
      xPlayer.removeMoney(amount)
      account.addMoney(amount)
    end)

    TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount))
  else
    TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
  end
end)

关键修正点

  1. 删除了语法错误的行,替换为逻辑合理的变量赋值逻辑
  2. 用新变量targetSociety避免覆盖原函数参数,同时保留默认协会的灵活性
  3. 修正了getSharedAccount的调用参数(原代码中society.account是错误用法,应直接传入协会名称字符串)

内容的提问来源于stack exchange,提问作者Chnewi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 16:24:13