20.12.2011, 13:15
On top of your script out of any callback
if you have he 2 color defines then don't copy it or else
if you use dcmd it's ok but if you don't then
In OnPlayerDisconnect(playerid, reason)
In OnPlayerSpawn(playerid)
OnPlayerCommandText(playerid, cmdtext[])
And now out of any callback
pawn Код:
new pChannel[MAX_PLAYERS]
pawn Код:
#define COLOUR_RED 0xFF0000FF
#define COLOUR_YELLOW 0xFFFF00FF
pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
pawn Код:
pChannel[playerid] = 0;
pawn Код:
pChannel[playerid] = 1;
pawn Код:
dcmd(cbchannel, 9, cmdtext);
dcmd(cb, 2, cmdtext);
pawn Код:
dcmd_cbchannel(playerid, params[])
{
if(!strlen(params) /*&& !IsNumeric(params)*/) return SendClientMessage(playerid, 0x00FFCCFF, "Usage: \"/cbchannel <1-40>\"");
//If the length of params is 0 (non existent) - it returns an error message
//I have commeneted our "IsNumeric" because I am not supplying it with the tutorial (because I can't find it!)
if(strval(params) < 1 || strval(params) > 40) return SendClientMessage(playerid, 0x00FFCCFF, "Please select 1-40 channel.");
//If the integer value of the parameters string is lower than 1 or bigger than 40 then it returns another error message
pChannel[playerid] = strval(params);
//Set the players channel
//You may also want to add a "Your channel is now %i" message.
static zmiana[128];
format(zmiana, sizeof(zmiana), "[CB] You changed CB channel to %i.", pChannel[playerid]);
SendClientMessage(playerid, 0x00FFCCFF, zmiana);
return 1;
//Return 1 (command complete)
}
dcmd_cb(playerid, params[])
{
if(!strlen(params)) return SendClientMessage(playerid, 0x00FFCCFF, "Usage: \"/cb <message>\"");
//Error message if the player did not specify any parameters
static str[128];
//Why static? It stops it being created more than once (in fact if you decompiled an AMX script you would find the "static" variable has become GLOBAL)
format(str, sizeof(str), "[CB %i] %s: %s", pChannel[playerid], ReturnName(playerid), params);
//Format the output message (str)
//ReturnName, is a function to return a players name - I will include it toward the end of this post
//You could use colour embedding here!
for(new i; i < GetMaxPlayers(); i++)
{
//Start the loop (GetMaxPlayers will return the MAXIMUM player slots on your server - you could use Foreach here instead)
if(!IsPlayerConnected(i)) continue;
//If the player is not connected, skip to the next one
if(pChannel[i] == pChannel[playerid])
{
//If the player channel matches the other players channel
SendClientMessage(i, 0x00FFCCFF, str);
}
}
return 1;
//End the command (return 1)
}
stock ReturnName(playerid)
{
static name[24];
GetPlayerName(playerid, name, 24);
return name;
}