How can you create a /apm
#1

Titel says Enough, Do somebody knows how to create it ^^ (Administrator Private Message)
Reply
#2

Learn sscanf or strtok. I recommend sscanf.

Example in ZCMD:
pawn Код:
CMD:apm(playerid,params[])
{
     new Msg[128],ID;
     if(AdminVar[playerid] == 0) return SendClientMessage(playerid,-1,"You not are a Admin");
     if(sscanf(params,"ds[128]",playerid,Msg)) return SendClientMessage(playerid,-1,"Invalid ID/MSG");
     SendClientMessage(ID,-1,Msg);
     return 1;
}
Reply
#3

pawn Код:
CMD:apm( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "You are not an Admin!" );
    new
        id,
        msg[ 120 ]
    ;
    if( sscanf( params, "rs[120]", id, msg ) ) return SendClientMessage( playerid, -1, "Usage: /apm <ID/Part Of Name> <message>" );
    if( id == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Invalid player!" );
   
    new
        sz_Msg[ 144 ]
    ;
    format( sz_Msg, sizeof( sz_Msg ), "PM From Administrator: %s", msg );
    SendClientMessage( id, 0xFFFF00FF, msg );
    return 1;
}
Reply
#4

Код:
COMMAND:apm(playerid, params[])
{
// Variable goes here.. EG: If(PlayerInfo[playerid][admin] < 1)
               return SendClientMessage(playerid, COLOR_RED,"CAN'T USE COMMAND");
	new iPlayer, iText[ 128 ];
	if( sscanf ( params, "us", iPlayer, iText))  return SCP(playerid, "[PlayerID/PartOfName] [message]");
	format(iStr, sizeof(iStr), "{b5cdda}(( {7b94a1}[Admin PM]%s(%d):{b5cdda} %s {7b94a1}))", RPName(playerid), playerid, iText);
	SendClientMessage(iPlayer, -1, iStr);
	format(iStr, sizeof(iStr), "{b5cdda}(( {7b94a1}[Admin PM] %s(%d):{b5cdda} %s {7b94a1}))", RPName(iPlayer), iPlayer, iText);
	SendClientMessage(playerid, -1, iStr);
	return 1;
}
Reply
#5

pawn Код:
CMD:apm(playerid, params[]) // Name of CMD apm
{
if(PlayerInfo[playerid][pAdmin] /*your enum could be different!*/ == 0) return SendClientMessage(playerid, COLOR, "You are not authorized to use this command!"); // If the player is NOT an admin, send him a message saying he can't use them
new strsend[130], targetid; // strsend is a string that stores the message the player types in the parameters, targetid is the id of the player that the admin will send the message to
if(sscanf(params, "us", targetid, strsend)) return SendClientMessage(playerid, COLOR, "Usage: /apm [playerid] [Message]"); // Check with sscanf if the player has used the command correctly, if he hasn't, show him how to
if(targetid == playerid) return SendClientMessage(playerid, COLOR, "You cannot message yourself!");
new str[35], name[MAX_PLAYER_NAME]; // MAX_PLAYER_NAME is he max characters that can be put in any SA:MP Name, name is the string which saves the name of the player, str is the string that will have the format of the message itself
GetPlayerName(playerid, name, sizeof(name)); // Save Admin's name in string "name"
format(str, sizeof(strsend), "Admin %s Says: %s", name, strsend); //Format of the message that will be sent to the Player, which will be saved in str
SendClientMessage(targetid, COLOR, str); // Send The Message to the player.
GetPlayerName(targetid, name, sizeof(name)); // Save the Player's name in string "name"
format(str, sizeof(strsend), "APM Sent to %s: %s", name, strsend); // Format of the message that will be sent to the Admin, which will be saved in str
SendClientMessage(playerid, COLOR, str); // Send Message to admin
return 1;
} // By: Elie1996
Reply
#6

pawn Код:
CMD:apm(playerid, params[])
{
   new str[128], str2[128], id;
   if(sscanf(params,"ds[128]", id, str2)) return SendClientMessage(playerid, red,"USAGE: /apm [id] [message]");
   if(IsPlayerConnected(id))
   {
       if(id != playerid)
       {

              if(PlayerInfo[playerid][Level] >= 1)
              {
                format(str, sizeof(str),"Admin PM to [%d]%s: %s", id, PlayerName2(id), str2);
                SendClientMessage(playerid, yellow, str);
                format(str, sizeof(str),"[PM]Admin: %s", str2);
                SendClientMessage(id, COLOR_PINK, str);
                PlayerPlaySound(id,1085,0.0,0.0,0.0);
                }
           else return SendClientMessage(playerid, red,"You are not a high enough level to use this command");
       }
       else return SendClientMessage(playerid, red,"You cannot PM yourself");
   }
   else return SendClientMessage(playerid, red,"Player is not connected");
   return 1;
}

P.S.
First time see CMD:apm with so many versions
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)