« [at-request] /s or /save like in SA:MP
Basic Near Player Chat For RP Servers

Sonmez

  • Jr. Member
  • Yo! It's time to play the fair game!
  • Posts: 63
Basic Near Player Chat For RP Servers
«  »Last edited
Code: [Select]
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

  • Newbie
  • Server Owner
  • Posts: 22
Mustafa Kemal ATATURK, the man who changed the course of history. https://en.wikipedia.org/wiki/Mustafa_Kemal_Atat%C3%BCrk

habi

  • Sr. Member
  • Posts: 360

Inferno

  • Jr. Member
  • Posts: 98
Re: Basic Near Player Chat For RP Servers
« Reply #3,  »
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

  • Jr. Member
  • Yo! It's time to play the fair game!
  • Posts: 63
Re: Basic Near Player Chat For RP Servers
« Reply #4,  »Last edited
Quote from Inferno on November 12th, 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.
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

  • Jr. Member
  • Posts: 98
Re: Basic Near Player Chat For RP Servers
« Reply #5,  »
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

  • Jr. Member
  • Yo! It's time to play the fair game!
  • Posts: 63
Re: Basic Near Player Chat For RP Servers
« Reply #6,  »
Quote from Inferno on November 12th, 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.
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

  • Jr. Member
  • Posts: 98
Viva la VU
VFS Developer
VCCNR Administrator

Anish87

  • Newbie
  • Posts: 23
Re: Basic Near Player Chat For RP Servers
« Reply #8,  »
Code: [Select]
            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

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,208
Re: Basic Near Player Chat For RP Servers
« Reply #9,  »Last edited
Code: [Select]
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

  • Wiki Contributor
  • Posts: 959
Re: Basic Near Player Chat For RP Servers
« Reply #10,  »
Quote from DizzasTeR on December 27th, 2020, 07:48 AM
Code: [Select]
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;
}
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

  • Sr. Member
  • In-Game Name:- We3da^
  • Posts: 265
After all this pain, peace will come brother.

[R3V]Kelvin

  • Newbie
  • Posts: 44

Sonmez

  • Jr. Member
  • Yo! It's time to play the fair game!
  • Posts: 63
if (!perfect) createAgain();