[Tutorial] /whisper (sscanf/zcmd)
#1

/whisper (sscanf/zcmd)

made by Romel
I create this because i'm bored
I made a /whisper too, but i will not copy the code from there
so i will use made from scratch

Requirements:

- Little Experience in scripting
- sscanf which can be found here!
Click here if you are having the sscanf ID 0 bug!

- zcmd which can be found here!

Full Code:

Before i explain each part please don't copy this code first i'm just previewing.
I will explain the /whisper command after this moment (sorry if my english speaking is bad)

pawn Code:
CMD:whisper(playerid, params[])
{
    new pname[MAX_PLAYER_NAME], str[128], Float:pPos[3];
    if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "Syntax: /whisper <text>");
    GetPlayerName(playerid, pname, sizeof(pname));
    GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 10.0, pPos[0], pPos[1], pPos[2]))
        {
            format(str, sizeof(str), "[Whisper] %s: %s", pname, params);
            SendClientMessage(i, -1, str);
        }
    }
    return 1;
}
Explain:

pawn Code:
new pname[MAX_PLAYER_NAME], str[128], Float:pPos[3];
pname will be the name of player who use /whisper
str will be use to send a whisper message
pPos[3] will be use to get the player position (who use /whisper)

pawn Code:
if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "Syntax: /whisper <text>");
If player types empty this message will be sent. s[128] means string[size]

pawn Code:
GetPlayerName(playerid, pname, sizeof(pname));
GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
like i mention above pname will be use for getting players name
like i mention above ppos will be use for getting player pos
Note: In using GetPlayerPos, there must be Float tag in new pPos[3];

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
looping all players

pawn Code:
if(IsPlayerInRangeOfPoint(i, 10.0, pPos[0], pPos[1], pPos[2]))
will check if a player is near in player's position with in float:distance 10.0, edit the float:distance 10.0

pawn Code:
format(str, sizeof(str), "[Whisper] %s: %s", pname, params);
like i mention above, str will use for sending whisper, we use str in format

pawn Code:
SendClientMessage(i, -1, str);
will sent to the players who are near in player's position with in float:distance 10.0, the message will be sent is the formatted string

Note: -1 is not a invalid color, -1 means COLOR_WHITE, change -1 to your color defines

Finish:

pawn Code:
CMD:whisper(playerid, params[])
{
    new pname[MAX_PLAYER_NAME], str[128], Float:pPos[3];
    if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "Syntax: /whisper <text>");
    GetPlayerName(playerid, pname, sizeof(pname));
    GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 10.0, pPos[0], pPos[1], pPos[2]))
        {
            format(str, sizeof(str), "[Whisper] %s: %s", pname, params);
            SendClientMessage(i, -1, str);
        }
    }
    return 1;
}
Credits to Y_Less for sscanf
Credits to Zeex for zcmd
and Credits to Me for tutorial

Have fun modifying your own made /whisper!
Reply


Messages In This Thread
/whisper (sscanf/zcmd) - by JaKe Elite - 18.06.2012, 12:22
Re: /whisper (sscanf/zcmd) - by Mimic - 18.06.2012, 12:25
Re: /whisper (sscanf/zcmd) - by CoDeZ - 28.06.2012, 17:00

Forum Jump:


Users browsing this thread: 1 Guest(s)