Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FILTERSCRIPT
- #include <a_samp>
- #include <a_mysql>
- #include <sscanf2>
- #include <zcmd>
- /*
- ---------------------------Functions List----------------------------------------
- GetRepPoints(playerid) > Will get the total rep points of the 'playerid'
- AddNewUser(playerid) > This will add a new user to the table 'repinfo' with 0 reputation points
- SetRep(playerid, rep) > Sets the total reputation points to 'rep'
- GiveRep(playerid, rep) > Will get the rep points of the playerid and add the 'rep'
- */
- //Your MySQL Setup
- #define host "localhost"
- #define user "root"
- #define db "testpurpose"
- #define password ""
- // Time to wait before a player can rep again. (In Milliseconds, default is set to 30 mins)
- #define TimetoWait 1800000
- #define First.RequiredScore 50 // When a player has less than 50 score and does /rep other players, he's gonna give them,
- #define FirstRepPoints 1 // 1 Reputation Point
- #define Second.RequiredScore 120 // When a players score is < 120 but >= 50 and does /rep other players, he's gonna give them,
- #define SecondRepPoints 2 // 2 Reputation Point
- #define Third.RequiredScore 200
- #define ThirdRepPoints 3 // You get the point here
- #define Fourth.RequiredScore 330
- #define FourthRepPoints 4 // Change all values of the defines to your preference
- #define Fifth.RequiredScore 400
- #define FifthRepPoints 5
- new query[256];
- new msg[128];
- new time[MAX_PLAYERS];
- new bool:USEonPlayerClickPlayer = true;
- public OnFilterScriptInit()
- {
- mysql_connect(host, user, db, password);
- if(mysql_ping() >= 1) {
- print("Connected to the database\n"); }
- else print("Cannot connect to the database\n");
- mysql_debug(1);
- SetupTable();
- print("=============================================================");
- print("============== Neil's Reputation System Loaded ==============");
- print("=============================================================");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- format(query,sizeof(query), "SELECT `username` FROM `repinfo` WHERE `username` = '%s'", escpname(playerid));
- mysql_query(query);
- mysql_store_result();
- new rows = mysql_num_rows();
- if(!rows)
- {
- AddNewUser(playerid);
- }
- mysql_free_result();
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- time[playerid] = 0;
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- if(USEonPlayerClickPlayer == true)
- {
- if(clickedplayerid == playerid)
- {
- format(msg,sizeof(msg), "Your reputation point(s): %d", GetRepPoints(playerid));
- ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "{FF0000}Rep Points", msg, "Close", "");
- }
- else
- {
- format(msg,sizeof(msg), "%s's(%d) reputation point(s): %d", GetRepPoints(clickedplayerid));
- ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "{FFFF00}Rep Points", msg, "Close", "");
- }
- }
- else return 1;
- return 1;
- }
- //---------------------------------------------CMD-------------------------------
- CMD:rep(playerid, params[])
- {
- new target, points, reason[30], targetname[24], playeridname[24], newtime;
- points = HowManyReps(playerid);
- newtime = GetTickCount() - time[playerid];
- if(newtime < TimetoWait) return SendClientMessage(playerid, -1, "You just gave someone a reputation.");
- if(sscanf(params, "us[30]", target, reason)) return SendClientMessage(playerid, -1, "[USAGE]: /rep [playerid] [reason]");
- if(target == playerid) return SendClientMessage(playerid, 0xFF0000AA, "You cannot reputate yourself");
- if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "Player is not online");
- {
- GetPlayerName(playerid, playeridname, 24);
- GiveRep(target, points);
- format(msg,sizeof(msg), "** %s(%d) has given you {FF0000}%d{FFFFFF} reputation points due to %s **", playeridname, playerid, HowManyReps(playerid), reason);
- SendClientMessage(target, -1, msg);
- format(msg,sizeof(msg), "You now have {00FF00}%d {FFFFFF}Total Rep Points", GetRepPoints(target));
- SendClientMessage(target, -1, msg);
- GetPlayerName(target, targetname, 24);
- format(msg,sizeof(msg), "You have given %s(%d) %d reputation points. He now has %d reputation points.", targetname, target, HowManyReps(playerid), GetRepPoints(target));
- SendClientMessage(playerid, -1, msg);
- time[playerid] = GetTickCount();
- }
- return 1;
- }
- CMD:checkrep(playerid, params[]) return cmd_checkreps(playerid, params);
- CMD:checkreps(playerid, params[])
- {
- new target;
- if(sscanf(params, "u", target)) return SendClientMessage(playerid, -1, "[USAGE]: /checkrep [playerid]");
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(target, name, sizeof(name));
- format(msg,sizeof(msg), "%s's(%d) current rep: %d", name, target, GetRepPoints(target));
- SendClientMessage(playerid, -1, msg);
- }
- return 1;
- }
- CMD:myreps(playerid, params[]) return cmd_myrep(playerid, params);
- CMD:myrep(playerid, params[])
- {
- format(msg,sizeof(msg), "Your current reputation point(s) is: %d", GetRepPoints(playerid));
- SendClientMessage(playerid, -1, msg);
- return 1;
- }
- //-------------------------------------------------------------------------------
- public HowManyReps(playerid)
- {
- new repped;
- new score;
- score = GetPlayerScore(playerid);
- if(score < First.RequiredScore) return repped = FirstRepPoints;
- else if(score < Second.RequiredScore && score >= First.RequiredScore) return repped = SecondRepPoints;
- else if(score < Third.RequiredScore && score >= Second.RequiredScore) return repped = ThirdRepPoints;
- else if(score < Fourth.RequiredScore && score >= Third.RequiredScore) return repped = FourthRepPoints;
- else if(score < Fifth.RequiredScore && score >= Fourth.RequiredScore) return repped = FifthRepPoints;
- return repped;
- }
- public SetRep(playerid, rep)
- {
- format(query,sizeof(query), "UPDATE `repinfo` SET `reps` = '%d' WHERE `username` = '%s'", rep, escpname(playerid));
- mysql_query(query);
- return 1;
- }
- public GiveRep(playerid, rep)
- {
- new total;
- total = GetRepPoints(playerid) + rep;
- format(query,sizeof(query), "UPDATE `repinfo` SET `reps` = '%d' WHERE `username` = '%s'", total, escpname(playerid));
- mysql_query(query);
- return 1;
- }
- public GetRepPoints(playerid)
- {
- new value[10];
- format(query,sizeof(query), "SELECT `reps` FROM `repinfo` WHERE `username` = '%s'", escpname(playerid));
- mysql_query(query);
- mysql_store_result();
- mysql_fetch_row_format(query, "|");
- {
- format(value, sizeof(value), "%s", query);
- }
- new reps = strval(value);
- mysql_free_result();
- return reps;
- }
- public AddNewUser(playerid)
- {
- format(query,sizeof(query), "INSERT INTO `repinfo` (`username`, `reps`) VALUES ('%s', 0)", escpname(playerid));
- mysql_query(query);
- return 1;
- }
- SetupTable()
- {
- return mysql_query("CREATE TABLE IF NOT EXISTS `repinfo`(`username` VARCHAR(30), `reps` INT(7))");
- }
- //----------------------------------STOCK----------------------------------------
- stock escpname(playerid)
- {
- new Pname[MAX_PLAYER_NAME];
- new escname[24];
- GetPlayerName(playerid, Pname, sizeof(Pname));
- mysql_real_escape_string(Pname, escname);
- return escname;
- }
- //-------------------------------------------------------------------------------
- //---------------------------------FORWARDS--------------------------------------
- forward HowManyReps(playerid);
- forward GetRepPoints(playerid);
- forward AddNewUser(playerid);
- forward SetRep(playerid, rep);
- forward GiveRep(playerid, rep);
- //-------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment