[Release] ChatBasics (/pm, /me, /do, localchat, /b)

The only best thing I have seen in this code is that you restricted the chat to local. finally. made what I wanted.

Changelog

  • Fixed /pm to display the correct ID of the person who sent you the PM.

There is a bug in the command console shows errors, and whenever using PM I can send myself instead of a message that says “You cannot PM yourself.”

One more thing that is required imo, is suggestions whenever typing in chat with slash/.

@3Bot Can you help me out. So i am trying to change the /pm from everyone using it to only where a mod & up can use it. So far this is what i have done.

TriggerEvent('es:addGroupCommand', 'pm', "mod", function(source, args, user)
	if(GetPlayerName(tonumber(args[2])) or GetPlayerName(tonumber(args[3])))then
		local player = tonumber(args[2])
		table.remove(args, 2)
		table.remove(args, 1)

		TriggerEvent("es:getPlayerFromId", player, function(target)
			TriggerClientEvent('chatMessage', player, "[STAFF PM]", {214, 214, 214}, "^2 From ^5"..GetPlayerName(source).. " [" .. source .. "]: ^7" ..table.concat(args, " "))
			TriggerClientEvent('chatMessage', source, "[STAFF PM]", {214, 214, 214}, "^3 Sent to ^5"..GetPlayerName(player).. ": ^7" ..table.concat(args, " "))
		end)
	else
		TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Incorrect player ID!")
	end
end, function(source, args, user)
	TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficienct permissions!")
end, {help = "Staff Private Message", params = {{name = "id", help = "The ID of the player"}, {name = "message", help = "Message."}}})

However when i change it from es:addCommand to es:addGroupCommand & setting it to mod i get this error

InvokeNative: execution failed: Argument at index 0 was null.
Error running call reference function for resource esx_customchat: citizen:/scripting/lua/scheduler.lua:351: Execution of native 00000000406b4b20 in script host failed.
stack traceback:
        [C]: in upvalue '_in'
        citizen:/scripting/lua/natives_server.lua:156: in function 'GetPlayerName'
        server.lua:21: in upvalue 'ref'
        citizen:/scripting/lua/scheduler.lua:337: in function <citizen:/scripting/lua/scheduler.lua:336>
        [C]: in function 'xpcall'
        citizen:/scripting/lua/scheduler.lua:336: in function <citizen:/scripting/lua/scheduler.lua:335>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:351: in function <citizen:/scripting/lua/scheduler.lua:322>
Error running call reference function for resource essentialmode: citizen:/scripting/lua/scheduler.lua:351: citizen:/scripting/lua/MessagePack.lua:830: missing bytes
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/MessagePack.lua:830: in method 'underflow'
        citizen:/scripting/lua/MessagePack.lua:465: in field 'any'
        citizen:/scripting/lua/MessagePack.lua:860: in field 'unpack'
        citizen:/scripting/lua/scheduler.lua:563: in upvalue 'callback'
        server/main.lua:235: in upvalue 'ref'
        citizen:/scripting/lua/scheduler.lua:337: in function <citizen:/scripting/lua/scheduler.lua:336>
        [C]: in function 'xpcall'
        citizen:/scripting/lua/scheduler.lua:336: in function <citizen:/scripting/lua/scheduler.lua:335>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:351: in function <citizen:/scripting/lua/scheduler.lua:322>

Hmm ok I will take a look at it, but from reading the error code I must ask you this. In what resource have you placed the code? It seems like right now the resource running it is esx_customchat. If you have es_admin2 installed on the server, try pasting that command in server.lua on the es_admin2 resource. Also, make sure you got the groups defined in es_admin2. Here are my ones.

TriggerEvent(“es:addGroup”, “mod”, “helper”, “user”, function(group) end)

I had originally tried es_admin2 but was getting that error. If you do it the other way i posted above either in es_admin2 or another resource it always threw en error in chat when doing the command id message. But so far from what i was able to get work was

TriggerEvent('es:addGroupCommand', 'reply', 'mod', function(source, args, user)
	if args[1] then
		if(GetPlayerName(tonumber(args[1])))then
			local player = tonumber(args[1])
			table.remove(args, 1)
			
			TriggerEvent("es:getPlayerFromId", player, function(target)
				TriggerClientEvent('chatMessage', player, "[STAFF PM]", {255, 0, 0}, "^2 From ^5"..GetPlayerName(source).. " [" .. source .. "]: ^7" ..table.concat(args, " "))
				TriggerClientEvent('chatMessage', source, "[STAFF PM]", {255, 0, 0}, "^3 Sent to ^5"..GetPlayerName(player).. ": ^7" ..table.concat(args, " "))
			end)
		else
			TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Player not online.")
		end
	else
		TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Incorrect syntax! You must provide a valid player ID")
	end
end, function(source, args, user)
	TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficienct permissions!")
end, {help = "Staff Private Message", params = {{name = "id", help = "The ID of the player"}, {name = "message", help = "Message."}}})

But i will need to do more testing to make sure it all works like it should. But i have tested the code with just myself and it works & only a mod & up can use it.

Makes sense. The /reply command is a good replace if you only want staff to use the /pm function. I mean you could also just keep it that way if you want to, but yea its weird how replacing the /pm to /reply makes it work…

Well i for one would rather have my players get their friends phone number & txt them through the phone. I just needed a way for staff to PM people when they send a report in-game. For instance if someone sends a report saying help i am being rdmed then staff can easily see it & reply to it via pm instead of not saying anything then leaving the person wonder if any staff read it.

1 Like

Yea but isn’t /reply working all the time. Like you can /reply ID message 100 times if you want to?

I have /reply set to where only staff can do it. Why. Well for instance if a player is handcuffed by police he can easily /pm someone and tell him to come break him out & there is no way for us to know what he is doing. However tho having it set to where the player must use a phone to message his friends is easy b/c we have it set to where if you are cuffed then you can’t open any of the menus except for messaging through chat.

But with the way i have it if a person who is not a mod, admin, or superadmin does /reply id message it tells them they have invalid permissions.

how? what would i change the code to?

This does not work on my server. When i type without anything. No “/” commands it types in local chat. People that are over 100 metres away from me cant see my messages.

Edit: Nevermind i found that was supposed to be like that. How can i change it so if i dont /command anything. How can i talk global chat if everything is local

How do i get the /pm only as i dont use essentialmode and kinda only looking for a nice pm script

Top part of the script

I receive this error in my console every time I try to use some command of this resource I use ESX and I already fix an error by changing addCommand by RegisterCommand and now this some solution?
Thank you

http://prntscr.com/nw9n62

hello I have a problem with the script.

When I write something, the first word does not appear, nor with the / do, / me and / b for example:

I write in the chat “/ b hello how are you” and in the chat only appears “how are you”.

I hope you can help me, regards :sonriendo:

2 Likes

i cant find the .sql for the pm function

Maybe this is not important, but for me the function of / do and / me is reversed.
/ do = action
/ me = describe / question

Is there a way to make /me /do and normal chat global?

is posible to change the random id to the user ID?

1 Like