PHP код:
#include <a_samp>
#include <zcmd>
#include <a_mysql>
#include <sscanf2>
#define MAX_FRIENDS 256
#define DIALOG_FRIENDS 1
#define DIALOG_NOFRIENDS 2
#define COLOR_GREEN {49ec4e}
#define COLOR_RED {ec4949}
#define COLOR_WHITE {ffffff}
public OnFilterScriptInit()
{
mysql_debug(1);
mysql_connect("localhost","root","friends","");
return 1;
}
enum E_PLAYER_DATA
{
TotalFriends = 0,
NombreAmigo[MAX_FRIENDS]
}
new PlayerInfo[MAX_PLAYERS][E_PLAYER_DATA];
public OnFilterScriptExit()
{
mysql_debug(0);
return 1;
}
CMD:friends(playerid, params[])
{
new query[254],
i[254],
name[512],string2[512];
format(query,sizeof(query),"SELECT * FROM `friendlist` WHERE `username` = '%s'",PlayerName(playerid));
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
while(mysql_fetch_row_format(query, "|"))
{
PlayerInfo[playerid][TotalFriends] ++;
mysql_fetch_field_row(i,"fr_name"); format(name,sizeof(name),i);
if(IsPlayerOnline(name))
{
format(name,sizeof(name),"{ffffff}%s - {49ec4e}ONLINE\n", name);
strcat(string2,name);
}
else
{
format(name,sizeof(name),"{ffffff}%s - {ec4949}OFFLINE\n", name);
strcat(string2,name);
}
ShowPlayerDialog(playerid, DIALOG_FRIENDS, DIALOG_STYLE_MSGBOX, "Your Friends:", string2, "Close", "");
}
}
else
{
ShowPlayerDialog(playerid, DIALOG_NOFRIENDS, DIALOG_STYLE_MSGBOX, "Your Friends:","You don't have any friends!", "Close", "");
}
return 1;
}
CMD:addfriend(playerid, params[])
{
new target;
if(sscanf(params, "u", target)) return SendClientMessage(playerid,-1,"Usage: /addfriend [PlayerName/ID]");
else if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid,-1,"ERROR: Invalid PlayerName/ID");
new string[256];
format(string,sizeof(string),"INSERT INTO `friendlist`(`username`, `fr_name`) VALUES ('%s','%s')",PlayerName(playerid),PlayerName(target));
mysql_query(string);
if(IsPlayerConnected(target))
{
format(string,sizeof(string),"You successfully added %s as friend",PlayerName(target));
SendClientMessage(playerid,-1,string);
}
mysql_free_result();
return 1;
}
stock TargetName(targetid)
{
new targetname[MAX_PLAYER_NAME];
GetPlayerName(playerid,targetname, sizeof(targetname));
return targetname;
}
stock PlayerName(playerid)
{
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,MAX_PLAYER_NAME);
return pname;
}
stock IsPlayerOnline(username[])
{
new pName[MAX_PLAYER_NAME];
for(new i=0; i < MAX_PLAYERS; i++)
{
GetPlayerName(i,pName, sizeof(pName));
if(!strcmp(pName,username,true)) return 1;//player online
}
return 0;//player offline
}