I have a set of commands but the proximity doesn’t seem to be working, if anyone could help me that would be great.
Here is my server.lua:
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/dis" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^4Dispatch ^7|^4 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/do" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^1Do ^7|^1 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/run" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^3 Runs Name On ID And Runs Plate On Vehicle ^7|^3 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/sp" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^5 Searches Ped (What Do I find?) ^7|^5 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/sv" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^2 Searches Vehicle (What Comes Back?) ^7|^2 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/id" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^8Shows ID ^7|^8 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/ad" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^7[^2Advert^7] |^2 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/uber" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^7[^2Uber^7] |^2 " .. name .. '^7(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,7), source)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/dark" then
CancelEvent()
TriggerClientEvent('chatMessage', -1, "^7[^8Dark Web^7]", { 255, 0, 0 }, string.sub(msg,7), source)
end
end)
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
Here is my client.lua:
AddEventHandler('chatMessage', function(author, color, text, serverID)
local myCoords = GetEntityCoords(GetPlayerPed(-1))
local pedCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(serverID))
local dist = #(myCoords - pedCoords)
if dist > 1.5 then
return
end
local args = { text }
if author ~= "" then
table.insert(args, 1, author)
end
SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = color,
multiline = true,
args = args
}
})
end)
I want to be able to make certain commands proximity based whereas still keep some that are global.