-
Notifications
You must be signed in to change notification settings - Fork 2
/
observer-mode-switch-lag-fix.sp
84 lines (69 loc) · 2.61 KB
/
observer-mode-switch-lag-fix.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <sourcemod>
public Plugin myinfo =
{
name = "observer-mode-switch-lag-fix",
author = "rtldg",
description = "Switches between 3rd person and back on spec_next/spec_prev to try and prevent a laggy view when watching certain people.",
version = "1.0",
url = "https://github.com/PMArkive/random-shavit-bhoptimer-stuff"
};
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
// up here so it hopefully hooks before shavit-misc...
AddCommandListener(CommandListener_SpecNextPrev, "spec_next");
AddCommandListener(CommandListener_SpecNextPrev, "spec_prev");
AddCommandListener(CommandListener_RandomSpecCommands, "spectate");
AddCommandListener(CommandListener_RandomSpecCommands, "sm_spec");
return APLRes_Success;
}
public Action Timer_ChangeObserverMode(Handle timer, DataPack pack)
{
pack.Reset();
int client = GetClientFromSerial(pack.ReadCell());
int mode = pack.ReadCell();
//delete pack;
if (client > 0 && !IsPlayerAlive(client))
SetEntProp(client, Prop_Send, "m_iObserverMode", mode);
return Plugin_Stop;
}
public Action CommandListener_SpecNextPrev(int client, const char[] command, int args)
{
//PrintToConsole(client, "_SpecNextPrev = %s", command);
int iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
if (iObserverMode != 4 /* OBS_MODE_IN_EYE */)
{
return Plugin_Continue;
}
SetEntProp(client, Prop_Send, "m_iObserverMode", 5 /* OBS_MODE_CHASE */);
DataPack pack;
CreateDataTimer(0.03, Timer_ChangeObserverMode, pack, TIMER_FLAG_NO_MAPCHANGE);
pack.WriteCell(GetClientSerial(client));
pack.WriteCell(iObserverMode);
return Plugin_Continue;
}
public Action Timer_RandomSpecCommands(Handle timer, DataPack pack)
{
pack.Reset();
int client = GetClientFromSerial(pack.ReadCell());
int prevTarget = pack.ReadCell();
bool alive = pack.ReadCell();
//delete pack;
int curTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if (client > 0 && !IsPlayerAlive(client) && (alive || prevTarget != curTarget))
{
SetEntProp(client, Prop_Send, "m_iObserverMode", 4 /* OBS_MODE_IN_EYE */);
CommandListener_SpecNextPrev(client, "Timer_RandomSpecCommands", 0);
//PrintToServer("HERE");
}
return Plugin_Stop;
}
public Action CommandListener_RandomSpecCommands(int client, const char[] command, int args)
{
//PrintToServer("CommandListener_RandomSpecCommands = %s", command);
DataPack pack;
CreateDataTimer(0.0, Timer_RandomSpecCommands, pack, TIMER_FLAG_NO_MAPCHANGE);
pack.WriteCell(GetClientSerial(client));
pack.WriteCell(GetEntPropEnt(client, Prop_Send, "m_hObserverTarget"));
pack.WriteCell(IsPlayerAlive(client));
return Plugin_Continue;
}