From d5280f32f2c305164e24847647970059d7bbaff6 Mon Sep 17 00:00:00 2001 From: Ethan Date: Wed, 13 Apr 2022 19:06:59 +1200 Subject: [PATCH] :racehorse: /me command - Convert pairs() loop to for loop As per test 9 @ https://springrts.com/wiki/Lua_Performance#TEST_9:_for-loops --- server/commands.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index 3200e7a..67b2c8c 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -258,11 +258,13 @@ QBCore.Commands.Add('me', 'Show local message', {{name = 'message', help = 'Mess local pCoords = GetEntityCoords(ped) local msg = table.concat(args, ' ') if string.match(msg, "<") then TriggerClientEvent('QBCore:Notify', source, Lang:t('error.wrong_format'), 'error') return end - for k,v in pairs(QBCore.Functions.GetPlayers()) do - local target = GetPlayerPed(v) + local Players = QBCore.Functions.GetPlayers() + for i=1, #Players do + local Player = Players[i] + local target = GetPlayerPed(Player) local tCoords = GetEntityCoords(target) - if #(pCoords - tCoords) < 20 then - TriggerClientEvent('QBCore:Command:ShowMe3D', v, source, msg) + if target == ped or #(pCoords - tCoords) < 20 then + TriggerClientEvent('QBCore:Command:ShowMe3D', Player, source, msg) end end end, 'user')