Client Messages
#1

Hello I need help with client messages I want that people near the person who types the command should see that message how can I do that?
Reply
#2

Look at the roleplay chat tutorial in my signature, I explain it pretty well.
Reply
#3

Short Tutorial by TheLazySloth

Step 1: The Command
First off we need a way for the player to tell the server he wants to send messages to players near-by.
We'll call the command /s. So let's make it!

> - Is where we need to indent.

public OnPlayerCommandText(playerid, cmdtext[]) {
>if(strcmp(cmdtext, "/s", true, 2) == 0) { // Checks if cmdtext starts with '/s'
>>return true; // Tells the server it does.
>}
>return false; // Tells the server it doesn't and sends cmdtext to OnPlayerText
}

Step 2: Making the parameters.
Now that the server can detect when the player typed the command /s we need the server to detect the parameters. Here's how.

> - Is where we need to indent.

public OnPlayerCommandText(playerid, cmdtext[]) {
>if(strcmp(cmdtext, "/s", true) == 0) {
>>strdel(cmdtext, 0, 2); // This will delete '/s ' from the cmdtext.
>>return true;
>}
>return false;
}

Step 3: Checking if other players are in range of the player.
Now that the server detected the command and "grinded the excess" parameters. We need a way for our server to check for players that are in range. Here's how.

> - Is where we need to indent.

public OnPlayerCommandText(playerid, cmdtext[]) {
>if(strcmp(cmdtext, "/s", true) == 0) {
>>strdel(cmdtext, 0, 2);
>>
>>new Float: pX, // These are the variables we need.
>>> Float: pY,
>>> Float: pZ;
>>
>>GetPlayerPos(playerid, pX, pY, pZ); // This gets the player's exact position.
>>
>>for(new i = 0; i < MAX_PLAYERS; i++) { // This will loop through every player.
>>>if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 15.0, pX, pY, pZ)) { // This is the range check.
>>>}
>>}
>>return true;
>}
>return false;
}

Step 4: Sending the message!
Okay we got every single player that is in range of the player who sent the command... Now our last and final step is telling the other players who sent the command and the message the types after the commands.

> - Is where we need to indent.

public OnPlayerCommandText(playerid, cmdtext[]) {
>if(strcmp(cmdtext, "/s", true) == 0) {
>>strdel(cmdtext, 0, 2);
>>
>>new Float: pX,
>>> Float: pY,
>>> Float: pZ,
>>> pName[MAX_PLAYER_NAME], // the name variable we need.
>>> String[128]; // where we store our string.
>>
>>GetPlayerPos(playerid, pX, pY, pZ);
>>GetPlayerName(playerid, pName, MAX_PLAYER_NAME); // Gets the player's name.
>>format(String, 128, "%s says, \"%s\"", pName, cmdtext); // Makes the message sent to other players.
>>
>>for(new i = 0; i < MAX_PLAYERS; i++) {
>>>if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 15.0, pX, pY, pZ)) {
>>>>SendClientMessage(i, -1, String); // Send the message for the other players.
>>>}
>>}
>>return true;
>}
>return false;
}

And that's how you do it! +rep appreciated =] (Yes, I got bored.)
Reply
#4

pawn Код:
if(!(strcmp(cmdtext,"/me")))
{
    if(strlen(cmdtext[4])) return SendClientMessage(playerid,-1,"USAGE: /me <action");
    static string[128],user[24],Float:x,Float:y,Float:z;
    GetPlayerName(playerid,user,24);
    format(string,sizeof string,"%s(%i): %s",user,playerid,cmdtext[4]);
    GetPlayerPos(playerid,x,y,z);
    for(new i; i < GetMaxPlayers();i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerInRangeOfPoint(i,30,x,y,z)) SendClientMessage(i,-1,string);
    }
    return 1;
}
I made that quickly on notepad :l
Reply
#5

Quote:
Originally Posted by FireCat
Посмотреть сообщение
pawn Код:
if(!(strcmp(cmdtext,"/me")))
{
    if(strlen(cmdtext[4])) return SendClientMessage(playerid,-1,"USAGE: /me <action");
    static string[128],user[24],Float:x,Float:y,Float:z;
    GetPlayerName(playerid,user,24);
    format(string,sizeof string,"%s(%i): %s",user,playerid,cmdtext[4]);
    GetPlayerPos(playerid,x,y,z);
    for(new i; i < GetMaxPlayers();i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerInRangeOfPoint(i,30,x,y,z)) SendClientMessage(i,-1,string);
    }
    return 1;
}
I made that quickly on notepad :l
I did mine using Quick Reply, therefore MINE is better and more well explained! >=]
Reply
#6

Okay for my roleplay server I am scripting Vampires so tell me how can I fix this that only people near can see this.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/vspeed", cmdtext, true, 10) == 0)
    {
        SendClientMessageToAll(0xDEEE20FF, "Vampire Speed 1");
        return 1;
    }
    return 0;
}
Reply
#7

Well if you payed attention to my little tutorial three posts up... you'll see you need three floats, getplayerpos, a loop to check for players, isplayerinrangeofpoint, and finally sendclientmessagetoall sends the message to EVERYONE therefore you need to use sendclientmessage in order to send the message to certain players.

PM me if you have skype and I'll be will to support you there.
Reply
#8

Bump any onevcan fix mine?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)