09.09.2011, 06:00
(
Last edited by KoczkaHUN; 09/09/2011 at 06:08 AM.
Reason: modify the expression in command
)
pawn Code:
#define REP_TYPE_GOLD (0)
#define REP_TYPE_SILVER (1)
#define REP_TYPE_BRONZE (2)
#define REP_TYPE_PLATINA (3)
stock GivePlayerReputation(playerid, type = REP_TYPE_BRONZE)
{
new REP_pFile[MAX_PLAYER_NAME+19] = "rep_", File:REP_pFileHnd, REP_repNum, REP_tmpStr[11];
if (!GetPlayerName(playerid, REP_pFile[4], MAX_PLAYER_NAME)) return 0;
strcat(REP_pFile, ".rep"); valstr(REP_tmpStr, type); strcat(REP_pFile, REP_tmpStr);
REP_pFileHnd = fopen(REP_pFile, io_readwrite);
fread(REP_pFileHnd, REP_tmpStr);
REP_repNum = strval(REP_tmpStr);
fclose(REP_pFileHnd);
REP_pFileHnd = fopen(REP_pFile, io_write);
valstr(REP_tmpStr, ++REP_repNum);
fwrite(REP_pFileHnd, REP_tmpStr);
fclose(REP_pFileHnd);
return REP_repNum;
}
stock GetPlayerReputation(playerid, type = REP_TYPE_BRONZE)
{
new REP_pFile[MAX_PLAYER_NAME+19] = "rep_", File:REP_pFileHnd, REP_repNum, REP_tmpStr[11];
if (!GetPlayerName(playerid, REP_pFile[4], MAX_PLAYER_NAME)) return 0;
strcat(REP_pFile, ".rep"); valstr(REP_tmpStr, type); strcat(REP_pFile, REP_tmpStr);
if (!fexist(REP_pFile)) return 0;
REP_pFileHnd = fopen(REP_pFile, io_read);
fread(REP_pFileHnd, REP_tmpStr);
REP_repNum = strval(REP_tmpStr);
fclose(REP_pFileHnd);
return REP_repNum;
}
// example usage with zcmd + sscanf
CMD:giverep(playerid, params[])
{
static gRep_playerid, gRep_reptype, gRep_current, gRep_string[128], gRep_reptypeStr[16], gRep_name[24];
if (sscanf(params, "ui", gRep_playerid, gRep_reptype)) return SendClientMessage(playerid, 0xff0000aa, "* Usage: /giverep [playerid/name] [reputation type]");
if (gRep_reptype < 0 || gRep_reptype > 3) return SendClientMessage(playerid, 0xff0000aa, "* Valid reputation types: 0-3");
if (0 == (gRep_current = GivePlayerReputation(gRep_playerid, gRep_reptype)) ) return SendClientMessage(playerid, 0xff0000aa, "* Error while trying to add to player's reputation.");
switch (gRep_reptype)
{
case REP_TYPE_GOLD: gRep_reptypeStr = "Gold";
case REP_TYPE_SILVER: gRep_reptypeStr = "Silver";
case REP_TYPE_BRONZE: gRep_reptypeStr = "Bronze";
case REP_TYPE_PLATINA: gRep_reptypeStr = "Platina";
}
GetPlayerName(gRep_playerid, gRep_name, 24);
format(gRep_string, 128, "* You have added to %s's %s reputation! Player's current %s reputation: %d",
gRep_name, gRep_reptypeStr, gRep_reptypeStr, gRep_current);
SendClientMessage(playerid, -1, gRep_string);
GetPlayerName(playerid, gRep_name, 24);
format(gRep_string, 128, "* %s's added to your %s reputation! Your current %s reputation: %d",
gRep_name, gRep_reptypeStr, gRep_reptypeStr, gRep_current);
return 1;
}

