From c56f9d21951709573550a1fefc3a8e5e70f51718 Mon Sep 17 00:00:00 2001 From: Don <30905704+ddh3@users.noreply.github.com> Date: Sun, 26 Nov 2017 23:58:41 -0800 Subject: [PATCH] Updated for ES5 --- server/main.lua | 108 +++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 62 deletions(-) diff --git a/server/main.lua b/server/main.lua index 6288f5b0..3ca33399 100644 --- a/server/main.lua +++ b/server/main.lua @@ -4,75 +4,59 @@ --]] -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) +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 + 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 + 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) - 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', '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) - table.remove(args, 1) - getIdentity(source, function(data) - TriggerClientEvent("sendProximityMessageDo", -1, source, data.firstname, table.concat(args, " ")) - end) -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) - 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', '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) - 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.'}) + 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.'}) 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 + 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