ATomas
May 18, 2019, 11:18am
1
Hello,
i create command to send chat message to chat with argument.
For example i write “/chatmessage hi all players on server”
and in chat is “hi,all,players,on,server”
How to fix it? There is my code:
RegisterCommand("chatmessage", function(source, args)
exports.mychat:sendMessage(args)
end)
We can’t see the code behind this, also i guess you have to table.concat(args, " ")
ATomas
May 18, 2019, 11:25am
3
Thanks its work, and question no.2.
How to to this with some argument?
Exhample:
RegisterCommand("pm", function(source, args)
exports.mychat:sendMessage(args[1],args[2])//args[1] mean playerid and args[2] rest of the string, but args[2]
end) is only first word.
Uh try
local player = args[1]
table.remove(args, 1) -- remove first arg from table
local message = table.concat(args, " ")
ATomas
May 18, 2019, 12:39pm
5
Thanks its work. Questiong no.3
I have this code:
RegisterCommand("pm", function(source, args)
local id = args[1]
--if not NetworkIsPlayerActive(id) then
-- sendMessage("Hráč není připojen")
-- return
--end
table.remove(args, 1)
local message = table.concat(args, " ")
TriggerServerEvent('chat:message',GetPlayerServerId(PlayerId()),{255, 255, 0},"PM pro " .. GetPlayerName(id) .. " (" .. id .. "): " .. message);
TriggerServerEvent('chat:message',id,{255, 255, 0},"PM od " .. GetPlayerName(PlayerId()) .. " (" .. GetPlayerServerId(PlayerId()) .. "): " .. message);
end)
But the result message is “PM od invalid (0): message” instead of the player name I want to send a message to “PM od ATomas (0): message”