From 3874050028a030fcb256bcd274de12cf60ca5835 Mon Sep 17 00:00:00 2001 From: nearbyplayer Date: Sun, 24 Sep 2017 15:15:11 -0400 Subject: [PATCH] chore(Upload Files) Committed on behalf of AdrineX --- .editorconfig | 9 ++++++ README.md | 32 +++++++++++++++++++- __resource.lua | 20 +++++++++++++ client/main.lua | 38 ++++++++++++++++++++++++ server/main.lua | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 __resource.lua create mode 100644 client/main.lua create mode 100644 server/main.lua diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..4bfca33b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +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 dc96414f..0e96f479 100644 --- a/README.md +++ b/README.md @@ -1 +1,31 @@ -# esx_rpchat \ No newline at end of file +# 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) + +#### Download + +**1) Using [fvm](https://github.com/qlaffont/fvm-installer)** +``` +fvm install --save --folder=esx esx-org/esx_rpchat +``` + +**2) Manually** +- Download https://github.com/ESX-Org/esx_rpchat/releases/latest +- Put it in resource/[esx] directory + +**3) Using Git** + +``` +cd resouces +git clone https://github.com/ESX-Org/esx_rpchat +``` + +#### Installation + +1) Add `start esx_rpchat` to your server.cfg \ No newline at end of file diff --git a/__resource.lua b/__resource.lua new file mode 100644 index 00000000..03ae3b2b --- /dev/null +++ b/__resource.lua @@ -0,0 +1,20 @@ +--[[ + + ESX RP Chat + +--]] + +resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' + +description 'ESX RP Chat' + +version '1.0.0' + +client_script 'client/main.lua' + +server_scripts { + + '@mysql-async/lib/MySQL.lua', + 'server/main.lua' + +} diff --git a/client/main.lua b/client/main.lua new file mode 100644 index 00000000..4ae97c33 --- /dev/null +++ b/client/main.lua @@ -0,0 +1,38 @@ +--[[ + + 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 +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 +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) diff --git a/server/main.lua b/server/main.lua new file mode 100644 index 00000000..6288f5b0 --- /dev/null +++ b/server/main.lua @@ -0,0 +1,78 @@ +--[[ + + ESX RP Chat + +--]] + +function getIdentity(source, callback) + local identifier = GetPlayerIdentifiers(source)[1] + MySQL.Async.fetchAll("SELECT * FROM `users` WHERE `identifier` = @identifier", {['@identifier'] = identifier}, + function(result) + if result[1]['firstname'] ~= nil then + local data = { + identifier = result[1]['identifier'], + firstname = result[1]['firstname'], + lastname = result[1]['lastname'], + dateofbirth = result[1]['dateofbirth'], + sex = result[1]['sex'], + height = result[1]['height'] + } + callback(data) + else + local data = { + identifier = '', + firstname = '', + lastname = '', + dateofbirth = '', + sex = '', + height = '' + } + callback(data) + end + end) +end + +AddEventHandler('chatMessage', function(source, name, message) + getIdentity(source, function(data) + if string.sub(message, 1, string.len("/")) ~= "/" then + TriggerClientEvent("sendProximityMessage", -1, source, data.firstname, message) + end + end) + CancelEvent() +end) + +TriggerEvent('es:addCommand', 'me', function(source, args, user) + table.remove(args, 1) + getIdentity(source, function(data) + TriggerClientEvent("sendProximityMessageMe", -1, source, data.firstname, table.concat(args, " ")) + end) +end) + +TriggerEvent('es:addCommand', 'do', function(source, args, user) + table.remove(args, 1) + getIdentity(source, function(data) + TriggerClientEvent("sendProximityMessageDo", -1, source, data.firstname, table.concat(args, " ")) + end) +end) + +TriggerEvent('es:addCommand', 'twt', function(source, args, user) + table.remove(args, 1) + 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) + table.remove(args, 1) + TriggerClientEvent('chatMessage', -1, "OOC | " .. GetPlayerName(source), {128, 128, 128}, table.concat(args, " ")) +end, {help = 'Send an out of character message to the whole server.'}) + +function stringsplit(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t={} ; i=1 + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + t[i] = str + i = i + 1 + end + return t +end