Basic Near Player Chat For RP Servers

Started by Sonmez, Nov 12, 2020, 02:23 PM

Previous topic - Next topic

Sonmez

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;
}
if (!perfect) createAgain();

Altay

This is goldmine, keep up the good work.
Mustafa Kemal ATATURK, the man who changed the course of history. https://en.wikipedia.org/wiki/Mustafa_Kemal_Atat%C3%BCrk

habi

perfect..

because
1. onplayerjoin setting array false
2. onplayerchat returning false
3. well informed messages


Inferno

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.
Viva la VU
VFS Developer
VCCNR Administrator

Sonmez

#4
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.
if (!perfect) createAgain();

Inferno

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.
Viva la VU
VFS Developer
VCCNR Administrator

Sonmez

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.
if (!perfect) createAgain();

Inferno

Viva la VU
VFS Developer
VCCNR Administrator

Anish87

            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...

DizzasTeR

#9
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;
}

Xmair

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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Mohamed Boubekri

Its give me error here:-
if (firstletter == "\")The console tell me 'error newline in constant'
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

Kelvin Garcia Mendoza

#12
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 == @"\" )

Sonmez

I recompiled the code. Added /s command for shouting. And still standard chat = nearplayer chat.
if (!perfect) createAgain();