Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Sonmez on Nov 12, 2020, 02:23 PM

Title: Basic Near Player Chat For RP Servers
Post by: Sonmez on Nov 12, 2020, 02:23 PM
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;
}
Title: Re: Basic Near Player Chat For RP Servers
Post by: Altay on Nov 12, 2020, 03:07 PM
This is goldmine, keep up the good work.
Title: Re: Basic Near Player Chat For RP Servers
Post by: habi on Nov 12, 2020, 03:52 PM
perfect..

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

Title: Re: Basic Near Player Chat For RP Servers
Post by: Inferno on Nov 12, 2020, 05:00 PM
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.
Title: Re: Basic Near Player Chat For RP Servers
Post by: Sonmez on Nov 12, 2020, 05:42 PM
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.
Title: Re: Basic Near Player Chat For RP Servers
Post by: Inferno on Nov 12, 2020, 05:52 PM
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.
Title: Re: Basic Near Player Chat For RP Servers
Post by: Sonmez on Nov 12, 2020, 06:38 PM
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.
Title: Re: Basic Near Player Chat For RP Servers
Post by: Inferno on Nov 12, 2020, 06:52 PM
Good work
Title: Re: Basic Near Player Chat For RP Servers
Post by: Anish87 on Dec 27, 2020, 07:27 AM
            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...
Title: Re: Basic Near Player Chat For RP Servers
Post by: DizzasTeR on Dec 27, 2020, 07:48 AM
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;
}
Title: Re: Basic Near Player Chat For RP Servers
Post by: Xmair on Dec 27, 2020, 09:15 AM
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.
Title: Re: Basic Near Player Chat For RP Servers
Post by: Mohamed Boubekri on Apr 05, 2021, 09:17 PM
Its give me error here:-
if (firstletter == "\")The console tell me 'error newline in constant'
Title: Re: Basic Near Player Chat For RP Servers
Post by: Kelvin Garcia Mendoza on Apr 05, 2021, 11:26 PM
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 == @"\" )
Title: Re: Basic Near Player Chat For RP Servers
Post by: Sonmez on Apr 10, 2021, 10:31 PM
I recompiled the code. Added /s command for shouting. And still standard chat = nearplayer chat.