From 95c662d0eb9cc8f3abb967bc71b98f44785ca7de Mon Sep 17 00:00:00 2001 From: nearbyplayer Date: Mon, 18 Mar 2019 22:25:38 -0400 Subject: [PATCH] Fixed #17 --- server/main.lua | 142 ++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/server/main.lua b/server/main.lua index 1398997a..7b3ca55c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,71 +1,71 @@ -AddEventHandler('es:invalidCommandHandler', function(source, command_args, user) - CancelEvent() - TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', _U('unknown_command', command_args[1]) } }) -end) - -AddEventHandler('chatMessage', function(source, name, 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 } }) - end -end) - -RegisterCommand('twt', function(source, args, rawCommand) - if source == 0 then - print('esx_rpchat: you can\'t use this command from rcon!') - return - 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) - if source == 0 then - print('esx_rpchat: you can\'t use this command from rcon!') - return - 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) - if source == 0 then - print('esx_rpchat: you can\'t use this command from rcon!') - return - 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] - }) - - if result[1] and result[1].firstname and result[1].lastname then - if Config.OnlyFirstname then - return result[1].firstname - else - return ('%s %s'):format(result[1].firstname, result[1].lastname) - end - else - return GetPlayerName(source) - end -end +AddEventHandler('es:invalidCommandHandler', function(source, command_args, user) + CancelEvent() + TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', _U('unknown_command', command_args[1]) } }) +end) + +AddEventHandler('chatMessage', function(source, name, 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 } }) + end +end) + +RegisterCommand('twt', function(source, args, rawCommand) + if source == 0 then + print('esx_rpchat: you can\'t use this command from rcon!') + return + 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) + if source == 0 then + print('esx_rpchat: you can\'t use this command from rcon!') + return + 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) + if source == 0 then + print('esx_rpchat: you can\'t use this command from rcon!') + return + 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] + }) + + if result[1] and result[1].firstname and result[1].lastname then + if Config.OnlyFirstname then + return result[1].firstname + else + return ('%s %s'):format(result[1].firstname, result[1].lastname) + end + else + return GetPlayerName(source) + end +end