/me and a /do command
#1

I want a /me and a /do command. Only players in range of 5 or 10 meters can see it.
Reply
#2

Here's a /me command via strcmp:

pawn Код:
{
        if(strcmp(cmdtext, "/me", true, 3)==0) {
        new pname1[24], string[256];
        GetPlayerName(playerid, pname1, 24);
        format(string, 256, "*%s (%d) %s", pname1, playerid, cmdtext[4]);
        SendClientMessageToAll(GetPlayerColor(playerid), string);
        return 1;
}
I don't know how to make it for close players only, but give IsPlayerInRangeOfPoint a try.

Edit this command as you desire.
Reply
#3

And here is the /do command

pawn Код:
if(strcmp(cmd, "/do", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You havent logged in yet !");
                return 1;
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /do [local chat]");
                return 1;
            }
            if(PlayerInfo[playerid][pMask] == 1)
            {
                format(string, sizeof(string), "* %s (( Stranger ))", result);
            }
            else
            {
                format(string, sizeof(string), "* %s (( %s ))",result , sendername);
            }
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
        }
        return 1;
Reply
#4

Why do you guys suggest him to use strcmp?

Zcmd is the way to go.

pawn Код:
#define DO_RANGE 300

command(me, playerid, params[])
{
    new string[128];
    if(strlen(params) < 5) return SendClientMessage(playerid, 0x0, "Your action has to contain at least 5 chars.");
    format(string, sizeof(string), "( ( %s [ %d ] ) : %s )", GetName(playerid), playerid, params);
    SendClientMessageToAll(GetPlayerColor(playerid), string);
    return 1;
}

command(do, playerid, params[])
{
    new string[128], Float: Pos[3];
    if(strlen(params) < 5) return SendClientMessage(playerid, 0x0, "Your action has to contain at least 5 chars.");
    format(string, sizeof(string), "( ( %s [ %d ] ) : %s )", GetName(playerid), playerid, params);
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(i != playerid && IsPlayerConnected(i) && IsPlayerInRange(i, DO_RANGE, DO_RANGE, Pos[0], Pos[1], Pos[2]))
        {
            SendClientMessage(i, GetPlayerColor(playerid), string);
        }
    }
    SendClientMessage(playerid, GetPlayerColor(playerid), string);
    return 1;
}

stock GetName(playerid)
{
    new pName[25];
    GetPlayerName(playerid, pName, sizeof(pName));
    return pName;
}

stock IsPlayerInRange(playerid, Float:Range, Float:Z_Range, Float:tar_x, Float:tar_y, Float:tar_z) //By Gabriel "Larcius" Cordes
{
    new bool:care_z = true, Float:player_x, Float:player_y, Float:player_z, Float:radius_xy, Float:radius_z;
    GetPlayerPos(playerid, player_x, player_y, player_z);
    radius_xy = floatsqroot(floatadd(floatpower(floatsub(player_x,tar_x),2.0),floatpower(floatsub(player_y,tar_y),2.0)));
    radius_z = floatsqroot(floatadd(floatpower(radius_xy,2.0),floatpower(floatsub(player_z,tar_z),2.0)));
    if(radius_z > Z_Range && radius_xy < radius_z)
    {
        care_z = false;
    }
    if(radius_xy <= Range && care_z)
    {
        return 1;
    }
    return 0;
}
Reply
#5

For godsake learn using the search function.
Also check this first, before asking for a script: http://forum.sa-mp.com/showthread.ph...2&highlight=me.
And you can simply use IsPlayerInRangeOfPoint to check if he's in range. If he is, send the message, otherwise not.

EDIT:

@Grand Theft Otto:
LOL 265 string? Lol, max is even 128. Don't use too big arrays.
Example: "** %s %s".
That are 8 characters. The PlayerName can be max 24, so 8+24 = 32.
And let's say the action can be maximal 35 characters (strlen) .So 32+35 = 67.
You could just do "new string[67];" !

@The other guy (forgot name):
Don't just copy it -.- - He might not have the same variables etc.
Reply
#6

Hmm, we all can copy from GFs..


I suggest you to use GetPlayerPos and than loop via all players, and send string to everyone who IsPlayerInRangeOfPoint
Reply
#7

pawn Код:
#define DO_RANGE 300

command(me, playerid, params[])
{
    new string[128];
    if(strlen(params) < 5) return SendClientMessage(playerid, 0x0, "Your action has to contain at least 5 chars.");
    format(string, sizeof(string), "( ( %s [ %d ] ) : %s )", GetName(playerid), playerid, params);
    SendClientMessageToAll(GetPlayerColor(playerid), string);
    return 1;
}

command(do, playerid, params[])
{
    new string[128], Float: Pos[3];
    if(strlen(params) < 5) return SendClientMessage(playerid, 0x0, "Your action has to contain at least 5 chars.");
    format(string, sizeof(string), "( ( %s [ %d ] ) : %s )", GetName(playerid), playerid, params);
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(i != playerid && IsPlayerConnected(i) && IsPlayerInRange(i, DO_RANGE, DO_RANGE, Pos[0], Pos[1], Pos[2]))
        {
            SendClientMessage(i, GetPlayerColor(playerid), string);
        }
    }
    SendClientMessage(playerid, GetPlayerColor(playerid), string);
    return 1;
}

stock GetName(playerid)
{
    new pName[25];
    GetPlayerName(playerid, pName, sizeof(pName));
    return pName;
}

stock IsPlayerInRange(playerid, Float:Range, Float:Z_Range, Float:tar_x, Float:tar_y, Float:tar_z) //By Gabriel "Larcius" Cordes
{
    new bool:care_z = true, Float:player_x, Float:player_y, Float:player_z, Float:radius_xy, Float:radius_z;
    GetPlayerPos(playerid, player_x, player_y, player_z);
    radius_xy = floatsqroot(floatadd(floatpower(floatsub(player_x,tar_x),2.0),floatpower(floatsub(player_y,tar_y),2.0)));
    radius_z = floatsqroot(floatadd(floatpower(radius_xy,2.0),floatpower(floatsub(player_z,tar_z),2.0)));
    if(radius_z > Z_Range && radius_xy < radius_z)
    {
        care_z = false;
    }
    if(radius_xy <= Range && care_z)
    {
        return 1;
    }
    return 0;
}
Should work properly.
Reply
#8

Quote:

C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\gamemode.pwn(17) : error 026: no matching "#if..."
C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\gamemode.pwn(77) : error 029: invalid expression, assumed zero
C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\gamemode.pwn(77) : error 017: undefined symbol "cmd_me"
C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\gamemode.pwn(77) : error 029: invalid expression, assumed zero
C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\gamemode.pwn(77) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.


After I added the: #define DO_RANGE 300 and the #include <zcmd> then I added the commands under OnPlayerCommand, etc. I got those errors.
Reply
#9

I included SSCANF & ZCMD. I put the #define right after the Includes. I get those errors:

Quote:

C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\Untitled.pwn(79) : error 029: invalid expression, assumed zero
C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\Untitled.pwn(79) : error 017: undefined symbol "cmd_me"
C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\Untitled.pwn(79) : error 029: invalid expression, assumed zero
C:\Users\Mijn pc\Desktop\SA-MP server\server\gamemodes\Untitled.pwn(79) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Reply
#10

Quote:
Originally Posted by davelord
Посмотреть сообщение
I included SSCANF & ZCMD. I put the #define right after the Includes. I get those errors:
BUMP!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)