Post Reply 
 
Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release AntiCamp Plugin
05-19-2012, 09:40 (This post was last modified: 05-21-2012 19:52 by zxz0O0.)
Post: #1
AntiCamp Plugin
A plugin that warns if player does not move a specific distance within a specific time.

Requires:
@Nukem's Server Addon v1.320 or higher

sv_config.ini entries:
Code:
[AntiCamp]
//Minimal distance
Distance=5
//Within this time
Time=4
//Message when someone is camping, use {0} for name, example: {0} stop camping!
Message=
//After how many warnings is the AdditionalAction executed
Warnings=2
//Additional action after too many warnings, kickClient, dropClient, tempBanClient, banClient
AdditionalAction=
//Plugin enabled, disabled
Enabled=1

Chat commands:
Code:
//Enable plugin
!camp 1
//Disable plugin
!camp 0

Thanks to @makavel for idea and testing

Source code:
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Addon;
  5.  
  6. namespace AntiCamp
  7. {
  8. public class Class1 : CPlugin
  9. {
  10. bool PluginEnabled = true;
  11. float distance = 5;
  12. uint time = 4;
  13. uint timer = 16;
  14. byte warnings = 2;
  15. string message = string.Empty;
  16. string AdditionalAction = string.Empty;
  17. // ClientNum, Origin
  18. Dictionary<int, Vector> Players = new Dictionary<int, Vector>();
  19. // ClientNum, Number of warnings
  20. Dictionary<int, uint> WarningDic = new Dictionary<int, uint>();
  21. // ClientNum, Ignores
  22. Dictionary<int, uint> IgnoreList = new Dictionary<int, uint>();
  23.  
  24. public override void OnServerLoad()
  25. {
  26. ServerPrint("\n AntiCamp loaded \n Author: zxz0O0 \n Idea and testing: Makavel \n Thanks to Nukem, Jariz and Pozzuh\n");
  27. ServerPrint(" youtube.com/zxz0O0 \n itsmods.com\n");
  28.  
  29. try
  30. {
  31. distance = float.Parse(GetServerCFG("AntiCamp", "Distance", "5"));
  32. time = uint.Parse(GetServerCFG("AntiCamp", "Time", "4"));
  33. timer = 4 * time;
  34. message = GetServerCFG("AntiCamp", "Message", string.Empty);
  35. AdditionalAction = GetServerCFG("AntiCamp", "AdditionalAction", string.Empty);
  36. warnings = byte.Parse(GetServerCFG("AntiCamp", "Warnings", "2"));
  37. if (GetServerCFG("AntiCamp", "Enabled", "1") == "0")
  38. PluginEnabled = false;
  39. }
  40. catch (Exception e)
  41. {
  42. ServerPrint(e.ToString());
  43. }
  44. }
  45.  
  46. public override void OnPlayerChangeWeapon(ServerClient Client, int WeaponID)
  47. {
  48. if (WeaponID == GetWeapon("briefcase_bomb_mp"))
  49. {
  50. if(!IgnoreList.ContainsKey(Client.ClientNum))
  51. IgnoreList.Add(Client.ClientNum, 1);
  52. else if (IgnoreList[Client.ClientNum]<2)
  53. IgnoreList[Client.ClientNum]++;
  54. }
  55. }
  56.  
  57. public override void OnPlayerUse(ServerClient Client)
  58. {
  59. if (!IgnoreList.ContainsKey(Client.ClientNum))
  60. IgnoreList.Add(Client.ClientNum, 1);
  61. else if (IgnoreList[Client.ClientNum] < 2)
  62. IgnoreList[Client.ClientNum]++;
  63. }
  64.  
  65. public override void OnPlayerSpawned(ServerClient Client)
  66. {
  67. if (!IgnoreList.ContainsKey(Client.ClientNum))
  68. IgnoreList.Add(Client.ClientNum, 2);
  69. else
  70. IgnoreList[Client.ClientNum] = 2;
  71. }
  72.  
  73. //4FPS
  74. public override void OnAddonFrame()
  75. {
  76. if (PluginEnabled)
  77. {
  78. timer--;
  79. if (timer == 0)
  80. {
  81. timer = 4 * time;
  82. foreach (ServerClient c in GetClients())
  83. {
  84. if (c.Ping == 999)
  85. continue;
  86. if (c.Team == Teams.Spectator)
  87. continue;
  88. if (CheckContinue(c.ClientNum))
  89. continue;
  90. if (!Players.ContainsKey(c.ClientNum))
  91. Players.Add(c.ClientNum, new Vector(c.OriginX, c.OriginY, c.OriginZ));
  92. else if (CalculateDistance(c.ClientNum) < distance)
  93. {
  94. if (!string.IsNullOrEmpty(message))
  95. ServerSay(string.Format(message, c.Name), true);
  96. if (!string.IsNullOrEmpty(AdditionalAction))
  97. {
  98. if (!WarningDic.ContainsKey(c.ClientNum))
  99. WarningDic.Add(c.ClientNum, 1);
  100. else
  101. WarningDic[c.ClientNum]++;
  102.  
  103. if (WarningDic[c.ClientNum] > warnings)
  104. ServerCommand(AdditionalAction + " " + c.ClientNum);
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111.  
  112. public override ChatType OnSay(string Message, ServerClient Client)
  113. {
  114. if (Message == "!camp 1")
  115. {
  116. TellClient(Client.ClientNum, "AntiCamp enabled", true);
  117. PluginEnabled = true;
  118. return ChatType.ChatNone;
  119. }
  120. else if (Message == "!camp 0")
  121. {
  122. TellClient(Client.ClientNum, "AntiCamp disabled", true);
  123. PluginEnabled = false;
  124. Players.Clear();
  125. WarningDic.Clear();
  126. return ChatType.ChatNone;
  127. }
  128. return ChatType.ChatContinue;
  129. }
  130.  
  131. private float CalculateDistance(int ClientNum)
  132. {
  133. try
  134. {
  135. ServerClient c = GetClient(ClientNum);
  136. Vector PlayerVec = Players[ClientNum];
  137. float x = PlayerVec.X - c.OriginX;
  138. x *= x;
  139. float y = PlayerVec.Y - c.OriginY;
  140. y *= y;
  141. float z = PlayerVec.Z - c.OriginZ;
  142. z *= z;
  143. Players[ClientNum] = new Vector(c.OriginX, c.OriginY, c.OriginZ);
  144. return (float)Math.Sqrt(x + y + z);
  145. }
  146. catch (Exception e)
  147. {
  148. ServerPrint(e.ToString());
  149. }
  150. return 0;
  151. }
  152.  
  153. private bool CheckContinue(int ClientNum)
  154. {
  155. if (IgnoreList.ContainsKey(ClientNum) && IgnoreList[ClientNum] > 0)
  156. {
  157. IgnoreList[ClientNum]--;
  158. return true;
  159. }
  160.  
  161. return false;
  162. }
  163.  
  164. public override void OnPlayerDisconnect(ServerClient Client)
  165. {
  166. if (Players.ContainsKey(Client.ClientNum))
  167. Players.Remove(Client.ClientNum);
  168. if (WarningDic.ContainsKey(Client.ClientNum))
  169. WarningDic.Remove(Client.ClientNum);
  170. if (IgnoreList.ContainsKey(Client.ClientNum))
  171. IgnoreList.Remove(Client.ClientNum);
  172. }
  173. }
  174. }

Related links


Attached File(s)
.zip  AntiCamp.zip (Size: 3.5 KB / Downloads: 796)

[Image: azuw.jpg]
Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 11 users say Thank You to zxz0O0 for this post:
amirdj (05-19-2012), Canta (05-19-2012), DidUknowiPwn (05-19-2012), G-Man (05-19-2012), iAegle (05-20-2012), itsmods.com76 (09-01-2012), jiuweiljp (06-01-2012), kokole (05-19-2012), narkos (08-17-2012), Pozzuh (05-19-2012), shadin23 (11-02-2012)
05-19-2012, 10:58
Post: #2
RE: AntiCamp Plugin
Fuu Anticamp.... Fuu Angry

[Image: veovuq.png]
Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 3 users say Thank You to Yamato for this post:
estebespt (05-19-2012), kokole (05-19-2012), The Clay Man (05-19-2012)
05-19-2012, 11:05
Post: #3
RE: AntiCamp Plugin
Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu Fuu
Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 4 users say Thank You to The Clay Man for this post:
estebespt (05-19-2012), FluffyGrenade (08-12-2012), kokole (05-19-2012), Yamato (05-19-2012)
05-19-2012, 12:03
Post: #4
RE: AntiCamp Plugin
oma faggots can't camp anymore booohoooh
Related links

[Image: MaEIQ.png]
Find all posts by this user
Add Thank You Quote this message in a reply
05-19-2012, 13:25
Post: #5
RE: AntiCamp Plugin
what is the range of the distance?
i presume the time is in seconds?

[Image: b_560_95_1.png]


[Image: b_560_95_1.png]
Find all posts by this user
Add Thank You Quote this message in a reply
05-19-2012, 13:41
Post: #6
RE: AntiCamp Plugin
(05-19-2012 13:25)hillbilly Wrote:  what is the range of the distance?
i presume the time is in seconds?

Time is seconds, distance, well I don't know what CoD uses, I suppose it's feets. In my plugin distance is a float so the range is ±1.5e−45 to ±3.4e38

[Image: azuw.jpg]
Find all posts by this user
Add Thank You Quote this message in a reply
05-19-2012, 18:03
Post: #7
RE: AntiCamp Plugin
You are great zxz0O0! Smile

Someone can tell me the difference between:
Kickclient
Dropclient

Another question:
The time camping, when you also account Turret, AC130, etc?

[Image: b_560_95_1.png]
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
05-19-2012, 18:37
Post: #8
RE: AntiCamp Plugin
(05-19-2012 18:03)Canta Wrote:  You are great zxz0O0! Smile

Someone can tell me the difference between:
Kickclient
Dropclient

Another question:
The time camping, when you also account Turret, AC130, etc?

KickClient is like a tempBan. DropClient just kicks the client Confused

Yes, though when you are 'using' something you get ignored for one cycle (planting, taking care package, using sentry)
Related links

[Image: azuw.jpg]
Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 2 users say Thank You to zxz0O0 for this post:
AboAlwe (06-01-2012), Canta (05-19-2012)
05-19-2012, 20:12
Post: #9
RE: AntiCamp Plugin
@zxz0O0 is now a Company of Heroes Camper Troll

[Image: veovuq.png]
Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 3 users say Thank You to Yamato for this post:
barata (05-19-2012), Canta (05-19-2012), zxz0O0 (05-19-2012)
05-20-2012, 00:10 (This post was last modified: 05-20-2012 00:26 by Canta.)
Post: #10
RE: AntiCamp Plugin
I was flying with "Reaper" and expelled me from the server with this message:

G_GetPlayerViewDrigin():Couldn't Find

edit:
The full server stopped working. Console.log:
[01:01:16] System.NullReferenceException: Object reference not set to an instance of an object.

at AntiCamp.Class1.OnAddonFrame()

at Addon.PluginCode.TriggerAddonFrame()

[Image: b_560_95_1.png]
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [Release] God Plugin v4.0 [Ingame Rcon Tool] OzonE 312 37,421 Yesterday 20:21
Last Post: xaliu
  [Release] For Plugin Developers yamraj 4 1,197 05-21-2013 17:55
Last Post: Jone Calerone
  [Release] Chat plugin for permissions SgtLegend 8 291 05-21-2013 11:21
Last Post: SgtLegend
  [Release] Waypoint plugin for users 8q4s8 0 135 05-16-2013 13:10
Last Post: 8q4s8
  [Release] NoKnife Plugin zxz0O0 85 11,069 05-14-2013 21:46
Last Post: Diskretor
  [Release] Bunker Plugin 1.3 archit 56 3,078 05-09-2013 14:13
Last Post: M4cbook
  [Release] Speed Plugin hillbilly 25 3,607 05-06-2013 18:19
Last Post: Hallla
  [Release] Votemap plugin zhp0083 82 11,408 04-12-2013 02:46
Last Post: .sepultura.
Brick [Release] Flag plugin for developers [Z00MBY] Alex 17 1,424 04-06-2013 17:52
Last Post: Dr3am95
Smile [Release] Map & Game Type Changer Plugin (Fixed) 30mba 30 2,753 04-05-2013 02:27
Last Post: BenderB

Forum Jump:


User(s) browsing this thread: 1 Guest(s)
Media Embeding by Simple Audio Video Embeder