Invalid Command - /me

Hi i just start and i try to make /me /do on my server and i use something like that…
For me its work find but that works on chat string not a command if i try to register this as a command they dont want to work :confused:

Client.lua

RegisterNetEvent('sendMessageMe')
AddEventHandler('sendMessageMe', function(id, name, message)
	local monid = PlayerId()
	local sonid = GetPlayerFromServerId(id)
	if sonid == monid then
		if chat then
			TriggerEvent('chatMessage', "", {255, 0, 0}, " ^6 me |1 " .. name .."  ".."^6  " .. message )
			TriggerEvent('chatMessage', "", messagesColorMe, "ID (" .. id .."):" .. message)
		end
		AddMessage('me', string.sub(message,4), messagesColorMe, PlayerPedId(), 10000)
	elseif GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), GetEntityCoords(GetPlayerPed(sonid)), true) < 7.01 and HasEntityClearLosToEntity(PlayerPedId(), GetPlayerPed(sonid), 17) == 1 then
		if chat then
			TriggerEvent('chatMessage', "", {255, 0, 0}, " ^6 me |2 " .. name .."  ".."^6  " .. message )
			TriggerEvent('chatMessage', "", messagesColorMe, "ID (" .. id .."):" .. message)
		end
		AddMessage('me', string.sub(message,4), messagesColorMe, GetPlayerPed(sonid), 10000)
	end
end)

Server.lua

AddEventHandler('chatMessage', function(source, n, msg)
  if string.find(msg,'/me') then
    CancelEvent()
	TriggerClientEvent('sendMessageOOCme', -1, source, GetPlayerName(source), string.sub(msg,4))
    TriggerClientEvent('sendMessageMe', -1, source, GetPlayerName(source), string.sub(msg,2))
  elseif string.find(msg,'/do') then
    CancelEvent()
	TriggerClientEvent('sendMessageOOCdo', -1, source, GetPlayerName(source), string.sub(msg,4))
    TriggerClientEvent('sendMessageDo', -1, source, GetPlayerName(source), string.sub(msg,2))
 end
end)

How to edit this to make RegisterCommand? If i try to make this they not send a chat message :confused:

GitHub - eblio/3dme: A FiveM script written in LUA that implements the /me command with 3D printing. This resource registers a command to call to a “me” chat system

I dont want another script i just ask how to use

RegisterCommand(me, FUNCTION)

on my own script… I gues i need to use them on server.lua but i dont know how…

The response above was to give you an example for you to go through and play with and learn on.

Ok i figure it out bot not fully… On server.lua i change all to this:

local function onMeCommand(source, n, msg)
    CancelEvent()
	TriggerClientEvent('sendMessageOOCdo', -1, source, GetPlayerName(source), string.sub(msg,4))
    TriggerClientEvent('sendMessageDo', -1, source, GetPlayerName(source), string.sub(msg,1))
 end

local function onMeCommand2(source, n, msg)
    CancelEvent()
	TriggerClientEvent('sendMessageOOCme', -1, source, GetPlayerName(source), string.sub(msg,4))
    TriggerClientEvent('sendMessageMe', -1, source, GetPlayerName(source), string.sub(msg,1))
 end


RegisterCommand("do", onMeCommand)
RegisterCommand("me", onMeCommand2)

They work fine and define my command but on definition and suggestion on chat they missing like on screen when i try to use /do or /me

You need each client to trigger the chat event addSuggestion when they connect to the server. The other’s are all registered using ESX.RegisterCommand which accepts the suggestion and automatically will tell the client to add it.

With 1st option i add them to client.lua if i restart or start server they dont want to work if i restart resource on working server they shows up and work correct. What i make wrong? I supost to add them on server.lua or on both?

TriggerEvent('chat:addSuggestion', '/me', 'Służy do opisania czynności', {{ name="opis", help="To opis czynności wykonywanej lub zaszłej np /me Podaje dokumenty" }
})

At the second option i dont understand them at all, i try change my existing registraion on server.lua

RegisterCommand("me", onMeCommand2)

to

ESX.RegisterCommand('me', 'user', onMeCommand2, false, {help = 'test'})

Command and sugestion dont work…

I believe if you Wait a bit to ensure chat’s NUI page is ready it should work on the client version you attempted

Citizen.CreateThread(function()
  Wait(2000)
  TriggerEvent('chat:addSuggestion', '/me', 'Służy do opisania czynności', {{ name="opis", help="To opis 
  czynności wykonywanej lub zaszłej np /me Podaje dokumenty" }})
end)

I add this to client.lua and now they works properly. You are awesome! Can you just explain me what this function doing?

I say they wait/pause but how they work on client side?

The chat resource uses a NUI page, which is not immediately ready upon client connect, but you were running code immediately upon client connect. You can create a listener to know exactly when the chat NUI page is prepared so you can trigger stuff right when it’s able to, but the above code just gives a generic wait time for the page to render before trying to call to the page.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.