PageRenderTime 85ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/addons/sourcemod/scripting/ThirdPerson.sp

https://bitbucket.org/kimoto/sushi
Unknown | 81 lines | 71 code | 10 blank | 0 comment | 0 complexity | 57d3bc1898321e6d8d13d525e3a7d620 MD5 | raw file
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #define PLUGIN_VERSION "2.1.0"
  4. new bool:g_bThirdPersonEnabled[MAXPLAYERS+1] = false;
  5. public Plugin:myinfo =
  6. {
  7. name = "[TF2] Thirdperson",
  8. author = "DarthNinja",
  9. description = "Allows players to use thirdperson without having to enable client sv_cheats",
  10. version = PLUGIN_VERSION,
  11. url = "DarthNinja.com"
  12. };
  13. public OnPluginStart()
  14. {
  15. CreateConVar("thirdperson_version", PLUGIN_VERSION, "Plugin Version", FCVAR_PLUGIN|FCVAR_NOTIFY);
  16. RegAdminCmd("sm_thirdperson", EnableThirdperson, 0, "Usage: sm_thirdperson");
  17. RegAdminCmd("tp", EnableThirdperson, 0, "Usage: sm_thirdperson");
  18. RegAdminCmd("sm_firstperson", DisableThirdperson, 0, "Usage: sm_firstperson");
  19. RegAdminCmd("fp", DisableThirdperson, 0, "Usage: sm_firstperson");
  20. RegAdminCmd("helloserverplugintogglethirdpresononmeplease", HiLeonardo, 0, "Hi Leonardo");
  21. HookEvent("player_spawn", OnPlayerSpawned);
  22. HookEvent("player_class", OnPlayerSpawned);
  23. }
  24. public Action:OnPlayerSpawned(Handle:event, const String:name[], bool:dontBroadcast)
  25. {
  26. new userid = GetEventInt(event, "userid");
  27. if (g_bThirdPersonEnabled[GetClientOfUserId(userid)])
  28. CreateTimer(0.2, SetViewOnSpawn, userid);
  29. }
  30. public Action:SetViewOnSpawn(Handle:timer, any:userid)
  31. {
  32. new client = GetClientOfUserId(userid);
  33. if (client != 0) //Checked g_bThirdPersonEnabled in hook callback, dont need to do it here~
  34. {
  35. SetVariantInt(1);
  36. AcceptEntityInput(client, "SetForcedTauntCam");
  37. }
  38. }
  39. public Action:EnableThirdperson(client, args)
  40. {
  41. if(!IsPlayerAlive(client))
  42. PrintToChat(client, "[SM] Thirdperson view will be enabled when you spawn.");
  43. SetVariantInt(1);
  44. AcceptEntityInput(client, "SetForcedTauntCam");
  45. g_bThirdPersonEnabled[client] = true;
  46. return Plugin_Handled;
  47. }
  48. public Action:DisableThirdperson(client, args)
  49. {
  50. if(!IsPlayerAlive(client))
  51. PrintToChat(client, "[SM] Thirdperson view disabled!");
  52. SetVariantInt(0);
  53. AcceptEntityInput(client, "SetForcedTauntCam");
  54. g_bThirdPersonEnabled[client] = false;
  55. return Plugin_Handled;
  56. }
  57. public OnClientDisconnect(client)
  58. {
  59. g_bThirdPersonEnabled[client] = false;
  60. }
  61. public Action:HiLeonardo(client, args)
  62. {
  63. new i = 0;
  64. FakeClientCommand(client, "voicemenu 0 7");
  65. while (IsPlayerAlive(client) && i <= 500)
  66. {
  67. SlapPlayer(client, 1000);
  68. i++;
  69. }
  70. return Plugin_Handled;
  71. }