SA-MP Forums Archive
Need small help with PM - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need small help with PM (/showthread.php?tid=567375)



Need small help with PM - Sc0pion - 13.03.2015

Fixed!


Re: Need small help with PM - ATGOggy - 13.03.2015

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.


Re: Need small help with PM - Nabster - 13.03.2015

Код:
 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


Re: Need small help with PM - Sc0pion - 13.03.2015

Fixed!


Re: Need small help with PM - ATGOggy - 13.03.2015

Try adding my code again because I edited it.


Re: Need small help with PM - Sc0pion - 13.03.2015

Fixed!


Re: Need small help with PM - ATGOggy - 13.03.2015

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.


Re: Need small help with PM - Sc0pion - 13.03.2015

Fixed!


Re: Need small help with PM - Nabster - 13.03.2015

use gettime and getdate


Re: Need small help with PM - ATGOggy - 13.03.2015

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'.