diff --git a/__resource.lua b/__resource.lua index 16eccc81..308a1ca6 100644 --- a/__resource.lua +++ b/__resource.lua @@ -5,6 +5,7 @@ description 'ESX RP Chat' version '1.1.0' server_scripts { + '@mysql-async/lib/MySQL.lua', '@es_extended/locale.lua', 'locates/sv.lua', 'locates/en.lua', diff --git a/config.lua b/config.lua index ad83260a..15e7a099 100644 --- a/config.lua +++ b/config.lua @@ -1,2 +1,5 @@ Config = {} -Config.Locale = 'en' \ No newline at end of file +Config.Locale = 'en' + +Config.EnableESXIdentity = false -- only turn this on if you are using esx_identity and want to use RP names +Config.OnlyFirstname = false \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index d15d81c7..7e9334fc 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,17 +1,21 @@ AddEventHandler('chatMessage', function(source, name, msg) local command = stringsplit(msg, " ")[1]; - + if command == "/ooc" then CancelEvent() + if Config.EnableESXIdentity then name = GetCharacterName(source) end TriggerClientEvent('chatMessage', -1, _U('ooc_prefix', name), { 128, 128, 128 }, string.sub(msg, 5)) elseif command == "/twt" then CancelEvent() + if Config.EnableESXIdentity then name = GetCharacterName(source) end TriggerClientEvent('chatMessage', -1, _U('twt_prefix', name), { 0, 153, 204 }, string.sub(msg, 5)) elseif command == "/me" then CancelEvent() - TriggerClientEvent('esx_rpchat:sendProximityMessage', -1, source, _U('me_prefix', name), string.sub(msg, 5), { 255, 0, 0 }) + if Config.EnableESXIdentity then name = GetCharacterName(source) end + TriggerClientEvent('esx_rpchat:sendProximityMessage', -1, source, _U('me_prefix', name), string.sub(msg, 4), { 255, 0, 0 }) elseif command == "/news" then CancelEvent() + if Config.EnableESXIdentity then name = GetCharacterName(source) end TriggerClientEvent('chatMessage', -1, _U('news_prefix', name), { 249, 166, 0 }, string.sub(msg, 6)) elseif string.sub(command, 1, 1) == "/" then CancelEvent() @@ -29,4 +33,22 @@ function stringsplit(inputstr, sep) i = i + 1 end return t +end + +function GetCharacterName(source) + -- fetch identity in sync + local result = MySQL.Sync.fetchAll('SELECT * FROM users WHERE identifier = @identifier', + { + ['@identifier'] = GetPlayerIdentifiers(source)[1] + }) + + if result[1] ~= nil and result[1].firstname ~= nil and result[1].lastname ~= nil then + if Config.OnlyFirstname then + return result[1].firstname + else + return result[1].firstname .. ' ' .. result[1].lastname + end + else + return GetPlayerName(source) + end end \ No newline at end of file