30.06.2015, 23:54
I would like to create /pm command, no idea how to start, any guides?
COMMAND:mp(playerid, params[])//OK { new OtherPlayer, Message[128], Msg1[128], Msg2[128],Msg3[128], Msg4[128], YourName[24], OtherPlayerName[24]; SendAdminText(playerid, "/mp", params); if (IsPlayerConnected(playerid)) { if (sscanf(params, "us[128]", OtherPlayer, Message)) SendClientMessage(playerid, 0xFF0000AA, "{FF0000}Use: /mp [id] [menssagem]"); else { if (IsPlayerConnected(OtherPlayer)) { GetPlayerName(playerid, YourName, sizeof(YourName)); GetPlayerName(OtherPlayer, OtherPlayerName, sizeof(OtherPlayerName)); format(Msg1, 128, "{666666}# Mensagem para {FF0000}(%s - ID: %d) {666666}Enviada", OtherPlayerName, OtherPlayer, Message); format(Msg3, 128, "{FFFF00}==================================================="); format(Msg2, 128, "{ffff00}MP de {666666}(%s - ID: %d){ffff00}: %s", YourName, playerid, Message); format(Msg4, 128, "{FFFF00}==================================================="); SendClientMessage(playerid, 0xFFFFFFFF, Msg1); SendClientMessage(OtherPlayer, 0xFFFFFFFF, Msg3); SendClientMessage(OtherPlayer, 0xFFFFFFFF, Msg2); SendClientMessage(OtherPlayer, 0xFFFFFFFF, Msg4); } else SendClientMessage(playerid, 0xFF0000FF, "{FF0000}ERROR: not connected!"); } } else return 0; return 1; }
CMD:pm(playerid, params[]) { new str[128], str2[128], id, adminstr[128]; if(sscanf(params,"ds[128]", id, str2)) return SendClientMessage(playerid, red,"USAGE: /pm [id] [message]"); if(IsPlayerConnected(id)) { if(id != playerid) { if(DND[id] == 0) { format(str, sizeof(str),"PM to [%d]%s: %s", id, PlayerName2(id), str2); SendClientMessage(playerid, yellow, str); format(str, sizeof(str),"PM from [%d]%s: %s", playerid, PlayerName2(playerid), str2); SendClientMessage(id, yellow, str); format(adminstr, sizeof(adminstr),"PM from %s[%d] to %s[%d]: %s", PlayerName2(playerid), playerid, PlayerName2(id), id, str2); PlayerPlaySound(id,1085,0.0,0.0,0.0); MessageTo4(grey, adminstr); LastPm[id] = playerid; } else return SendClientMessage(playerid, red,"That player is in do not disturb mode!"); } else return SendClientMessage(playerid, red,"You cannot PM yourself"); } else return SendClientMessage(playerid, red,"Player is not connected"); return 1; }
#include <a_samp>
#include <sscanf2>
#include <zcmd>
CMD:pm (playerid, params[] ) {
// Define sender ID and text variable...
new id, message[128];
// Sscanf specifiers so we can use the params we defined in our command
if ( sscanf ( params, "us[128]", id, message ) ) {
// If a param isn't used correctly, return a error message
return SendClientMessage ( playerid, -1, " /pm [ id ] [ text ] " );
}
// Define a variable for the compiled string
new compStr [ 144 ] ;
// Check if reciever ID is connected
if ( ! IsPlayerConnected ( id ) ) {
// If not return a message
return SendClientMessage ( playerid, -1, "This user isn't connected!");
}
// If message is longer than 120 characters return a error message
if(strlen ( message ) > 120 ) {
return SendClientMessage ( playerid, -1, "Can't have more than 120 characters in a PM!");
}
// Send a message to the reciever ID
format ( compStr, sizeof(compStr), "PM from (%d) %s: %s", playerid, GetName ( playerid ) , message);
SendClientMessage ( id, -1, compStr ) ;
// And sender id
format ( compStr, sizeof(compStr), "PM to (%d) %s: %s", id, GetName ( id ) , message);
SendClientMessage ( playerid, -1, compStr ) ;
return true;
}
// GetName function
GetName ( id ) {
new str[ MAX_PLAYER_NAME];
GetPlayerName( id, str, sizeof ( str ) );
return str;
}