Problems utilizing events within external resources

Hi there everyone!

I am modifying the chat resource to ban people spamming chat and I’m having issues with errors that I can’t seem to resolve.

Chat resource is the default chat. the resource handling the banning is called esx_anticheat. From my understanding, I need to include the files in the resource lua that I plan on using from the external resource and I need to make sure that the external resource loads prior to chat.

My server.cfg:

start mapmanager
start spawnmanager
start sessionmanager
start fivem
start ■■■■■■■
start scoreboard
start mysql-async
start essentialmode
set mysql_debug false
start esplugin_mysql
start async
start es_admin2
start es_ui
start pNotify
start es_extended
.
.
.  Lots of resources
.
.
start esx_anticheat
.
.
. Lots of resources
.
.
start chat # moved to integrate ESX functionality into chat system.

And the chat resource.lua:

description 'chat management stuff'

ui_page 'html/index.html'

client_script 'cl_chat.lua'
server_script ''

server_scripts {
	'@esx_anticheat/config.lua',
	'@esx_anticheat/anticheat-sv.lua',
    'sv_chat.lua'
}

files {
    'html/index.html',
    'html/index.css',
    'html/config.default.js',
    'html/config.js',
    'html/App.js',
    'html/Message.js',
    'html/Suggestions.js',
    'html/vendor/vue.2.3.3.min.js',
    'html/vendor/flexboxgrid.6.3.1.min.css',
    'html/vendor/animate.3.5.2.min.css',
    'html/vendor/latofonts.css',
    'html/vendor/fonts/LatoRegular.woff2',
    'html/vendor/fonts/LatoRegular2.woff2',
    'html/vendor/fonts/LatoLight2.woff2',
    'html/vendor/fonts/LatoLight.woff2',
    'html/vendor/fonts/LatoBold.woff2',
    'html/vendor/fonts/LatoBold2.woff2',
  }

  dependencies {
	'esx_anticheat'
}

My chat’s server event:

-- Event to handle chat spam.
RegisterServerEvent('chat:handleSpam')
AddEventHandler('chat:handleSpam', function(source)
	local _source = source
	local xPlayer  = ESX.GetPlayerFromId(_source)
	print("[AntiCheat] | " ..xPlayer.name.. "["..xPlayer.identifier.. "] was banned for chatspam.")
	TriggerClientEvent('chatMessage', -1, '^3[AntiCheat]', {255, 0, 0}, "^3" ..xPlayer.name.. "^1 was banned for chatspam.")
	--DropPlayer(source, _U('drop_player_blcars_notification')..Config.Discord)
	bandata = {}
	bandata.reason = " Banned for chat spam.  If you feel this was in error, please visit our discord: discord.scotchandiron.org" -- drop/ban reason
	bandata.period = '0' -- hours, 0 for permanent
	TriggerEvent('Anticheat:AutoBan', _source, bandata)
end)

And I don’t get any errors of any sort with this. The problem is that I get a missing MYSQL on server start in my esx_anticheat:

Error resuming coroutine: @esx_anticheat/anticheat-sv.lua:485: attempt to index a nil value (global 'MySQL')
stack traceback:
	@esx_anticheat/anticheat-sv.lua:485: in function 'loadBanList'
	@esx_anticheat/anticheat-sv.lua:755: in function <@esx_anticheat/anticheat-sv.lua:751>
The BanList has been loaded successfully.
The BanListHistory has been loaded successfully.

which is calling a function using a MySQL.Async.fetchAll . This works without issue, just throws an error if I’m starting chat on server start. if I comment out my chat resource when I start the server, my anticheat loads without error during server start. Also, if I restart the anticheat after the server is running, this error doesn’t show up.

Can someone tell me what might be causing this issue?

Hello,

In your resource.lua, add :

server_scripts {
	'@mysql-async/lib/MySQL.lua'
}

Hal, first off, thanks so much for that. Secondly, I have another question. I included MySQL, then it complained about locale, so I included that. Then it complained about en.lua, which I then included, which caused it to complain… you get the idea.

My question: Do I need to include every single file in the export resource to use a single function in it? It’s complaining about files not being included that I don’t even need, they just are in other functions/events in that export resource.

Is there a way to compact this type of thing so I don’t have to include every single file separately from the export resource? I want to use this event across many resources and I would like to streamline it’s inclusion.

Thanks for your time!

So there, good question. I use very little exports because I do not need it. I would not tell you how to do :thinking:

Hi there Hal, and thanks for the reply!

I’ve found the export system to be absolutely terrible and will find another way to manage what I need.