Advertisement
Guest User

Karma

a guest
Sep 22nd, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.50 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <clientprefs>
  3.  
  4. // Add your own functions, stocks, natives and/or forwards here
  5. /** Double-include prevention */
  6. #if defined _karma_included_
  7.   #endinput
  8. #endif
  9. #define _karma_included_
  10.  
  11. #define CLR_DEFAULT     1
  12. #define CLR_LIGHTGREEN  3
  13. #define CLR_GREEN       4
  14. #define CLR_DARKGREEN   5
  15.  
  16. enum KarmaInfo
  17. {
  18.     Karma_Value,
  19.     Karma_Kicks,
  20.     Karma_Bans
  21. }
  22.  
  23. enum KarmaSetting
  24. {
  25.     Karma_Max,
  26.     Karma_Min,
  27.     Karma_KickBan, // Kick Or Ban, 0 = Kick, 1 = Ban
  28.     Karma_BanTime,
  29.     Karma_MaxKicks,
  30.     Karma_MaxBans,
  31.     Karma_ResetTime
  32. }
  33.  
  34. /**
  35.  * Gets a clients current karma value
  36.  *
  37.  * @param   client  Client index
  38.  * @param   type    KarmaInfo type
  39.  * @return          The integer value correlating with the type.
  40.  */
  41. native Karma_Get(client,KarmaInfo:type);
  42.  
  43. /**
  44.  * Sets a clients current karma value
  45.  *
  46.  * @param   client  Client index
  47.  * @param   type    KarmaInfo type
  48.  * @param   value   The value (integer) in which to set a client's karma to.
  49.  * @noreturn
  50.  */
  51. native Karma_Set(client, KarmaInfo:type, value);
  52.  
  53. /**
  54.  * Sets a clients current karma value
  55.  *
  56.  * @param   type    KarmaSetting type
  57.  * @return          The integer value of KarmaSetting, -1 if fails to find setting
  58.  */
  59. native Karma_Setting(KarmaSetting:type);
  60.  
  61. public SharedPlugin:__pl_stac =
  62. {
  63.     name = "karma",
  64.     file = "karma.smx",
  65.     #if defined REQUIRE_PLUGIN
  66.     required = 1,
  67.     #else
  68.     required = 0,
  69.     #endif
  70. };
  71.  
  72. public __pl_stac_SetNTVOptional()
  73. {
  74.     MarkNativeAsOptional("Karma_Get");
  75.     MarkNativeAsOptional("Karma_Set");
  76.     MarkNativeAsOptional("Karma_Setting");
  77. }
  78.  
  79.  
  80. ================================================================================
  81.  
  82. #include <karma>
  83.  
  84. public Plugin:myinfo =
  85. {
  86.     name = "Karma",
  87.     author = "FlyingMongoose",
  88.     description = "Creates a Karma System",
  89.     version = "1.0",
  90.     url = "http://www.brbuninstalling.com/"
  91. }
  92.  
  93. new Handle:cvarMaxKarma;
  94. new Handle:cvarMinKarma;
  95. new Handle:cvarKickBan;
  96. new Handle:cvarBanTime;
  97. new Handle:cvarMaxKicks;
  98. new Handle:cvarMaxBans;
  99. new Handle:cvarResetTime;
  100.  
  101. new Handle:cookieKarma;
  102. new Handle:cookieKicks;
  103. new Handle:cookieBans;
  104.  
  105. public OnPluginStart()
  106. {
  107.     cvarMaxKarma = CreateConVar("sm_karma_maxkarma","3","Maximum karma a user can have",FCVAR_PLUGIN,true,0.0,false);
  108.     cvarMinKarma = CreateConVar("sm_karma_minkarma","0","Minimum karma a user can have (at this point action is taken)",FCVAR_PLUGIN,true,0.0,false);
  109.     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);
  110.     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);
  111.     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);
  112.     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);
  113.     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);
  114.    
  115.     cookieKarma = RegClientCookie("karma_value","Stored Karma Value of User", CookieAccess_Private);
  116.     cookieKicks = RegClientCookie("karma_kicks","Stored number of kicks for Karma", CookieAccess_Private);
  117.     cookieBans = RegClientCookie("karma_bans","Stored number of bans for Karma", CookieAccess_Private);
  118. }
  119.  
  120. public OnClientPostAdminCheck(client)
  121. {
  122.     CheckData(client);
  123. }
  124.  
  125. public OnClientDisconnect(client)
  126. {
  127.     CheckData(client);
  128. }
  129.  
  130. CheckData(client)
  131. {
  132.     new iKarmaTime = GetClientCookieTime(client,cookieKarma);
  133.     new iKickTime = GetClientCookieTime(client,cookieKicks);
  134.     new iBanTime = GetClientCookieTime(client,cookieBans);
  135.    
  136.     new iCurrentTime = GetTime();
  137.    
  138.     new iResetTime = Karma_Setting(Karma_ResetTime) * 60;
  139.    
  140.     new iKarmaDifference = iCurrentTime - iKarmaTime;
  141.     new iKickDifference = iCurrentTime - iKickTime;
  142.     new iBanDifference = iCurrentTime - iBanTime;
  143.    
  144.     if(iKarmaDifference >= iResetTime)
  145.     {
  146.         Karma_Set(client,Karma_Value,Karma_Setting(Karma_Max));
  147.     }
  148.     if(iKickDifference >= iResetTime)
  149.     {
  150.         Karma_Set(client,Karma_Kicks,0);
  151.     }
  152.     if(iBanDifference >= iResetTime)
  153.     {
  154.         Karma_Set(client,Karma_Bans,0);
  155.     }
  156. }
  157. CheckKarma(client)
  158. {
  159.     if(Karma_Get(client,Karma_Value) <= GetConVarInt(cvarMinKarma))
  160.     {
  161.         Karma_Set(client,Karma_Value,Karma_Setting(Karma_Max));
  162.         switch (Karma_Setting(Karma_KickBan))
  163.         {
  164.             case 0:
  165.             {
  166.                 CheckKicks(client);
  167.             }
  168.             case 1:
  169.             {
  170.                 CheckBans(client);
  171.             }
  172.         }
  173.     }
  174. }
  175.  
  176. CheckKicks(client)
  177. {
  178.     if(Karma_Get(client,Karma_Kicks) >= Karma_Setting(Karma_MaxKicks))
  179.     {
  180.         Karma_Set(client,Karma_Kicks,0);
  181.         CheckBans(client);
  182.     }else{
  183.         new iNewKicks = Karma_Get(client,Karma_Kicks) + 1;
  184.        
  185.         Karma_Set(client,Karma_Kicks,iNewKicks);
  186.        
  187.         KickClient(client,"You were kicked for reaching the minimum karma.");
  188.     }
  189. }
  190.  
  191. CheckBans(client)
  192. {
  193.     new String:sKickMessage[128];
  194.    
  195.     if(Karma_Setting(Karma_BanTime) == 0)
  196.     {
  197.         sKickMessage = "You have been permanently banned due to karma limits.";
  198.     }else{
  199.         sKickMessage = "You have been banned due to karma limits."
  200.     }
  201.    
  202.     if(Karma_Get(client,Karma_Bans) >= Karma_Setting(Karma_MaxBans))
  203.     {  
  204.         Karma_Set(client,Karma_Bans,0);
  205.         BanClient(client,0,BANFLAG_AUTO,"Maximum karma bans","You have been permanently banned due to karma limits","karma_permban");  
  206.     }else{
  207.         new iNewBans = Karma_Get(client,Karma_Bans) + 1;
  208.        
  209.         Karma_Set(client,Karma_Bans,iNewBans);
  210.        
  211.         BanClient(client,Karma_Setting(Karma_BanTime),BANFLAG_AUTO,"Karma Banned",sKickMessage,"karma_permban");
  212.     }
  213. }
  214.  
  215. public APLRes:AskPluginLoad2(Handle:myself, bool:late,String:error[],err_max)
  216. {
  217.     CreateNative("Karma_Get",       Native_KarmaGet);
  218.     CreateNative("Karma_Set",       Native_KarmaSet);
  219.     CreateNative("Karma_Setting",   Native_KarmaSetting);
  220.     return APLRes_Success;
  221. }
  222.  
  223. public Native_KarmaGet(Handle:plugin, numParams)
  224. {
  225.     new iClient = GetNativeCell(1);
  226.     new String:sValue[32];
  227.     switch(GetNativeCell(2))
  228.     {
  229.         case Karma_Value:
  230.         {
  231.             GetClientCookie(iClient,cookieKarma,sValue,sizeof(sValue));
  232.         }
  233.         case Karma_Kicks:
  234.         {
  235.             GetClientCookie(iClient,cookieKicks,sValue,sizeof(sValue));
  236.         }
  237.         case Karma_Bans:
  238.         {
  239.             GetClientCookie(iClient,cookieBans,sValue,sizeof(sValue));
  240.         }
  241.     }
  242.     return StringToInt(sValue);
  243. }
  244.  
  245. public Native_KarmaSet(Handle:plugin, numParams)
  246. {
  247.     new iClient = GetNativeCell(1);
  248.     new String:sValue[32];
  249.     switch(GetNativeCell(2))
  250.     {
  251.         case Karma_Value:
  252.         {
  253.             SetClientCookie(iClient,cookieKarma,sValue);
  254.             CheckKarma(iClient);
  255.         }
  256.         case Karma_Kicks:
  257.         {
  258.             SetClientCookie(iClient,cookieKicks,sValue);
  259.             CheckKicks(iClient);
  260.         }
  261.         case Karma_Bans:
  262.         {
  263.             SetClientCookie(iClient,cookieBans,sValue);
  264.             CheckBans(iClient);
  265.         }
  266.     }
  267. }
  268.  
  269. public Native_KarmaSetting(Handle:plugin, numParams)
  270. {
  271.     new iReturnValue;
  272.     switch(GetNativeCell(1))
  273.     {
  274.         case Karma_Max:
  275.         {
  276.             iReturnValue = GetConVarInt(cvarMaxKarma);
  277.         }
  278.         case Karma_Min:
  279.         {
  280.             iReturnValue = GetConVarInt(cvarMinKarma);
  281.         }
  282.         case Karma_KickBan:
  283.         {
  284.             iReturnValue = GetConVarInt(cvarKickBan);
  285.         }
  286.         case Karma_BanTime:
  287.         {
  288.             iReturnValue = GetConVarInt(cvarBanTime);
  289.         }
  290.         case Karma_MaxKicks:
  291.         {
  292.             iReturnValue = GetConVarInt(cvarMaxKicks);
  293.         }
  294.         case Karma_MaxBans:
  295.         {
  296.             iReturnValue = GetConVarInt(cvarMaxBans);
  297.         }
  298.         case Karma_ResetTime:
  299.         {
  300.             iReturnValue = GetConVarInt(cvarResetTime);
  301.         }
  302.         default:
  303.         {
  304.             iReturnValue = -1;
  305.         }
  306.     }
  307.     return iReturnValue;
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement