diff --git a/README.md b/README.md index 492ed3be..bf364c90 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ git clone https://github.com/ESX-Org/esx_rpchat [esx]/esx_rpchat ### License esx_rpchat - RP chat for ESX -Copyright (C) 2015-2018 Jérémie N'gadi +Copyright (C) 2015-2020 Jérémie N'gadi This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. diff --git a/__resource.lua b/__resource.lua index 58c0093b..0685eab3 100644 --- a/__resource.lua +++ b/__resource.lua @@ -5,7 +5,6 @@ description 'ESX RP Chat' version '1.3.1' server_scripts { - '@mysql-async/lib/MySQL.lua', '@es_extended/locale.lua', 'locales/sv.lua', 'locales/en.lua', diff --git a/client/main.lua b/client/main.lua index c94a255b..5beb7495 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,22 +1,20 @@ RegisterNetEvent('esx_rpchat:sendProximityMessage') AddEventHandler('esx_rpchat:sendProximityMessage', function(playerId, title, message, color) - local source = PlayerId() + local player = PlayerId() local target = GetPlayerFromServerId(playerId) - local sourcePed, targetPed = PlayerPedId(), GetPlayerPed(target) - local sourceCoords, targetCoords = GetEntityCoords(sourcePed), GetEntityCoords(targetPed) + local playerPed, targetPed = PlayerPedId(), GetPlayerPed(target) + local playerCoords, targetCoords = GetEntityCoords(playerPed), GetEntityCoords(targetPed) - if target == source then - TriggerEvent('chat:addMessage', { args = { title, message }, color = color }) - elseif GetDistanceBetweenCoords(sourceCoords, targetCoords, true) < 20 then - TriggerEvent('chat:addMessage', { args = { title, message }, color = color }) + if target == player or #(playerCoords - targetCoords) < 20 then + TriggerEvent('chat:addMessage', {args = {title, message}, color = color}) end end) Citizen.CreateThread(function() - TriggerEvent('chat:addSuggestion', '/twt', _U('twt_help'), { { name = _U('generic_argument_name'), help = _U('generic_argument_help') } } ) - TriggerEvent('chat:addSuggestion', '/me', _U('me_help'), { { name = _U('generic_argument_name'), help = _U('generic_argument_help') } } ) - TriggerEvent('chat:addSuggestion', '/do', _U('do_help'), { { name = _U('generic_argument_name'), help = _U('generic_argument_help') } } ) + TriggerEvent('chat:addSuggestion', '/twt', _U('twt_help'), {{name = _U('generic_argument_name'), help = _U('generic_argument_help')}}) + TriggerEvent('chat:addSuggestion', '/me', _U('me_help'), {{name = _U('generic_argument_name'), help = _U('generic_argument_help')}}) + TriggerEvent('chat:addSuggestion', '/do', _U('do_help'), {{name = _U('generic_argument_name'), help = _U('generic_argument_help')}}) end) AddEventHandler('onResourceStop', function(resource) diff --git a/config.lua b/config.lua index 15e7a099..b8f2f98d 100644 --- a/config.lua +++ b/config.lua @@ -1,5 +1,4 @@ -Config = {} -Config.Locale = 'en' +Config = {} 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/locales/fi.lua b/locales/fi.lua index e85ad38b..8416d4e2 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -4,7 +4,7 @@ Locales['fi'] = { ['twt_prefix'] = '^0[^4Twitter^0] (^5@%s^0)', ['me_help'] = 'teet jotain', ['me_prefix'] = 'me | %s', - ['do_help'] = 'roolipeliä tiedot', --TODO: check translation + ['do_help'] = 'roolipeliä tiedot', ['do_prefix'] = 'do | %s', ['generic_argument_name'] = 'viesti', ['generic_argument_help'] = 'viestin sisältö', diff --git a/locales/fr.lua b/locales/fr.lua index 22ae4f93..7ae7dd6f 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -4,7 +4,7 @@ Locales['fr'] = { ['twt_prefix'] = '^0[^4Twitter^0] (^5@%s^0)', ['me_help'] = 'action personnelle', ['me_prefix'] = 'me | %s', - ['do_help'] = 'RP information', --TODO: check translation + ['do_help'] = 'RP information', ['do_prefix'] = 'faire | %s', ['generic_argument_name'] = 'message', ['generic_argument_help'] = 'le message', diff --git a/server/main.lua b/server/main.lua index 7b3ca55c..4ec542a3 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,71 +1,65 @@ AddEventHandler('es:invalidCommandHandler', function(source, command_args, user) CancelEvent() - TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', _U('unknown_command', command_args[1]) } }) + TriggerClientEvent('chat:addMessage', source, {args = {'^1SYSTEM', _U('unknown_command', command_args[1])}}) end) -AddEventHandler('chatMessage', function(source, name, message) +AddEventHandler('chatMessage', function(playerId, playerName, message) if string.sub(message, 1, string.len('/')) ~= '/' then CancelEvent() - if Config.EnableESXIdentity then name = GetCharacterName(source) end - TriggerClientEvent('chat:addMessage', -1, { args = { _U('ooc_prefix', name), message }, color = { 128, 128, 128 } }) + local xPlayer = ESX.GetPlayerFromId(playerId) + if xPlayer then playerName = xPlayer.getName() end + TriggerClientEvent('chat:addMessage', -1, {args = {_U('ooc_prefix', playerName), message}, color = {128, 128, 128}}) end end) -RegisterCommand('twt', function(source, args, rawCommand) - if source == 0 then - print('esx_rpchat: you can\'t use this command from rcon!') - return +RegisterCommand('twt', function(playerId, args, rawCommand) + if playerId == 0 then + print('esx_rpchat: you can\'t use this command from console!') + else + args = table.concat(args, ' ') + local playerName = GetRealPlayerName(playerId) + + TriggerClientEvent('chat:addMessage', -1, {args = {_U('twt_prefix', playerName), args}, color = {0, 153, 204}}) end - - args = table.concat(args, ' ') - local name = GetPlayerName(source) - if Config.EnableESXIdentity then name = GetCharacterName(source) end - - TriggerClientEvent('chat:addMessage', -1, { args = { _U('twt_prefix', name), args }, color = { 0, 153, 204 } }) - --print(('%s: %s'):format(name, args)) end, false) -RegisterCommand('me', function(source, args, rawCommand) +RegisterCommand('me', function(playerId, args, rawCommand) if source == 0 then - print('esx_rpchat: you can\'t use this command from rcon!') - return + print('esx_rpchat: you can\'t use this command from console!') + else + args = table.concat(args, ' ') + local playerName = GetRealPlayerName(playerId) + + TriggerClientEvent('esx_rpchat:sendProximityMessage', -1, source, _U('me_prefix', playerName), args, {255, 0, 0}) end - - args = table.concat(args, ' ') - local name = GetPlayerName(source) - if Config.EnableESXIdentity then name = GetCharacterName(source) end - - TriggerClientEvent('esx_rpchat:sendProximityMessage', -1, source, _U('me_prefix', name), args, { 255, 0, 0 }) - --print(('%s: %s'):format(name, args)) end, false) -RegisterCommand('do', function(source, args, rawCommand) +RegisterCommand('do', function(playerId, args, rawCommand) if source == 0 then - print('esx_rpchat: you can\'t use this command from rcon!') - return + print('esx_rpchat: you can\'t use this command from console!') + else + args = table.concat(args, ' ') + local playerName = GetRealPlayerName(playerId) + + TriggerClientEvent('esx_rpchat:sendProximityMessage', -1, source, _U('do_prefix', playerName), args, {0, 0, 255}) end - - args = table.concat(args, ' ') - local name = GetPlayerName(source) - if Config.EnableESXIdentity then name = GetCharacterName(source) end - - TriggerClientEvent('esx_rpchat:sendProximityMessage', -1, source, _U('do_prefix', name), args, { 0, 0, 255 }) - --print(('%s: %s'):format(name, args)) end, false) -function GetCharacterName(source) - local result = MySQL.Sync.fetchAll('SELECT firstname, lastname FROM users WHERE identifier = @identifier', { - ['@identifier'] = GetPlayerIdentifiers(source)[1] - }) +function GetRealPlayerName(playerId) + local xPlayer = ESX.GetPlayerFromId(playerId) - if result[1] and result[1].firstname and result[1].lastname then - if Config.OnlyFirstname then - return result[1].firstname + if xPlayer then + if Config.EnableESXIdentity then + if Config.OnlyFirstname then + return xPlayer.get('firstName') + else + return xPlayer.getName() + end else - return ('%s %s'):format(result[1].firstname, result[1].lastname) + return xPlayer.getName() end else - return GetPlayerName(source) + return GetPlayerName(playerId) end end