Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <clientprefs>
- // Add your own functions, stocks, natives and/or forwards here
- /** Double-include prevention */
- #if defined _karma_included_
- #endinput
- #endif
- #define _karma_included_
- #define CLR_DEFAULT 1
- #define CLR_LIGHTGREEN 3
- #define CLR_GREEN 4
- #define CLR_DARKGREEN 5
- enum KarmaInfo
- {
- Karma_Value,
- Karma_Kicks,
- Karma_Bans
- }
- enum KarmaSetting
- {
- Karma_Max,
- Karma_Min,
- Karma_KickBan, // Kick Or Ban, 0 = Kick, 1 = Ban
- Karma_BanTime,
- Karma_MaxKicks,
- Karma_MaxBans,
- Karma_ResetTime
- }
- /**
- * Gets a clients current karma value
- *
- * @param client Client index
- * @param type KarmaInfo type
- * @return The integer value correlating with the type.
- */
- native Karma_Get(client,KarmaInfo:type);
- /**
- * Sets a clients current karma value
- *
- * @param client Client index
- * @param type KarmaInfo type
- * @param value The value (integer) in which to set a client's karma to.
- * @noreturn
- */
- native Karma_Set(client, KarmaInfo:type, value);
- /**
- * Sets a clients current karma value
- *
- * @param type KarmaSetting type
- * @return The integer value of KarmaSetting, -1 if fails to find setting
- */
- native Karma_Setting(KarmaSetting:type);
- public SharedPlugin:__pl_stac =
- {
- name = "karma",
- file = "karma.smx",
- #if defined REQUIRE_PLUGIN
- required = 1,
- #else
- required = 0,
- #endif
- };
- public __pl_stac_SetNTVOptional()
- {
- MarkNativeAsOptional("Karma_Get");
- MarkNativeAsOptional("Karma_Set");
- MarkNativeAsOptional("Karma_Setting");
- }
- ================================================================================
- #include <karma>
- public Plugin:myinfo =
- {
- name = "Karma",
- author = "FlyingMongoose",
- description = "Creates a Karma System",
- version = "1.0",
- url = "http://www.brbuninstalling.com/"
- }
- new Handle:cvarMaxKarma;
- new Handle:cvarMinKarma;
- new Handle:cvarKickBan;
- new Handle:cvarBanTime;
- new Handle:cvarMaxKicks;
- new Handle:cvarMaxBans;
- new Handle:cvarResetTime;
- new Handle:cookieKarma;
- new Handle:cookieKicks;
- new Handle:cookieBans;
- public OnPluginStart()
- {
- cvarMaxKarma = CreateConVar("sm_karma_maxkarma","3","Maximum karma a user can have",FCVAR_PLUGIN,true,0.0,false);
- cvarMinKarma = CreateConVar("sm_karma_minkarma","0","Minimum karma a user can have (at this point action is taken)",FCVAR_PLUGIN,true,0.0,false);
- cvarKickBan = CreateConVar("sm_karma_kickorban","1","Should a user be kicked or banned when reaching 0 karma",FCVAR_PLUGIN,true,0.0,true,1.0);
- cvarBanTime = CreateConVar("sm_karma_bantime","0","Amount of time (in minutes) to ban someone when karma triggers it (0 for permanent).",FCVAR_PLUGIN,true,0.0,false);
- cvarMaxKicks = CreateConVar("sm_karma_maxkicks","2","Maximum number of kicks for a ban to occur (reaching this creates the ban)",FCVAR_PLUGIN,true,0.0,true,1.0);
- cvarMaxBans = CreateConVar("sm_karma_maxbans","0","Maximum numer of bans before a permanent ban if sm_bantime is not set to 0",FCVAR_PLUGIN,true,0.0,false);
- cvarResetTime = CreateConVar("sm_karma_resettime","360","How long (in minutes) before an individuals karma is reset back to sm_maxkarma",FCVAR_PLUGIN,true,1.0,false);
- cookieKarma = RegClientCookie("karma_value","Stored Karma Value of User", CookieAccess_Private);
- cookieKicks = RegClientCookie("karma_kicks","Stored number of kicks for Karma", CookieAccess_Private);
- cookieBans = RegClientCookie("karma_bans","Stored number of bans for Karma", CookieAccess_Private);
- }
- public OnClientPostAdminCheck(client)
- {
- CheckData(client);
- }
- public OnClientDisconnect(client)
- {
- CheckData(client);
- }
- CheckData(client)
- {
- new iKarmaTime = GetClientCookieTime(client,cookieKarma);
- new iKickTime = GetClientCookieTime(client,cookieKicks);
- new iBanTime = GetClientCookieTime(client,cookieBans);
- new iCurrentTime = GetTime();
- new iResetTime = Karma_Setting(Karma_ResetTime) * 60;
- new iKarmaDifference = iCurrentTime - iKarmaTime;
- new iKickDifference = iCurrentTime - iKickTime;
- new iBanDifference = iCurrentTime - iBanTime;
- if(iKarmaDifference >= iResetTime)
- {
- Karma_Set(client,Karma_Value,Karma_Setting(Karma_Max));
- }
- if(iKickDifference >= iResetTime)
- {
- Karma_Set(client,Karma_Kicks,0);
- }
- if(iBanDifference >= iResetTime)
- {
- Karma_Set(client,Karma_Bans,0);
- }
- }
- CheckKarma(client)
- {
- if(Karma_Get(client,Karma_Value) <= GetConVarInt(cvarMinKarma))
- {
- Karma_Set(client,Karma_Value,Karma_Setting(Karma_Max));
- switch (Karma_Setting(Karma_KickBan))
- {
- case 0:
- {
- CheckKicks(client);
- }
- case 1:
- {
- CheckBans(client);
- }
- }
- }
- }
- CheckKicks(client)
- {
- if(Karma_Get(client,Karma_Kicks) >= Karma_Setting(Karma_MaxKicks))
- {
- Karma_Set(client,Karma_Kicks,0);
- CheckBans(client);
- }else{
- new iNewKicks = Karma_Get(client,Karma_Kicks) + 1;
- Karma_Set(client,Karma_Kicks,iNewKicks);
- KickClient(client,"You were kicked for reaching the minimum karma.");
- }
- }
- CheckBans(client)
- {
- new String:sKickMessage[128];
- if(Karma_Setting(Karma_BanTime) == 0)
- {
- sKickMessage = "You have been permanently banned due to karma limits.";
- }else{
- sKickMessage = "You have been banned due to karma limits."
- }
- if(Karma_Get(client,Karma_Bans) >= Karma_Setting(Karma_MaxBans))
- {
- Karma_Set(client,Karma_Bans,0);
- BanClient(client,0,BANFLAG_AUTO,"Maximum karma bans","You have been permanently banned due to karma limits","karma_permban");
- }else{
- new iNewBans = Karma_Get(client,Karma_Bans) + 1;
- Karma_Set(client,Karma_Bans,iNewBans);
- BanClient(client,Karma_Setting(Karma_BanTime),BANFLAG_AUTO,"Karma Banned",sKickMessage,"karma_permban");
- }
- }
- public APLRes:AskPluginLoad2(Handle:myself, bool:late,String:error[],err_max)
- {
- CreateNative("Karma_Get", Native_KarmaGet);
- CreateNative("Karma_Set", Native_KarmaSet);
- CreateNative("Karma_Setting", Native_KarmaSetting);
- return APLRes_Success;
- }
- public Native_KarmaGet(Handle:plugin, numParams)
- {
- new iClient = GetNativeCell(1);
- new String:sValue[32];
- switch(GetNativeCell(2))
- {
- case Karma_Value:
- {
- GetClientCookie(iClient,cookieKarma,sValue,sizeof(sValue));
- }
- case Karma_Kicks:
- {
- GetClientCookie(iClient,cookieKicks,sValue,sizeof(sValue));
- }
- case Karma_Bans:
- {
- GetClientCookie(iClient,cookieBans,sValue,sizeof(sValue));
- }
- }
- return StringToInt(sValue);
- }
- public Native_KarmaSet(Handle:plugin, numParams)
- {
- new iClient = GetNativeCell(1);
- new String:sValue[32];
- switch(GetNativeCell(2))
- {
- case Karma_Value:
- {
- SetClientCookie(iClient,cookieKarma,sValue);
- CheckKarma(iClient);
- }
- case Karma_Kicks:
- {
- SetClientCookie(iClient,cookieKicks,sValue);
- CheckKicks(iClient);
- }
- case Karma_Bans:
- {
- SetClientCookie(iClient,cookieBans,sValue);
- CheckBans(iClient);
- }
- }
- }
- public Native_KarmaSetting(Handle:plugin, numParams)
- {
- new iReturnValue;
- switch(GetNativeCell(1))
- {
- case Karma_Max:
- {
- iReturnValue = GetConVarInt(cvarMaxKarma);
- }
- case Karma_Min:
- {
- iReturnValue = GetConVarInt(cvarMinKarma);
- }
- case Karma_KickBan:
- {
- iReturnValue = GetConVarInt(cvarKickBan);
- }
- case Karma_BanTime:
- {
- iReturnValue = GetConVarInt(cvarBanTime);
- }
- case Karma_MaxKicks:
- {
- iReturnValue = GetConVarInt(cvarMaxKicks);
- }
- case Karma_MaxBans:
- {
- iReturnValue = GetConVarInt(cvarMaxBans);
- }
- case Karma_ResetTime:
- {
- iReturnValue = GetConVarInt(cvarResetTime);
- }
- default:
- {
- iReturnValue = -1;
- }
- }
- return iReturnValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement