Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Profile System by [SP]Sinner
- Public release on SA-MP forums
- on June 27th 2012
- Please keep all credits intact.
- */
- #include <a_samp>
- #include <a_mysql>
- #include <sscanf2>
- // dcmd: credits to Dracoblue
- #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- #define DIALOG_PROFILE (400)
- #define DIALOG_PROFILE_CREATE0 (401)
- #define DIALOG_PROFILE_CREATE1 (402)
- #define DIALOG_PROFILE_CREATE2 (403)
- #define DIALOG_PROFILE_CREATE3 (404)
- #define DIALOG_FRIENDS (405)
- #define COLOR_NICEBLUE 0x00FFFFFF
- #define COLOR_REDONLY 0xE60000FF
- #define COLOR_RED 0xAA3333AA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_ORANGE 0xFF9900AA
- #define COLOR_YELLOW 0xFFDD00AA
- ////////////////////////////////////////////////////////////////////////////////
- // FILL IN YOUR MYSQL DATABASE DETAILS HERE
- #define SQL_HOST ""
- #define SQL_USER ""
- #define SQL_PASS ""
- #define SQL_DB ""
- ////////////////////////////////////////////////////////////////////////////////
- new StrColors[][] = {
- {"White"},{"Green"},{"Blue"},{"Red"},{"Yellow"},{"Pink"},{"Orange"},{"Aqua"},{"Cyan"},{"Lime"}
- };
- new HexColors[][] = {
- "FFFFFF","00FF00","2222FF","FF0000","FFFF33","FF33CC","FF9900","33FFFF","66CCFF","00FF33"
- };
- new ProfileCreate[][] = {
- {"{FFFFFF}Profile Creation: Step 1\n\n{00FF00}What is your {FF0000}Sex?\n{FFFFFF}Options: {00FF00}[Male/Female]"},
- {"{FFFFFF}Profile Creation: Step 2\n\n{00FF00}What is your {FF0000}Age?\n{FFFFFF}Options: {00FF00}[1-100]"},
- {"{FFFFFF}Profile Creation: Step 3\n\n{00FF00}What is your {FF0000}email?\n{FFFFFF}Example: {00FF00}[[email protected]]"},
- {"{FFFFFF}{00FF00}Please choose your profile color."}
- };
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" Profile system by [SP]Sinner");
- print("--------------------------------------\n");
- f_mysql_connect();
- CreateProfileMySQL();
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason) {
- if(GetPVarInt(playerid, "call_host")) {
- new str[128];
- format(str, sizeof(str), "The call hosted by %s has been closed because the host left!", PlayerName(playerid));
- SendCallRoomMessage(GetPVarInt(playerid, "call_host"), str);
- CloseCall(playerid);
- }
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- if(strcmp("showcalls", text, true) == 0) {
- toString();
- }
- if(text[0] == '&') {
- new str[128];
- format(str, sizeof(str), "[FRIEND-CHAT] %s (ID:%d): %s", PlayerName(playerid), playerid, text[1]);
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i)) {
- if(IsAcceptedFriend(playerid, PlayerName(i)) || playerid == i) {
- SendClientMessage(i, COLOR_NICEBLUE << 1, str);
- }
- }
- }
- return 0;
- }
- if(text[0] == '$') {
- if(GetPVarInt(playerid, "callid")) {
- format(text, 128, "[CALL] %s: %s", PlayerName(playerid), text[1]);
- SendCallRoomMessage(GetPVarInt(playerid, "callid"), text);
- return 0;
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_PROFILE) {
- if(!response) {
- new pname[24];
- GetPVarString(playerid, "profileviewing", pname, sizeof(pname));
- new str[128];
- if(strcmp(pname, PlayerName(playerid), true) != 0) {
- AddLikes(pname, 1);
- format(str, sizeof(str), "%s (ID:%d) has liked the profile of player %s!", PlayerName(playerid), playerid, pname);
- SendClientMessageToAll(COLOR_GREEN, str);
- } else {
- SendClientMessage(playerid, COLOR_RED, "You can't like your own profile!");
- }
- DeletePVar(playerid, "profileviewing");
- }
- }
- if(dialogid == DIALOG_PROFILE_CREATE0) {
- if(response) {
- if(strcmp(inputtext, "male", true) == 0 || strcmp(inputtext, "female", true) == 0) {
- SetSex(playerid, inputtext);
- new query[128];
- format(query, sizeof(query), "[PROFILE] You have changed your sex to %s", inputtext);
- SendClientMessage(playerid, COLOR_NICEBLUE, query);
- ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE1, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[1], "OK", "CANCEL");
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "[PROFILE] Please enter a valid sex [Male/Female]");
- ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE0, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[0], "OK", "CANCEL");
- }
- } else ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE0, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[0], "OK", "CANCEL");
- }
- if(dialogid == DIALOG_PROFILE_CREATE1) {
- if(response) {
- new age;
- sscanf(inputtext, "d", age);
- if(age > 0 && age < 100) {
- SetAge(playerid, age);
- new query[128];
- format(query, sizeof(query), "[PROFILE] You have changed your age to %d", age);
- SendClientMessage(playerid, COLOR_NICEBLUE, query);
- ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE2, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[2], "OK", "CANCEL");
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "[PROFILE] Please enter a valid age [1-100]");
- ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE1, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[1], "OK", "CANCEL");
- }
- } else ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE1, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[1], "OK", "CANCEL");
- }
- if(dialogid == DIALOG_PROFILE_CREATE2) {
- new bigstr[512];
- for(new i=0; i<sizeof(StrColors); i++) {
- if(strlen(bigstr)) format(bigstr, sizeof(bigstr), "%s\n%s", bigstr, StrColors[i]);
- else format(bigstr, sizeof(bigstr), "%s", StrColors[i]);
- }
- if(response) {
- new atcount, dotcount, len = strlen(inputtext);
- for(new i=0; i<(strlen(inputtext)); i++) {
- if(inputtext[i] == '@') atcount++;
- if(inputtext[i] == '.') dotcount++;
- }
- if(atcount && dotcount && len > 9) {
- SetEmail(playerid, inputtext);
- new query[128];
- format(query, sizeof(query), "[PROFILE] You have changed your email to %s", inputtext);
- SendClientMessage(playerid, COLOR_NICEBLUE, query);
- ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE3, DIALOG_STYLE_LIST, ProfileCreate[3], bigstr, "OK", "CANCEL");
- }
- } else ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE2, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[2], "OK", "CANCEL");
- }
- if(dialogid == DIALOG_PROFILE_CREATE3) {
- if(response) {
- SetColor(playerid, listitem);
- new query[128];
- format(query, sizeof(query), "[PROFILE] You have changed your profile color to %s", StrColors[listitem]);
- SendClientMessage(playerid, COLOR_NICEBLUE, query);
- SendClientMessage(playerid, COLOR_GREEN, "[PROFILE] Your profile has been created! Go to your profile by typing /Profile, edit it by typing /CreateProfile again");
- } else {
- new bigstr[512];
- for(new i=0; i<sizeof(StrColors); i++) {
- if(strlen(bigstr)) format(bigstr, sizeof(bigstr), "%s\n%s", bigstr, StrColors[i]);
- else format(bigstr, sizeof(bigstr), "%s", StrColors[i]);
- }
- ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE3, DIALOG_STYLE_LIST, ProfileCreate[3], bigstr, "OK", "CANCEL");
- }
- }
- return 0;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(profile, 7, cmdtext);
- dcmd(createprofile, 13, cmdtext);
- dcmd(addfriend, 9, cmdtext);
- dcmd(removefriend, 12, cmdtext);
- dcmd(friends, 7, cmdtext);
- dcmd(uafriends, 9, cmdtext);
- dcmd(like, 4, cmdtext);
- dcmd(call, 4, cmdtext);
- dcmd(pickup, 6, cmdtext);
- dcmd(hangup, 6, cmdtext);
- dcmd(invite, 6, cmdtext);
- return 0;
- }
- dcmd_profile(playerid, params[]) {
- new pid;
- if(sscanf(params, "d", pid)) {
- if(HasProfile(PlayerName(playerid))) {
- ShowProfile(playerid, PlayerName(playerid));
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "You don't have a profile yet, type /CreateProfile to make one!");
- }
- } else if(HasProfile(PlayerName(pid))) {
- ShowProfile(playerid, PlayerName(pid));
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "This player does not have a profile yet!");
- }
- return 1;
- }
- dcmd_createprofile(playerid, params[]) {
- #pragma unused params
- if(!HasProfile(PlayerName(playerid))) {
- CreateProfile(PlayerName(playerid));
- }
- SetPVarInt(playerid, "creatingprofile", 1);
- ShowPlayerDialog(playerid, DIALOG_PROFILE_CREATE0, DIALOG_STYLE_INPUT, "Profile Creation", ProfileCreate[0], "OK", "CANCEL");
- return 1;
- }
- dcmd_addfriend(playerid, params[]) {
- new pid;
- if(sscanf(params, "d", pid)) return SendClientMessage(playerid, COLOR_REDONLY, "USAGE: /AddFriend [ID] - Add a player as a friend");
- new friend[24];
- GetPlayerName(pid, friend, sizeof(friend));
- if(pid == playerid) return SendClientMessage(playerid, COLOR_REDONLY, "You can't add yourself as a friend");
- if(IsAcceptedFriend(playerid, friend)) return SendClientMessage(playerid, COLOR_REDONLY, "This player is already your friend, type /FriendChat to chat with your friends");
- new str[128];
- if(IsInvitedFriend(playerid, friend)) {
- AcceptFriend(playerid, friend);
- format(str, sizeof(str), "(/Profile) %s and %s are now friends!", PlayerName(playerid), friend);
- SendClientMessageToAll(COLOR_NICEBLUE, str);
- } else {
- AddFriend(playerid, friend);
- format(str, sizeof(str), "[PROFILE] %s invited to be your friend, you will be friends as soon as he/she accepts your request!", friend);
- SendClientMessage(playerid, COLOR_NICEBLUE, str);
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i)) {
- if(strcmp(PlayerName(i), friend, true) == 0) {
- format(str, sizeof(str), "[FRIEND INVITE] %s wants to be friends with you! Type \"/AddFriend %d\" to add him as a friend!", PlayerName(playerid), playerid);
- SendClientMessage(pid, COLOR_YELLOW, str);
- }
- }
- }
- }
- return 1;
- }
- dcmd_removefriend(playerid, params[]) {
- new pid;
- if(sscanf(params, "d", pid)) return SendClientMessage(playerid, COLOR_REDONLY, "USAGE: /RemoveFriend [ID] - Remove one of your friends");
- if(!IsPlayerConnected(pid)) return SendClientMessage(playerid, COLOR_REDONLY, "This player is not connected");
- if(IsInvitedFriend(playerid, PlayerName(pid)) || IsAcceptedFriend(playerid, PlayerName(pid))) {
- RemoveFriend(playerid, PlayerName(pid));
- new str[128];
- format(str, sizeof(str), "You have removed %s (ID:%d) from your friends list", PlayerName(pid), pid);
- SendClientMessage(playerid, COLOR_ORANGE, str);
- format(str, sizeof(str), "%s (ID:%d) has removed you from his/her friends list", PlayerName(playerid), playerid);
- SendClientMessage(pid, COLOR_ORANGE, str);
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "this player is not your friend");
- }
- return 1;
- }
- dcmd_friends(playerid, params[]) {
- new pid;
- if(sscanf(params, "d", pid)) {
- ShowAcceptedFriends(playerid, PlayerName(playerid));
- } else {
- ShowAcceptedFriends(playerid, PlayerName(pid));
- }
- return 1;
- }
- dcmd_uafriends(playerid, params[]) {
- new pid;
- if(sscanf(params, "d", pid)) {
- ShowUnAcceptedFriends(playerid, PlayerName(playerid));
- } else {
- ShowUnAcceptedFriends(playerid, PlayerName(pid));
- }
- return 1;
- }
- dcmd_like(playerid, params[]) {
- new pid;
- if(sscanf(params, "d", pid)) return SendClientMessage(playerid, COLOR_REDONLY, "USAGE: /Like [ID] - Like a players profile");
- new pname[24];
- GetPlayerName(pid, pname, sizeof(pname));
- new str[128];
- if(pid != playerid) {
- AddLikes(pname, 1);
- format(str, sizeof(str), "%s (ID:%d) has liked the profile of player %s!", PlayerName(playerid), playerid, pname);
- SendClientMessageToAll(COLOR_GREEN, str);
- } else {
- SendClientMessage(playerid, COLOR_RED, "You can't like your own profile!");
- }
- return 1;
- }
- dcmd_call(playerid, params[]) {
- new data[32];
- if(sscanf(params, "s[32]", data)) return SendClientMessage(playerid, COLOR_REDONLY, "USAGE: /Call [ID/phone number] - Call a player who (do /profile [ID] to find a players phone)");
- new pid;
- if(IsPlayerConnected(strval(data))) {
- pid = strval(data);
- } else {
- pid = GetPlayerIDByPhone(data);
- }
- if(IsPlayerConnected(pid)) {
- if(GetPVarInt(playerid, "callid")) return SendClientMessage(playerid, COLOR_REDONLY, "You are already calling someone, type /hangup to hang up first");
- if(GetPVarInt(pid, "callid")) {
- new str[128];
- format(str, sizeof(str), "%s (ID:%d) tried to call you, /invite him to your call or /hangup if you want to speak with him", PlayerName(playerid), playerid);
- SendClientMessage(pid, COLOR_ORANGE, str);
- return SendClientMessage(playerid, COLOR_REDONLY, "This player is already in a call, we told him you tried to contact him");
- }
- if(pid == playerid) return SendClientMessage(playerid, COLOR_REDONLY, "You cant call yourself");
- if(CreateCallRoom(playerid)) {
- if(CallPlayer(playerid, pid)) {
- new str[128];
- format(str, sizeof(str), "You started calling, %s will have to /pickup your call", PlayerName(pid));
- SendClientMessage(playerid, COLOR_ORANGE, str);
- format(str, sizeof(str), "%s (ID:%d) is calling you!! Type /Pickup to pickup your phone", PlayerName(playerid), playerid);
- SendClientMessage(pid, COLOR_ORANGE, str);
- }
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "You are already in a call, or the host of a call, type /Hangup to leave your current conversation");
- }
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "Error: We could not find this player, he is either offline or you entered a wrong phone number/ID");
- }
- return 1;
- }
- dcmd_invite(playerid, params[]) {
- new data[32];
- if(sscanf(params, "s[32]", data)) return SendClientMessage(playerid, COLOR_REDONLY, "USAGE: /Invite [ID/phone number] - Invite a player to your call (do /profile [ID] to find a players phone)");
- new pid;
- if(IsPlayerConnected(strval(data))) {
- pid = strval(data);
- } else {
- pid = GetPlayerIDByPhone(data);
- }
- if(IsPlayerConnected(pid)) {
- if(!GetPVarInt(playerid, "callid")) return SendClientMessage(playerid, COLOR_REDONLY, "You are currently not in a call");
- if(!GetPVarInt(playerid, "call_host")) return SendClientMessage(playerid, COLOR_REDONLY, "You are not rhe host of this call, can't invite someone");
- if(GetPVarInt(pid, "callid")) return SendClientMessage(playerid, COLOR_REDONLY, "This player is already in a call");
- if(pid == playerid) return SendClientMessage(playerid, COLOR_REDONLY, "You cant invite yourself");
- if(CallPlayer(playerid, pid)) {
- new str[128];
- format(str, sizeof(str), "You started calling, %s will have to /pickup your call", PlayerName(pid));
- SendClientMessage(playerid, COLOR_ORANGE, str);
- format(str, sizeof(str), "%s (ID:%d) is calling you!! Type /Pickup to pickup your phone", PlayerName(playerid), playerid);
- SendClientMessage(pid, COLOR_ORANGE, str);
- }
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "Error: We could not find this player, he is either offline or you entered a wrong phone number/ID");
- }
- return 1;
- }
- dcmd_pickup(playerid, params[]) {
- #pragma unused params
- if(GetPVarInt(playerid, "call_invite")) {
- if(!GetPVarInt(playerid, "callid")) {
- new callid = GetPVarInt(playerid, "call_invite");
- DeletePVar(playerid, "call_invite");
- if(JoinCall(callid, playerid)) {
- new str[128];
- format(str, sizeof(str), "%s (ID:%d) picked up the call! You can talk to him using $[text]", PlayerName(playerid), playerid);
- SendCallRoomMessage(callid, str);
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "Oops! This call room is full or does not exist!");
- }
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "You are already in a call!");
- }
- }
- return 1;
- }
- dcmd_hangup(playerid, params[]) {
- #pragma unused params
- if(GetPVarInt(playerid, "call_host")) {
- new str[128];
- format(str, sizeof(str), "The call hosted by %s has been closed because the host left!", PlayerName(playerid));
- SendCallRoomMessage(GetPVarInt(playerid, "call_host"), str);
- CloseCall(playerid);
- } else if(GetPVarInt(playerid, "callid")) {
- new str[128];
- format(str, sizeof(str), "%s (ID:%s) has left the call!", PlayerName(playerid), playerid);
- SendCallRoomMessage(GetPVarInt(playerid, "callid"), str);
- LeaveCall(playerid);
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "You are currently not in a call");
- }
- return 1;
- }
- stock CreateProfileMySQL() {
- mysql_query("\
- CREATE TABLE profiles\
- (\
- ID int NOT NULL AUTO_INCREMENT,\
- PRIMARY KEY(ID),\
- username varchar(24),\
- sex varchar(12),\
- age int,\
- email varchar(64),\
- phone varchar(32),\
- likes int,\
- status int,\
- color int\
- );\
- ");
- mysql_query("\
- CREATE TABLE friends\
- (\
- ID int NOT NULL AUTO_INCREMENT,\
- PRIMARY KEY(ID),\
- username varchar(24),\
- friend varchar(24),\
- accepted int\
- );\
- ");
- return 1;
- }
- stock SetSex(playerid, sex[]) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `sex` = '%s' WHERE `username` = '%s'", sex, PlayerName(playerid));
- mysql_query(query);
- }
- stock GetSex(playerid) {
- new sex[12];
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- mysql_get_field("sex", sex);
- }
- mysql_free_result();
- return sex;
- }
- stock SetAge(playerid, age) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `age` = %d WHERE `username` = '%s'", age, PlayerName(playerid));
- mysql_query(query);
- }
- stock GetAge(playerid) {
- new age;
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- age = mysql_get_int("age");
- }
- mysql_free_result();
- return age;
- }
- stock SetEmail(playerid, email[]) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `email` = '%s' WHERE `username` = '%s'", email, PlayerName(playerid));
- mysql_query(query);
- }
- stock GetEmail(playerid) {
- new email[64];
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- mysql_get_field("email", email);
- }
- mysql_free_result();
- return email;
- }
- stock SetPhone(playerid, phone[]) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `phone` = '%s' WHERE `username` = '%s'", phone, PlayerName(playerid));
- mysql_query(query);
- }
- stock GetPhone(playerid) {
- new phone[32];
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- mysql_get_field("phone", phone);
- }
- mysql_free_result();
- return phone;
- }
- stock GetPlayerIDByPhone(data[]) {
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i)) {
- if(strcmp(data, GetPhone(i), true) == 0) {
- return i;
- }
- }
- }
- return -1;
- }
- stock SetLikes(playerid, likes) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `likes` = %d WHERE `username` = '%s'", likes, PlayerName(playerid));
- mysql_query(query);
- }
- stock GetLikes(playerid) {
- new likes;
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- likes = mysql_get_int("likes");
- }
- mysql_free_result();
- return likes;
- }
- stock AddLikes(name[], amount) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `likes` = (`likes` + %d) WHERE `username` = '%s'", amount, name);
- mysql_query(query);
- }
- stock SetStatus(playerid, status) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `status` = %d WHERE `username` = '%s'", status, PlayerName(playerid));
- mysql_query(query);
- }
- stock GetStatus(playerid) {
- new status;
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- status = mysql_get_int("status");
- }
- mysql_free_result();
- return status;
- }
- stock SetColor(playerid, color) {
- new query[128];
- format(query, sizeof(query), "UPDATE `profiles` SET `color` = %d WHERE `username` = '%s'", color, PlayerName(playerid));
- mysql_query(query);
- }
- stock GetColor(playerid) {
- new color;
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- color = mysql_get_int("color");
- }
- mysql_free_result();
- return color;
- }
- stock AddFriend(playerid, friend[]) {
- new query[256];
- format(query, sizeof(query), "INSERT INTO `friends` (`username`, `friend`, `accepted`) VALUES('%s', '%s', 0)", PlayerName(playerid), friend);
- mysql_query(query);
- }
- stock RemoveFriend(playerid, friend[]) {
- new query[256];
- format(query, sizeof(query), "DELETE FROM `friends` WHERE (`username` = '%s' AND `friend` = '%s') OR (`friend` = '%s' AND `username` = '%s')", PlayerName(playerid), friend, PlayerName(playerid), friend);
- mysql_query(query);
- }
- stock IsInvitedFriend(playerid, friend[]) {
- new query[256];
- new bool:isfriend = false;
- format(query, sizeof(query), "SELECT * FROM `friends` WHERE (`username` = '%s' AND `friend` = '%s' AND `accepted` = 0) OR (`username` = '%s' AND `friend` = '%s' AND `accepted` = 0)",
- PlayerName(playerid), friend, friend, PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- isfriend = mysql_num_rows()>0;
- mysql_free_result();
- return isfriend;
- }
- stock IsAcceptedFriend(playerid, friend[]) {
- new query[256];
- new bool:isfriend = false;
- format(query, sizeof(query), "SELECT * FROM `friends` WHERE (`username` = '%s' AND `friend` = '%s' AND `accepted` = 1) OR (`username` = '%s' AND `friend` = '%s' AND `accepted` = 1) ",
- PlayerName(playerid), friend, friend, PlayerName(playerid));
- mysql_query(query);
- mysql_store_result();
- isfriend = mysql_num_rows()>0;
- mysql_free_result();
- return isfriend;
- }
- stock AcceptFriend(playerid, friend[]) {
- new query[256];
- format(query, sizeof(query), "UPDATE `friends` SET `accepted` = 1 WHERE (`username` = '%s' AND `friend` = '%s') OR (`username` = '%s' AND `friend` = '%s')",
- PlayerName(playerid), friend, friend, PlayerName(playerid));
- mysql_query(query);
- }
- stock HasProfile(name[]) {
- new query[128];
- new bool:hasprofile = false;
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` LIKE '%s'", name);
- mysql_query(query);
- mysql_store_result();
- hasprofile = mysql_num_rows()>0;
- mysql_free_result();
- return hasprofile;
- }
- stock ShowProfile(playerid, name[]) {
- new query[128];
- format(query, sizeof(query), "SELECT * FROM `profiles` WHERE `username` = '%s'", name);
- mysql_query(query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- new str[1024];
- new sex[12], age, email[64], phone[6], likes, status, color;
- mysql_get_field("sex", sex);
- age = mysql_get_int("age");
- mysql_get_field("email", email);
- mysql_get_field("phone", phone);
- likes = mysql_get_int("likes");
- status = mysql_get_int("status");
- color = mysql_get_int("color");
- format(str, sizeof(str), "{%s}Profile of %s\n\nSex\t\t:\t\t%s\nAge\t\t:\t\t%d\nEmail\t\t:\t\t%s\nPhone\t\t:\t\t%s\nProfile Likes\t:\t\t%d\nProfile Status\t:\t\t%d",
- HexColors[color], name, sex, age, email, phone, likes, status);
- ShowPlayerDialog(playerid, DIALOG_PROFILE, DIALOG_STYLE_MSGBOX, "Profile", str, "OK", "LIKE");
- SetPVarString(playerid, "profileviewing", name);
- }
- mysql_free_result();
- }
- stock CreateProfile(name[]) {
- new query[256], phone[6];
- format(phone, sizeof(phone), "%d%d%d%d%d", random(10), random(10), random(10), random(10), random(10));
- format(query, sizeof(query), "INSERT INTO `profiles` (`username`, `sex`, `age`, `email`, `phone`, `likes`, `status`, `color`) VALUES('%s', null, null, null, '%s', 0, 0, 0)",
- name, phone);
- mysql_query(query);
- }
- stock ShowAcceptedFriends(playerid, name[]) {
- new query[256];
- format(query, sizeof(query), "SELECT * FROM `friends` WHERE (`username` = '%s' OR `friend` = '%s') AND `accepted` = 1 ORDER BY `accepted` DESC", name, name);
- mysql_query(query);
- mysql_store_result();
- if(mysql_num_rows()>0) {
- new str[1024];
- format(str, sizeof(str), "{00FF00}%s{FFFFFF}'s friends list\n{FFFFFF}=================================\n{00FF00}||| = Accepted {FF0000}||| = Not accepted yet\n{FFFFFF}=================================\n\n{FFAA00}", name);
- new uname[24], fname[24];
- while(mysql_retrieve_row()) {
- mysql_get_field("username", uname);
- mysql_get_field("friend", fname);
- new color[16];
- format(color, sizeof(color), "{00FF00}");
- if(strcmp(uname, name, true) == 0) {
- format(str, sizeof(str), "%s%s%s\n", str, color, fname);
- } else {
- format(str, sizeof(str), "%s%s%s\n", str, color, uname);
- }
- }
- ShowPlayerDialog(playerid, DIALOG_FRIENDS, DIALOG_STYLE_MSGBOX, "Accepted Friends list", str, "OK", "CANCEL");
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "This player doesn't have any friends yet!");
- }
- mysql_free_result();
- return 1;
- }
- stock ShowUnAcceptedFriends(playerid, name[]) {
- new query[256];
- format(query, sizeof(query), "SELECT * FROM `friends` WHERE (`username` = '%s' OR `friend` = '%s') AND `accepted` = 0 ORDER BY `accepted` DESC", name, name);
- mysql_query(query);
- mysql_store_result();
- if(mysql_num_rows()>0) {
- new str[1024];
- format(str, sizeof(str), "{00FF00}%s{FFFFFF}'s friends list\n{FFFFFF}=================================\n{00FF00}||| = Accepted {FF0000}||| = Not accepted yet\n{FFFFFF}=================================\n\n{FFAA00}", name);
- new uname[24], fname[24];
- while(mysql_retrieve_row()) {
- mysql_get_field("username", uname);
- mysql_get_field("friend", fname);
- new color[16];
- format(color, sizeof(color), "{FF0000}");
- if(strcmp(uname, name, true) == 0) {
- format(str, sizeof(str), "%s%s%s\n", str, color, fname);
- } else {
- format(str, sizeof(str), "%s%s%s\n", str, color, uname);
- }
- }
- ShowPlayerDialog(playerid, DIALOG_FRIENDS, DIALOG_STYLE_MSGBOX, "Unaccepted Friends list", str, "OK", "CANCEL");
- } else {
- SendClientMessage(playerid, COLOR_REDONLY, "This player doesn't have any unaccepted friends yet!");
- }
- mysql_free_result();
- return 1;
- }
- stock GetCallHost(callid) {
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i)) {
- if(GetPVarInt(i, "call_host") == callid) {
- return i;
- }
- }
- }
- return -1;
- }
- stock CreateCallRoom(p_host) {
- new callid = 1+p_host;
- if(IsPlayerConnected(p_host)) {
- SetPVarInt(p_host, "call_host", callid);
- JoinCall(callid, p_host);
- return 1;
- } else {
- //printf("DEBUG: Could not create call room");
- return 0;
- }
- }
- stock JoinCall(callid, p_joinid) {
- if(GetCallHost(callid) != -1) {
- SetPVarInt(p_joinid, "callid", callid);
- return 1;
- } else {
- //printf("DEBUG: Player ID:%d could not join call %d", p_joinid, callid);
- return 0;
- }
- }
- stock CallPlayer(p_caller, p_called) {
- new callid = GetPVarInt(p_caller, "callid");
- if(GetPVarInt(p_caller, "call_host") == callid) {
- SetPVarInt(p_called, "call_invite", callid);
- printf("DEBUG: Call host %d invited player ID:%d to call with id %d", p_caller, p_called, callid);
- return 1;
- } else {
- //printf("DEBUG: p_caller ID:%d was not host of call @ CallPlayer(p_caller, p_called), please fix.", p_caller);
- return 0;
- }
- }
- stock SendCallRoomMessage(callid, string[]) {
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i)) {
- if(GetPVarInt(i, "callid") == callid) {
- SendClientMessage(i, COLOR_YELLOW, string);
- }
- }
- }
- }
- stock toString() {
- new str[128];
- printf("Printing out all current calls and their callers:");
- printf("---------------------------------------------------------------------");
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(GetPVarInt(i, "call_host")) {
- format(str, sizeof(str), "Call ID:%d, host: %s ID:%d", i, PlayerName(i), i);
- SendClientMessageToAll(-1, str);
- for(new j=0; j<MAX_PLAYERS; j++) {
- if(IsPlayerConnected(j) && GetPVarInt(j, "callid") == GetPVarInt(i, "call_host")) {
- format(str, sizeof(str), "--- Caller %d: %s", j, PlayerName(j));
- SendClientMessageToAll(-1, str);
- }
- }
- }
- }
- }
- stock GetCallCount() {
- new count = 0;
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i) && GetPVarInt(i, "call_host"))
- count++;
- }
- return count;
- }
- stock LeaveCall(playerid) {
- DeletePVar(playerid, "callid");
- }
- stock CloseCall(host) {
- new count=0;
- for(new i=0; i<MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i) && GetPVarInt(i, "callid") == GetPVarInt(host, "call_host")) {
- LeaveCall(i);
- count++;
- }
- }
- DeletePVar(host, "call_host");
- //printf("DEBUG: The call hosted by %s has been closed, %d people were disconnected", PlayerName(host), count);
- }
- stock f_mysql_connect()
- {
- new conn;
- if(!(conn = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))) {
- print("SQL connection attempt 1 FAILED!");
- if(!(conn = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))) {
- print("SQL connection attempt 2 FAILED!");
- if(!(conn = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))) {
- print("SQL connection attempt 3 FAILED!");
- print("Server could not connect to SQL database");
- return 0;
- }
- }
- }
- printf("Server succesfully connected to SQL database \"%d\"", conn);
- SetPVarInt(-1, "mysql_connection", conn);
- return 1;
- }
- stock mysql_get_int(field[])
- {
- new str[19];
- mysql_get_field(field, str);
- return strval(str);
- }
- stock PlayerName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
Advertisement
Add Comment
Please, Sign In to add comment