hello, so recently I have been making /me and /ooc commands and they work perfectly but in chat it says “[OOC] Kevin M: example” when I want it to say “[OOC] Kevin M : example” with the place between the M and the :
Here Is The Server.lua
Sever.lua
3 `
AddEventHandler(‘chatMessage’, function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == “/ooc” then
CancelEvent()
TriggerClientEvent(‘chatMessage’, -1, "[OOC] " … name, {255, 165, 0}, string.sub(msg,5))
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
3 `
lol, A RegisterCommand example look like this: Works on both server & Client
Code[This example is for Server, Replace TriggerClientEvent with TriggerEvent & Remove the target for use of this from a client file]
RegisterCommand("TheCommand", function(source , args)
-- [[This code gets executed when the command is entered in chat.]]
TriggerClientEvent('chatMessage', -1, "Look at me boys, I can make a command :))", {255,255,255})
end, false)
Explainations
Source: Your Server ID
Args: Args are your arguments, First Word is args[1], Second Word is args[2] etc.
false: at the bottom of the command, If this is true, You need ‘group.admin’ in Ace Permissions to use the command
I’m not gonna feed you the code by spoon, I sent you an example of a command being registered, Asking for the code/Copy Pasting wont teach you anything
If none of that made any sense, I recommend reading the documentation, there’s a lot of useful information on there regarding scripting. I would also recommend learning basic Lua and Lua syntax before you go ahead and try to make your own code.
For a /me you would have to register a proximity event, so its only sent to those nearby. Then call that event when you register the command. Here is an example of a chat commands script.
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)`
any time you see someone registering commands server side (Excluding Essentialmode <3), that method is deprecated. All commands should go into a client side file that you mark with client_script in the __resouce.lua.
I don’t think anyone is seeing what i’m trying to do here!
" I have been making /me and /ooc commands and they work perfectly but in chat it says “[OOC] Kevin M: example” when I want it to say “[OOC] Kevin M : example” with the place between the M and the : "