1
+ #include <sourcemod>
2
+ #include <sdkhooks>
3
+
4
+ #include <msharedutil/arrayvec>
5
+ #include <msharedutil/ents>
6
+
7
+
8
+ enum
9
+ {
10
+ SPD_VEL [3 ] = 0 ,
11
+ SPD_SPD ,
12
+ SPD_ONGROUND ,
13
+
14
+ SPD_SIZE
15
+ };
16
+
17
+
18
+ ArrayList g_hSpds [MAXPLAYERS + 1 ];
19
+
20
+
21
+ int g_fLastFlags [MAXPLAYERS + 1 ];
22
+ int g_nJumps [MAXPLAYERS + 1 ];
23
+ int g_nMaxJumps [MAXPLAYERS + 1 ];
24
+
25
+
26
+ public void OnPluginStart ()
27
+ {
28
+ RegAdminCmd ( " sm_spdinfo" , Cmd_SpdInfo , ADMFLAG_ROOT );
29
+ RegAdminCmd ( " sm_outputspdinfo" , Cmd_SpdInfo_Output , ADMFLAG_ROOT );
30
+ }
31
+
32
+ public void OnClientPutInServer ( int client )
33
+ {
34
+ UnhookThinks ( client );
35
+ }
36
+
37
+ public void OnClientDisconnect ( int client )
38
+ {
39
+
40
+ }
41
+
42
+ public Action Cmd_SpdInfo_Output ( int client , int args )
43
+ {
44
+ if ( ! client ) return Plugin_Handled ;
45
+
46
+ if ( g_hSpds [client ] == null ) return Plugin_Handled ;
47
+
48
+ if ( g_hSpds [client ].Length < 1 ) return Plugin_Handled ;
49
+
50
+
51
+ decl String :szFile [256 ];
52
+
53
+ GetCmdArgString ( szFile , sizeof ( szFile ) );
54
+
55
+ if ( szFile [0 ] == 0 )
56
+ {
57
+ strcopy ( szFile , sizeof ( szFile ), " spdoutput.txt" );
58
+ }
59
+
60
+
61
+ decl data [SPD_SIZE ];
62
+
63
+
64
+ File file = OpenFile ( szFile , " w" );
65
+
66
+
67
+ int len = g_hSpds [client ].Length ;
68
+ for ( int i = 0 ; i < len ; i ++ )
69
+ {
70
+ g_hSpds [client ].GetArray ( i , data );
71
+
72
+ file .WriteLine ( " SPD: %07.3f | ON GROUND: %i | VEL: {%.1f , %.1f , %.1f }" ,
73
+ data [SPD_SPD ],
74
+ data [SPD_ONGROUND ],
75
+ data [SPD_VEL + 0 ],
76
+ data [SPD_VEL + 1 ],
77
+ data [SPD_VEL + 2 ] );
78
+ }
79
+
80
+ file .Close ();
81
+
82
+ PrintToChat ( client , " Wrote %i frames to file '%s '!" , g_hSpds [client ].Length , szFile );
83
+
84
+ return Plugin_Handled ;
85
+ }
86
+
87
+ public Action Cmd_SpdInfo ( int client , int args )
88
+ {
89
+ if ( ! client ) return Plugin_Handled ;
90
+
91
+
92
+ delete g_hSpds [client ];
93
+
94
+ g_hSpds [client ] = new ArrayList ( SPD_SIZE );
95
+
96
+
97
+ g_nJumps [client ] = 0 ;
98
+
99
+
100
+ char sz [32 ];
101
+ GetCmdArgString ( sz , sizeof ( sz ) );
102
+
103
+ g_nMaxJumps [client ] = StringToInt ( sz );
104
+
105
+ if ( g_nMaxJumps [client ] <= 0 ) g_nMaxJumps [client ] = 6 ;
106
+
107
+
108
+ g_fLastFlags [client ] = GetEntityFlags ( client );
109
+
110
+
111
+ UnhookThinks ( client );
112
+
113
+ SDKHook ( client , SDKHook_PostThinkPost , E_PostThinkPost_Client );
114
+
115
+
116
+ PrintToChat ( client , " Jump to start... (%i jumps)" , g_nMaxJumps [client ] );
117
+
118
+
119
+ return Plugin_Handled ;
120
+ }
121
+
122
+ public void E_PostThinkPost_Client ( int client )
123
+ {
124
+ int flags = GetEntityFlags ( client );
125
+
126
+
127
+ bool onground = ( flags & FL_ONGROUND ) ? true : false ;
128
+
129
+ bool lastonground = ( g_fLastFlags [client ] & FL_ONGROUND ) ? true : false ;
130
+
131
+
132
+ if ( ! onground && lastonground )
133
+ {
134
+ if ( ! g_nJumps [client ] )
135
+ {
136
+ PrintToChat ( client , " Started recording..." );
137
+ }
138
+
139
+ ++ g_nJumps [client ];
140
+ }
141
+
142
+
143
+ if ( g_nJumps [client ] )
144
+ {
145
+ static int data [SPD_SIZE ];
146
+
147
+ float vec [3 ];
148
+ GetEntityAbsVelocity ( client , vec );
149
+
150
+ float spd = SquareRoot ( vec [0 ] * vec [0 ] + vec [1 ] * vec [1 ] );
151
+
152
+
153
+ CopyArray ( vec , data [SPD_VEL ], 3 );
154
+ data [SPD_SPD ] = view_as <int >( spd );
155
+ data [SPD_ONGROUND ] = onground ;
156
+
157
+ g_hSpds [client ].PushArray ( data );
158
+ }
159
+
160
+
161
+ if ( onground && ! lastonground && g_nJumps [client ] >= g_nMaxJumps [client ] )
162
+ {
163
+ PrintToChat ( client , " Done! (sm_outputspdinfo)" );
164
+
165
+ UnhookThinks ( client );
166
+ return ;
167
+ }
168
+
169
+
170
+ g_fLastFlags [client ] = flags ;
171
+ }
172
+
173
+ stock void UnhookThinks ( int client )
174
+ {
175
+ SDKUnhook ( client , SDKHook_PostThinkPost , E_PostThinkPost_Client );
176
+ }
0 commit comments