function onPlayerCommand(player,cmd,text)
{
if (cmd == "s"){
local aColour = player.Colour, pcolor = format("[#%02X%02X%02X]", aColour.r, aColour.g, aColour.b);
if(text.len()>1){
text = text.slice(1,text.len());
for(local i = 0; i < 100; i++){
local allplr = FindPlayer(i);
if (allplr){MessagePlayer(pcolor+""+player.Name+"[#ffffff]: " + text + "", allplr);}
}
}
}
}
function onPlayerChat( player, text ){
local aColour = player.Colour, pcolor = format("[#%02X%02X%02X]", aColour.r, aColour.g, aColour.b);
for(local i = 0; i < 100; i++){
local nearplr = FindPlayer(i);
if (nearplr){
if(DistanceFromPoint( player.Pos.x, player.Pos.y, nearplr.Pos.x, nearplr.Pos.y ) < 20){
MessagePlayer(pcolor+""+player.Name+"[#ffffff]: " + text + "", nearplr);
}
}
}
return false;
}
This is goldmine, keep up the good work.
perfect..
because
1. onplayerjoin setting array false
2. onplayerchat returning false
3. well informed messages
Why not only using the /shout cmd to chat nearby instead of using OnPlayerChat event.
Will save a lot of time and a bit easier for others.
Anyways, good work.
Quote from: Inferno on Nov 12, 2020, 05:00 PMWhy not only using the /shout cmd to chat nearby instead of using OnPlayerChat event.
Will save a lot of time and a bit easier for others.
Anyways, good work.
Chatbox is often used heavily. Typing /shout every time will annoy the players. So this is the most useful method for players.
Use alias ( /sh ) or you can even use a keybind to send a shout. Or teamchat prefix \ .
They are much reliable.
Because if someone is using custom onplayerchat function, they might find it confusing or bugged, i.e Using ignore snippet by Doomkiller.
Quote from: Inferno on Nov 12, 2020, 05:52 PMUse alias ( /sh ) or you can even use a keybind to send a shout. Or teamchat prefix \ .
They are much reliable.
Because if someone is using custom onplayerchat function, they might find it confusing or bugged, i.e Using ignore snippet by Doomkiller.
Thank you for feedback. I reproduced the code. Now standard chat = nearplayer chat. And firstletter "\" means shouting. With this method, the code has been further simplified for all producers.
Good work
for(local i = 0; i < 100; i++)
{
local nearplr = FindPlayer(i);
if (nearplr)
{
MessagePlayer(pcolor+""+player.Name+"[#ffffff]: " + text + "", nearplr);
}
}
I think this code is mistaken, this will send a message to all the players in the server instead of anyone standing nearby... I might be wrong but check it once again...
function onPlayerChat( player, text )
{
local aColour = player.Colour, pcolor = format("[#%02X%02X%02X]", aColour.r, aColour.g, aColour.b);
local firstletter = text.slice(0,1)
if (firstletter == "\\")
return 1;
for(local i = 0; i < 100; i++)
{
local nearplr = FindPlayer(i);
if (nearplr)
if(DistanceFromPoint( player.Pos.x, player.Pos.y, nearplr.Pos.x, nearplr.Pos.y ) < 20)
MessagePlayer(pcolor+""+player.Name+"[#ffffff]: " + text + "", nearplr);
}
return 0;
}
Quote from: DizzasTeR on Dec 27, 2020, 07:48 AMfunction onPlayerChat( player, text )
{
local aColour = player.Colour, pcolor = format("[#%02X%02X%02X]", aColour.r, aColour.g, aColour.b);
local firstletter = text.slice(0,1)
if (firstletter == "\")
return 1;
for(local i = 0; i < 100; i++)
{
local nearplr = FindPlayer(i);
if (nearplr)
if(DistanceFromPoint( player.Pos.x, player.Pos.y, nearplr.Pos.x, nearplr.Pos.y ) < 20)
MessagePlayer(pcolor+""+player.Name+"[#ffffff]: " + text + "", nearplr);
}
return 0;
}
You need to escape the backslash.
Its give me error here:-
if (firstletter == "\")
The console tell me 'error newline in constant'
Quote from: We3da on Apr 05, 2021, 09:17 PMIts give me error here:-
if (firstletter == "\")
The console tell me 'error newline in constant'
Just like
@Xmair said, you need to escape the backslash. So you can replace it with either
if ( firstletter == "\\" )
or
if ( firstletter == @"\" )
I recompiled the code. Added /s command for shouting. And still standard chat = nearplayer chat.