Need small help with PM
#1

Fixed!
Reply
#2

PHP код:
    CMD:pm(playerid,params[])
    {
        new 
targetidmsg[128];
        if(
sscanf(params"us[128]"targetidmsg)) return SendClientMessage(playeridLIGHTBLUE,"[ USAGE: /pm (name/id) (Message) ]");
        if(!
IsPlayerConnected(targetid)) return SendClientMessage(playeridred"[ ERROR: Player is not online! ]");
        if(
pm[targetid] == false) return SendClientMessage(playeridred,"[ ERROR: Player has blocked private messages! ]");
        if(
targetid == playerid) return SendClientMessage(playeridred"[ ERROR: You can't pm yourself! ]");
        new 
string[128], Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
        
GetPlayerName(playeridName1sizeof(Name1));
        
GetPlayerName(targetidName2sizeof(Name2));
        
format(stringsizeof(string),"Private Message from %s (%d): %s"Name1playeridmsg);
        
SendClientMessage(targetid,COLOR_PINKstring);
        
format(stringsizeof(string),"Private Message sent to %s (%d): %s"Name2targetidmsg);
        
SendClientMessage(playerid,COLOR_PINKstring);
        new 
File:file=fopen("PM.log"io_append);
        
format(stringsizeof(string), "%s to %s: %s\r\n"Name1Name2msg);
        
fwrite(filestring);
        
fclose(file);
        return 
1;

They won't be shown in server logs because it is not a chat message, it is just a command.
Reply
#3

Код:
 CMD:pm(playerid,params[])
    {
        new targetid, msg[128];
        if(sscanf(params, "us[128]", targetid, msg)) return SendClientMessage(playerid, LIGHTBLUE,"[ USAGE: /pm (name/id) (Message) ]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, red, "[ ERROR: Player is not online! ]");
        if(pm[targetid] == false) return SendClientMessage(playerid, red,"[ ERROR: Player has blocked private messages! ]");
        if(targetid == playerid) return SendClientMessage(playerid, red, "[ ERROR: You can't pm yourself! ]");
        new string[128], Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
        GetPlayerName(playerid, Name1, sizeof(Name1));
        GetPlayerName(targetid, Name2, sizeof(Name2));
        format(string, sizeof(string),"Private Message from %s (%d): %s", Name1, playerid, msg);
        SendClientMessage(targetid,COLOR_PINK, string);
        format(string, sizeof(string),"Private Message sent to %s (%d): %s", Name2, targetid, msg);
        SendClientMessage(playerid,COLOR_PINK, string);
        MessageLog(msg);
        return 1;
}

Код:
forward MessageLog(msg[]);
public MessageLog(msg[])
{
	new entry[256];
	format(entry,sizeof(entry),"%s\r\n",msg);
	new File:rFile;
	rFile = fopen("PM.txt",io_append);
	fwrite(rFile,entry);
	fclose(rFile);
}
Not tested but i think this will work
Reply
#4

Fixed!
Reply
#5

Try adding my code again because I edited it.
Reply
#6

Fixed!
Reply
#7

This will store date and time:
PHP код:
CMD:pm(playerid,params[]) 
    { 
        new 
targetidmsg[128]; 
        if(
sscanf(params"us[128]"targetidmsg)) return SendClientMessage(playeridLIGHTBLUE,"[ USAGE: /pm (name/id) (Message) ]"); 
        if(!
IsPlayerConnected(targetid)) return SendClientMessage(playeridred"[ ERROR: Player is not online! ]"); 
        if(
pm[targetid] == false) return SendClientMessage(playeridred,"[ ERROR: Player has blocked private messages! ]"); 
        if(
targetid == playerid) return SendClientMessage(playeridred"[ ERROR: You can't pm yourself! ]"); 
        new 
string[128], Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME]; 
        
GetPlayerName(playeridName1sizeof(Name1)); 
        
GetPlayerName(targetidName2sizeof(Name2)); 
        
format(stringsizeof(string),"Private Message from %s (%d): %s"Name1playeridmsg); 
        
SendClientMessage(targetid,COLOR_PINKstring); 
        
format(stringsizeof(string),"Private Message sent to %s (%d): %s"Name2targetidmsg); 
        
SendClientMessage(playerid,COLOR_PINKstring); 
        new 
File:file=fopen("PM.log"io_append), hourminutesecondyearmonthday;
        
Gettime(hourminutesecond);
        
Getdate(yearmonthday);
        
format(stringsizeof(string), "[%d/%d/%d, %d:%d:%d] %s to %s: %s\r\n"daymonthyearhourminutesecondName1Name2msg);
        
fwrite(filestring); 
        
fclose(file); 
        return 
1

If you want to change the directory, just change this line:
PHP код:
new File:file=fopen("PM.log"io_append); 
to:
PHP код:
new File:file=fopen("/database/PM.log"io_append); 
or anything.
Reply
#8

Fixed!
Reply
#9

use gettime and getdate
Reply
#10

Fixed:
PHP код:
CMD:pm(playerid,params[])  
    {  
        new 
targetidmsg[128];  
        if(
sscanf(params"us[128]"targetidmsg)) return SendClientMessage(playeridLIGHTBLUE,"[ USAGE: /pm (name/id) (Message) ]");  
        if(!
IsPlayerConnected(targetid)) return SendClientMessage(playeridred"[ ERROR: Player is not online! ]");  
        if(
pm[targetid] == false) return SendClientMessage(playeridred,"[ ERROR: Player has blocked private messages! ]");  
        if(
targetid == playerid) return SendClientMessage(playeridred"[ ERROR: You can't pm yourself! ]");  
        new 
string[128], Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];  
        
GetPlayerName(playeridName1sizeof(Name1));  
        
GetPlayerName(targetidName2sizeof(Name2));  
        
format(stringsizeof(string),"Private Message from %s (%d): %s"Name1playeridmsg);  
        
SendClientMessage(targetid,COLOR_PINKstring);  
        
format(stringsizeof(string),"Private Message sent to %s (%d): %s"Name2targetidmsg);  
        
SendClientMessage(playerid,COLOR_PINKstring);  
        new 
File:file=fopen("PM.log"io_append), hourminutesecondyearmonthday
        
gettime(hourminutesecond); 
        
getdate(yearmonthday); 
        
format(stringsizeof(string), "[%d/%d/%d, %d:%d:%d] %s to %s: %s\r\n"daymonthyearhourminutesecondName1Name2msg); 
        
fwrite(filestring);  
        
fclose(file);  
        return 
1;  

The title of this function in wiki https://sampwiki.blast.hk/wiki/Getdate is 'Getdate' but the real one is 'getdate' and 'gettime'.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)