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