MP
pawn Код:
|
if(strcmp(cmdtext, "/Pm", true) == 0)
{
static giveid,texto[128],mandou[MAX_PLAYER_NAME],recebeu[MAX_PLAYER_NAME],string[128];
if(sscanf(params, "us[128]", giveid, texto))return SendClientMessage(playerid, COLOR_BRANCO, "/mp [ID] [Mensagem]");
if(!IsPlayerConnected(giveid))return SendClientMessage(playerid, COLOR_BRANCO, "Player nгo conectado!");
GetPlayerName(giveid,recebeu,sizeof(recebeu));
GetPlayerName(playerid,mandou,sizeof(mandou));
format(string,sizeof(string),"MP ENVIADA PARA[%s] Nela vocк diz [%s]",recebeu,texto);
SendClientMessage(playerid,COLOR_BRANCO,string);
format(string,sizeof(string),"MP RECEBIDA DE [%s] NEla ele diz [%s]",mandou,texto);
SendClientMessage(giveid,COLOR_BRANCO,string);
return true;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256];
new tmp[256];
new Message[256];
new gMessage[256];
new pName[MAX_PLAYER_NAME+1];
new iName[MAX_PLAYER_NAME+1];
new idx;
cmd = strtok(cmdtext, idx);
// PM Command
if(strcmp("/pm", cmd, true) == 0)
{
tmp = strtok(cmdtext,idx);
if(!strlen(tmp) || strlen(tmp) > 5) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
return 1;
}
new id = strval(tmp);
gMessage = strrest(cmdtext,idx);
if(!strlen(gMessage)) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
return 1;
}
if(!IsPlayerConnected(id)) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID");
return 1;
}
if(playerid != id) {
GetPlayerName(id,iName,sizeof(iName));
GetPlayerName(playerid,pName,sizeof(pName));
format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage);
SendClientMessage(playerid,PM_OUTGOING_COLOR,Message);
format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
SendClientMessage(id,PM_INCOMING_COLOR,Message);
PlayerPlaySound(id,1085,0.0,0.0,0.0);
printf("PM: %s",Message);
}
else {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself");
}
return 1;
}
if(!strcmp("/pm", cmd, true) || !strcmp("/mp", cmd, true))
{
if(PlayerInfo[playerid][pAdmin] > 0)
{
tmp = strtok(cmdtext,idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GREY, "USE: /MP [PlayerID/Nome] [Texto]");
return 1;
}
new id = ReturnUser(tmp);
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_GREY, "Jogador Nгo Conectado.");
tmp = strrest(cmdtext,idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GREY, "USE: /MP [PlayerID/Nome] [Texto]");
return 1;
}
new Rank[25];
if(PlayerInfo[playerid][pAdmin] == 1) Rank = "Sub-Moderador";
if(PlayerInfo[playerid][pAdmin] == 2) Rank = "Moderador";
if(PlayerInfo[playerid][pAdmin] == 3) Rank = "Admin 1";
if(PlayerInfo[playerid][pAdmin] == 4) Rank = "Admin 2";
if(PlayerInfo[playerid][pAdmin] == 5) Rank = "Admin 3";
format(string, sizeof(string), "[MP] %s %s[%d]: %s", Rank, sendername, playerid, tmp);
SendClientMessage(id, COLOR_GREEN, string); new nomeid[MAX_PLAYER_NAME];
GetPlayerName(id, nomeid, sizeof(nomeid));
format(string, sizeof(string), "[MP] %s %s[%d] %s", Rank, nomeid, id, tmp);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Vocк nгo pode usar este comando.");
return 1;
}
}
//----------------------------------------------------------
stock strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
//------------------------------------------------
stock strrest(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[128];
while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
//----------------------------------------------------------
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21) /
{
if (text[pos] == 0) return INVALID_PLAYER_ID;
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos]))
{
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
{
userid = INVALID_PLAYER_ID;
}
else
{
return userid;
}
}
}
new len = strlen(text[pos]);
new count = 0;
new name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0)
{
if (len == strlen(name))
{
return i;
}
else
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count)
{
SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
}
}
userid = INVALID_PLAYER_ID;
}
return userid;
}