diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 4bfca33b..00000000 --- a/.editorconfig +++ /dev/null @@ -1,9 +0,0 @@ -root = true - -[*] -indent_size = 2 -indent_style = space -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true diff --git a/README.md b/README.md index 0e96f479..18cdf46b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,7 @@ # esx_rpchat -FXServer ESX RP Chat - #### Description -This is a proximity chat script. With a few commands such as Twitter, OOC, Local Me, and Local Do. - -#### Requirements -- [esx_identity](https://github.com/ESX-Org/esx_identity) +This is a proximity chat script. With a few commands such as Twitter, OOC and Local Me #### Download diff --git a/__resource.lua b/__resource.lua index 03ae3b2b..2c7124e9 100644 --- a/__resource.lua +++ b/__resource.lua @@ -1,20 +1,21 @@ ---[[ - - ESX RP Chat - ---]] - resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' description 'ESX RP Chat' -version '1.0.0' - -client_script 'client/main.lua' +version '1.1.0' server_scripts { - - '@mysql-async/lib/MySQL.lua', - 'server/main.lua' - + '@es_extended/locale.lua', + 'locates/sv.lua', + 'locates/en.lua', + 'config.lua', + 'server/main.lua' } + +client_scripts { + '@es_extended/locale.lua', + 'locates/sv.lua', + 'locates/en.lua', + 'config.lua', + 'client/main.lua' +} \ No newline at end of file diff --git a/client/main.lua b/client/main.lua index 4ae97c33..ac311ecc 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,38 +1,27 @@ ---[[ - - ESX RP Chat - ---]] - -RegisterNetEvent('sendProximityMessage') -AddEventHandler('sendProximityMessage', function(id, name, message) - local myId = PlayerId() - local pid = GetPlayerFromServerId(id) - if pid == myId then - TriggerEvent('chatMessage', "^4" .. name .. "", {0, 153, 204}, "^7 " .. message) - elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then - TriggerEvent('chatMessage', "^4" .. name .. "", {0, 153, 204}, "^7 " .. message) - end +RegisterNetEvent('esx_rpchat:sendProximityMessage') +AddEventHandler('esx_rpchat:sendProximityMessage', function(id, prefix, message, color) + local _source = PlayerId() + local target = GetPlayerFromServerId(id) + + if target == _source then + TriggerEvent('chatMessage', prefix, color, message) + elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(_source)), GetEntityCoords(GetPlayerPed(target)), true) < 19.999 then + TriggerEvent('chatMessage', prefix, color, message) + end end) -RegisterNetEvent('sendProximityMessageMe') -AddEventHandler('sendProximityMessageMe', function(id, name, message) - local myId = PlayerId() - local pid = GetPlayerFromServerId(id) - if pid == myId then - TriggerEvent('chatMessage', "", {255, 0, 0}, " ^6 " .. name .." ".."^6 " .. message) - elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then - TriggerEvent('chatMessage', "", {255, 0, 0}, " ^6 " .. name .." ".."^6 " .. message) - end +Citizen.CreateThread(function() + TriggerEvent('chat:addSuggestion', '/ooc', _U('ooc_help'), {{name=_U('ooc_argument_name'), help=_U('ooc_argument_help')}}) + TriggerEvent('chat:addSuggestion', '/twt', _U('twt_help'), {{name=_U('ooc_argument_name'), help=_U('ooc_argument_help')}}) + TriggerEvent('chat:addSuggestion', '/me', _U('me_help'), {{name=_U('ooc_argument_name'), help=_U('ooc_argument_help')}}) + TriggerEvent('chat:addSuggestion', '/news', _U('news_help'), {{name=_U('ooc_argument_name'), help=_U('ooc_argument_help')}}) end) -RegisterNetEvent('sendProximityMessageDo') -AddEventHandler('sendProximityMessageDo', function(id, name, message) - local myId = PlayerId() - local pid = GetPlayerFromServerId(id) - if pid == myId then - TriggerEvent('chatMessage', "", {255, 0, 0}, " ^0* " .. name .." ".."^0 " .. message) - elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then - TriggerEvent('chatMessage', "", {255, 0, 0}, " ^0* " .. name .." ".."^0 " .. message) - end -end) +AddEventHandler('onResourceStop', function(resource) + if resource == GetCurrentResourceName() then + TriggerEvent('chat:removeSuggestion', '/ooc') + TriggerEvent('chat:removeSuggestion', '/twt') + TriggerEvent('chat:removeSuggestion', '/me') + TriggerEvent('chat:removeSuggestion', '/news') + end +end) \ No newline at end of file diff --git a/config.lua b/config.lua new file mode 100644 index 00000000..ad83260a --- /dev/null +++ b/config.lua @@ -0,0 +1,2 @@ +Config = {} +Config.Locale = 'en' \ No newline at end of file diff --git a/locates/en.lua b/locates/en.lua new file mode 100644 index 00000000..23c74b14 --- /dev/null +++ b/locates/en.lua @@ -0,0 +1,14 @@ +Locales['en'] = { + -- ooc chat + ['ooc_help'] = 'type an out of character message', + ['ooc_prefix'] = 'OOC | %s', + ['twt_help'] = 'send a tweet', + ['twt_prefix'] = '^0[^4Twitter^0] (^5@%s^0)', + ['me_help'] = 'personal action', + ['me_prefix'] = 'me | %s', + ['news_help'] = 'announce news (do not abuse)', + ['news_prefix'] = 'news | %s', + ['ooc_argument_name'] = 'message', + ['ooc_argument_help'] = 'the message', + ['ooc_unknown_command'] = '^1%s^0 is not a valid command!', +} \ No newline at end of file diff --git a/locates/sv.lua b/locates/sv.lua new file mode 100644 index 00000000..09ecfee3 --- /dev/null +++ b/locates/sv.lua @@ -0,0 +1,14 @@ +Locales['sv'] = { + -- ooc chat + ['ooc_help'] = 'skicka ett meddelande som inte kopplat till din karaktär', + ['ooc_prefix'] = 'OOC | %s', + ['twt_help'] = 'skicka en tweet', + ['twt_prefix'] = '^0[^4Twitter^0] (^5@%s^0)', + ['me_help'] = 'skriv en händelse, t.ex \'visar körkort\'', + ['me_prefix'] = 'jag | %s', + ['news_help'] = 'meddela en nyhet (missbruka inte)', + ['news_prefix'] = 'TV4 Stockholm', + ['ooc_argument_name'] = 'meddelande', + ['ooc_argument_help'] = 'det meddelandet du vill skicka', + ['ooc_unknown_command'] = '^1%s^0 är inte ett giltigt kommando!', +} diff --git a/server/main.lua b/server/main.lua index 3ca33399..2e997f3c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,53 +1,23 @@ ---[[ - - ESX RP Chat - ---]] - -function getIdentity(source) - local identifier = GetPlayerIdentifiers(source)[1] - local result = MySQL.Sync.fetchAll("SELECT * FROM users WHERE identifier = @identifier", {['@identifier'] = identifier}) - if result[1] ~= nil then - local identity = result[1] - - return { - identifier = identity['identifier'], - firstname = identity['firstname'], - lastname = identity['lastname'], - dateofbirth = identity['dateofbirth'], - sex = identity['sex'], - height = identity['height'] - } - else - return nil +AddEventHandler('chatMessage', function(source, name, msg) + local command = stringsplit(msg, " ")[1]; + + if command == "/ooc" then + CancelEvent() + TriggerClientEvent('esx_rpchat:sendProximityMessage', -1, source, _U('ooc_prefix', name), string.sub(msg, 5), { 128, 128, 128 }) + elseif command == "/twt" then + CancelEvent() + 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 }) + elseif command == "/news" then + CancelEvent() + TriggerClientEvent('chatMessage', -1, _U('news_prefix', name), { 249, 166, 0 }, string.sub(msg, 6)) + elseif string.sub(command, 1, 1) == "/" then + CancelEvent() + TriggerClientEvent('chatMessage', source, '', {132, 13, 37}, _U('ooc_unknown_command', command)) end -end - - AddEventHandler('chatMessage', function(source, name, message) - if string.sub(message, 1, string.len("/")) ~= "/" then - local name = getIdentity(source) - TriggerClientEvent("sendProximityMessage", -1, source, name.firstname, message) - end - CancelEvent() - end) - - TriggerEvent('es:addCommand', 'me', function(source, args, user) - local name = getIdentity(source) - TriggerClientEvent("sendProximityMessageMe", -1, source, name.firstname, table.concat(args, " ")) - end) - - TriggerEvent('es:addCommand', 'do', function(source, args, user) - local name = getIdentity(source) - TriggerClientEvent("sendProximityMessageDo", -1, source, name.firstname, table.concat(args, " ")) - end) - - TriggerEvent('es:addCommand', 'twt', function(source, args, user) - TriggerClientEvent('chatMessage', -1, "^0[^4Twitter^0] (^5@" .. GetPlayerName(source) .. "^0)", {30, 144, 255}, table.concat(args, " ")) - end, {help = 'Send a tweet. [IC]'}) - - TriggerEvent('es:addCommand', 'ooc', function(source, args, user) - TriggerClientEvent('chatMessage', -1, "OOC | " .. GetPlayerName(source), {128, 128, 128}, table.concat(args, " ")) - end, {help = 'Send an out of character message to the whole server.'}) +end) function stringsplit(inputstr, sep) if sep == nil then @@ -59,4 +29,4 @@ function stringsplit(inputstr, sep) i = i + 1 end return t -end +end \ No newline at end of file