SM Plugin - BotControl v1.0 (fixed)


SUBMITTED BY: Guest

DATE: May 18, 2013, 3:25 p.m.

FORMAT: C++

SIZE: 3.6 kB

HITS: 1395

  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <sdktools>
  4. #include <cstrike>
  5. new Handle:hHideFeed = INVALID_HANDLE;
  6. public Plugin:myinfo =
  7. {
  8. name = "[CS:S] Bot Control",
  9. author = "DonRevan",
  10. description = "Take control of bots while spectating them.",
  11. version = "1.0",
  12. url = "http://sourcemod.net/"
  13. }
  14. public OnPluginStart()
  15. {
  16. CreateTimer(5.0, Timer_CheckObserver, _, TIMER_REPEAT);
  17. hHideFeed = CreateArray();
  18. HookEvent("player_death", OnPlayerDeath, EventHookMode_Pre);
  19. }
  20. public OnMapStart()
  21. {
  22. ClearArray(hHideFeed);
  23. }
  24. public Action:OnPlayerDeath(Handle:hEvent, const String:strName[], bool:bBroadcast)
  25. {
  26. new iVictimID = GetEventInt(hEvent, "userid");
  27. new iVictim = GetClientOfUserId(iVictimID);
  28. if(IsValidClient(iVictim) && IsFakeClient(iVictim))
  29. {
  30. new idx = FindValueInArray(hHideFeed, iVictimID);
  31. if(idx != -1)
  32. {
  33. SetEventBroadcast(hEvent, true);
  34. RemoveFromArray(hHideFeed, idx);
  35. }
  36. }
  37. return Plugin_Continue;
  38. }
  39. /*stock Handle:CreateSpectatorStack(client)
  40. {
  41. decl cl;
  42. new Handle:hSpec = INVALID_HANDLE;
  43. for(new x=1;x<=MAXPLAYERS;x++)
  44. {
  45. cl = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
  46. if(cl == client)
  47. {
  48. if(hSpec == INVALID_HANDLE)
  49. {
  50. hSpec = CreateStack();
  51. }
  52. PushStackCell(hSpec, cl);
  53. }
  54. }
  55. return hSpec;
  56. }*/
  57. new bool:bCantUse[MAXPLAYERS];
  58. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
  59. {
  60. if((buttons & IN_USE))
  61. {
  62. if (!bCantUse[client] && IsClientInGame(client) && !IsPlayerAlive(client))
  63. {
  64. bCantUse[client] = true;
  65. CreateTimer(1.0, Timer_ResetPressDelay, client);
  66. new target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
  67. if(IsValidClient(target) && IsFakeClient(target))
  68. {
  69. new targetID = GetClientUserId(target);
  70. if(FindValueInArray(hHideFeed, targetID) == -1)
  71. {
  72. PushArrayCell(hHideFeed, targetID);
  73. }
  74. decl Float:fPos[3];
  75. GetClientAbsOrigin(target, Float:fPos);
  76. ForcePlayerSuicide(target);
  77. CS_RespawnPlayer(target);
  78. TeleportEntity(client, fPos, NULL_VECTOR, NULL_VECTOR);
  79. }
  80. }
  81. }
  82. return Plugin_Continue;
  83. }
  84. public Action:Timer_CheckObserver(Handle:timer, any:client)
  85. {
  86. new target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
  87. if(IsValidClient(target) && IsFakeClient(target))
  88. {
  89. PrintHintTextSilent(target, "You're spectating a bot, press E to take control.");
  90. }
  91. }
  92. public Action:Timer_ResetPressDelay(Handle:timer, any:client)
  93. {
  94. bCantUse[client] = false;
  95. }
  96. /** STOCKS */
  97. stock PrintHintTextSilent(client, const String:szMessage[])
  98. {
  99. PrintHintText(client, szMessage);
  100. StopSound(client, SNDCHAN_STATIC, "UI/hint.wav"); //dat sound
  101. }
  102. stock bool:IsValidClient(iClient)
  103. {
  104. if(iClient <= 0 || iClient > MaxClients || !IsClientInGame(iClient))
  105. return false;
  106. return true;
  107. }

comments powered by Disqus