LUA Help With /OOC

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 `

Hey.

  1. Why not use RegisterCommand()?
  2. To get the all arguments in RegisterCommand use table.concat(args, " ")
  3. Please use code blocks or Pastebin when you upload code.
Use 3 ` <-- this to get the codeblock.
  1. Good Luck

Sincerely Big Yoda.

lmao to my head that was giberish. haha

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

Didn’t that really cool guy FAXES make a tutorial video on this sort of thing but with /me?

MY Cool Deets

https://youtu.be/2IqCaZyoc8M

Well, Faxes. You kinda only sent the message to yourself, Not anyone else… :joy: :fax:

1 Like

Simple to change a source tho :stuck_out_tongue:

fuck that /me I just made only goes to myself? faxes teach me how I can make it server side.

Check what I sent a few messages up

Don’t understand that, could you make a quick /me so I know what to base off of?

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.

Thank you.

K, made my first client could you give me a base for a server side RC?

Could someone actually answer my question though? I wasn’t asking to learn new code, I was asking how to change it.

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 : "

name .. " : " .. more stuff

Just add a space to the string…

that broke it.

TriggerClientEvent("chatMessage", -1, "[OOC] " .. name .. " : " .. string.sub(msg,5))