[Half-Life AMXX] / climb.sma Repository:
ViewVC logotype

Annotation of /climb.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (view) (download)

1 : ian 1 /*
2 :     Climb v2.0a4
3 :     Copyright (C) 2006-2007 Ian (Juan) Cammarata
4 :    
5 : ian 25 This program is free software: you can redistribute it and/or modify
6 :     it under the terms of the GNU Affero General Public License as
7 :     published by the Free Software Foundation, either version 3 of the
8 :     License, or (at your option) any later version.
9 : ian 1
10 : ian 25 This program is distributed in the hope that it will be useful,
11 :     but WITHOUT ANY WARRANTY; without even the implied warranty of
12 :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 :     GNU Affero General Public License for more details.
14 : ian 1
15 : ian 25 You should have received a copy of the GNU Affero General Public License
16 :     along with this program. If not, see <http://www.gnu.org/licenses/>.
17 : ian 1 --------------------------------------------------------------------------------
18 :    
19 :     http://ian.cammarata.us
20 :     Sep 21 18:27
21 :    
22 :    
23 :     To do:
24 :     Save user/pass login data for sessions (don't require login ever map change)
25 :     Account management for accounts with user/pass login. email, change password, password recovery
26 :     Unsolid as function of position and velocity
27 :     Recode custom flashlight without temp entities
28 :    
29 :    
30 :     Description:
31 :     This plugin is designed for use in climbing maps like those available from www.kreedz.com.
32 :    
33 :    
34 :     Commands:
35 :     say /checkpoint : Save your position.
36 :     say /gocheck : Teleport you to your last saved position.
37 :     say /ungocheck : Undo a gocheck in case you accidentally use one after you make a tough jump.
38 :     say /stuck : Teleport you to your previous checkpoint in case you get stuck in a wall.
39 :     amx_goto : Teleport to another player. (Can't be used while timer is running)
40 :    
41 :     A full help page can be found at http://ian.cammarata.us/projects/climb/help/2a3/en/commands
42 :    
43 :    
44 :     Cvars:
45 :     climb <1|0> : Enables|Disables all plugin functionality. The plugin now enables and disables itself, you should only use this cvar to turn the plugin on in maps which don't have a start button.
46 :     climb_boost <1|0> : Enables|Disables boosting.
47 :     climb_cpprice <0|...> : Set to dollar amount for cost of checkpoints.
48 :     climb_startmoney <1337|0-16000> : Money amount set when players start timer.
49 :    
50 :     climb_render <0|1> : Changes unsolid rendering style, 0=classic, other=new more see through rendering.
51 :     climb_sounds <1|0> : Enables|Disables sounds build in to the Climb plugin.
52 :     climb_start_respawn <0|1> : When enabled, eliminates unnecessary respawning. (Defaults to off)
53 :     climb_water_nodraw: <0|1> : When enabled makes func_water entities invisible to help with players FPS issues. (Defaults to off)
54 :    
55 :     climb_webmod <0|1> : Disables|Enables web mod interoperability.
56 :     climb_stats_path <NULL|...> : Path to save generated stats pages. (If using WebMod, enter path to WebMod's www folder.)
57 :     climb_stats_url <NULL|...> : URL to send clients to for stats pages. Only use if you have a web server running on the same machine as the game server. IF WEBMOD=1 THIS IS IGNORED.
58 :     climb_stats_hsurl <NULL|...> : "%s" will be replaced with map name. Set to send client to URL if you have a page that automatically generates high scores via direct DB access. IF WEBMOD=1 THIS IS IGNORED.
59 :     climb_stats_msg <NULL|...> : Message to display on scoreboard. Use HTML
60 :    
61 :     ip_internal <localhost|...> : Set to internal network IP or hostname. (If server behind NAT)
62 :     ip_external <localhost|...> : Set to external network IP or hostname.
63 :    
64 :     climb_msg_r <0|0-255> : Display message red value.
65 :     climb_msg_g <150|0-255> : Display message green value.
66 :     climb_msg_b <250|0-255> : Display message blue value.
67 :     climb_msg_x <0.05|0-1> : Display message x position.
68 :     climb_msg_y <0.5|0-1> : Display message y position.
69 :    
70 :     climb_light_r <255|0-255> : Sets the red value for the custom flashlight's color.
71 :     climb_light_g <255|0-255> : Sets the green value for the custom flashlight's color.
72 :     climb_light_b <255|0-255> : Sets the blue value for the custom flashlight's color.
73 :    
74 :     *The following cvars are only read at plugin load, changes will not take effect until the map is changed.
75 :     climb_save <1|0> : Enables|Disables saving of stats to a database.
76 :    
77 :     climb_db_type <sqlite|mysql> : Database type.
78 :     climb_db_host <127.0.0.1> : Database host name/ip.
79 :     climb_db_user <NULL|...> : Database user name.
80 :     climb_db_pass <NULL|...> : Database password.
81 :     climb_db_name <climb|...> : Database name.
82 :     climb_db_prefix <climb_|...> : Table name prefix.
83 :    
84 :    
85 :     Requirements:
86 :     AMXX 1.76 or higher
87 :     Engine module
88 :     Fakemeta module
89 :     DB Module (MySQL or SQLite/Only needed if using CLIMB_SAVE 1.)
90 :    
91 :    
92 :     Notes:
93 :     Make sure you place the climb.txt file in addons\amxmodx\data\lang
94 :    
95 :     I highly recommend using All Chat along with this plugin:
96 :     http://forums.alliedmods.net/showthread.php?t=56825
97 :    
98 :     DF Hook Frontend plugin is included with this plugin, but still requires the Hookmod from AdminOP:
99 :     http://www.adminop.net/modules.php?name=Downloads&d_op=viewdownloaddetails&lid=73&ttitle=Hook_Mod_Windows
100 :    
101 :     To be able to get a full player listing on the scoreboard, you'll need to install WebMod and set the appropriate cvars for this plugin.
102 :     WebMod site: http://djeyl.net/w.php
103 :    
104 :    
105 :     Credits:
106 :     Borrowed some code from Space Headed's bot_api.sma
107 :     Borrowed some code from KCE's attack blocking tutorial (http://forums.alliedmods.net/showthread.php?t=41265)
108 :     Thanks to Lola for letting me use her awesome server for testing purposes.
109 :     http://1337bunnies.com
110 :     66.55.131.63:27015
111 :     Thanks to r33d and Woofie for testing and suggestions.
112 :    
113 :    
114 :     Supported Languages:
115 :     Not Applicable... yet.
116 :    
117 :    
118 :     Change Log:
119 :     Key (+ added | - removed | c changed | f fixed)
120 :    
121 :     v2.0a4 (SEPT ??, 2007)
122 :     +: New db admin commands: climb_dbwho, climb_dbmap, climb_dbplayer, climb_dbdelete.
123 :     +: High scores now saves boosts, cps/gcs, and weapon used.
124 :     +: New high scores sorting method.
125 :     +: Breakable objects with health less than 9999 are now removed at map load.
126 :     +: Duplicate names in database are now appended with "(#)" like the game scoreboard.
127 :     +: Client commands 'cp+' and 'cp-' to cycle through checkpoints.
128 :     +: Cvars mp_autoteambalance and mp_limitteams are set to 0 when a start button is found, and reverted when the map changes.
129 :     +: Support for a2 maps start/finish buttons.
130 :     +: Commands measure and measure2.
131 :     +: Command 'weapons', gives client one of each speed weapon.
132 :     +: Ranking by weapon speed. ex: If you beat a map with AWP, you'll be ranked above other weapon scores.
133 :     +: Command countdown to have time countdown from your best time instead of counting up.
134 :     +: Instantly switch to spectator without death animation.
135 :     -: Plugin ad on client connect.
136 :     -: WebMod support since it is a huge security vulnerability.
137 :     -: Cvars: climb_webmod, climb_stats_path, climb_stats_url, ip_internal, ip_external
138 : ian 41 //c: New semiclip, should be flawless now. (not completely done yet)
139 : ian 1 c: Cvar climb_water_nodraw changes take effect without reloading map.
140 :     c: Database now stores multiple records per map per player.
141 :     c: Cvar climb_db_pass is now protected.
142 :     c: Optimized html layout of scoreboards to fit more data without using WebMod.
143 :     c: Command '/stuck' is now an alias for 'cp-' and doesn't deduct from cp count.
144 :     c: Start and restart commands now tp client to the start button (Spawn and respawn still tp to spawn point).
145 :     c: Clients now spawn at start button.
146 :     c: USP and M4 forced to be always silent.
147 :     c: Guns reload with only 2 bullets, admins get unlimited clip for silenced guns.
148 :     c: Timeout on knife slash. (The sound makes my ears bleed)
149 :     c: Set 0.4 second timeout on cp, gc, and ungc commands.
150 :     c: Set 2 second timeout on usp and scout commands.
151 :     c: Re-enabled default flashlight, at least untill I recode the custom one. Custom NVG still in place.
152 :     c: Respawn command now stops your timer, to prevent cheating in some maps.
153 :     f: Bug where maps with built in auto-heal and healing doors didn't give 511 hp. (ex: kz_man_streetclimb)
154 :     f: Showing high scores from previous map if client executes cmd a second time within the timeout period and current map has no scores in the DB.
155 :     f: An exploit that involved a paused player with their view attached to something else.
156 :     f: Bug where respawn command would spawn clients at maps origin if plugin was enabled without running init functions.
157 :     f: Bug where multiple players could connect and get logged in with the same db user id.
158 :    
159 :     v2.0a3 (JUNE 21, 2007)
160 :     +: New alias for restart, /start.
161 :     +: HP set to 512 when finished as god mode replacement. God mode prevents people from seeign each others names.
162 :     +: Replicate hud messages and timer to spectators.
163 :     +: Replacement flashlight/nightvision. Change color with cvars climb_light_r, ..._g, ..._b
164 :     +: Cvar climb_start_respawn: eliminates unnecessary respawning, admin can enable if needed
165 :     +: Cvar climb_water_nodraw: Makes func_water entities invisible to help with players FPS issues(off by default).
166 :     +: Fake client added to CT team to prevent round end. Automatically leaves when the server is almost full, and rejoins as it empties.
167 :     +: Two new commands, /scout and /usp, to get a scout or usp if you need one, or more ammo.
168 :     +: New command /ungocheck or /ungc. Takes you to where you were before you last used gocheck.
169 :     +: Can use chooseteam button or kill command to switch between spectating and playing.
170 :     +: Plugin automatically disables on map change. Automatically enables if it finds a start button in new map. Setting the cvar climb to 1 in a map config will force the plugin to run.
171 :     c: Spectators stay listed as CT on CS scoreboard so their rank will always show.
172 :     c: Command amx_goto can be used by any player once they've completed the map.
173 :     c: Players don't spawn with scout or c4 anymore.
174 :     c: Newer unsolid render is default.
175 :     c: New unsolid code provides perfect touch detection and eliminates problems that occurred in some maps.
176 :     c: Decreased the wait time on some of the command timeouts.
177 :     c: Replicated button use code from HL SDK. Start and finish button use detection is now perfect.
178 :     c: In maps with built in healing climb auto heal is disabled(some maps like this have falling areas where you're not supposed to heal).
179 :     f: Lag caused by respawning is pretty much eliminated by new weapon cleanup code and not giving as many weapons on spawn.
180 :     f: MySQL query format problem for auto increment fields.
181 :     f: SQLite query problem. Replaced single quotes around strings with double quotes.
182 :     f: HLTV proxies caused two adjacent rows in scoreboard to be same color.
183 :     f: Spectator lag bug.
184 :     f: Bug where players had 511 HP on every map.
185 :    
186 :     v2.0a2 (FEB 16, 2007)
187 :     +: 2 addition boost types. Super jump and double jump. (No partner needed for boosting anymore)
188 :     +: Boosts are counted. (Not logged in DB yet.)
189 :     +: Stats saving in database. MySQL or SQLite. (MySQL not tested yet. Only works with single db module enabled)
190 :     +: Players now get rewarded for finishing even without starting the timer.
191 :     +: Cvars for message color and position. (climb_msg_r, ..._g, ..._b, ..._x, ..._y)
192 :     +: Cvar climb_startmoney - Value to set money to when players start timer.
193 :     +: Cvar climb_stats_msg - Message to display on the HTML scoreboards.
194 :     +: Cvar climb_unsolid_type - Change rendering style for unsolid players.
195 :     +: Cvar climb_sounds - Disabled Climb plugin sounds.
196 :     +: Several cvars for database settings.
197 :     +: All players spawn at spawn point closest to the start button. (Eliminates cheat in maps with a spawn point at the finish button.)
198 :     +: Additional spawns added during map load to fix maps without enough spawns.
199 :     +: Timeouts for respawning and boosting.
200 :     +: Command "help". Displays HTML help pages.
201 :     -: AMX compatibility. (AMX is officially dead)
202 :     c: Cvars now prefixed with climb_ instead of amx_.
203 :     c: Minor code optimizations.
204 :     c: Command "Boost" now takes players to the boost help page instead of activating solid boost.
205 :     c: All internal cvar handling is now done with pointers. (With the acception of cvars used only during init functions.)
206 :     c: Solid boost only lasts 15 seconds at a time now since its usage is being tracked.
207 :     c: Major internal rewrite (Probably added a few bugs. More major rewrites coming in next release.)
208 :    
209 :     v1.9.19 (AUG 02, 2006)
210 :     +: New public cvar 'climb_version' to aid in searching for server with this plugin.
211 :     +: Show checkpoints, gochecks, and finish stats (Stats will be more extensive in next version) with finish announcement.
212 :     -: Global chat. Use AllChat plugin instead.
213 :     -: Cvar: amx_climb_globchat
214 :     c: The /spec command now obeys the cvar "allow_spectators", clients with reserved slot always allowed.
215 :     c: Shows number of checks and gocheck on client finish announcement.
216 :     f: Bug caused by using stop command while paused.
217 :     c: Client commands reworked. Everything functions the same, but with more functionality. For example the gc command can be entered as any of the following: gc, /gc, \gc, say gc, say /gc, say \gc, say_team gc, etc...
218 :    
219 :     v1.9.18 (MAY 15, 2006)
220 :     c: Recoded the way health is handled. Should work for any map now.
221 :    
222 :     v1.9.17 (APR 07, 2006)
223 :     c: Plugin is now compatible with both AMX and AMXX.
224 :     c: The /spectate command can now be used by anyone. Admin no longer required.
225 :    
226 :     v1.9.16a
227 :     f: Added health fix for kz_cfl_yamakasi.
228 :     c: New CSS theme for html scoreboard.
229 :    
230 :     v1.9.16
231 :     +: Counts usage of CP and GC commands(only displayed on html scoreboard).
232 :     f: Added health fix for kz_lighthouse and kz_phoogi.
233 :    
234 :     v1.9.15
235 :     +: Colorized global chat. ADMIN_RESERVATION has name in green instead of team color.
236 :     +: /stop command. Resets timer to zero, end climbing session.
237 :     c: Reset function. /stop + /respawn. Client is now reset automatically when pressing the start button if they are not already started.
238 :     f: YOU CAN'T GET STUCK ANYMORE!!! (Well almost. Doing gocheck a second time gets you unstuck.)
239 :     f: Global chat is now logged correctly and shows up in HLSW.
240 :    
241 :     v1.9.14
242 :     +: Hook is taken away when client starts timer, given back if they reset.
243 :     +: Max health fixes for several new maps.
244 :     +: Sort clients on CS scoreboard by climb rank.
245 :     +: Cvar amx_climb_boost - enable\disable boosting.
246 :     +: Cvar amx_climb_cpprice - charge money for checkpoints.
247 :     +: Custom configurable commands based on events. (climb.ini)
248 :     +: Global chat. cvar: amx_climb_globchat <1|0>
249 :     +: Client climb time is now shown using the round time HUD sprites.
250 :     -: Command /mytime, not needed because of HUD sprite timer.
251 :     -: Auto time display every 30 seconds, not needed because of HUD sprite timer.
252 :     c: Added another start button sound.
253 :     c: Super healing doors no longer removed. (Needed for shortcuts in some maps.)
254 :     f: Admins can't be alive as spectator even with 3rd party respawn plugin.
255 :     f: Keep godmode after respawning if finished map and not reset.
256 :     f: Admins VIP display on CS scoreboard is now updated whenever clients connect.
257 :     f: Health charger minimaps in kz_real_skyscraper & kz_northpole_b01.
258 :     f: Not teleporting to exact cp position if another client is on your cp.
259 :     f: Respawning outside of maps sometimes immediately after leaving spectator.
260 :     */
261 :     #include <amxmodx>
262 :     #include <fun>
263 :     #include <amxmisc>
264 :     #include <engine>
265 :     #include <fakemeta>
266 :     #include <sqlx>
267 :     #include <string2>
268 :     #include <cstrike>
269 :     #include <cstrike2>
270 :    
271 : ian 41 new const VERSION[ ] = "a3.7.8 Feb 24 20:55 MST"
272 : ian 22 new const TRKCVAR[ ] = "climb_version"
273 : ian 32
274 : ian 22 new const DONOTHING[ ] = "donothing"
275 :     new const NULLSTR[ ] = ""
276 : ian 1
277 :     #define IN_ATTACK_EITHER ( IN_ATTACK + IN_ATTACK2 )
278 :    
279 :     #define SF_MAX 50 //Maximum number of start/finish commands in climb.ini
280 :    
281 :     #define CPGC_TIMEOUT 0.4 //In seconds, decimal allowed
282 :     #define SPAWN_TIMEOUT 2 //In seconds, whole number only / used for start button also
283 :     #define WPN_TIMEOUT 2 //In seconds, whole number only
284 :     #define BOOST_TIMEOUT 5 //In seconds, whole number only
285 :     #define KNIFE_TIMEOUT 2 //In seconds, whole number only
286 :    
287 :     #define NAMELEN 15
288 :    
289 :     #define DBADMIN ADMIN_RCON
290 :     #define VIP ADMIN_RESERVATION
291 :    
292 :     new MAXPLAYERS
293 :    
294 :     //DB data
295 :     new Handle:DB_TUPLE, DB_PREFIX[11], bool:CLIMB_SAVE, DB_SERVER_ID[16]
296 :     new db_last_del_id
297 :    
298 :     //Client flags arrays
299 :     #define ORIGINS_SIZE 48
300 : ian 19 new Float:origins[33][ORIGINS_SIZE]
301 : ian 1 #define ORIG_UNGC 40
302 : ian 38 #define ORIG_PAUSX 44
303 :     #define ORIG_PAUSY 45
304 :     #define ORIG_PAUSZ 46
305 :     #define ORIG_PAUSG 47
306 : ian 1 #define ORIG_GRAV 3
307 :    
308 : ian 19 new time_stamps[33][5]//time_stamps[id][x]
309 : ian 1 #define TS_SPAWN 0
310 :     #define TS_BOOST 1
311 :     #define TS_WPN 2
312 :     #define TS_CPGC 3 //This one holds a flag, not a timestamp so it can be < 1 second
313 :     #define TS_KNIFE 4
314 :    
315 : ian 23 #define TIMER_SIZE 15
316 : ian 19 new timer[33][TIMER_SIZE]//timer[id][x]:
317 : ian 1 #define TMR_CFLAGS 0 //Status
318 : ian 23 #define TMR_CNTTME 1 //Time / in deciseconds
319 :     #define TMR_CNTCPS 2 //CP Count
320 :     #define TMR_CNTGCS 3 //GC Count
321 :     #define TMR_CNTBST 4 //Boosts
322 :     #define TMR_BSTTME 5 //Best Time / in deciseconds
323 :     #define TMR_BSTCPS 6 //Best CP
324 :     #define TMR_BSTGCS 7 //Best GC
325 :     #define TMR_BSTBST 8 //Number of boosts used
326 :     #define TMR_SESFIN 9 //Finished this session
327 :     #define TMR_MAPFIN 10 //Total times finished this map
328 :     #define TMR_DBUSER 11 //Database player ID; 0=not registered; -1=not registered & shared steam id
329 :     #define TMR_CPPOS 12 //Current CP offset, for cycling back and forward through cps
330 :     #define TMR_CNTWPN 13 //Current weapon rank modifier
331 :     #define TMR_BSTWPN 14 //Best score weapon rank modifier
332 : ian 1
333 :     //Temp save vars
334 :     new savepos = 0, steamid[32][32], Float:originssave[32][ORIGINS_SIZE], timersave[32][TIMER_SIZE]
335 :    
336 :     //Other stuff
337 : ian 19 new hooked[33], hp = 100
338 : ian 1 new sfactions[SF_MAX][50], sfcount = 0
339 :     new ts_score, ts_hscore, bool:has_hscores = false //scoreboard timeouts
340 : ian 19 new spec_ids[33][33]
341 : ian 1 new beam_sprite
342 :    
343 :     new ST_BTNS[9], FN_BTNS[9], ST_BTN_CNT = 0, FN_BTN_CNT = 0
344 :     new dyn_spawn_ids[32], dyn_spawn_count, Float:spawn_tp_orig[3], Float:start_tp_orig[3]
345 :    
346 : ian 37 new Float:post_think_vel[33][3]
347 : ian 1
348 :     new LIMIT_TEAMS_OLD, TEAM_BALANCE_OLD
349 :    
350 :     //Cvar Pointers
351 :     new p_climb, p_auto, p_boost, p_cpprice, p_startmoney
352 :     new p_msg_r, p_msg_g, p_msg_b, p_msg_x, p_msg_y
353 :     new p_sounds, p_render
354 :     new p_stats_hsurl, p_stats_msg
355 :     new p_light_r, p_light_g, p_light_b
356 :     new p_start_respawn, p_water_nodraw
357 :     new p_allow_spectators, p_teambalance, p_limitteams
358 :    
359 :     //Model size
360 :     //standing 32x32x72
361 :     //crouched 32x32x36
362 :    
363 :     //Tasks:
364 :     //#define TSK_AUTOHEAL 50 //50+ : Auto Heal
365 :     #define TSK_AUTORSPN 100 //100+: Auto Respawn
366 :     //#define TSK_BOOSTTMR 150 //150+: Solid Boost Timer
367 :     #define TSK_FLIGHT 200
368 : ian 32 #define TSK_MEASURE2 250
369 : ian 1
370 : ian 19 //Status timer[id][TMR_CFLAGS]&=x
371 : ian 1 #define CF_NULL 0 //Passed to change_boost() to remove all boost flags
372 :     #define CF_STOP (1<<0) //STATUS FLAG: Not Started
373 :     #define CF_START (1<<1) //STATUS FLAG: Climbing
374 :     #define CF_PAUSE (1<<2) //STATUS FLAG: Paused
375 :     #define CF_STATUSFLAGS ( CF_STOP + CF_START + CF_PAUSE )
376 :     #define CF_SOLID (1<<3) //BOOST FLAG
377 :     #define CF_SUPER_JUMP (1<<4) //BOOST FLAG
378 :     #define CF_DOUBLE_JUMP (1<<5) //BOOST FLAG
379 :     #define CF_LIGHT_ON (1<<6)
380 :     //#define CF_NO_VIP (1<<7)
381 :     #define CF_JUST_REGD (1<<8)
382 :     #define CF_MEASURE (1<<9)
383 :     #define CF_MEASURE2 (1<<10)
384 :     #define CF_COUNTDOWN (1<<11)
385 :     #define CF_SUNGLASSES (1<<12)
386 :    
387 : ian 23 #define SILENT 1
388 :    
389 : ian 37 //Boost Flags for climb_boost CVAR
390 :     #define SOLID 1
391 :     #define DJUMP 2
392 :     #define SJUMP 4
393 :    
394 : ian 38 new SVC_STATUSICON, SVC_TEAMINFO, SVC_ROUNDTIME, SVC_FLASHLIGHT, SVC_SCREENFADE, SVC_CLCORPSE;
395 : ian 1
396 :     new SCORES_PATH[100], HSCORES_PATH[100]
397 :    
398 :     ////////////////////////////////////////////////////////////////////////////////
399 :     // Start: Init forwards
400 :     ////////////////////////////////////////////////////////////////////////////////
401 :     public plugin_init( )
402 : ian 22 {
403 : ian 1 register_plugin( "Climb", VERSION, "Ian Cammarata" )
404 : ian 22 register_cvar( TRKCVAR, VERSION, FCVAR_SERVER )
405 :     set_cvar_string( TRKCVAR, VERSION )
406 : ian 1
407 :     p_climb = register_cvar( "climb", "0", FCVAR_SERVER )
408 :     p_auto = register_cvar( "climb_auto", "1" )
409 : ian 37 p_boost = register_cvar( "climb_boost", "7" )
410 : ian 1 p_cpprice = register_cvar( "climb_cpprice", "0" )
411 :     p_startmoney = register_cvar( "climb_startmoney", "1337" )
412 :    
413 :     register_cvar( "climb_save", "1" )
414 :     register_cvar( "climb_db_type", "sqlite" )
415 :     register_cvar( "climb_db_host", "127.0.0.1" )
416 : ian 22 register_cvar( "climb_db_user", NULLSTR )
417 :     register_cvar( "climb_db_pass", NULLSTR, FCVAR_PROTECTED )
418 : ian 1 register_cvar( "climb_db_name", "climb" )
419 :     register_cvar( "climb_db_prefix", "climb_" )
420 : ian 22 register_cvar( "climb_db_serverid", NULLSTR )
421 : ian 1 register_cvar( "climb_db_exists", "0" )
422 :    
423 : ian 38 p_msg_r = register_cvar( "climb_msg_r", "0" );
424 :     p_msg_g = register_cvar( "climb_msg_g", "150" );
425 :     p_msg_b = register_cvar( "climb_msg_b", "250" );
426 :     p_msg_x = register_cvar( "climb_msg_x", "0.05" );
427 :     p_msg_y = register_cvar( "climb_msg_y", "0.5" );
428 : ian 1
429 : ian 38 p_light_r = register_cvar( "climb_light_r", "255" );
430 :     p_light_g = register_cvar( "climb_light_g", "255" );
431 :     p_light_b = register_cvar( "climb_light_b", "255" );
432 : ian 1
433 : ian 38 p_sounds = register_cvar( "climb_sounds", "1" );
434 :     p_render = register_cvar( "climb_unsolid_type", "0" );
435 :     p_start_respawn = register_cvar( "climb_start_respawn", "0" );
436 :     p_water_nodraw = register_cvar( "climb_water_nodraw", "0" );
437 : ian 1
438 : ian 38 p_stats_hsurl = register_cvar( "climb_stats_hsurl", NULLSTR ); //Use %s in place of map name
439 :     p_stats_msg = register_cvar( "climb_stats_msg", NULLSTR );
440 : ian 1
441 : ian 38 p_allow_spectators = get_cvar_pointer( "allow_spectators" );
442 :     p_teambalance = get_cvar_pointer( "mp_autoteambalance" );
443 :     p_limitteams = get_cvar_pointer( "mp_limitteams" );
444 : ian 1
445 : ian 38 MAXPLAYERS = get_maxplayers( );
446 : ian 22
447 : ian 38 TEAM_BALANCE_OLD = get_pcvar_num( p_teambalance );
448 :     LIMIT_TEAMS_OLD = get_pcvar_num( p_limitteams );
449 : ian 1
450 :     //Message Pseudo-Constants
451 : ian 38 SVC_STATUSICON = get_user_msgid( "StatusIcon" );
452 :     SVC_TEAMINFO = get_user_msgid( "TeamInfo" );
453 :     SVC_ROUNDTIME = get_user_msgid( "RoundTime" );
454 :     SVC_FLASHLIGHT = get_user_msgid( "Flashlight" );
455 :     SVC_SCREENFADE = get_user_msgid( "ScreenFade" );
456 :     SVC_CLCORPSE = get_user_msgid( "ClCorpse" );
457 : ian 1
458 :     //These commands get blocked always.
459 : ian 38 register_clcmd( "fullupdate", "block_cmd2" );
460 : ian 1
461 :     //These commands get blocked when climb is enabled.
462 : ian 38 register_clcmd( "chooseteam", "spectate" );
463 :     register_clcmd( "buy", "block_cmd" );
464 :     register_clcmd( "buyammo1", "block_cmd" );
465 :     register_clcmd( "buyammo2", "block_cmd" );
466 :     register_clcmd( "buyequip", "block_cmd" );
467 : ian 1
468 : ian 38 register_clcmd( "jointeam", "block_jointeam" );
469 : ian 1
470 :     //Commands to detect cheats.
471 : ian 38 register_clcmd( "+hook", "phook" );
472 :     register_clcmd( "+rope", "phook" );
473 :     register_clcmd( "-hook", "mhook" );
474 :     register_clcmd( "-rope", "mhook" );
475 : ian 1
476 :     //Commands referencing function 'donothing' are picked up by the more flexible code in the client_command forward.
477 :     register_clcmd( "say help", "help_msg" )
478 :     register_clcmd( "say /help", "help_msg" )
479 : ian 22 register_clcmd( "climbhelp", DONOTHING, 0, "- Veiw climb help." )
480 :     register_clcmd( "cp", DONOTHING, _, "- Make a checkpoint" )
481 :     register_clcmd( "gc", DONOTHING, _, "- Teleport to last checkpoint" )
482 :     register_clcmd( "stuck", DONOTHING, _, "- Teleport to previous checkpoint" )
483 :     register_clcmd( "restart", DONOTHING, _, "- Stop and respawn." )
484 :     register_clcmd( "stop", DONOTHING, _, "- End current climbing run." )
485 :     register_clcmd( "pause", DONOTHING, _, "- Pause yourself." )
486 :     register_clcmd( "scoreboard", DONOTHING, _, "- View score board." )
487 :     register_clcmd( "respawn", DONOTHING, _, "- Force respawn" )
488 :     register_clcmd( "boost", DONOTHING, _, "- Boost." )
489 :     register_clcmd( "spec", DONOTHING, _, "- Spectate mode." )
490 :     register_clcmd( "ungc", DONOTHING, _, "- Undo last gocheck." )
491 : ian 1
492 :     //Commands related to stats account system.
493 :     //register_clcmd( "register", "reg", _, "- (Console Only) Register for stats tracking." )
494 :     register_clcmd( "login", "db_login", _, "- (Console Only) Login to stats account." )
495 :    
496 :     register_concmd( "climb_dbwho", "climb_dbwho", DBADMIN, "- List DB ID of current clients." )
497 :     register_concmd( "climb_dbmap", "climb_dbmap", DBADMIN, "<Map Name> - List high scores for current map." )
498 :     register_concmd( "climb_dbuser", "climb_dbuser", DBADMIN, "[DB User ID] - List high scores for given DB User ID." )
499 :     register_concmd( "climb_dbdelete", "climb_dbdelete", DBADMIN, "[DB Score ID] - Delete score for given DB Score ID." )
500 :    
501 :     //temp commands
502 :     register_concmd("climb_dbrecalc","climb_dbrecalc",DBADMIN)
503 :    
504 :     //Admin Commands
505 :     register_clcmd("amx_goto","goto_player")
506 :    
507 :     //Climb Flashlight
508 :     //register_impulse(100,"tog_flight")
509 :     register_clcmd("nightvision","tog_flight")
510 :    
511 :     //Events
512 :     register_event("DeathMsg","DeathMsg","a")
513 :     register_event("ResetHUD","ResetHUD","b")
514 : ian 22 register_event("Health","Health","b")
515 : ian 1 register_event("ShowMenu","menuclass","b","4&CT_Select","4&Terrorist_Select")
516 :     register_event("ShowMenu","menuteam","b","4&Team_Select_Spect","4&Team_Select","4&IG_Team_Select")
517 :    
518 :     //Init DB
519 :     if( get_cvar_num( "climb_save" ) ) CLIMB_SAVE = true
520 :     if( CLIMB_SAVE ) db_init( )
521 :    
522 :     //Init anti flood time stamps
523 :     ts_score = get_systime( )
524 :     ts_hscore = get_systime( )
525 :     set_task( 0.5, "hudtime", _, _, _, "b" ) //Task to update time on clients HUD; Task set for half second to minimize flickering of the timer.
526 :     set_task( 1.0, "spec_update", _, _, _, "b" ) //Task to update spectator array
527 :     set_task( 5.0, "run_tasks", _, _, _, "b" )
528 : ian 23 set_task( 0.1, "timer_tick", _, _, _, "b" )
529 : ian 1
530 :     register_message( get_user_msgid( "CurWeapon" ), "CurWeapon" )
531 :    
532 :     register_forward( FM_UpdateClientData, "PostUpdateClientData", 1 )
533 :    
534 :     //register_dictionary("climb.txt")
535 :    
536 :     //Make var folder if not exists
537 :     new path[61]
538 :     get_localinfo( "amxx_datadir", path, 60 )
539 :     format( path, 60, "%s/var", path )
540 :     if( !dir_exists( path ) ) mkdir( path )
541 :     formatex( SCORES_PATH, 99, "%s/climb_scores.html", path )
542 :     formatex( HSCORES_PATH, 99, "%s/climb_highscores.html", path )
543 :    
544 :     //Load Start/Finish Commands
545 :     new ini[50]
546 :     get_configsdir( ini, 49 )
547 :     format( ini, 49, "%s/climb.ini", ini )
548 :     if( file_exists( ini ) )
549 :     {
550 :     new line = 0, text[50], len
551 : ian 37 while( read_file( ini, line++, text, 49 , len ) )
552 : ian 1 {
553 :     if( !equal( text, ";", 1 ) && !equal( text, "#", 1 ) && !equal( text, "//", 2 ) )
554 :     {
555 :     if( sfcount < SF_MAX )
556 :     {
557 :     sfactions[sfcount] = text
558 :     sfcount++
559 :     }
560 :     }
561 :     }
562 :     }
563 :     return PLUGIN_CONTINUE
564 :     }
565 :    
566 :     public pfn_keyvalue( ent )
567 :     {
568 :     //Create more ct spawns so everyone can join team
569 :     if( dyn_spawn_count < 1 )
570 :     {
571 :     new id
572 :     for( dyn_spawn_count = 0; dyn_spawn_count < 30; dyn_spawn_count++ )
573 :     {
574 :     id = create_entity( "info_player_start" )
575 :     if( id > 0 )
576 :     {
577 :     dyn_spawn_ids[dyn_spawn_count] = id
578 :     entity_set_int( id, EV_INT_iuser1, 1 )
579 :     }
580 :     }
581 :     }
582 :    
583 :     return PLUGIN_CONTINUE
584 :     }
585 :    
586 :     public plugin_cfg( )
587 :     {
588 :     new ent, ent2, tmpstr[33], Float:tmpflt
589 :    
590 :     //Store ent id's for start/fin buttons, some maps change target value after timer starts
591 :     ent = find_ent_by_class( -1, "func_button" )
592 :     while( ent > 0 )
593 :     {
594 :     entity_get_string( ent, EV_SZ_target, tmpstr, 32 )
595 :    
596 :     if( equal( tmpstr, "counter_start" ) || equal( tmpstr, "clockstartbutton" )
597 :     || equal( tmpstr, "firsttimerelay" ) || equal( tmpstr, "gogogo" ) )
598 :     {
599 :     ST_BTNS[ST_BTN_CNT] = ent
600 :     ST_BTN_CNT++
601 :     }
602 :     else if( equal( tmpstr, "counter_off" ) || equal( tmpstr, "clockstopbutton" )
603 :     || equal( tmpstr, "clockstop" ) || equal( tmpstr, "stop_counter" ) )
604 :     {
605 :     FN_BTNS[FN_BTN_CNT] = ent
606 :     FN_BTN_CNT++
607 :     }
608 :    
609 :     ent = find_ent_by_class( ent, "func_button" )
610 :     }
611 :    
612 :     if( ST_BTN_CNT /*|| get_pcvar_num( p_climb )*/ )
613 :     {
614 :     get_brush_entity_origin( ST_BTNS[0], start_tp_orig )
615 :    
616 :     set_pcvar_num( p_teambalance, 0 )
617 :     set_pcvar_num( p_limitteams, 0 )
618 :    
619 :     set_cvar_num( "sv_restartround", 1 )//reset timer built into map
620 :     set_cvar_num( "sv_gravity", 800 )
621 :     set_pcvar_num( p_climb, 1 )
622 :    
623 :     remove_entity_name("player_weaponstrip")
624 :     remove_entity_name("armoury_entity")
625 :     remove_entity_name("info_player_deathmatch")
626 :     remove_entity_name("game_player_equip")//Remove map built in spawn weapons
627 :    
628 :     //Remove func_breakables with < 9999 hp
629 :     ent = find_ent_by_class( -1, "func_breakable" )
630 :     while( ent > 0 )
631 :     {
632 :     tmpflt = entity_get_float( ent, EV_FL_health )
633 :     if( tmpflt < 9999 ) remove_entity( ent )
634 :     ent = find_ent_by_class( ent, "func_breakable" )
635 :     }
636 :    
637 :     //Remove neg dmg func_door that aren't targeted by a button
638 :     ent=find_ent_by_class(-1,"func_door")
639 :     while(ent>0)
640 :     {
641 :     tmpflt=entity_get_float(ent,EV_FL_dmg)
642 :     if(tmpflt<0)
643 :     {
644 :     hp=floatround(tmpflt)//record hp for auto heal
645 :     entity_get_string( ent, EV_SZ_targetname, tmpstr, 32 )
646 :     if(strlen(tmpstr))
647 :     {
648 :     ent2=find_ent_by_target(-1,tmpstr)
649 :     //entity_get_string(ent2,EV_SZ_classname,tmpstr,32)
650 :     //if(!equal("func_button",tmpstr)){
651 :     remove_entity(ent2)
652 :     }
653 :     remove_entity(ent)
654 :     //}
655 :     //if(!strlen(tmpstr))remove_entity(ent)
656 :     //ent=-1
657 :     }
658 :     ent=find_ent_by_class(ent,"func_door")
659 :     }
660 :    
661 :     if( hp < 0 ) hp = 511
662 :     //Disable climb auto heal if there is a neg dmg trigger hurt
663 :     else
664 :     {
665 :     ent=find_ent_by_class(-1,"trigger_hurt")
666 :     while(ent>0){
667 :     tmpflt=entity_get_float(ent,EV_FL_dmg)
668 :     if(tmpflt<0){
669 :     hp=0
670 :     break
671 :     }
672 :     ent=find_ent_by_class(ent,"trigger_hurt")
673 :     }
674 :     }
675 :    
676 :     //Remove map built in start button sounds
677 :     ent = find_ent_by_class( -1, "ambient_generic" )
678 :     while( ent > 0 )
679 :     {
680 :     entity_get_string( ent, EV_SZ_targetname, tmpstr, 32 )
681 :     if( equal( tmpstr, "counter_start" ) || equal( tmpstr, "clockstartbutton" )
682 :     || equal( tmpstr, "firsttimerelay" ) || equal( tmpstr, "gogogo" ) )
683 :     remove_entity( ent )
684 :     ent = find_ent_by_class( ent, "ambient_generic" )
685 :     }
686 :    
687 :     //Count original map spawns and remove extra dyn created spawns
688 :     new map_spawns[32][2], map_spawns_count, Float:orig[3]
689 :     ent = find_ent_by_class( -1, "info_player_start" )
690 :     while( ent > 0 && map_spawns_count < 32 )
691 :     {
692 :     if( entity_get_int( ent, EV_INT_iuser1 ) != 1 )
693 :     {
694 :     entity_get_vector( ent, EV_VEC_origin, orig )
695 :     map_spawns[map_spawns_count][0] = floatround( vector_distance( orig, start_tp_orig ) )
696 :     map_spawns[map_spawns_count][1] = ent
697 :     map_spawns_count++
698 :     while( dyn_spawn_count >= 0 )
699 :     {
700 :     entity_get_string( dyn_spawn_ids[dyn_spawn_count], EV_SZ_classname, tmpstr, 32 )
701 :     if( equal( tmpstr, "info_player_start" ) &&
702 :     entity_get_int( dyn_spawn_ids[dyn_spawn_count], EV_INT_iuser1 ) == 1 )
703 :     {
704 :     remove_entity( dyn_spawn_ids[dyn_spawn_count] )
705 :     dyn_spawn_count--
706 :     break
707 :     }
708 :     else dyn_spawn_count--
709 :     }
710 :     }
711 :     ent = find_ent_by_class( ent, "info_player_start" )
712 :     }
713 :    
714 :     //Save origin of spawn closest to start
715 :     SortStrings( map_spawns, map_spawns_count )
716 :     entity_get_vector( map_spawns[0][1], EV_VEC_origin, spawn_tp_orig )
717 :    
718 :     new Float:tmpvec[3], Float:tmpvec2[3]
719 :     tmpvec = start_tp_orig
720 :    
721 :     start_tp_orig[2] += 24
722 :    
723 :     start_tp_orig[0] += 40
724 :     trace_line( ST_BTNS[0], tmpvec, start_tp_orig, tmpvec2 )
725 :     if( !trace_hull( start_tp_orig, HULL_HUMAN ) && tmpvec2[2] == start_tp_orig[2] )
726 :     return PLUGIN_CONTINUE
727 :    
728 :     start_tp_orig[0] -= 80
729 :     trace_line( ST_BTNS[0], tmpvec, start_tp_orig, tmpvec2 )
730 :     if( !trace_hull( start_tp_orig, HULL_HUMAN ) && tmpvec2[2] == start_tp_orig[2] )
731 :     return PLUGIN_CONTINUE
732 :    
733 :     start_tp_orig[0] += 40
734 :     start_tp_orig[1] += 40
735 :     trace_line( ST_BTNS[0], tmpvec, start_tp_orig, tmpvec2 )
736 :     if( !trace_hull( start_tp_orig, HULL_HUMAN ) && tmpvec2[2] == start_tp_orig[2] )
737 :     return PLUGIN_CONTINUE
738 :    
739 :     start_tp_orig[1] -= 80
740 :     trace_line( ST_BTNS[0], tmpvec, start_tp_orig, tmpvec2 )
741 :     if( !trace_hull( start_tp_orig, HULL_HUMAN ) && tmpvec2[2] == start_tp_orig[2] )
742 :     return PLUGIN_CONTINUE
743 :    
744 :     start_tp_orig = spawn_tp_orig
745 :     }
746 :     else
747 :     {//if not kz map remove dyn created spawns
748 :     while( dyn_spawn_count >= 0 )
749 :     {
750 :     ent = dyn_spawn_ids[dyn_spawn_count]
751 :     entity_get_string( ent, EV_SZ_classname, tmpstr, 32 )
752 :     //entity_get_string(dyn_spawn_ids[i],EV_SZ_classname,tmpstr,32)
753 :     if( equal( tmpstr, "info_player_start" ) && entity_get_int( ent, EV_INT_iuser1 ) == 1 )
754 :     remove_entity(ent)
755 :     dyn_spawn_count--
756 :     }
757 :     }
758 :     return PLUGIN_CONTINUE
759 :     }
760 :    
761 :     public plugin_precache( )
762 :     {
763 :     beam_sprite = precache_model( "sprites/laserbeam.spr" )
764 :     return PLUGIN_CONTINUE
765 :     }
766 :    
767 :     stock Float:float_clamp( Float:curval, Float:minval, Float:maxval )
768 :     {
769 :     if( curval < minval )return minval
770 :     if( curval > maxval )return maxval
771 :     return curval
772 :     }
773 :    
774 :     ////////////////////////////////////////////////////////////////////////////////
775 :     // End: Init forwards
776 :     ////////////////////////////////////////////////////////////////////////////////
777 :     public client_putinserver( id )
778 :     {
779 :     if( get_pcvar_num( p_climb ) && !is_user_bot( id ) && !is_user_hltv( id ) )
780 :     {
781 : ian 19 timer[id][TMR_DBUSER] = 0
782 : ian 1
783 :     //search steamid to position reference for match
784 :     new searchid[32]
785 :     get_user_authid( id, searchid, 31 )
786 :     for(new i = 0; i < 32; i++ )
787 :     if( equal( searchid, steamid[i] ) )
788 :     {//load origins & timer array if match found
789 : ian 19 origins[id] = originssave[i]
790 :     timer[id] = timersave[i]
791 : ian 1 return PLUGIN_CONTINUE
792 :     }
793 :    
794 : ian 19 timer[id][TMR_CFLAGS] += CF_STOP
795 : ian 1
796 :     new ida[1]
797 :     ida[0]=id
798 :    
799 : ian 19 if( CLIMB_SAVE && timer[id][TMR_DBUSER] < 1 )
800 : ian 1 set_task( 5.0, "auto_login", 0, ida, 1 )
801 :     }
802 :     return PLUGIN_CONTINUE
803 :     }
804 :    
805 :     public client_disconnect( id )
806 :     {
807 :     if( get_pcvar_num(p_climb) )
808 :     {
809 :     savepos++
810 :     if( savepos == 31 ) savepos = 0
811 :    
812 :     new saveid[32]
813 :     get_user_authid( id, saveid, 32 )
814 :    
815 :     //erase previous save if exists
816 :     for( new i=0; i<32; i++ )
817 : ian 22 if( equal( saveid, steamid[i] ) ) steamid[i] = NULLSTR
818 : ian 1
819 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START ) change_status( id, CF_PAUSE ) //Pause if running
820 : ian 1 steamid[savepos] = saveid //save steamid to position reference
821 : ian 19 originssave[savepos] = origins[id] //save origins
822 :     timersave[savepos] = timer[id] //save timer array
823 : ian 1
824 :     //clear data for new client in that slot
825 : ian 19 for( new i = 0; i < 48; i++ ) origins[id][i] = 0.0
826 :     for( new i = 0; i < 14; i++ ) timer[id][i] = 0
827 : ian 1 hooked[id] = 0
828 :     sortcssb( ) //Update frags to reorder scoreboard
829 :     }
830 :     return PLUGIN_CONTINUE
831 :     }
832 :     ////////////////////////////////////////////////////////////////////////////////
833 :     // Start: CP/GC functions
834 :     ////////////////////////////////////////////////////////////////////////////////
835 :     public set_cpgc_timeout( id )
836 :     {
837 :     //Set timeout flag and set_task to clear it
838 :     new ida[1]
839 :     ida[0] = id
840 : ian 19 time_stamps[id][TS_CPGC] = 1
841 : ian 1 set_task( CPGC_TIMEOUT, "clear_cpgc_timeout", _, ida, 1 )
842 :     }
843 :    
844 :     public clear_cpgc_timeout( ida[1] )
845 : ian 19 return time_stamps[ida[0]][TS_CPGC]=0
846 : ian 1
847 :     //Save a checkpoint
848 :     public check( id )
849 :     {
850 :     if( get_pcvar_num( p_climb ) && isalive( id ) && notpaused( id ) )
851 :     {
852 :     new cpprice = get_pcvar_num( p_cpprice )
853 :     if( cpprice > 0 )
854 :     {
855 :     new cash = cs_get_user_money(id)
856 :     if( cpprice > cash )
857 :     {
858 :     clmsg(id,"You don't have enough cash for more checkpoints.")
859 :     client_print(id,print_chat,"You don't have enough cash for more checkpoints.")
860 :     return PLUGIN_HANDLED
861 :     }
862 :     cs_set_user_money( id, cash - cpprice )
863 :     }
864 :     if( !hooked[id] )//If they're not hooked...
865 :     {
866 :     new Float:vel[3]
867 :     entity_get_vector( id, EV_VEC_velocity, vel )
868 :     if( vel[2] >= 0 )//and they're not falling...
869 :     {
870 :     new Float:coords[3]
871 :     entity_get_vector( id, EV_VEC_origin, coords )
872 :     if( coords[0] || coords[1] || coords[2] )//and they're not at world origin, then save checkpoint
873 :     {
874 : ian 19 if( timer[id][TMR_CPPOS] > 0 ) timer[id][TMR_CPPOS]--
875 :     new cppos = timer[id][TMR_CPPOS] * 4
876 : ian 1
877 :     //If cp position is 0 then bump all cps back before saving.
878 : ian 19 if( !cppos ) for(new i=39; i>3 ;i-- ) origins[id][i] = origins[id][i-4]
879 : ian 1
880 : ian 19 for( new i=0; i<3; i++ ) origins[id][cppos + i] = coords[i]
881 :     origins[id][3]=entity_get_float(id, EV_FL_gravity)
882 : ian 1
883 :     new msg[100]="Checkpoint saved."
884 : ian 19 if(timer[id][TMR_CFLAGS]&CF_START){
885 :     timer[id][TMR_CNTCPS]++
886 :     formatex(msg,99,"Checkpoint saved. (%d CPS/ %d GCS/ %d Boosts)",timer[id][TMR_CNTCPS],timer[id][TMR_CNTGCS],timer[id][TMR_CNTBST])
887 : ian 1 }
888 :     clmsg(id,msg)
889 :    
890 :     set_cpgc_timeout( id )
891 :     }
892 :     else clmsg(id,"Can not save checkpoint at current location.")
893 :     }
894 :     else clmsg(id,"You can't make checkpoints while falling.")
895 :     }
896 :     else clmsg(id,"You can't make checkpoints while using hook.")
897 :     }
898 :     return PLUGIN_HANDLED
899 :     }
900 :    
901 :     //Go to most recent checkpoint
902 :     public gocheck( id )
903 :     {
904 : ian 19 if( get_pcvar_num( p_climb ) && isalive( id ) && notpaused( id ) && !time_stamps[id][TS_CPGC] )
905 : ian 1 {
906 : ian 19 if( origins[id][0] || origins[id][1] || origins[id][2] )
907 : ian 1 {
908 :     new Float:coords[3]
909 :    
910 :     //Store ungocheck data
911 :     entity_get_vector( id, EV_VEC_origin, coords )
912 : ian 19 for( new i=0; i<3; i++ ) origins[id][ORIG_UNGC + i] = coords[i]
913 :     origins[id][ORIG_UNGC + 3] = entity_get_float( id, EV_FL_gravity )
914 : ian 1
915 :     //Do gocheck
916 : ian 19 new cppos = timer[id][TMR_CPPOS] * 4
917 : ian 38 coords[0] = origins[id][cppos]
918 :     coords[1] = origins[id][cppos + 1]
919 :     coords[2] = origins[id][cppos + 2]
920 : ian 19 entity_set_float( id, EV_FL_gravity, origins[id][3] )
921 : ian 1 teleport( id, coords )
922 :    
923 :     new msg[100]="Checkpoint restored."
924 : ian 19 if(timer[id][TMR_CFLAGS]&CF_START){
925 :     timer[id][TMR_CNTGCS]++
926 :     formatex(msg,99,"Checkpoint restored. (%d CPS/ %d GCS/ %d Boosts)",timer[id][TMR_CNTCPS],timer[id][TMR_CNTGCS],timer[id][TMR_CNTBST])
927 : ian 1 }
928 :     clmsg(id,msg)
929 :    
930 :     set_cpgc_timeout( id )
931 :     }
932 :     else{
933 :     clmsg(id,"You must make a checkpoint first.")
934 :     return 0
935 :     }
936 :     }
937 :     return 1
938 :     }
939 :    
940 :     //Undo a gocheck
941 :     public ungocheck( id )
942 :     {
943 : ian 19 if( get_pcvar_num(p_climb) && isalive(id) && notpaused(id) && !time_stamps[id][TS_CPGC] )
944 : ian 1 {
945 : ian 19 if( origins[id][ORIG_UNGC] || origins[id][ORIG_UNGC + 1] || origins[id][ORIG_UNGC + 2])
946 : ian 1 {
947 :     new Float:coords[3]
948 : ian 19 for( new i=0; i<3; i++ )coords[i] = origins[id][ORIG_UNGC + i]
949 : ian 1 teleport( id, coords )
950 : ian 19 entity_set_float( id, EV_FL_gravity, origins[id][ORIG_UNGC + 3] )
951 :     if( timer[id][TMR_CFLAGS] & CF_START ) timer[id][TMR_CNTGCS]++
952 : ian 1 clmsg( id, "You have been ungochecked." )
953 :    
954 :     set_cpgc_timeout( id )
955 :     }
956 :     else clmsg(id,"Cannot ungocheck.")
957 :     }
958 :     }
959 :    
960 :     //Cycle back through CPs
961 :     public cp_back( id )
962 :     {
963 : ian 19 if( get_pcvar_num( p_climb ) && isalive( id ) && notpaused( id ) && !time_stamps[id][TS_CPGC] )
964 : ian 1 {
965 : ian 19 if( timer[id][TMR_CPPOS] < 9 ) timer[id][TMR_CPPOS]++
966 :     new cppos = timer[id][TMR_CPPOS] * 4
967 :     if( origins[id][cppos] || origins[id][cppos + 1] || origins[id][cppos + 2] )
968 : ian 1 {
969 :     new Float:coords[3]
970 : ian 19 //for( new i=0; i<36; i++ ) origins[id][i] = origins[id][i+4]
971 :     for( new i=0; i<3; i++ ) coords[i] = origins[id][cppos + i]
972 :     entity_set_float( id, EV_FL_gravity, origins[id][cppos + ORIG_GRAV] )
973 : ian 1 teleport( id, coords )
974 :    
975 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START ) timer[id][TMR_CNTGCS]++
976 : ian 1
977 :     /*new msg[100]="Previous checkpoint restored."
978 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START )
979 : ian 1 {
980 : ian 19 timer[id][TMR_CNTCPS]--
981 : ian 1 formatex( msg, 99, "Previous checkpoint restored. (%d CPS/ %d GCS/ %d Boosts)",\
982 : ian 19 timer[id][TMR_CNTCPS], timer[id][TMR_CNTGCS], timer[id][TMR_CNTBST] )
983 : ian 1 }
984 :     clmsg( id, msg )*/
985 :    
986 :     /*new cpprice = get_pcvar_num( p_cpprice )
987 :     if( cpprice > 0 )
988 :     {
989 :     new cash = cs_get_user_money( id )
990 :     cs_set_user_money( id, cash + cpprice )
991 :     }*/
992 :    
993 :     set_cpgc_timeout( id )
994 :     }
995 :     else
996 :     {
997 :     clmsg(id,"You have no previous checkpoints remaining.")
998 : ian 19 timer[id][TMR_CPPOS]--
999 : ian 1 }
1000 :     }
1001 :     return PLUGIN_HANDLED
1002 :     }
1003 :    
1004 :     //Cycle forward through CPs
1005 :     public cp_forward( id )
1006 :     {
1007 : ian 19 if( get_pcvar_num( p_climb ) && isalive( id ) && notpaused( id ) && !time_stamps[id][TS_CPGC] && timer[id][TMR_CPPOS] > 0 )
1008 : ian 1 {
1009 : ian 19 timer[id][TMR_CPPOS]--
1010 :     new cppos = timer[id][TMR_CPPOS] * 4
1011 : ian 1
1012 :     new Float:coords[3]
1013 : ian 19 for( new i=0; i<3; i++ ) coords[i] = origins[id][cppos + i]
1014 :     entity_set_float( id, EV_FL_gravity, origins[id][cppos + ORIG_GRAV] )
1015 : ian 1 teleport( id, coords )
1016 :    
1017 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START ) timer[id][TMR_CNTGCS]++
1018 : ian 1
1019 :     set_cpgc_timeout( id )
1020 :     }
1021 :     return PLUGIN_HANDLED
1022 :     }
1023 :     ////////////////////////////////////////////////////////////////////////////////
1024 :     // End: CP/GC functions
1025 :     ////////////////////////////////////////////////////////////////////////////////
1026 :     public change_status( id, newstat )
1027 :     {
1028 : ian 19 new cflags_old = timer[id][TMR_CFLAGS]
1029 : ian 1 new cflags_new = cflags_old & ~CF_STATUSFLAGS
1030 :    
1031 :     if( newstat & CF_PAUSE )
1032 :     {
1033 :     if( cflags_old & CF_PAUSE ) //unpause
1034 :     {
1035 :     cflags_new += CF_START
1036 :     set_entity_flags( id, FL_FROZEN, 0 )
1037 : ian 37 //set_solid( id, 0 );
1038 : ian 38 entity_set_float( id, EV_FL_gravity, origins[id][ORIG_PAUSG] )
1039 : ian 1 clmsg( id, "UNPAUSED" )
1040 :     sfexec( id, 2 )
1041 :     }
1042 :     else if( cflags_old & CF_START ) //pause
1043 :     {
1044 :     cl_pause( id )
1045 :     cflags_new += CF_PAUSE
1046 :     }
1047 :     else
1048 :     {
1049 :     clmsg( id, "You must start the timer before you can pause." )
1050 :     cflags_new = cflags_old
1051 :     }
1052 :     }
1053 :     else cflags_new += newstat
1054 : ian 19 timer[id][TMR_CFLAGS] = cflags_new
1055 : ian 1 return PLUGIN_HANDLED
1056 :     }
1057 :    
1058 :     public cl_pause( id )
1059 :     {
1060 :     if( is_climber_alive( id ) )
1061 :     {
1062 : ian 37 set_solid( id, 0 );
1063 : ian 1 set_rendering( id, kRenderFxGlowShell, 0, 0, 255, kRenderTransColor, 1 )
1064 : ian 37 //set_pev( id, pev_flags, pev( id, pev_flags ) & FL_FROZEN )
1065 : ian 1 set_entity_flags( id, FL_FROZEN, 1 )
1066 :     clmsg( id, "PAUSED - say '/unpause' to resume." )
1067 :     }
1068 :     return PLUGIN_HANDLED
1069 :     }
1070 :    
1071 : ian 23 public timer_tick( )
1072 :     {
1073 :     new players[32], num, id
1074 :     get_players( players, num, "ach" )
1075 :    
1076 :     for( new i = 0; i < num; i++ )
1077 :     {
1078 :     id = players[i]
1079 :     if( timer[id][TMR_CFLAGS] & CF_START )
1080 :     timer[id][TMR_CNTTME]++
1081 :     }
1082 :     }
1083 :    
1084 : ian 1 public stop( id )
1085 :     {
1086 : ian 19 if( get_pcvar_num( p_climb ) && timer[id][TMR_CFLAGS] & CF_START )
1087 : ian 1 {
1088 :     change_status( id, CF_STOP )
1089 :     heal(id)
1090 :     //Erase start/finish time stamps, prevents crazy number on scoreboard
1091 : ian 23 timer[id][TMR_CNTTME] = 0
1092 : ian 1
1093 :     sfexec(id,4) //Execute commands from start/finish config
1094 :     }
1095 :     return PLUGIN_HANDLED
1096 :     }
1097 :    
1098 :     //Start borrowed code : from KCE's attack blocking tutorial (http://forums.alliedmods.net/showthread.php?t=41265)
1099 :     public PostUpdateClientData( id, sendweapons, cd_handle )
1100 :     {
1101 :     if( get_pcvar_num( p_climb ) && is_climber_alive( id ) )
1102 :     {
1103 :     new wpn, clip, ammo
1104 :     wpn = get_user_weapon( id, clip, ammo )
1105 :     if( wpn == CSW_KNIFE )
1106 :     {
1107 : ian 19 new remain = check_timeout( 0, time_stamps[id][TS_KNIFE], KNIFE_TIMEOUT, _, 1 )
1108 : ian 1 if( remain )
1109 :     {
1110 :     set_cd(cd_handle, CD_flNextAttack, halflife_time() + remain )
1111 :     return FMRES_HANDLED
1112 :     }
1113 :     }
1114 :     }
1115 :     return FMRES_IGNORED
1116 :     }
1117 :     //End borrowed code
1118 :    
1119 :     public CurWeapon( msg_id, msg_dest, id )
1120 :     {
1121 :     new wpn = get_msg_arg_int( 2 )
1122 :     if( !get_pcvar_num( p_climb ) || !( 0 < wpn <= 30 ) )
1123 :     return PLUGIN_CONTINUE
1124 :    
1125 : ian 19 static client_oldwpn[33]
1126 :     if( wpn != client_oldwpn[id] )
1127 : ian 1 rank_mod_update( id )
1128 :    
1129 : ian 19 client_oldwpn[id] = wpn
1130 : ian 1
1131 : ian 22 if( wpn == CSW_C4 ||
1132 :     wpn == CSW_HEGRENADE ||
1133 :     wpn == CSW_FLASHBANG ||
1134 :     wpn == CSW_SMOKEGRENADE ||
1135 :     wpn == CSW_KNIFE
1136 :     ) return PLUGIN_CONTINUE
1137 :    
1138 : ian 1 //If it's a gun, update pack and clip ammo & silencer
1139 : ian 24 new wpn_name[17]
1140 :     get_weaponname( wpn, wpn_name,16 )
1141 :     new wpn_id = find_ent_by_owner( -1, wpn_name, id )
1142 : ian 22 if( !wpn_id ) return PLUGIN_CONTINUE
1143 :    
1144 :     new clip = get_msg_arg_int( 3 )
1145 :     new maxammo = 2
1146 :    
1147 :     //Force silencer w/o animation
1148 :     if( wpn == CSW_USP || wpn == CSW_M4A1 || wpn == CSW_TMP )
1149 : ian 1 {
1150 : ian 22 if( wpn != CSW_TMP ) cs_set_weapon_silen( wpn_id, 1, 0 )
1151 :     maxammo = 10
1152 : ian 1
1153 : ian 22 //Unlimited ammo for VIPs
1154 :     if( get_user_flags(id) & VIP )
1155 : ian 1 {
1156 : ian 22 cs_set_weapon_ammo( wpn_id, 12 )
1157 :     if( clip != 12 )return PLUGIN_HANDLED
1158 :     set_msg_arg_int( 3, ARG_BYTE, 12 )
1159 :     return PLUGIN_CONTINUE
1160 : ian 1 }
1161 :     }
1162 :    
1163 : ian 22 //Set clip and backpack ammo
1164 :     cs_set_user_bpammo( id, wpn, maxammo - clip )
1165 :     if( clip > maxammo )
1166 :     {
1167 :     set_msg_arg_int( 3, ARG_BYTE, maxammo )
1168 :     cs_set_weapon_ammo( wpn_id, maxammo )
1169 :     }
1170 :    
1171 : ian 1 return PLUGIN_CONTINUE
1172 :     }
1173 :    
1174 :     public rank_mod_update( id )
1175 : ian 22 {
1176 : ian 1 new rank, maxspeed = pev( id, pev_maxspeed )
1177 :     switch( maxspeed )
1178 :     {
1179 :     case 210:
1180 :     rank = 0
1181 :     case 220:
1182 :     rank = 1
1183 :     case 230:
1184 :     rank = 2
1185 :     case 235:
1186 :     rank = 3
1187 :     case 240:
1188 :     rank = 4
1189 :     case 245:
1190 :     rank = 5
1191 :     case 250:
1192 :     rank = 6
1193 :     case 260:
1194 :     rank = 7
1195 :     }
1196 :    
1197 : ian 19 if( rank > timer[id][TMR_CNTWPN] )
1198 :     timer[id][TMR_CNTWPN] = rank
1199 : ian 1
1200 :     new msg[100]
1201 :     format( msg, 99, "Weapon Max Speed: %d^nRank Modifier: %d", maxspeed, rank )
1202 :     clmsg( id, msg )
1203 :     }
1204 :    
1205 :     public get_weapon_name( wpn_rank, ret_name[], len )
1206 :     {
1207 :     new name[21]
1208 :     switch( wpn_rank )
1209 :     {
1210 :     case 0:
1211 :     name = "AWP"
1212 :     case 1:
1213 :     name = "Para"
1214 :     case 2:
1215 :     name = "M4A1"
1216 :     case 3:
1217 :     name = "SG552"
1218 :     case 4:
1219 :     name = "Famas"
1220 :     case 5:
1221 :     name = "P90"
1222 :     case 6:
1223 :     name = "USP"
1224 :     case 7:
1225 :     name = "Scout"
1226 :     }
1227 :     formatex( ret_name, len, name )
1228 :     }
1229 :    
1230 :     public DeathMsg( )
1231 :     {//Respawn client when they die unless switching to spec
1232 :     if( get_pcvar_num( p_climb ) )
1233 :     {
1234 :     new id = read_data(2)
1235 :     set_entity_flags( id, FL_FROZEN, 0 )//Unfreeze in case of switch to spectator.
1236 :     new ida[1]
1237 :     ida[0]=id
1238 :     if(task_exists(100+id))remove_task(100+id)
1239 :     if(isct(id)){
1240 :     set_task(0.2,"respawn_task",100+id,ida,1)
1241 :     }
1242 :     }
1243 :     return PLUGIN_HANDLED
1244 :     }
1245 :    
1246 :     public respawn_task(ida[]){//used by death_msg function
1247 :     new id=ida[0]
1248 :     if( !get_user_team( id ) || is_climber_alive( id ) || !isct( id ) )
1249 :     return PLUGIN_HANDLED
1250 :     //cs_user_spawn(id)
1251 :     climb_user_spawn( id, 0 )
1252 :     return PLUGIN_HANDLED
1253 :     }
1254 :    
1255 :     public frespawn( id )
1256 :     {
1257 :     stop(id)
1258 :     if( is_climber_alive( id ) ) teleport( id, spawn_tp_orig )
1259 : ian 19 else if( !check_timeout( id, time_stamps[id][TS_SPAWN], SPAWN_TIMEOUT ) )
1260 : ian 1 {
1261 :     //if( get_user_team ( id ) == 3 ) cs_set_user_team( id, 2 )
1262 :     //cs_user_spawn( id )
1263 :     climb_user_spawn( id )
1264 :     }
1265 :     return PLUGIN_HANDLED
1266 :     }
1267 :    
1268 :     public tp_start_btn( id )
1269 :     {
1270 :     if ( !is_climber_alive( id ) )
1271 :     {
1272 :     //if( get_user_team ( id ) == 3 ) cs_set_user_team( id, 2 )
1273 :     //cs_user_spawn( id )
1274 :     climb_user_spawn( id )
1275 :     }
1276 :     if( teleport( id, start_tp_orig ) ) return
1277 :     clmsg( id, "This map doesn't have a start button." )
1278 :     }
1279 :    
1280 :     stock climb_user_spawn( id, give_wpns = 1 )
1281 :     {
1282 :     cs_user_spawn( id )
1283 :    
1284 :     set_pev( id, pev_movetype, MOVETYPE_WALK )
1285 : ian 37 set_pev( id, pev_solid, SOLID_SLIDEBOX )
1286 : ian 1 set_pev( id, pev_effects, 0 )
1287 :     set_pev( id, pev_deadflag, DEAD_NO )
1288 :     set_pev( id, pev_takedamage, DAMAGE_AIM )
1289 :     set_pev( id, pev_health, 100 )
1290 :    
1291 :     cs_set_user_team( id, 2 )
1292 :    
1293 :     if( give_wpns )
1294 :     {
1295 :     give_item( id, "weapon_knife" )
1296 :     give_item( id, "weapon_usp" )
1297 :     }
1298 :     }
1299 :    
1300 :     public ResetHUD( id )
1301 :     {//Spawned
1302 : ian 37 if( !get_pcvar_num( p_climb ) )
1303 : ian 1 {
1304 : ian 38 set_msg_block( SVC_STATUSICON, BLOCK_NOT );
1305 :     set_msg_block( SVC_CLCORPSE, BLOCK_NOT );
1306 :     return;
1307 : ian 37 }
1308 :    
1309 : ian 38 if( is_user_bot( id ) || is_user_hltv( id ) ) return;
1310 : ian 37
1311 : ian 38 flight_icons( id ); //redraw flashlight hud icons
1312 :     set_msg_block( SVC_STATUSICON, BLOCK_SET ); //Block buy menu
1313 :     set_msg_block( SVC_CLCORPSE, BLOCK_SET ); //block client corpses
1314 :    
1315 :     flight_icons( id ); //redraw flashlight hud icons
1316 : ian 37
1317 :     if( is_climber_alive( id ) )
1318 :     {
1319 : ian 38 heal( id );
1320 : ian 37
1321 :     //Execute commands from start/finish config
1322 : ian 38 sfexec( id, 1 );
1323 : ian 37
1324 :     //Show admin as VIP on Scoreboard.
1325 : ian 38 if( get_user_flags( id ) & VIP ) cs_set_user_scoreattrib( id, 4 );
1326 : ian 37
1327 : ian 38 new cppos = timer[id][TMR_CPPOS] * 4;
1328 :    
1329 : ian 37 //If they are paused tp to pause spot and freeze them again.
1330 :     if( timer[id][TMR_CFLAGS] & CF_PAUSE )
1331 :     {
1332 : ian 38 new Float:coords[3];
1333 :     coords[0] = origins[ id ][ ORIG_PAUSX ];
1334 :     coords[1] = origins[ id ][ ORIG_PAUSY ];
1335 :     coords[2] = origins[ id ][ ORIG_PAUSZ ];
1336 :     teleport( id, coords );
1337 :     cl_pause( id );
1338 : ian 1 }
1339 : ian 37 //Teleport to cp, start, or primary spawn position
1340 : ian 38 else if( origins[ id ][ cppos ] || origins[ id ][ cppos+1 ] || origins[ id ][ cppos+2 ] ) gocheck( id );
1341 :     else teleport( id, start_tp_orig );
1342 :     //else if( !teleport( id, start_tp_orig ) ) teleport( id, spawn_tp_orig ); //no need to tp to spawn_tp_orig, they're already there
1343 : ian 1 }
1344 : ian 37 sortcssb( )
1345 : ian 1 }
1346 :    
1347 :     public run_tasks( )
1348 :     {
1349 :     updatebot( )
1350 :     check_cvars( )
1351 :     }
1352 :    
1353 :     public updatebot( )
1354 :     {
1355 : ian 37 if( !get_pcvar_num(p_climb) ) return
1356 :    
1357 :     new id = find_player( "i" )
1358 :     new cl = get_playersnum( )
1359 :     if( cl < MAXPLAYERS - 2 && !id )
1360 : ian 1 {
1361 : ian 37 //Start borrowed code : from Space Headed's AMXX Bot(bot_api.sma) v0.5.1
1362 :     new name[32]
1363 :     format( name, 31, "Climb v%s", VERSION )
1364 :     id = engfunc( EngFunc_CreateFakeClient, name )
1365 :     if( pev_valid( id ) )
1366 : ian 1 {
1367 : ian 37 engfunc( EngFunc_FreeEntPrivateData, id )
1368 :     dllfunc( MetaFunc_CallGameEntity, "player", id )
1369 :     set_user_info( id, "rate", "3500" )
1370 :     set_user_info( id, "cl_updaterate", "25" )
1371 :     set_user_info( id, "cl_lw", "1" )
1372 :     set_user_info( id, "cl_lc", "1" )
1373 :     set_user_info( id, "cl_dlmax", "128" )
1374 :     set_user_info( id, "cl_righthand", "1" )
1375 :     set_user_info( id, "_vgui_menus", "0" )
1376 :     set_user_info( id, "_ah", "0" )
1377 :     set_user_info( id, "dm", "0" )
1378 :     set_user_info( id, "tracker", "0" )
1379 :     set_user_info( id, "friends", "0" )
1380 :     set_user_info( id, "*bot", "1" )
1381 :     set_pev( id, pev_flags, pev( id, pev_flags ) | FL_FAKECLIENT )
1382 :     set_pev( id, pev_colormap, id )
1383 :    
1384 :     new msg[128]
1385 :     dllfunc( DLLFunc_ClientConnect, id, name, "127.0.0.1", msg )
1386 :     dllfunc( DLLFunc_ClientPutInServer, id )
1387 :     engfunc( EngFunc_RunPlayerMove, id, Float:{0.0,0.0,0.0}, 0.0, 0.0, 0.0, 0, 0, 76 )
1388 :     //End borrowed code
1389 :    
1390 :     cs_set_user_team( id, 2 )
1391 :     cs_user_spawn( id )
1392 : ian 1 }
1393 :     }
1394 : ian 37 else if( cl == MAXPLAYERS - 1 && id )
1395 :     {
1396 :     set_entity_visibility( id, 1 )
1397 :     server_cmd( "kick #%d", get_user_userid( id ) )
1398 :     }
1399 :     else if( id )
1400 :     {
1401 :     set_entity_visibility( id, 0 )
1402 :     entity_set_int( id, EV_INT_solid, SOLID_NOT )
1403 :     set_pev( id, pev_takedamage, DAMAGE_NO )
1404 :     entity_set_vector( id, EV_VEC_origin, Float:{999999,999999,999999} )
1405 :     call_think( id )
1406 :     }
1407 : ian 1 }
1408 :    
1409 :     public check_cvars( )
1410 :     {
1411 : ian 38 static bool:nodraw;
1412 : ian 1 if( get_pcvar_num( p_water_nodraw ) && !nodraw )
1413 :     {
1414 : ian 38 new ent = find_ent_by_class( -1, "func_water" );
1415 : ian 1 while( ent > 0 )
1416 :     {
1417 : ian 38 set_entity_visibility( ent, 0 );
1418 :     ent = find_ent_by_class( ent, "func_water" );
1419 : ian 1 }
1420 : ian 38 nodraw = true;
1421 : ian 1 }
1422 :     else if( !get_pcvar_num( p_water_nodraw ) && nodraw )
1423 :     {
1424 : ian 38 new ent = find_ent_by_class( -1, "func_water" );
1425 : ian 1 while( ent > 0 )
1426 :     {
1427 : ian 38 set_entity_visibility( ent, 1 );
1428 :     ent = find_ent_by_class( ent, "func_water" );
1429 : ian 1 }
1430 : ian 38 nodraw = false;
1431 : ian 1 }
1432 :     }
1433 :    
1434 :     //Calculate a timeout, returns time remaining on timeout
1435 :     stock check_timeout( id, &checktime, freq = 1, curtime = -1, nowrite = 0 )
1436 :     {
1437 :     if( curtime < 0 ) curtime = get_systime( )
1438 :    
1439 :     new dif = checktime - curtime
1440 :     if( dif > 3600 ) checktime = curtime + freq
1441 :    
1442 :     if( curtime >= checktime )
1443 :     {
1444 :     if( !nowrite ) checktime = curtime + freq
1445 :     return 0
1446 :     }
1447 :    
1448 :     new msg[76]
1449 :     if( id > 0)
1450 :     {
1451 :     format( msg, 75, "You must wait %d more seconds to use this command again.", dif )
1452 :     clmsg( id, msg )
1453 :     }
1454 :    
1455 :     return dif
1456 :     }
1457 :    
1458 : ian 37 public boost_enabled( id, boost_type, silent )
1459 :     {
1460 :     if( get_pcvar_num( p_boost ) & boost_type ) return true;
1461 :     if( !silent ) clmsg( id, "That boost type has been disabled by the server admin." );
1462 :     return false;
1463 :     }
1464 :    
1465 : ian 23 stock change_boost( id, newboost, silent = 0 )
1466 : ian 1 {//Change Boost flags
1467 : ian 40 //if( !( cvar_enabled( id, p_boost, silent ) && isalive( id ) ) && notpaused( id ) ) return;
1468 :     if( !isalive( id ) || !notpaused( id ) ) return;
1469 : ian 1
1470 : ian 40 new msg[151], rmflag, cflags = timer[ id ][ TMR_CFLAGS ];
1471 : ian 1 if( cflags & CF_SOLID )
1472 :     {
1473 : ian 40 if( task_exists( 150 + id ) ) remove_task( 150 + id );
1474 :     rmflag = CF_SOLID;
1475 :     msg = "Solid Boost Disabled.^n";
1476 : ian 1 }
1477 :     else if( cflags & CF_SUPER_JUMP )
1478 :     {
1479 : ian 40 rmflag = CF_SUPER_JUMP;
1480 :     msg = "Super Jump Disabled.^n";
1481 : ian 1 }
1482 :     else if( cflags & CF_DOUBLE_JUMP)
1483 :     {
1484 : ian 40 rmflag = CF_DOUBLE_JUMP;
1485 :     msg = "Double Jump Disabled.^n";
1486 : ian 1 }
1487 : ian 40 if( rmflag > 0 ) timer[ id ][ TMR_CFLAGS ] -= rmflag;
1488 :     if( !( rmflag & newboost ) &&
1489 : ian 23 !check_timeout( id, time_stamps[id][TS_BOOST], BOOST_TIMEOUT, ( cflags & CF_START ? timer[id][TMR_CNTTME] / 10 : get_systime() ) ) )
1490 : ian 1 {
1491 : ian 37 if( newboost == CF_SOLID && boost_enabled( id, SOLID, silent ) )
1492 : ian 1 {
1493 : ian 40 format( msg, 150, "%sSolid Boost Enabled.", msg );
1494 :     new ida[1];
1495 :     ida[0] = id;
1496 :     set_task( 15.0, "solid_boost_timer", 150 + id, ida, 1 );
1497 :     if( timer[ id ][ TMR_CFLAGS ] & CF_START ) timer[ id ][ TMR_CNTBST ]++;
1498 : ian 1 }
1499 : ian 40 else if( newboost == CF_SUPER_JUMP && boost_enabled( id, SJUMP, silent ) )
1500 :     format( msg, 150, "%sSuper Jump Enabled.", msg );
1501 :     else if( newboost == CF_DOUBLE_JUMP && boost_enabled( id, DJUMP, silent ) )
1502 :     format( msg, 150, "%sDouble Jump Enabled.", msg );
1503 :     else return;
1504 :     timer[ id ][ TMR_CFLAGS ] += newboost;
1505 : ian 1 }
1506 : ian 40 clmsg( id, msg );
1507 : ian 1 }
1508 :    
1509 :     //Task to auto disable solid boost after timeout
1510 :     public solid_boost_timer( ida[] )
1511 :     change_boost( ida[0], CF_SOLID )
1512 :    
1513 : ian 37 //Semi-clip
1514 :     public server_frame( )
1515 :     {
1516 :     if( !get_pcvar_num( p_climb ) ) return FMRES_IGNORED
1517 :    
1518 :     new players[32], num, i, j, Float:c1[3], Float:c2[3];
1519 :     new Float:c1z[3], Float:c2z[3];
1520 :     new id_i, id_j, cflags_i, cflags_j;
1521 :     get_players( players, num, "ach" );
1522 :    
1523 :     //new Float:c1d[3],Float:c2d[3],xyadd,zadd
1524 :     for( i = 0; i < num; i++ )
1525 : ian 1 {
1526 : ian 37 id_i = players[ i ];
1527 :     cflags_i = timer[id_i][TMR_CFLAGS];
1528 :     if( !( cflags_i & CF_PAUSE ) )
1529 : ian 1 {
1530 : ian 37 //Auto Semiclip
1531 :     entity_get_vector( id_i, EV_VEC_origin, c1 );
1532 : ian 1
1533 : ian 37 c1z[2] = c1[2];
1534 :     c1[2] = 0.0;
1535 :     for( j = 0; j < num; j++ )
1536 :     {
1537 :     id_j = players[j];
1538 :     cflags_j = timer[id_j][TMR_CFLAGS];
1539 :     if( !( cflags_j & CF_SOLID ) && i != j )
1540 : ian 1 {
1541 : ian 37 entity_get_vector( id_j, EV_VEC_origin, c2 );
1542 :    
1543 :     c2z[2] = c2[2];
1544 :     c2[2] = 0.0;
1545 :     if( vector_distance( c1, c2 ) < 90 && vector_distance( c1z, c2z ) < 110)
1546 : ian 1 {
1547 : ian 37 if( !(cflags_i & CF_SOLID && cflags_j & CF_SOLID ) )
1548 : ian 1 {
1549 : ian 37 set_solid( id_i, 0 );
1550 :     set_solid( id_j, 0 );
1551 :     j = num;
1552 : ian 1 }
1553 :     }
1554 :     }
1555 : ian 37 if( j + 1 == num ) set_solid( id_i );
1556 : ian 1 }
1557 : ian 37
1558 :    
1559 :     //Semiclip touch detection
1560 :     if( pev( id_i, pev_solid ) == SOLID_NOT )
1561 :     {
1562 :     new class[9], ptr, Float:v_orig[3];
1563 :     pev( id_i, pev_origin, v_orig );
1564 :     //v_orig[2] -= 18;
1565 :     v_orig[2] -= 10;
1566 :    
1567 :     new ent = engfunc( EngFunc_FindEntityInSphere, MAXPLAYERS, v_orig, 16.0 );
1568 :     while( ent > MAXPLAYERS )
1569 :     {
1570 :     pev( ent, pev_classname, ptr, class, 8 );
1571 :     //trigger_teleport, trigger_once, trigger_multiple, trigger_gravity, trigger_push, trigger_hurt, func_door
1572 :     //if( equal( class, "trigger_", 8 ) || equal( class, "func_", 5 ) && !equal( class, "func_water" ) )
1573 :     if( equal( class, "trigger_teleport" ) || equal( class, "trigger_hurt" ) ||
1574 :     equal( class, "trigger_once" ) || equal( class, "trigger_multiple" ) ||
1575 :     equal( class, "trigger_gravity" ) || equal( class, "trigger_push" ) ||
1576 :     equal( class, "func_door" ) )
1577 :     {
1578 :     dllfunc( DLLFunc_Touch, ent, id_i );
1579 :     //break;
1580 : ian 1 }
1581 : ian 37 ent = engfunc( EngFunc_FindEntityInSphere, ent, v_orig, 16.0 );
1582 : ian 1 }
1583 : ian 37
1584 : ian 1 }
1585 :     }
1586 :     }
1587 : ian 37
1588 :     return FMRES_IGNORED
1589 : ian 1 }
1590 :    
1591 :     stock bool:is_between_f( Float:mid, Float:a, Float:b )
1592 :     {
1593 :     if( a < b && ( a < mid < b ) ) return true
1594 :     if( a > b && ( a > mid > b ) ) return true
1595 :     return false
1596 :     }
1597 :    
1598 :     stock Float:vector_z_distance_f( Float:vec1[3], Float:vec2[3] )
1599 :     {
1600 :     return Float:floatsqroot( ( vec1[2] - vec2[2] ) ^ 2.0 )
1601 :     }
1602 :    
1603 :     stock Float:vector_xy_distance_f( Float:vec1[3], Float:vec2[3] )
1604 :     {
1605 :     return Float:floatsqroot( ( ( vec1[0] - vec2[0] ) ^ 2.0 ) + ( ( vec1[1] - vec2[1] ) ^ 2.0 ) )
1606 :     }
1607 :    
1608 :     public client_PreThink( id )
1609 :     {
1610 :     if( !get_pcvar_num( p_climb ) || is_user_bot( id ) || !is_climber_alive( id ) )
1611 :     return PLUGIN_CONTINUE
1612 :    
1613 : ian 37 /*
1614 :     //Auto Semiclip
1615 :     new Float:vOrig[3], ent, count, Float:range
1616 : ian 1
1617 : ian 37 range = pev( id, pev_speed ) * 0.5 + 50.0
1618 :    
1619 :     pev( id, pev_origin, vOrig )
1620 :    
1621 :     //if( !( timer[ id ][ TMR_CFLAGS ] & CF_SOLID ) )
1622 :     //{
1623 :     ent = engfunc( EngFunc_FindEntityInSphere, -1, vOrig, range )
1624 :     while( ent <= MAXPLAYERS )
1625 :     {
1626 :     if( ent != id )
1627 :     {
1628 :     set_solid( ent, 0 )
1629 :     count++
1630 :     }
1631 :     ent = engfunc( EngFunc_FindEntityInSphere, ent, vOrig, range )
1632 :     }
1633 :     //}
1634 :     if( count ) set_solid( id, 0 )
1635 :     else set_solid( id )
1636 :    
1637 :    
1638 :     //Semiclip touch detection
1639 :     if( pev( id, pev_solid ) == SOLID_NOT )
1640 :     {
1641 :     new class[9], ptr
1642 :     //pev( id, pev_origin, vOrig )
1643 :    
1644 :     new ent = engfunc( EngFunc_FindEntityInSphere, MAXPLAYERS, vOrig, 17.0 )
1645 :     while( ent > 0 )
1646 :     {
1647 :     pev( ent, pev_classname, ptr, class, 8 )
1648 :     if( equal( class, "trigger_", 8 ) || equal( class, "func_", 5 ) )
1649 :     dllfunc( DLLFunc_Touch, ent, id )
1650 :     ent = engfunc( EngFunc_FindEntityInSphere, ent, vOrig, 17.0 )
1651 :     }
1652 :    
1653 :     }
1654 :     */
1655 :    
1656 : ian 1 //Detect button use. Replicated from HL SDK
1657 :     if( get_user_button( id ) & IN_USE && !( get_user_oldbutton( id ) & IN_USE ) )
1658 :     {
1659 :     new entlist[3], count
1660 :     count = find_sphere_class( id, "func_button", 64.0, entlist, 3 )
1661 :     if( count )
1662 :     {
1663 :     new Float:orig[3]
1664 :     for( new i = 0; i < count; i++ )
1665 :     {
1666 :     get_brush_entity_origin( entlist[i], orig )
1667 :     if( is_in_viewcone( id, orig ) ) button_used( id, entlist[i] )
1668 : ian 37 }
1669 : ian 1 }
1670 :     }
1671 :    
1672 : ian 19 new cflags = timer[id][TMR_CFLAGS]
1673 : ian 1
1674 :     //Double and super jump boosts
1675 :     if( get_pcvar_num( p_boost ) )
1676 :     {
1677 :     new bool:onground = false
1678 :     if( get_entity_flags( id ) & FL_ONGROUND ) onground = true
1679 :     if( get_user_button( id ) & IN_JUMP )
1680 :     {
1681 :     if( cflags & CF_SUPER_JUMP && onground )
1682 :     {
1683 : ian 19 entity_get_vector( id, EV_VEC_velocity, post_think_vel[id] )
1684 :     if( post_think_vel[id][0] != 0.0 || post_think_vel[id][1] != 0.0)
1685 : ian 1 {
1686 : ian 19 velocity_by_aim( id, 400, post_think_vel[id] )
1687 :     if( post_think_vel[id][2] < 250.0) post_think_vel[id][2] = 250.0
1688 :     if( post_think_vel[id][2] > 350.0) post_think_vel[id][2] = 350.0
1689 : ian 1 }
1690 : ian 19 else post_think_vel[id] = Float:{0.0,0.0,0.0}
1691 : ian 1 }
1692 :     else if( cflags & CF_DOUBLE_JUMP )
1693 :     {
1694 :     if( !onground && !(get_user_oldbutton( id ) & IN_JUMP ) )
1695 :     {
1696 : ian 19 entity_get_vector( id, EV_VEC_velocity, post_think_vel[id] )
1697 :     float_clamp( post_think_vel[id][0], -150.0, 150.0 )
1698 :     float_clamp( post_think_vel[id][1], -150.0, 150.0 )
1699 :     if( is_finished( id ) || post_think_vel[id][2] > -500 ) post_think_vel[id][2] = 250.0
1700 :     else post_think_vel[id] = Float:{ 0.0, 0.0, 0.0 }
1701 : ian 1 }
1702 :     }
1703 :     }
1704 :     }
1705 :    
1706 :     //Prevent drowning
1707 :     // waterlevel 0 - not in water
1708 :     // waterlevel 1 - feet in water
1709 :     // waterlevel 2 - waist in water
1710 :     // waterlevel 3 - head in water
1711 :     if( pev( id, pev_waterlevel ) == 3 ) set_pev( id, pev_waterlevel, 2 )
1712 :    
1713 :     new button = pev( id, pev_button )
1714 :     new oldbutton = pev( id, pev_oldbuttons )
1715 :    
1716 :     //If measure flag is set, call measure function
1717 :     if( !( oldbutton & IN_ATTACK ) && button & IN_ATTACK )
1718 :     if( cflags & CF_MEASURE ) do_measure( id )
1719 :     else if( cflags & CF_MEASURE2 ) do_measure2( id, 1 )
1720 :    
1721 :     //Knife attack timeout
1722 :     new wpn, clip, ammo
1723 :     wpn = get_user_weapon( id, clip, ammo )
1724 :     if( wpn == CSW_KNIFE )
1725 :     {
1726 :    
1727 :     if( button & IN_ATTACK || button & IN_ATTACK2 )
1728 : ian 19 if( check_timeout( 0, time_stamps[id][TS_KNIFE], KNIFE_TIMEOUT ) )
1729 : ian 1 set_pev( id, pev_button, pev( id, pev_button ) & ~IN_ATTACK_EITHER )
1730 :     }
1731 :     return PLUGIN_CONTINUE
1732 :     }
1733 :    
1734 :     public client_PostThink(id)
1735 :     {
1736 :     if( !( get_pcvar_num(p_climb) && get_pcvar_num(p_boost) && is_climber_alive( id ) ) || is_user_bot(id) )
1737 :     return PLUGIN_CONTINUE
1738 :    
1739 : ian 19 if( _:get_distance( _:post_think_vel[id], { 0, 0, 0 } ) )
1740 : ian 1 {
1741 : ian 19 entity_set_vector( id, EV_VEC_velocity, post_think_vel[id] )
1742 :     post_think_vel[id] = Float:{ 0.0, 0.0, 0.0 }
1743 :     if( timer[id][TMR_CFLAGS] & CF_START )
1744 : ian 1 {
1745 : ian 19 timer[id][TMR_CNTBST]++ //Increment client boost count
1746 : ian 1 change_boost( id, CF_NULL )
1747 :     }
1748 :     else if( !is_finished(id) )change_boost( id, CF_NULL )
1749 :     }
1750 :    
1751 :     //Store pause data
1752 : ian 19 if( !( timer[id][TMR_CFLAGS] & CF_PAUSE ) )
1753 : ian 1 {
1754 :     new Float:coords[3]
1755 :     entity_get_vector( id, EV_VEC_origin, coords )
1756 : ian 37
1757 : ian 38 origins[id][ORIG_PAUSX] = coords[0]
1758 :     origins[id][ORIG_PAUSY] = coords[1]
1759 :     origins[id][ORIG_PAUSZ] = coords[2]
1760 :     origins[id][ORIG_PAUSG] = entity_get_float( id, EV_FL_gravity )
1761 : ian 1 }
1762 :     return PLUGIN_CONTINUE
1763 :     }
1764 :    
1765 :     public button_used( id, button )
1766 :     {
1767 :     new btn_type = 0
1768 :     for( new i = 0; i < ST_BTN_CNT || i < FN_BTN_CNT; i++ )
1769 :     {
1770 :     if( i < ST_BTN_CNT )
1771 :     if( button == ST_BTNS[i] )
1772 :     {
1773 :     btn_type = 1
1774 :     break
1775 :     }
1776 :     if( i < FN_BTN_CNT )
1777 :     if( button == FN_BTNS[i] )
1778 :     {
1779 :     btn_type = 2
1780 :     break
1781 :     }
1782 :     }
1783 :    
1784 : ian 19 //new cflags = timer[id][TMR_CFLAGS]
1785 : ian 1
1786 : ian 38 if( btn_type == 1 && !check_timeout( id, time_stamps[id][TS_SPAWN], SPAWN_TIMEOUT ) )//Start Button
1787 : ian 1 {
1788 :     new Float:orig[3], bool:need_respawn = true //Float:view[3]
1789 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START ) need_respawn = false
1790 : ian 1
1791 : ian 19 for( new i = 0; i < 48; i++ ) origins[id][i] = 0.0 //Erase checkpoints
1792 : ian 1
1793 :     //Set all associated variables
1794 : ian 23 timer[id][TMR_CNTTME] = 0
1795 : ian 19 timer[id][TMR_CNTCPS] = 0
1796 :     timer[id][TMR_CNTGCS] = 0
1797 :     timer[id][TMR_CNTBST] = 0
1798 :     timer[id][TMR_CPPOS] = 0
1799 :     timer[id][TMR_CNTWPN] = 0
1800 :     time_stamps[id][TS_BOOST] = BOOST_TIMEOUT
1801 : ian 23 change_status(id,CF_START)
1802 : ian 1
1803 : ian 19 if( timer[id][TMR_CFLAGS] & CF_COUNTDOWN ) set_countdown_time( id )
1804 : ian 1
1805 :     //Record starting weapon
1806 :     rank_mod_update( id )
1807 :    
1808 :     //Respawn client to clear items.
1809 :     if( need_respawn && get_pcvar_num( p_start_respawn ) )
1810 :     {
1811 :     entity_get_vector( id, EV_VEC_origin, orig )
1812 :     //entity_get_vector( id, EV_VEC_angles, view )
1813 :     cs_user_spawn( id )
1814 :     entity_set_vector( id, EV_VEC_origin, orig )
1815 :     //entity_set_vector( id, EV_VEC_angles, view )
1816 :     delay_duck( id )
1817 : ian 19 //time_stamps[id][TS_SPAWN]=get_systime()
1818 : ian 1 }
1819 :     heal( id )
1820 :     cs_set_user_money( id, get_pcvar_num( p_startmoney ) )
1821 :    
1822 :     //Play random start sound and text messages
1823 :     if( get_pcvar_num( p_sounds ) ) switch( random_num( 0, 2 ) )
1824 :     {
1825 :     case 0:client_cmd( id, "spk barney/beertopside" )
1826 :     case 1:client_cmd( id, "spk scientist/c3a2_sci_portopen" )
1827 :     case 2:client_cmd( id, "spk barney/c1a2_ba_climb" )
1828 :     }
1829 :    
1830 : ian 23 change_boost( id, CF_NULL, SILENT ) //Disable Boosts
1831 : ian 19 //time_stamps[id][TS_BOOST]=0
1832 : ian 1 clmsg(id,"Timer started. Go Go Go!!!")
1833 :     //client_print(id,print_chat,"Timer started. Go Go Go!!!")
1834 :    
1835 :     sfexec( id, 2 ) //Execute commands from start/finish config
1836 :    
1837 :     sortcssb( ) //Update frags to reorder scoreboard
1838 :     }
1839 :     else if( btn_type == 2 )//Finish Button
1840 :     {
1841 : ian 23 if( timer[id][TMR_CFLAGS] & CF_START )
1842 : ian 1 {
1843 : ian 23 new cnttme = timer[id][TMR_CNTTME] / 10
1844 :     new cntbst = timer[id][TMR_CNTBST]
1845 :     new cntcps = timer[id][TMR_CNTCPS]
1846 :     new cntgcs = timer[id][TMR_CNTGCS]
1847 :     new cntwpn = timer[id][TMR_CNTWPN]
1848 :    
1849 : ian 1 //Set client variables
1850 :     change_status( id, CF_STOP )
1851 : ian 19 timer[id][TMR_SESFIN]++
1852 :     timer[id][TMR_MAPFIN]++
1853 : ian 1
1854 :     //Announce to client
1855 :     if( get_pcvar_num( p_sounds ) ) client_cmd( 0, "spk woop" )
1856 :     clmsg( id, "Congratulations 1337 climber." )
1857 :     //client_print(id,print_chat,"Congratulations 1337 climber.")
1858 : ian 23 new name[32], msg[23]
1859 :     formatex( msg, 22, "%s^t%s", getuserstatus( id ), parsetime( timer[id][TMR_CNTTME] ) )
1860 : ian 1 //clmsg(id,msg)
1861 :     //client_print(id,print_chat,msg)
1862 :    
1863 :     new wpn[11]
1864 : ian 23 get_weapon_name( cntwpn, wpn, 10 )
1865 : ian 1
1866 :     //Announce to all
1867 :     get_user_name( id, name, 32 )
1868 : ian 23 client_print( 0, print_chat,
1869 :     "%s^t%s^t(%s/ %d CPS/ %d GCS/ %d Boosts)^tCompleted (%d, %d)",
1870 :     name, msg, wpn, cntcps, cntgcs, cntbst,
1871 :     timer[id][TMR_SESFIN], timer[id][TMR_MAPFIN]
1872 :     )
1873 : ian 1
1874 : ian 23 new cntscore = ( ( ( cntbst > 0 ? 1 : 0 ) * 1000000 ) +
1875 :     ( ( cntcps > 0 ? 1 : 0 ) * 100000 ) +
1876 :     ( cntwpn * 10000 ) +
1877 :     cnttme )
1878 : ian 1
1879 : ian 23 new bstscore = ( ( ( timer[id][TMR_BSTBST] > 0 ? 1 : 0 ) * 1000000 ) +
1880 : ian 19 ( ( timer[id][TMR_BSTCPS] > 0 ? 1 : 0 ) * 100000 ) +
1881 :     ( timer[id][TMR_BSTWPN] * 10000 ) +
1882 : ian 23 timer[id][TMR_BSTTME] / 10 )
1883 : ian 1
1884 : ian 23 if( cntscore < bstscore || bstscore == 0 )
1885 : ian 1 {
1886 : ian 23 timer[id][TMR_BSTTME] = cnttme
1887 :     timer[id][TMR_BSTCPS] = cntcps
1888 :     timer[id][TMR_BSTGCS] = cntgcs
1889 :     timer[id][TMR_BSTBST] = cntbst
1890 :     timer[id][TMR_BSTWPN] = cntwpn
1891 : ian 1 }
1892 :    
1893 :     sfexec( id, 2 )//Execute commands from start/finish config
1894 :    
1895 :     if( CLIMB_SAVE ) db_save( id )
1896 :    
1897 :     sortcssb( ) //Update frags to reorder scoreboard
1898 :     }
1899 : ian 19 else if(timer[id][TMR_CFLAGS]&CF_STOP&&timer[id][TMR_SESFIN]==0){
1900 : ian 1 //change_status(id,CF_FINISH)
1901 : ian 19 timer[id][TMR_SESFIN]++
1902 : ian 1 new msg[100]="Congratulations, you finished! But you didn't start the timer. :("
1903 :     clmsg(id,msg)
1904 :     client_print(id,print_chat,msg)
1905 :     //Execute commands from start/finish config
1906 :     sfexec(id,2)
1907 :     //If stats save enabled warn unregistered clients to register
1908 :     //if(CLIMB_SAVE)regwarn(id)
1909 :     }
1910 :     heal(id)
1911 :     }
1912 :     return PLUGIN_HANDLED
1913 :     }
1914 :    
1915 :     //Execute commands from start/finish config
1916 : ian 37 public sfexec( id, clevent )
1917 :     {
1918 :     new clstat[3], cflags = timer[id][TMR_CFLAGS]
1919 :    
1920 :     if( is_finished( id ) ) clstat="fn"
1921 :     else if( cflags & CF_STOP ) clstat="ns"
1922 :     else if( cflags & CF_START ) clstat="st"
1923 :    
1924 :     new cmdstat[3], cmdevent[2], cmdtype[3], cmd[60], idtype[5], name[24]
1925 :     for( new i = 0; i < sfcount; i++ )
1926 :     {
1927 :     parse( sfactions[i], cmdstat, 2, cmdevent, 1, cmdtype, 2, cmd, 59, idtype, 4 )
1928 :     if( ( equali( cmdstat, clstat ) || equali( cmdstat, "ay" ) ) && str_to_num( cmdevent ) & clevent )
1929 :     {
1930 :     if( equali( cmdtype, "sc" ) )
1931 :     {
1932 :     if( equali( idtype, "uid" ) )
1933 :     format( cmd, 59, cmd, get_user_userid( id ) )
1934 :     else
1935 :     {
1936 :     get_user_name( id, name, 23 )
1937 :     format( name, 23, "^"%s^"", name )
1938 :     format( cmd, 59, cmd, name )
1939 :     client_print( id, print_chat, cmd )
1940 : ian 1 }
1941 : ian 37 server_cmd( cmd )
1942 : ian 1 }
1943 : ian 37 else
1944 :     {
1945 :     client_cmd( id, cmd )
1946 : ian 1 }
1947 :     }
1948 :     }
1949 :     }
1950 :    
1951 :     //Update frags to reorder scoreboard
1952 :     public sortcssb( )
1953 :     {
1954 :     new players[32], num, id
1955 :     get_players_ordered( players, num )
1956 :     for( new i = 0 ; i < num; i++ )
1957 :     {
1958 :     id = players[i]
1959 :     set_user_frags( id, 0 )
1960 :     cs_set_user_deaths( id, i + 1 )
1961 :    
1962 :     message_begin( MSG_ALL, SVC_TEAMINFO )
1963 :     write_byte( id )
1964 :     write_string( "CT" )
1965 :     message_end( )
1966 :     }
1967 :    
1968 :     //Show bot as spectator on scoreboard
1969 :     message_begin( MSG_ALL, SVC_TEAMINFO )
1970 :     write_byte( find_player( "i" ) )
1971 :     write_string( "SPECTATOR" )
1972 :     message_end( )
1973 :     }
1974 :    
1975 :     //Returns array of client id's sorted by climb time
1976 :     public get_players_ordered( players[32], &num )
1977 :     {
1978 :     get_players( players, num, "ch" )
1979 :    
1980 :     new i, id, pdata[32][3] //{ status, score, id }
1981 :     for( i = 0; i < num; i++ )
1982 :     {//Fill player data sorting array
1983 :     id = players[i]
1984 :     pdata[i][2] = id
1985 :    
1986 : ian 19 if( timer[id][TMR_BSTTME] )
1987 : ian 1 {//Has high score
1988 :     pdata[i][0] = 0
1989 : ian 19 pdata[i][1] = ( ( ( timer[id][TMR_BSTBST] > 0 ? 1 : 0 ) * 1000000 ) +
1990 :     ( ( timer[id][TMR_BSTCPS] > 0 ? 1 : 0 ) * 100000 ) +
1991 :     ( timer[id][TMR_BSTWPN] * 10000 ) +
1992 : ian 23 timer[id][TMR_BSTTME] / 10 )
1993 : ian 1 }
1994 : ian 19 else if( timer[id][TMR_CFLAGS] & CF_START || timer[id][TMR_CFLAGS] & CF_PAUSE )
1995 : ian 1 {//Has time but no high score
1996 :     pdata[i][0] = 1
1997 : ian 19 pdata[i][1] = ( ( ( timer[id][TMR_CNTBST] > 0 ? 1 : 0 ) * 1000000 ) +
1998 :     ( ( timer[id][TMR_CNTCPS] > 0 ? 1 : 0 ) * 100000 ) +
1999 :     ( timer[id][TMR_CNTWPN] * 10000 ) +
2000 : ian 23 timer[id][TMR_CNTTME] / 10 )
2001 : ian 1 }
2002 :     else pdata[i][0] = 2 //No time or high score
2003 :     }
2004 :    
2005 :     SortStrings( pdata, num )
2006 :     for( i = 0; i < num; i++ )
2007 :     players[i] = pdata[i][2]
2008 :     }
2009 :    
2010 :     stock sb_add_tabs( str[], size)
2011 :     {
2012 :     new len = strlen( str )// > 7 ? 1 : 2
2013 :     add( str[len], size, "^t")
2014 :     if( len < 8 ) add( str[len+1], size, "^t")
2015 :     }
2016 :    
2017 :     public climbscores( id )
2018 :     {//Show scoreboard
2019 : ian 23 if( !get_pcvar_num( p_climb ) ) return PLUGIN_HANDLED
2020 :    
2021 :     if( get_systime() - ts_score > 2 )
2022 : ian 1 {
2023 : ian 23 new fh = fopen( SCORES_PATH, "w" )
2024 :    
2025 :     //Header-8 cols: #, name, status, time, sct/cp/gc/boost, Best, cp/gc/boost, Completed
2026 :     fprintf( fh, "<link rel=stylesheet href=http://ian.cammarata.us/sb><table><tr><td id=a>" )
2027 :     fprintf( fh, "<pre># Name Status Time Wpn/CP/GC/Bst Best ... Fin</pre>" )
2028 :     fprintf( fh, "</td></tr><tr id=b><td></td></tr><tr><td><pre>" )
2029 :    
2030 :     new line[251], name[NAMELEN+2], players[32], num, tid, written_len
2031 :     new ctime, cwpn, ccp, cgc, cbst
2032 :     new btime, bwpn, bcp, bgc, bbst
2033 :     new ctime_str[20], btime_str[20]
2034 :    
2035 :     get_players_ordered( players, num )
2036 :    
2037 : ian 24 for( new i = 0; i < num; i++ )
2038 : ian 1 {
2039 : ian 23 tid = players[i]
2040 : ian 1
2041 : ian 23 get_user_name( tid, name, NAMELEN)
2042 :     sb_add_tabs( name, NAMELEN+2 )
2043 : ian 1
2044 : ian 23 ctime = timer[tid][TMR_CNTTME]
2045 :     cwpn = timer[tid][TMR_CNTWPN]
2046 :     ccp = timer[tid][TMR_CNTCPS]
2047 :     cgc = timer[tid][TMR_CNTGCS]
2048 :     cbst = timer[tid][TMR_CNTBST]
2049 :     format( ctime_str, 19, "%d/%d/%d/%d", cwpn, ccp, cgc, cbst )
2050 :     sb_add_tabs( ctime_str, 19 )
2051 : ian 1
2052 : ian 23 btime = timer[tid][TMR_BSTTME]
2053 :     bwpn = timer[tid][TMR_BSTWPN]
2054 :     bcp = timer[tid][TMR_BSTCPS]
2055 :     bgc = timer[tid][TMR_BSTGCS]
2056 :     bbst = timer[tid][TMR_BSTBST]
2057 :     format( btime_str, 19, "%d/%d/%d/%d", bwpn, bcp, bgc, bbst )
2058 :     sb_add_tabs( btime_str, 19 )
2059 : ian 1
2060 : ian 23 formatex( line, 250,
2061 :     "%s%d %s%s %s %s%s %s%d%s",
2062 :     i % 2 ? NULLSTR : "<div>",
2063 : ian 32 i + 1, htmlspecialchars( name ),
2064 : ian 23 getuserstatus( tid ),
2065 :     parsetime( ctime ), ctime_str,
2066 :     parsetime( btime ), btime_str,
2067 :     timer[tid][TMR_MAPFIN],
2068 :     i % 2 ? NULLSTR : "</div>" )
2069 :     written_len += strlen( line )
2070 :     //if( limit && written_len > ( 1263 - strlen( cust_msg ) ) ) break
2071 :     if( written_len > 1263 ) break
2072 :     fprintf( fh, line )
2073 : ian 1 }
2074 : ian 23 //1530-150-117=1263
2075 :     new cust_msg[33]
2076 :     get_pcvar_string( p_stats_msg, cust_msg, 32 )
2077 :     if( !strlen( cust_msg ) ) formatex( cust_msg, 32, "Climb %s", VERSION )
2078 :     fprintf( fh, "</pre></td></tr><tr id=d><td></td></tr><tr><td id=e></td></tr><tr>" )
2079 :     fprintf( fh, "<td id=a>%s</td></tr></table>", cust_msg )
2080 :     fclose( fh )
2081 :     ts_score = get_systime()
2082 : ian 1 }
2083 : ian 23
2084 :     show_motd( id, SCORES_PATH, "Current Scores" )
2085 :    
2086 : ian 1 return PLUGIN_HANDLED
2087 :     }
2088 :    
2089 : ian 23 //Convert seconds to time string with zero padded seconds field
2090 :     public parsetime( decisec )
2091 :     {
2092 :     new timestr[11], mins, sec, dec, decstr[3]
2093 :    
2094 :     sec = decisec / 10
2095 :     dec = decisec % 10
2096 :     mins = sec / 60
2097 :     sec = sec % 60
2098 :     if( dec ) formatex( decstr, 2, ".%d", dec )
2099 :     formatex( timestr, 10, "%d:%s%d%s", mins, sec < 10 ? "0" : NULLSTR , sec, decstr )
2100 : ian 1 return timestr
2101 :     }
2102 :    
2103 :     public hudtime( )
2104 :     {//Set clock on HUD to current climb time
2105 :     if( !get_pcvar_num( p_climb ) ) return
2106 :    
2107 :     new id, players[32], num, cltime, cflags
2108 :     get_players( players, num, "ach" )
2109 :     for( new i = 0; i < num; i++ )
2110 :     {
2111 :     id = players[i]
2112 : ian 19 cflags = timer[id][TMR_CFLAGS]
2113 : ian 23 cltime = timer[id][TMR_CNTTME] / 10 + 1
2114 : ian 1 if( cflags & CF_PAUSE )
2115 :     {
2116 :     clmsg( id, "PAUSED - say '/unpause' to resume." )
2117 :     cl_pause( id )
2118 :     }
2119 :    
2120 : ian 23 if( !( cflags & CF_COUNTDOWN ) || ( timer[id][TMR_BSTTME] >= timer[id][TMR_CNTTME] ) )
2121 : ian 1 hudtime_msg( id, cltime )
2122 :     else if( cflags & CF_PAUSE )
2123 : ian 23 hudtime_msg( id, timer[id][TMR_BSTTME] / 10 - cltime + 1 )
2124 : ian 1
2125 : ian 19 for( new j = 1; j <= spec_ids[id][0]; j++ )
2126 :     hudtime_msg( spec_ids[id][j], cltime )
2127 : ian 1 }
2128 :     }
2129 :    
2130 :     public toggle_countdown( id )
2131 :     {
2132 :     //Toggle countdown flag and print message
2133 : ian 19 timer[id][TMR_CFLAGS] ^= CF_COUNTDOWN
2134 :     if( timer[id][TMR_CFLAGS] & CF_COUNTDOWN )
2135 : ian 1 {
2136 :     if( set_countdown_time( id ) )
2137 :     clmsg( id, "Countdown enabled." )
2138 :     }
2139 :     else
2140 :     clmsg( id, "Countdown disabled." )
2141 :     }
2142 :    
2143 :     public bool:set_countdown_time( id )
2144 :     {
2145 : ian 23 new bsttme = timer[id][TMR_BSTTME] / 10
2146 :     if( bsttme > 0 )
2147 : ian 1 {
2148 : ian 19 new cflags = timer[id][TMR_CFLAGS]
2149 : ian 1 if( cflags & CF_START || cflags & CF_PAUSE )
2150 : ian 23 hudtime_msg( id, bsttme - timer[id][TMR_CNTTME] / 10 )
2151 : ian 1 return true
2152 :     }
2153 :     clmsg( id, "Countdown disabled: No high score available." )
2154 : ian 19 timer[id][TMR_CFLAGS] ^= CF_COUNTDOWN
2155 : ian 1 return false
2156 :     }
2157 :    
2158 :     public hudtime_msg( id, cltime )
2159 :     {
2160 :     message_begin( MSG_ONE, SVC_ROUNDTIME, _, id )
2161 :     write_short( cltime )
2162 :     message_end( )
2163 :     }
2164 :    
2165 :     public getuserstatus( id )
2166 :     {//Return string describing user status
2167 : ian 19 new msg[12], cflags = timer[id][TMR_CFLAGS]
2168 : ian 1 msg = "PAUSED"
2169 : ian 19 if( cflags & CF_STOP && timer[id][TMR_SESFIN] > 0 )
2170 : ian 1 msg = "Finished"
2171 :     else if( cflags & CF_STOP )
2172 :     msg = "Not Started"
2173 :     else if( cflags & CF_START )
2174 :     msg = "Climbing"
2175 :     //else if( cflags & CF_PAUSE ) msg = "PAUSED"
2176 :     //return "PAUSED"
2177 :     return msg
2178 :     }
2179 :    
2180 :     stock clmsg( id, msg[] )
2181 :     {//Show Hud Message
2182 : ian 40 //if( !strlen( msg ) ) return PLUGIN_HANDLED;
2183 : ian 1 set_hudmessage( get_pcvar_num( p_msg_r ), get_pcvar_num( p_msg_g ), get_pcvar_num( p_msg_b ),
2184 : ian 40 get_pcvar_float( p_msg_x ), get_pcvar_float( p_msg_y ), 0, 0.0, 5.0, 0.5, 0.5, 4 );
2185 :     show_hudmessage( id, msg );
2186 : ian 1
2187 :     //Show to spectators
2188 : ian 19 for( new i = 1; i <= spec_ids[id][0]; i++ )
2189 : ian 40 show_hudmessage( spec_ids[id][i], msg );
2190 :    
2191 :     return PLUGIN_HANDLED;
2192 : ian 1 }
2193 : ian 37
2194 : ian 1 //Fill spectator data array used for msg replication
2195 : ian 37 public spec_update()
2196 :     {
2197 :     if( !get_pcvar_num( p_climb ) ) return;
2198 :    
2199 :     new players[32], num, id, id2, i;
2200 :     for( i = 1; i < 33; i++ ) spec_ids[i][0] = 0;
2201 :     get_players( players, num, "bch" );
2202 :     for( i = 0; i < num; i++ )
2203 :     {
2204 :     id = players[i];
2205 :     id2 = pev( id, pev_iuser2 );
2206 :     if( id2 )
2207 :     {
2208 :     spec_ids[id2][0]++;
2209 :     spec_ids[id2][ spec_ids[id2][0] ] = id;
2210 : ian 1 }
2211 :     }
2212 :     }
2213 : ian 37
2214 :     //Make client solid or unsolid
2215 :     stock set_solid( id, solid = 1 )
2216 : ian 1 {
2217 : ian 37 static old_fx[33], Float:old_col[33][3], old_render[33], old_amt[33];
2218 :     if( solid && pev( id, pev_solid ) == SOLID_NOT )
2219 :     {
2220 :     set_pev( id, pev_renderfx, old_fx[id] );
2221 :     set_pev( id, pev_rendermode, old_render[id] );
2222 :     set_pev( id, pev_rendercolor, old_col[id] );
2223 :     set_pev( id, pev_renderamt, old_amt[id] );
2224 :    
2225 :     set_pev( id, pev_solid, SOLID_SLIDEBOX );
2226 :     }
2227 :     else if( !solid && pev( id, pev_solid ) == SOLID_SLIDEBOX )
2228 :     {
2229 :     old_fx[id] = pev( id, pev_renderfx );
2230 :     old_render[id] = pev( id, pev_rendermode );
2231 :     pev( id, pev_rendercolor, old_col[id] );
2232 :     old_amt[id] = pev( id, pev_renderamt );
2233 :    
2234 :     set_pev( id, pev_rendercolor, Float:{ 0.0, 0.0, 0.0 } );
2235 :     if( get_pcvar_num(p_render) )
2236 :     {
2237 :     set_pev( id, pev_renderfx, kRenderFxHologram );
2238 :     set_pev( id, pev_rendermode, kRenderTransAdd );
2239 :     set_pev( id, pev_renderamt, float( 0 ) );
2240 :     }
2241 :     else
2242 :     {
2243 :     set_pev( id, pev_renderfx, kRenderFxPulseSlow );
2244 :     set_pev( id, pev_rendermode, kRenderTransTexture );
2245 :     set_pev( id, pev_renderamt, float( 50 ) );
2246 :     }
2247 :    
2248 :     set_pev( id, pev_solid, SOLID_NOT );
2249 :     }
2250 : ian 1 }
2251 : ian 37
2252 : ian 1 ////////////////////////////////////////////////////////////////////////////////
2253 :     // Start: Functions for use in if statements
2254 :     ////////////////////////////////////////////////////////////////////////////////
2255 :     public is_climber_alive( id )
2256 :     {
2257 :     new movetype = pev( id, pev_movetype )
2258 :     if( movetype == MOVETYPE_WALK || movetype == MOVETYPE_FLY )
2259 :     return 1
2260 :     return 0
2261 :     }
2262 :    
2263 :     public playersolid( id )
2264 :     {
2265 : ian 37 if( pev( id, pev_solid ) == SOLID_SLIDEBOX ) return 1
2266 : ian 1 return 0
2267 :     }
2268 :    
2269 :     public isct(id){//Used in IF statements a lot
2270 :     if(get_user_team(id)==2)return 1
2271 :     return 0
2272 :     }
2273 :    
2274 :     public is_finished( id )
2275 :     {
2276 : ian 19 new cflags = timer[id][TMR_CFLAGS]
2277 :     if( cflags & CF_STOP && ( get_user_flags( id ) & VIP || timer[id][TMR_SESFIN] > 0 ) )
2278 : ian 1 return 1
2279 :     return 0
2280 :     }
2281 :    
2282 :     public isalive(id){//Use in IF statements to automatically print error if false
2283 :     if( is_climber_alive( id ) )return 1
2284 :     clmsg(id,"You must be alive to execute this command.")
2285 :     return 0
2286 :     }
2287 :    
2288 :     public notpaused(id){//Use in IF statements to automatically print error if false
2289 : ian 19 if(!(timer[id][TMR_CFLAGS]&CF_PAUSE))return 1
2290 : ian 1 clmsg(id,"You can't execute this command while paused.")
2291 :     return 0
2292 :     }
2293 :    
2294 :     /*public regwarn(id){
2295 : ian 19 if(timer[id][TMR_DBUSER]<1){
2296 : ian 1 saytext(id,id,"^x04You must register/login for your stats to save. Say /climbhelp for more info.")
2297 :     return 1
2298 :     }
2299 :     return 0
2300 :     }*/
2301 :     ////////////////////////////////////////////////////////////////////////////////
2302 :     // End: Functions for use in if statements
2303 :     ////////////////////////////////////////////////////////////////////////////////
2304 :     // Start: Auto Heal functions
2305 :     ////////////////////////////////////////////////////////////////////////////////
2306 : ian 22 public Health( id )
2307 :     {//Called when client takes damage
2308 : ian 1 new ida[1]
2309 : ian 22 ida[0] = id
2310 :     set_task( 0.1, "damage_handle", _, ida, 1 )
2311 : ian 1 }
2312 :    
2313 :     public damage_handle( ida[1] )
2314 :     {//Damage hander, delayed to provide HUD consistency
2315 :     new id = ida[0]
2316 :     if( get_pcvar_num( p_climb )&& is_climber_alive( id ) )
2317 :     {
2318 :     new chp = get_user_health( id )
2319 :     if( chp != hp )
2320 :     {
2321 :     heal( id )
2322 :     /*new wpn, atk = get_user_attacker( id, wpn )
2323 :    
2324 :     //Heal hp immediately
2325 :     if( ( atk == 0 || ( id == atk && wpn == 0) ) && !task_exists( 50 + id ) )
2326 :     heal(id)
2327 :    
2328 :     //Heal delayed
2329 :     else
2330 :     {
2331 :     if( task_exists( 50 + id ) ) remove_task( 50 + id )
2332 :     set_task( 5.0, "task_heal", 50 + id, ida, 1 )
2333 :    
2334 :     //Fix hp display at 0
2335 :     if( chp == 256 ) set_user_health( id, 257 )
2336 :     }*/
2337 :     }
2338 :     else if( task_exists( 50 + id ) ) remove_task( 50 + id )
2339 :     }
2340 :     return PLUGIN_HANDLED
2341 :     }
2342 :    
2343 :     public task_heal(ida[]){//Heal client to predetermined HP required by map
2344 :     heal(ida[0])
2345 :     return PLUGIN_HANDLED
2346 :     }
2347 :    
2348 :     public heal(id){
2349 :     if( is_climber_alive( id ) )
2350 :     {
2351 :     if(is_finished(id))set_user_health(id,511)
2352 :     else if(hp)set_user_health(id,hp)
2353 :     else if(get_user_health(id)>100)set_user_health(id,100)
2354 :     }
2355 :     }
2356 :     ////////////////////////////////////////////////////////////////////////////////
2357 :     // End: Auto Heal functions
2358 :     ////////////////////////////////////////////////////////////////////////////////
2359 : ian 32
2360 : ian 1 public pfn_touch( ent, id )
2361 :     {
2362 :     if( !get_pcvar_num( p_climb ) )
2363 :     return PLUGIN_CONTINUE
2364 :    
2365 :     //Clean up dropped stuff
2366 :     new str[21]
2367 :     entity_get_string( ent, EV_SZ_classname, str, 20 )
2368 :     if( equal( str, "weaponbox" ) || equal( str, "item_thighpack" ) )
2369 :     {
2370 :     remove_entity( ent )
2371 :     return PLUGIN_HANDLED
2372 :     }
2373 :     if( pev_valid( id ) )
2374 :     {
2375 :     entity_get_string( id, EV_SZ_classname, str, 20 )
2376 :     if( equal( str, "weaponbox" ) || equal( str, "item_thighpack" ) )
2377 :     {
2378 :     remove_entity( id )
2379 :     return PLUGIN_HANDLED
2380 :     }
2381 :     }
2382 :     else return PLUGIN_HANDLED
2383 :    
2384 :     return PLUGIN_CONTINUE
2385 :     }
2386 :    
2387 :     //Future use, to block hook, or detect hook cheaters a.k.a. hookers
2388 :     public phook( id )
2389 :     {
2390 :     hooked[id] = 1
2391 :     return PLUGIN_CONTINUE
2392 :     }
2393 :    
2394 :     public mhook( id )
2395 :     {
2396 :     hooked[id] = 0
2397 :     return PLUGIN_CONTINUE
2398 :     }
2399 :    
2400 :     ////////////////////////////////////////////////////////////////////////////////
2401 :     // Start: Flashlight functions
2402 :     ////////////////////////////////////////////////////////////////////////////////
2403 :     public flight_icons( id )
2404 :     {
2405 : ian 19 if( timer[id][TMR_CFLAGS] & CF_LIGHT_ON )
2406 : ian 1 {
2407 :     if( !task_exists( TSK_FLIGHT + id ) )
2408 :     set_task( 0.1, "flight_msg", TSK_FLIGHT + id, _, _, "b" )
2409 :    
2410 :     message_begin( MSG_ONE, SVC_FLASHLIGHT, _, id )
2411 :     write_byte( 1 )
2412 :     write_byte( 100 )
2413 :     message_end( )
2414 :    
2415 :     message_begin( MSG_ONE, SVC_STATUSICON, _, id )
2416 :     write_byte( 1 ) //on
2417 :     write_string( "flash_beam" )
2418 :     write_byte( get_pcvar_num( p_light_r ) ) //r
2419 :     write_byte( get_pcvar_num( p_light_g ) ) //g
2420 :     write_byte( get_pcvar_num( p_light_b ) ) //b
2421 :     message_end( )
2422 :     }
2423 :     else
2424 :     {
2425 :     message_begin( MSG_ONE, SVC_FLASHLIGHT, _, id )
2426 :     write_byte( 0 )
2427 :     write_byte( 100 )
2428 :     message_end( )
2429 :    
2430 :     message_begin( MSG_ONE, SVC_STATUSICON, _, id )
2431 :     write_byte( 0 ) //off
2432 :     write_string( "flash_beam" )
2433 :     message_end( )
2434 :     }
2435 :     }
2436 :     public tog_flight(id){
2437 :     if(!get_pcvar_num(p_climb))return PLUGIN_CONTINUE
2438 : ian 19 if(!(timer[id][TMR_CFLAGS]&CF_LIGHT_ON)){
2439 :     timer[id][TMR_CFLAGS]+=CF_LIGHT_ON
2440 : ian 1 set_task(0.1,"flight_msg",TSK_FLIGHT+id,_,_,"b")
2441 :     }
2442 : ian 19 else timer[id][TMR_CFLAGS]-=CF_LIGHT_ON
2443 : ian 1 flight_icons(id)
2444 :     return PLUGIN_HANDLED
2445 :     }
2446 :    
2447 :     public flight_msg(tskid){
2448 :     if(get_pcvar_num(p_climb)){
2449 :     new orig[3],id=tskid-TSK_FLIGHT
2450 : ian 19 if(!(timer[id][TMR_CFLAGS]&CF_LIGHT_ON))remove_task(tskid)
2451 : ian 1 get_user_origin(id,orig)
2452 :     message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,_,id)
2453 :     write_byte(TE_DLIGHT)
2454 :     write_coord(orig[0])//x
2455 :     write_coord(orig[1])//y
2456 :     write_coord(orig[2])//z
2457 :     write_byte(60)//radius
2458 :     write_byte(get_pcvar_num(p_light_r))//r
2459 :     write_byte(get_pcvar_num(p_light_g))//g
2460 :     write_byte(get_pcvar_num(p_light_b))//b
2461 :     write_byte(4)//life
2462 :     write_byte(2)//decay
2463 :     message_end()
2464 :     }
2465 :     return PLUGIN_HANDLED
2466 :     }
2467 :     ////////////////////////////////////////////////////////////////////////////////
2468 :     // End: Flashlight functions
2469 :     ////////////////////////////////////////////////////////////////////////////////
2470 :     public teleport( id, Float:orig[3] )
2471 :     {//Used to teleport clients, prevents client collisions and getting stuck
2472 :     //Don't tp if vector is all zeros
2473 :     if( !( orig[0] || orig[1] || orig[2] ) ) return 0
2474 :    
2475 :     new Float:c2[3], player, players[32], num
2476 :     get_players( players, num, "ac" )
2477 : ian 37 set_solid( id, 0 );
2478 : ian 1 for( new i = 0; i < num; i++ )
2479 :     {
2480 :     player = players[i]
2481 :     if( id != player )
2482 :     {
2483 :     entity_get_vector( player, EV_VEC_origin, c2 )
2484 : ian 37 if( vector_distance( orig, c2 ) < 90 ) set_solid( player, 0 );
2485 : ian 1 }
2486 :     }
2487 :     entity_set_vector( id, EV_VEC_velocity, Float:{0.0, 0.0, 0.0} )
2488 :     entity_set_vector( id, EV_VEC_origin, orig )
2489 :     delay_duck( id )
2490 :     return 1
2491 :     }
2492 :    
2493 :     public delay_duck(id){//Used by teleport and timer start respawn, prevents getting stuck
2494 :     new ida[1]
2495 :     ida[0]=id
2496 :     set_task(0.01,"force_duck",_,ida,1)
2497 :     set_entity_flags(ida[0],FL_DUCKING,1)
2498 :     }
2499 :    
2500 :     public force_duck(ida[1]){//Task for delay_duck
2501 :     set_entity_flags(ida[0],FL_DUCKING,1)
2502 :     }
2503 :    
2504 : ian 23 //Used in IF statements to automatically print error if false
2505 :     stock cvar_enabled( id, p_cvar, silent = 0 )
2506 :     {
2507 :     if( get_pcvar_num(p_cvar) == 0 )
2508 :     {
2509 :     if( !silent )
2510 :     {
2511 :     clmsg( id, "This command is disabled." )
2512 :     client_print(id,print_chat,"This command has been disabled by the server administrator.")
2513 :     }
2514 : ian 1 return 0
2515 :     }
2516 :     return 1
2517 :     }
2518 :     ////////////////////////////////////////////////////////////////////////////////
2519 :     // Start: Climb command handling functions
2520 :     ////////////////////////////////////////////////////////////////////////////////
2521 :    
2522 :     public sunglasses( id )
2523 :     {
2524 :     //Toggle flag for this measure and print message
2525 : ian 19 timer[id][TMR_CFLAGS] ^= CF_SUNGLASSES
2526 :     if( timer[id][TMR_CFLAGS] & CF_SUNGLASSES )
2527 : ian 1 {
2528 :     message_begin( MSG_ONE, SVC_SCREENFADE, _, id )
2529 :     write_short( 1 ) //total duration
2530 :     write_short( 0 ) //time it stays one color
2531 :     write_short( 5 ) //fade type
2532 :     write_byte( 0 ) //r
2533 :     write_byte( 0 ) //g
2534 :     write_byte( 0 ) //b
2535 :     write_byte( 127 ) //a
2536 :     message_end( )
2537 :     }
2538 :     else
2539 :     {
2540 :     message_begin( MSG_ONE, SVC_SCREENFADE, _, id )
2541 :     write_short( 1 ) //total duration
2542 :     write_short( 0 ) //time it stays one color
2543 :     write_short( 0 ) //fade type
2544 :     write_byte( 0 ) //r
2545 :     write_byte( 0 ) //g
2546 :     write_byte( 0 ) //b
2547 :     write_byte( 127 ) //a
2548 :     message_end( )
2549 :     }
2550 :     }
2551 :    
2552 :     public give_scout( id )
2553 : ian 19 if( !check_timeout( id, time_stamps[id][TS_WPN], WPN_TIMEOUT ) )
2554 : ian 1 give_item( id, "weapon_scout" )
2555 :    
2556 :     public give_usp( id )
2557 : ian 19 if( !check_timeout( id, time_stamps[id][TS_WPN], WPN_TIMEOUT ) )
2558 : ian 1 give_item( id, "weapon_usp" )
2559 :    
2560 :     public give_weapons( id )
2561 : ian 19 if( !check_timeout( id, time_stamps[id][TS_WPN], WPN_TIMEOUT ) )
2562 : ian 1 {
2563 :     give_item( id, "weapon_awp" )
2564 :     give_item( id, "weapon_m249" )
2565 :     give_item( id, "weapon_m4a1" )
2566 :     give_item( id, "weapon_sg552" )
2567 :     give_item( id, "weapon_famas" )
2568 :     give_item( id, "weapon_p90" )
2569 :     give_item( id, "weapon_usp" )
2570 :     give_item( id, "weapon_scout" )
2571 :     }
2572 :    
2573 :    
2574 :     public help_msg(id)
2575 :     {
2576 :     client_print( id, print_chat, "Say /climbhelp to get help with the Climb kz plugin." )
2577 :     return PLUGIN_CONTINUE
2578 :     }
2579 :    
2580 :     public climb_help(id)
2581 :     if( get_pcvar_num( p_climb ) )
2582 :     show_motd( id, "http://ian.cammarata.us/projects/climb/help/2a3/en/commands?agent=hl", "Climb Plugin Help" )
2583 :    
2584 :     public boost_help(id)
2585 :     if( get_pcvar_num( p_climb ) )
2586 :     show_motd( id, "http://ian.cammarata.us/projects/climb/help/2a3/en/boosts?agent=hl", "Climb Plugin Help" )
2587 :    
2588 : ian 37 //Admin command, teleport to client
2589 : ian 1 public goto_player( id )
2590 : ian 37 {
2591 :     if( !is_finished( id ) || !get_pcvar_num( p_climb ) )
2592 :     return
2593 :    
2594 :     new tid, arg[24]
2595 :     read_argv( 1, arg, 23 )
2596 :     tid = cmd_target( tid, arg, 4 )
2597 :     if( tid )
2598 : ian 1 {
2599 : ian 37 new Float:orig[3]
2600 :     entity_get_vector( tid, EV_VEC_origin, orig )
2601 :     teleport( id, orig )
2602 : ian 1 }
2603 :     }
2604 :    
2605 :     public spectate( id )
2606 :     {//Client switch to spectator
2607 :     if( get_pcvar_num( p_climb ) && !is_user_bot( id ) && !is_user_hltv( id ) )
2608 :     {
2609 :     if( !is_climber_alive( id ) )
2610 :     {
2611 :     climb_user_spawn( id )
2612 :    
2613 : ian 37 //already does this in the resethud function
2614 :     /*if( timer[id][TMR_CFLAGS] & CF_PAUSE )
2615 : ian 1 {//If they are paused tp to pause spot and freeze them again.
2616 :     new Float:coords[3]
2617 : ian 37
2618 : ian 38 coords[0] = origins[ id ][ ORIG_PAUSX ]
2619 :     coords[1] = origins[ id ][ ORIG_PAUSY ]
2620 :     coords[2] = origins[ id ][ ORIG_PAUSZ ]
2621 : ian 37
2622 : ian 1 teleport( id, coords )
2623 :     cl_pause( id )
2624 : ian 37 }*/
2625 : ian 1
2626 :     }
2627 :     else if( get_user_flags( id ) & VIP ? 1 : ( cvar_enabled( id, p_allow_spectators ) ) )
2628 :     {
2629 :     set_pev( id, pev_movetype, MOVETYPE_NOCLIP )
2630 :     set_pev( id, pev_solid, SOLID_NOT )
2631 :     set_pev( id, pev_effects, EF_NODRAW )
2632 :     set_pev( id, pev_deadflag, DEAD_DEAD )
2633 :     set_pev( id, pev_takedamage, DAMAGE_NO )
2634 :     set_entity_flags( id, FL_FROZEN, 0 )
2635 :    
2636 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START ) change_status( id, CF_PAUSE )
2637 : ian 1 }
2638 :     return PLUGIN_HANDLED
2639 :     }
2640 :     return PLUGIN_CONTINUE
2641 :     }
2642 :    
2643 :     public tsk_spec_tp_back( ida[4] )
2644 :     {
2645 :     new Float:orig[3]
2646 :     orig[0] = Float:ida[1]
2647 :     orig[1] = Float:ida[2]
2648 :     orig[2] = Float:ida[3]
2649 :     entity_set_vector( ida[0], EV_VEC_origin, orig )
2650 :     }
2651 :    
2652 :     public client_command( id )
2653 :     {//Forward to catch all formats for commands
2654 :     if(!get_pcvar_num(p_climb))
2655 :     return PLUGIN_CONTINUE
2656 :     new cmd[21]
2657 :     read_argv(0,cmd,20)
2658 :    
2659 :     //If say command, trim "say", abort if more than one word
2660 :     if(equal(cmd,"say")||equal(cmd,"say_team")){
2661 :     read_argv(1,cmd,20)
2662 :     trim(cmd)
2663 : ian 37 if( contain( cmd, " " ) > -1 ) return PLUGIN_CONTINUE
2664 : ian 1 }
2665 :    
2666 :     //Remove slashes
2667 :     if( equal(cmd,"/",1) || equal(cmd,"\",1) || equal(cmd,".",1) || equal(cmd,"!",1) )
2668 :     copy(cmd,20,cmd[1])
2669 :    
2670 :     //Make a checkpoint
2671 :     if( equali(cmd,"checkpoint") || equali(cmd,"check") || equali(cmd,"cp") )
2672 :     check(id)
2673 :    
2674 :     //Go to checkpoint
2675 :     else if( equali(cmd,"gocheck") || equali(cmd,"gc") || equali(cmd,"tp") || equali(cmd,"tele") )
2676 :     gocheck(id)
2677 :    
2678 :     //Ungocheck
2679 :     else if( equali(cmd,"ungc") || equali(cmd,"ungocheck") )
2680 :     ungocheck(id)
2681 :    
2682 :     //Boost help page
2683 :     else if( equali(cmd,"boost") )
2684 :     boost_help(id)
2685 :    
2686 :     //Solid Boost
2687 :     else if( equali(cmd,"solid") || equali(cmd,"semiclip") )
2688 :     change_boost(id,CF_SOLID)
2689 :    
2690 :     //Jump Boost
2691 :     else if( equali(cmd,"superjump") || equali(cmd,"sjump") || equali(cmd,"sj") || equali(cmd,"longjump") ||\
2692 :     equali(cmd,"ljump") || equali(cmd,"lj") )
2693 :     change_boost(id,CF_SUPER_JUMP)
2694 :    
2695 :     //Double Jump Boost
2696 :     else if( equali(cmd,"doublejump") || equali(cmd,"djump") || equali(cmd,"dj") )
2697 :     change_boost(id,CF_DOUBLE_JUMP)
2698 :    
2699 :     //Cycle CPs reverse
2700 :     else if( equali(cmd,"cp-") || equali(cmd,"stuck") || equali(cmd,"unstuck") )
2701 :     {
2702 :     cp_back( id )
2703 :     return PLUGIN_CONTINUE
2704 :     }
2705 :    
2706 :     //Cycle CPs forward
2707 :     else if( equali(cmd,"cp+") )
2708 :     {
2709 :     cp_forward( id )
2710 :     return PLUGIN_CONTINUE
2711 :     }
2712 :    
2713 :     //Pause
2714 :     else if( equali(cmd,"pause") || equali(cmd,"unpause") )
2715 :     change_status(id,CF_PAUSE)
2716 :    
2717 :     //Stop
2718 :     else if( equali(cmd,"stop") )
2719 :     stop(id)
2720 :    
2721 :     //Time/Scores
2722 :     else if( equali(cmd,"scoreboard") || equali(cmd,"score") || equali(cmd,"scores") )
2723 :     climbscores(id)
2724 :    
2725 :     //High Scores
2726 :     else if( equali(cmd,"top10") || equali(cmd,"top15") || equali(cmd,"top") || equali(cmd,"highscores") ||\
2727 :     equali(cmd,"best") || equali(cmd,"rank") || equali(cmd,"pro15") || equali(cmd,"nub15") )
2728 :     highscores(id)
2729 :    
2730 :     //Respawn
2731 :     else if( equali( cmd, "respawn" ) || equali( cmd, "spawn" ) )
2732 :     frespawn( id )
2733 :    
2734 :     //TP to start button
2735 :     else if( equali( cmd, "restart" ) || equali( cmd, "start" ) || equali( cmd, "reset" ) )
2736 :     tp_start_btn( id )
2737 :    
2738 :     //Spectate
2739 :     else if( equali(cmd,"spectate") || equali(cmd,"spec") )
2740 :     spectate(id)
2741 :    
2742 :     //Get scout
2743 :     else if( equali( cmd, "scout" ) )
2744 :     give_scout( id )
2745 :    
2746 :     //Get usp
2747 :     else if( equali( cmd, "usp" ) )
2748 :     give_usp( id )
2749 :    
2750 :     else if( equali( cmd, "weapons" ) )
2751 :     {
2752 :     give_weapons( id )
2753 :     return PLUGIN_CONTINUE
2754 :     }
2755 :    
2756 :     else if( equali( cmd, "measure" ) )
2757 :     {
2758 :     toggle_measure( id )
2759 :     return PLUGIN_CONTINUE
2760 :     }
2761 :    
2762 :     else if( equali( cmd, "measure2" ) )
2763 :     {
2764 :     toggle_measure2( id )
2765 :     return PLUGIN_CONTINUE
2766 :     }
2767 :    
2768 :     else if( equali( cmd, "countdown" ) || equali( cmd, "countup" ) )
2769 :     {
2770 :     toggle_countdown( id )
2771 :     return PLUGIN_CONTINUE
2772 :     }
2773 :    
2774 :     else if( equali( cmd, "sunglasses" ) )
2775 :     {
2776 :     sunglasses( id )
2777 :     return PLUGIN_CONTINUE
2778 :     }
2779 :    
2780 :     //Climb Help
2781 :     else if( equali( cmd, "climbhelp" ) || equali( cmd, "kzhelp" ) )
2782 :     climb_help( id )
2783 :    
2784 :     //If none of above conditions met, don't block the command
2785 :     else return PLUGIN_CONTINUE
2786 :     return PLUGIN_HANDLED
2787 :     }
2788 :    
2789 :     ////////////////////////////////////////////////////////////////////////////////
2790 :     // End: Climb command handling functions
2791 :     ////////////////////////////////////////////////////////////////////////////////
2792 :     // Start: Measure functions
2793 :     ////////////////////////////////////////////////////////////////////////////////
2794 :    
2795 :     public toggle_measure( id )
2796 :     {
2797 :     //Remove flag for other measure
2798 : ian 19 new cflags = timer[id][TMR_CFLAGS]
2799 :     if( cflags & CF_MEASURE2 ) timer[id][TMR_CFLAGS] = cflags & ~CF_MEASURE2
2800 : ian 1
2801 :     //Toggle flag for this measure and print message
2802 : ian 19 timer[id][TMR_CFLAGS] ^= CF_MEASURE
2803 : ian 1 if( cflags & CF_MEASURE )
2804 :     clmsg( id, "Measure disabled." )
2805 :     else
2806 :     clmsg( id, "Measure enabled, use attack to measure." )
2807 :     }
2808 :    
2809 :     public do_measure( id )
2810 :     {
2811 :     new Float:orig[3], Float:look[3], Float:end[3], Float:ret[3]
2812 :     new Float:ln_st[3], Float:ln_fn[3]
2813 :    
2814 :     entity_get_vector( id, EV_VEC_origin, orig )
2815 :     entity_get_vector( id, EV_VEC_view_ofs, ret )
2816 :     for( new i = 0; i < 3; i++ ) orig[i] += ret[i]
2817 :    
2818 :     velocity_by_aim( id, 1, ret )
2819 :     for( new i = 0; i < 3; i++ ) end[i] = orig[i] + ( ret[i] * 9999 )
2820 :    
2821 :     trace_line( id, orig, end, ln_st )
2822 :     trace_normal( id, orig, end, look )
2823 :    
2824 :     for( new i = 0; i < 3; i++ ) end[i] = ln_st[i] + ( look[i] * 9999 )
2825 :    
2826 :     trace_line( id, ln_st, end, ln_fn )
2827 :    
2828 :     end[0] = ln_st[0] + ( ret[0] * -9999 )
2829 :     end[1] = ln_st[1] + ( ret[1] * -9999 )
2830 :     end[2] = ln_st[2]
2831 :    
2832 :     trace_line( id, ln_st, end, orig )
2833 :    
2834 :     new msg[101]
2835 :     format( msg, 100, "Distance: red %d / blue %d",
2836 :     floatround( vector_distance( ln_st, ln_fn ), floatround_ceil ),
2837 :     floatround( vector_distance( ln_st, orig ), floatround_ceil ) )
2838 :     clmsg( id, msg )
2839 :     console_print( id, msg )
2840 :    
2841 :     message_begin( MSG_ONE, SVC_TEMPENTITY, _, id )
2842 :     write_byte( TE_BEAMPOINTS )
2843 :     write_coord( floatround( ln_st[0] ) )
2844 :     write_coord( floatround( ln_st[1] ) )
2845 :     write_coord( floatround( ln_st[2] ) )
2846 :     write_coord( floatround( ln_fn[0] ) )
2847 :     write_coord( floatround( ln_fn[1] ) )
2848 :     write_coord( floatround( ln_fn[2] ) )
2849 :     write_short( beam_sprite ) // sprite index
2850 :     write_byte( 0 ) // starting frame
2851 :     write_byte( 10 ) // frame rate in 0.1's
2852 :     write_byte( 100 ) // life in 0.1's
2853 :     write_byte( 10 ) // line width in 0.1's
2854 :     write_byte( 2 ) // noise amplitude in 0.01's
2855 :     write_byte( 255 ) // Red
2856 :     write_byte( 0 ) // Green
2857 :     write_byte( 0 ) // Blue
2858 :     write_byte( 127 ) // brightness
2859 :     write_byte( 50 ) // scroll speed in 0.1's
2860 :     message_end( )
2861 :    
2862 :     message_begin( MSG_ONE, SVC_TEMPENTITY, _, id )
2863 :     write_byte( TE_BEAMPOINTS )
2864 :     write_coord( floatround( ln_st[0] ) )
2865 :     write_coord( floatround( ln_st[1] ) )
2866 :     write_coord( floatround( ln_st[2] ) )
2867 :     write_coord( floatround( orig[0] ) )
2868 :     write_coord( floatround( orig[1] ) )
2869 :     write_coord( floatround( orig[2] ) )
2870 :     write_short( beam_sprite ) // sprite index
2871 :     write_byte( 0 ) // starting frame
2872 :     write_byte( 10 ) // frame rate in 0.1's
2873 :     write_byte( 100 ) // life in 0.1's
2874 :     write_byte( 10 ) // line width in 0.1's
2875 :     write_byte( 2 ) // noise amplitude in 0.01's
2876 :     write_byte( 0 ) // Red
2877 :     write_byte( 0 ) // Green
2878 :     write_byte( 255 ) // Blue
2879 :     write_byte( 127 ) // brightness
2880 :     write_byte( 50 ) // scroll speed in 0.1's
2881 :     message_end( )
2882 :     }
2883 :    
2884 :     public toggle_measure2( id )
2885 :     {
2886 :     //Remove flag for other measure
2887 : ian 19 new cflags = timer[id][TMR_CFLAGS]
2888 :     if( cflags & CF_MEASURE ) timer[id][TMR_CFLAGS] = cflags & ~CF_MEASURE
2889 : ian 1
2890 :     //Toggle flag for this measure and print message
2891 : ian 19 timer[id][TMR_CFLAGS] ^= CF_MEASURE2
2892 : ian 1 if( cflags & CF_MEASURE2 )
2893 :     clmsg( id, "Measure 2 disabled." )
2894 :     else
2895 :     clmsg( id, "Measure 2 enabled, use attack to measure." )
2896 :     }
2897 :    
2898 :     public tsk_do_measure2( tskid )
2899 :     do_measure2( tskid - TSK_MEASURE2 )
2900 :    
2901 :     stock do_measure2( id, set = 0 )
2902 :     {
2903 :     new tskid = TSK_MEASURE2 + id
2904 :    
2905 : ian 19 static Float:ln_st_static[33][3]
2906 : ian 1
2907 :     new Float:orig[3], Float:ret[3], Float:end[3]
2908 :    
2909 :     entity_get_vector( id, EV_VEC_origin, orig )
2910 :     entity_get_vector( id, EV_VEC_view_ofs, ret )
2911 :     for( new i = 0; i < 3; i++ ) orig[i] += ret[i]
2912 :    
2913 :     velocity_by_aim( id, 1, ret )
2914 :    
2915 :     for( new i = 0; i < 3; i++ ) end[i] = orig[i] + ( ret[i] * 9999 )
2916 :     trace_line( id, orig, end, ret )
2917 :    
2918 :     new Float:ln_st[3]
2919 : ian 19 ln_st = ln_st_static[id]
2920 : ian 1
2921 :     //If first iteration, save point to static and return
2922 :     if( !( ln_st[0] || ln_st[0] || ln_st[0] ) )
2923 :     {
2924 : ian 19 ln_st_static[id] = ret
2925 : ian 1 set_task( 0.1, "tsk_do_measure2", tskid, _, _, "b" )
2926 :     return
2927 :     }
2928 :    
2929 :     new Float:ln_fn[3], Float:ln_stmid[3], Float:ln_fnmid[3]
2930 :     ln_fn = ret
2931 :    
2932 :     ln_stmid[0] = ln_st[0]
2933 :     ln_stmid[1] = ln_st[1]
2934 :     ln_stmid[2] = ln_fn[2]
2935 :    
2936 :     ln_fnmid[0] = ln_fn[0]
2937 :     ln_fnmid[1] = ln_st[1]
2938 :     ln_fnmid[2] = ln_fn[2]
2939 :    
2940 :     new msg[101]
2941 :     format( msg, 100, "Distance: r %d / g %d / b %d",
2942 :     floatround( vector_distance( ln_st, ln_stmid ), floatround_ceil ),
2943 :     floatround( vector_distance( ln_stmid, ln_fnmid ), floatround_ceil ),
2944 :     floatround( vector_distance( ln_fnmid, ln_fn ), floatround_ceil ) )
2945 :     clmsg( id, msg )
2946 :    
2947 :     new life = 1, dest = MSG_ONE_UNRELIABLE
2948 :     if( set )
2949 :     {
2950 :     life = 125
2951 :     dest = MSG_ONE
2952 :     console_print( id, msg )
2953 :     }
2954 :    
2955 :     message_begin( dest, SVC_TEMPENTITY, _, id )
2956 :     write_byte( TE_BEAMPOINTS )
2957 :     write_coord( floatround( ln_st[0] ) )
2958 :     write_coord( floatround( ln_st[1] ) )
2959 :     write_coord( floatround( ln_st[2] ) )
2960 :     write_coord( floatround( ln_stmid[0] ) )
2961 :     write_coord( floatround( ln_stmid[1] ) )
2962 :     write_coord( floatround( ln_stmid[2] ) )
2963 :     write_short( beam_sprite ) // sprite index
2964 :     write_byte( 0 ) // starting frame
2965 :     write_byte( 10 ) // frame rate in 0.1's
2966 :     write_byte( life ) // life in 0.1's
2967 :     write_byte( 10 ) // line width in 0.1's
2968 :     write_byte( 2 ) // noise amplitude in 0.01's
2969 :     write_byte( 255 ) // Red
2970 :     write_byte( 0 ) // Green
2971 :     write_byte( 0 ) // Blue
2972 :     write_byte( 127 ) // brightness
2973 :     write_byte( 50 ) // scroll speed in 0.1's
2974 :     message_end( )
2975 :    
2976 :     message_begin( dest, SVC_TEMPENTITY, _, id )
2977 :     write_byte( TE_BEAMPOINTS )
2978 :     write_coord( floatround( ln_stmid[0] ) )
2979 :     write_coord( floatround( ln_stmid[1] ) )
2980 :     write_coord( floatround( ln_stmid[2] ) )
2981 :     write_coord( floatround( ln_fnmid[0] ) )
2982 :     write_coord( floatround( ln_fnmid[1] ) )
2983 :     write_coord( floatround( ln_fnmid[2] ) )
2984 :     write_short( beam_sprite ) // sprite index
2985 :     write_byte( 0 ) // starting frame
2986 :     write_byte( 10 ) // frame rate in 0.1's
2987 :     write_byte( life ) // life in 0.1's
2988 :     write_byte( 10 ) // line width in 0.1's
2989 :     write_byte( 2 ) // noise amplitude in 0.01's
2990 :     write_byte( 0 ) // Red
2991 :     write_byte( 255 ) // Green
2992 :     write_byte( 0 ) // Blue
2993 :     write_byte( 127 ) // brightness
2994 :     write_byte( 50 ) // scroll speed in 0.1's
2995 :     message_end( )
2996 :    
2997 :     message_begin( dest, SVC_TEMPENTITY, _, id )
2998 :     write_byte( TE_BEAMPOINTS )
2999 :     write_coord( floatround( ln_fnmid[0] ) )
3000 :     write_coord( floatround( ln_fnmid[1] ) )
3001 :     write_coord( floatround( ln_fnmid[2] ) )
3002 :     write_coord( floatround( ln_fn[0] ) )
3003 :     write_coord( floatround( ln_fn[1] ) )
3004 :     write_coord( floatround( ln_fn[2] ) )
3005 :     write_short( beam_sprite ) // sprite index
3006 :     write_byte( 0 ) // starting frame
3007 :     write_byte( 10 ) // frame rate in 0.1's
3008 :     write_byte( life ) // life in 0.1's
3009 :     write_byte( 10 ) // line width in 0.1's
3010 :     write_byte( 2 ) // noise amplitude in 0.01's
3011 :     write_byte( 0 ) // Red
3012 :     write_byte( 0 ) // Green
3013 :     write_byte( 255 ) // Blue
3014 :     write_byte( 127 ) // brightness
3015 :     write_byte( 50 ) // scroll speed in 0.1's
3016 :     message_end( )
3017 :    
3018 :     //Remove task if flag has been removed
3019 : ian 19 if( task_exists( tskid ) && !( timer[id][TMR_CFLAGS] & CF_MEASURE2 ) ) remove_task( tskid )
3020 : ian 1
3021 :     //If a second point hasn't been set then end here
3022 :     if( !set ) return
3023 :    
3024 :     //If it gets this far it's the second iteration, /*so disable flag and*/ reset static var
3025 : ian 19 //timer[id][TMR_CFLAGS] ^= CF_MEASURE2
3026 :     ln_st_static[id] = Float:{ 0.0, 0.0, 0.0 }
3027 : ian 1 if( task_exists( tskid ) ) remove_task( tskid )
3028 :     }
3029 :    
3030 :     ////////////////////////////////////////////////////////////////////////////////
3031 :     // End: Measure functions
3032 :     ////////////////////////////////////////////////////////////////////////////////
3033 :     // Start: Blocked/Forwarded default CS commands
3034 :     ////////////////////////////////////////////////////////////////////////////////
3035 :     public client_kill( id )
3036 :     {//Block kill, forward to spectate command
3037 :     if( get_pcvar_num( p_climb ) )
3038 :     {
3039 :     spectate( id )
3040 :     return PLUGIN_HANDLED
3041 :     }
3042 :     return PLUGIN_CONTINUE
3043 :     }
3044 :    
3045 :     public block_cmd(id){//Block some commands if climb enabled
3046 :     if(get_pcvar_num(p_climb))return PLUGIN_HANDLED
3047 :     return PLUGIN_CONTINUE
3048 :     }
3049 :    
3050 :     public block_cmd2(id){//Used to block fullupdate always
3051 :     return PLUGIN_HANDLED
3052 :     }
3053 :    
3054 :     public block_jointeam(id){//Block client trying to switch teams
3055 :     if(get_pcvar_num(p_climb)&&isct(id))return PLUGIN_HANDLED
3056 :     return PLUGIN_CONTINUE
3057 :     }
3058 :    
3059 :     public donothing(){//register_clcmd reference this function, but are picked up by the more flexible code in the client_command forward.
3060 :     return PLUGIN_CONTINUE
3061 :     }
3062 :    
3063 :     public menuteam(id){//Connect choose team menu - force client to select CT
3064 :     if(get_pcvar_num(p_climb))client_cmd(id,"slot2")
3065 :     return PLUGIN_CONTINUE
3066 :     }
3067 :    
3068 :     public menuclass(id){//Force client to choose random model
3069 :     if(get_pcvar_num(p_climb)){
3070 :     client_cmd(id,"slot5")
3071 :     }
3072 :     return PLUGIN_CONTINUE
3073 :     }
3074 :    
3075 :     ////////////////////////////////////////////////////////////////////////////////
3076 :     // End: Blocked/Forwarded default CS commands
3077 :     ////////////////////////////////////////////////////////////////////////////////
3078 :     // Start: Database functions
3079 :     ////////////////////////////////////////////////////////////////////////////////
3080 :     public db_init( )
3081 :     {
3082 :    
3083 :     static host[32], user[32], pass[32], name[32], type[12]
3084 :    
3085 :     get_cvar_string( "climb_db_host", host, 31 )
3086 :     get_cvar_string( "climb_db_user", user, 31 )
3087 :     get_cvar_string( "climb_db_pass", pass, 31 )
3088 :     get_cvar_string( "climb_db_name", name, 31 )
3089 :     get_cvar_string( "climb_db_type", type, 11 )
3090 :     get_cvar_string( "climb_db_prefix", DB_PREFIX, 10 )
3091 :     get_cvar_string( "climb_db_serverid", DB_SERVER_ID, 15 )
3092 :    
3093 :     //SQL_SetAffinity(type)
3094 :     DB_TUPLE=SQL_MakeDbTuple(host,user,pass,name)
3095 :    
3096 :     if( !get_cvar_num( "climb_db_exists" ) )
3097 :     {
3098 :     new autoinc[15]="autoincrement"
3099 :     if(equal(type,"mysql"))autoinc="auto_increment"
3100 :     new query[600]
3101 :    
3102 :     formatex( query, 599,
3103 :     "create table if not exists %splayers (\
3104 :     user_id integer primary key %s,\
3105 :     steam_id char(25) unique,\
3106 :     password char(6),\
3107 :     user_name varchar(20) unique,\
3108 :     alias varchar(32) unique,\
3109 :     email varchar(50) unique,\
3110 :     cflags integer)",
3111 :     DB_PREFIX, autoinc )
3112 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler", query )
3113 :    
3114 :     formatex( query, 599,
3115 :     "create table if not exists %sscores (\
3116 :     score_id integer primary key %s,\
3117 :     score integer,\
3118 :     server_ip char(15),\
3119 :     user_id integer,\
3120 :     map_name varchar(32),\
3121 : ian 23 fin_time float,\
3122 : ian 1 cps integer,\
3123 :     gcs integer,\
3124 :     boosts integer,\
3125 :     wpns integer,\
3126 :     server_time_stamp integer)",
3127 :     DB_PREFIX, autoinc )
3128 :     SQL_ThreadQuery(DB_TUPLE,"db_generic_handler",query)
3129 :    
3130 :     formatex( query, 599, "create index scores_score on %sscores (score)", DB_PREFIX )
3131 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler", query )
3132 :    
3133 :     formatex( query, 599,
3134 :     "create table if not exists %ssessions (\
3135 :     steam_id char(25) primary key,\
3136 :     user_id integer unique)",
3137 :     DB_PREFIX )
3138 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler", query )
3139 :    
3140 :     set_cvar_num( "climb_db_exists", 1 )
3141 :     }
3142 :     }
3143 :    
3144 :     public db_generic_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3145 :     return query_failed( failstate, error, errnum )
3146 :    
3147 :     public auto_login(ida[1])
3148 :     {
3149 :     new id=ida[0]
3150 :    
3151 :     //debug
3152 :     new name[33],sid[33],data[2],query[151]
3153 :     get_user_name( id, name, 32 )
3154 :     get_user_authid( id, sid, 32 )
3155 :     //log_amx( "CLIMB: auto_login( %d ) / %s / %s", id, name, sid )
3156 :    
3157 :     data[0] = id
3158 :     data[1] = 2
3159 :     formatex( query, 150,
3160 :     "select user_id, steam_id, password from %splayers where steam_id=^"%s^"",
3161 :     DB_PREFIX, sid )
3162 :     //formatex( data[2], 24, sid)
3163 :     SQL_ThreadQuery( DB_TUPLE, "login_handler", query, data, 2 )
3164 :    
3165 :     //log_amx( "CLIMB: Login Query for id=%d - ^"%s^";", id, query )
3166 :    
3167 :     //return client_cmd( id, "login" )
3168 :     //return db_login( id )
3169 :     }
3170 :    
3171 :     public db_login( id )
3172 :     {
3173 :     //log_amx( "CLIMB: Function entry - login( %d )", id )
3174 :     if( get_pcvar_num( p_climb ) )
3175 :     {
3176 :     if( CLIMB_SAVE )
3177 :     {
3178 :     //log_amx( "CLIMB: Begin login client id=%d.", id )
3179 : ian 19 //log_amx( "CLIMB: timer[id][TMR_DBUSER]=%d.", timer[id][TMR_DBUSER] )
3180 : ian 1
3181 : ian 19 if( timer[id][TMR_DBUSER] > 0 ) //Already logged in
3182 : ian 1 {
3183 :     client_print( id, print_console, "[Climb] Login Error: You are already logged in." )
3184 :     return PLUGIN_HANDLED
3185 :     }
3186 :     new query[151], data[2] //data[28]
3187 :     data[0] = id
3188 :    
3189 :     /*if( read_argc() > 1 ) //Client is logging in with a user/pass
3190 :     {
3191 :     new user[21], pass[21]
3192 :     read_argv( 1, user, 20 )
3193 :     read_argv( 2, pass, 20 )
3194 :     rotwtf( pass, 6 )
3195 :     data[1] = 1
3196 :     formatex( query, 150,
3197 :     "select user_id, steam_id, from %splayers where user_id=^"%s^" and password=^"%s^";",
3198 :     DB_PREFIX, user, pass )
3199 :     //formatex( data[2], 24, user)
3200 :     SQL_ThreadQuery( DB_TUPLE, "login_handler", query, data, 2 )
3201 :     }
3202 :     else //Client is logging in with SteamID
3203 :     {*/
3204 :     new sid[32]
3205 :     get_user_authid( id, sid, 31 )
3206 :     data[1] = 2
3207 :     formatex( query, 150,
3208 :     "select user_id, steam_id, password from %splayers where steam_id=^"%s^"",
3209 :     DB_PREFIX, sid )
3210 :     //formatex( data[2], 24, sid)
3211 :     SQL_ThreadQuery( DB_TUPLE, "login_handler", query, data, 2 )
3212 :    
3213 :     //log_amx( "CLIMB: Login Query for id=%d - ^"%s^";", id, query )
3214 :     //}
3215 :     }
3216 :     else client_print( id, print_console, "[Climb] Login Error: Can't Login; Stats not enabled." )
3217 :     }
3218 :     return PLUGIN_HANDLED
3219 :     }
3220 :    
3221 :     public login_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3222 :     {
3223 :     new id = data[0]
3224 :     //log_amx( "CLIMB: Function entry - login_handler( %d )", id )
3225 :     //If they've disonnected since the login attempt initiated, abort
3226 :     if( !is_user_connected( id ) ) return log_amx( "CLIMB: Login Error id=%d - Client no longer exists.", id )
3227 :    
3228 :     if( SQL_NumResults( query ) < 1 )
3229 :     {
3230 :     //log_amx( "CLIMB: Login Error id=%d - Not a valid account. 0 result returned", id )
3231 :     return client_print( id, print_console, "[Climb] Login Error: Not a valid account." )
3232 :     }
3233 :    
3234 :     if( !query_failed( failstate, error, errnum) )
3235 :     {
3236 :     //If database steamid doesn't match client steamid, abort
3237 :     new db_sid[32], sid[32]
3238 :     SQL_ReadResult( query, 1, db_sid, 31 )
3239 :     get_user_authid( id, sid, 31 )
3240 :     if( !equal( sid, db_sid ) ) return log_amx( "CLIMB: Login Error id=%d - SteamID mismatch.", id )
3241 :    
3242 :     //Fail if steamid login attempt, and steamid is registered as shared
3243 :     if( data[1] == 2 )
3244 :     {
3245 :     new pass[7]
3246 :     SQL_ReadResult( query, 2, pass, 6 )
3247 :     if( equali( pass, "shared" ) )
3248 :     {
3249 :     //log_amx( "CLIMB: Login Error id=%d - Shared SteamID.", id )
3250 :     return client_print( id, print_console,\
3251 :     "[Climb] Login Error: You are using a shared SteamID. Please login with a username and password." )
3252 :     }
3253 :     }
3254 :    
3255 :     //Everything is ok, add db userid to timer info, display login messages
3256 : ian 19 timer[id][TMR_DBUSER] = SQL_ReadResult( query, 0 )
3257 : ian 1 new msg[100]
3258 :     formatex( msg, 99, "[Climb] Login: Success - Account: %s", sid )
3259 :     //log_amx( "CLIMB: Login Success id=%d", id )
3260 :     client_print(id,print_console,msg )
3261 :     format( msg, 99, "^x04%s", msg )
3262 :     saytext( id, id, msg )
3263 :    
3264 :     //If they just registered and logged in, save score, else load score
3265 : ian 19 if( timer[id][TMR_CFLAGS] & CF_JUST_REGD )
3266 : ian 1 {
3267 :     db_save( id )
3268 : ian 19 timer[id][TMR_CFLAGS] -= CF_JUST_REGD
3269 : ian 1 }
3270 :     else db_load(id)
3271 :     }
3272 :     return PLUGIN_HANDLED
3273 :     }
3274 :    
3275 :     /*public logout(id)
3276 :     {
3277 : ian 19 for(new i=0;i<8;i++)origins[id][i]=0.0
3278 :     for(new i=0;i<11;i++)timer[id][i]=0
3279 : ian 1 }*/
3280 :    
3281 :     public db_load( id )
3282 :     {
3283 :     new query[351], mapname[33], data[1]
3284 :     data[0] = id
3285 :     get_mapname( mapname, 32 )
3286 : ian 32
3287 : ian 1 formatex( query, 350,
3288 : ian 32 "select s.fin_time, s.cps, s.gcs, g.fin_cnt, s.boosts, s.wpns from %sscores s, (select user_id, count(*) fin_cnt from %sscores where map_name = ^"%s^" group by user_id) g where map_name = ^"%s^" and s.user_id = %d and g.user_id = %d order by score",
3289 : ian 19 DB_PREFIX, DB_PREFIX, mapname, mapname, timer[id][TMR_DBUSER], timer[id][TMR_DBUSER] )
3290 : ian 32
3291 : ian 1 SQL_ThreadQuery( DB_TUPLE, "db_load_handler", query, data, 1 )
3292 :     }
3293 :    
3294 :     public db_load_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3295 :     {
3296 :     new id=data[0]
3297 :     if( !query_failed( failstate, error, errnum) )
3298 :     {
3299 :     new msg[100]
3300 :     if(!SQL_NumResults(query))
3301 :     msg="^x04No stats available for this account on the current map."
3302 :     else
3303 :     {
3304 : ian 32 new mapname[33], Float:fTmp
3305 : ian 1 get_mapname(mapname,32)
3306 : ian 32 SQL_ReadResult( query, 0, fTmp )
3307 :     timer[id][TMR_BSTTME] = floatround( fTmp * 10 )
3308 : ian 19 timer[id][TMR_BSTCPS] = SQL_ReadResult( query, 1 )
3309 :     timer[id][TMR_BSTGCS] = SQL_ReadResult( query, 2 )
3310 :     timer[id][TMR_MAPFIN] = SQL_ReadResult( query, 3 )
3311 :     timer[id][TMR_BSTBST] = SQL_ReadResult( query, 4 )
3312 :     timer[id][TMR_BSTWPN] = SQL_ReadResult( query, 5 )
3313 : ian 32 //timer[id][TMR_CFLAGS]+=SQL_ReadResult(query,5)?CF_BSTSCT:0 //Read cflag preferences from db, maybe this should be setinfos instead
3314 : ian 1
3315 :     formatex( msg, 99,
3316 :     "^x04Stats loaded for %s - %s^t(%d/ %d CP/%d GC/%d Boost)^tCompleted %d",
3317 : ian 23 mapname, parsetime( timer[id][TMR_BSTTME] ), timer[id][TMR_BSTWPN], timer[id][TMR_BSTCPS],
3318 : ian 19 timer[id][TMR_BSTGCS], timer[id][TMR_BSTBST], timer[id][TMR_MAPFIN] )
3319 : ian 1 }
3320 :     saytext( id, id, msg )
3321 :     }
3322 :     else client_print( id, print_chat, "[Climb] DB Read Error: Please notify a server admin." )
3323 :     return PLUGIN_HANDLED
3324 :     }
3325 :    
3326 :     public db_save( id )
3327 :     {
3328 : ian 23 new user_id = timer[id][TMR_DBUSER]
3329 :    
3330 :     if( user_id < 1 )
3331 : ian 1 {
3332 :     auto_reg( id )
3333 :     return PLUGIN_HANDLED
3334 :     }
3335 : ian 23
3336 : ian 1 new query[351], name[33], data[2]
3337 :     data[0] = id
3338 :     get_mapname( name, 32 )
3339 :     strtolower( name )
3340 :    
3341 : ian 23 new cntbst = timer[id][TMR_CNTBST]
3342 :     new cntcps = timer[id][TMR_CNTCPS]
3343 :     new cntwpn = timer[id][TMR_CNTWPN]
3344 : ian 1
3345 : ian 23 new score = ( ( ( cntbst > 0 ? 1 : 0 ) * 1000000 ) +
3346 :     ( ( cntcps > 0 ? 1 : 0 ) * 100000 ) +
3347 :     ( cntwpn * 10000 ) +
3348 :     timer[id][TMR_CNTTME] / 10 )
3349 : ian 1
3350 :     formatex( query, 350,
3351 : ian 23 "insert into %sscores (server_ip, user_id, map_name, fin_time, cps, gcs, boosts, wpns, score, server_time_stamp) values (^"%s^", %d, ^"%s^", %f, %d, %d, %d, %d, %d, %d)",\
3352 :     DB_PREFIX, DB_SERVER_ID, user_id, name, timer[id][TMR_CNTTME] * 0.1, cntcps, timer[id][TMR_CNTGCS], cntbst, cntwpn, score, get_systime() )
3353 : ian 1 SQL_ThreadQuery(DB_TUPLE,"db_save_handler",query,data,2)
3354 :    
3355 :     data[1] = 0
3356 :     get_user_name( id, name, 32 )
3357 : ian 23 formatex( query, 350, "update %splayers set alias=^"%s^" where user_id=%d;", DB_PREFIX, name, user_id )
3358 : ian 1 SQL_ThreadQuery( DB_TUPLE, "db_name_update_handler", query, data, 2 )
3359 :     return PLUGIN_HANDLED
3360 :     }
3361 :    
3362 :     public db_save_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3363 :     {
3364 :     if( query_failed( failstate, error, errnum ) )
3365 :     {
3366 :     new id=data[0]
3367 :     client_print(id,print_chat,"[Climb] DB Write Error: Could not update your score. Please notify a server admin.")
3368 :     }
3369 :    
3370 :     return PLUGIN_HANDLED
3371 :     }
3372 :    
3373 :     public db_name_update_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3374 :     {
3375 :     if( query_failed( failstate, error, errnum ) )
3376 :     {
3377 :     new id = data[0]
3378 :    
3379 :     if( data[1] > 9 )
3380 :     client_print(id,print_chat,"[Climb] DB Write Error: Could not update your name. Please notify a server admin.")
3381 :     else
3382 :     {
3383 :     new query[250]
3384 :     new data2[2]
3385 :     data2[0] = id
3386 :     data2[1] = data[1] + 1
3387 :    
3388 :    
3389 :     new name[33]
3390 :     get_user_name( id, name, 29 )
3391 :     format( name, 32, "%s(%d)", name, data2[1] )
3392 :    
3393 :     formatex( query, 249,\
3394 :     "update %splayers set alias=^"%s^" where user_id=%d;",\
3395 : ian 19 DB_PREFIX, name, timer[id][TMR_DBUSER] )
3396 : ian 1 SQL_ThreadQuery(DB_TUPLE,"db_name_update_handler",query,data2,2)
3397 :     }
3398 :     }
3399 :    
3400 :     return PLUGIN_HANDLED
3401 :     }
3402 :    
3403 :     public reg(id)
3404 :     {
3405 :     if(get_pcvar_num(p_climb)){
3406 :     if(CLIMB_SAVE){
3407 :     new query[100],sid[26],name[33],data[43]
3408 :     data[0]=id
3409 :     data[1]=0
3410 :     get_user_authid(id,sid,25)
3411 :     get_user_name(id,name,32)
3412 :     //Register user/pass
3413 :     if(read_argc()>1){
3414 :     if(read_argc()!=3){
3415 :     client_print(id,print_console,"[Climb] Registration Error: Invalid number of arguments")
3416 :     return PLUGIN_HANDLED
3417 :     }
3418 :     new user[21],pass[50]
3419 :     //Read password and check length
3420 :     read_argv(2,pass,20)
3421 :     if(strlen(pass)<10){
3422 :     client_print(id,print_console,"[Climb] Registration Error: Password must be at least 10 characters.")
3423 :     return PLUGIN_HANDLED
3424 :     }
3425 :     //Read user
3426 :     read_argv(1,user,20)
3427 :     //Store user/pass in data array to pass to handler for autologin
3428 :     formatex(data[2],20,user)
3429 :     formatex(data[22],20,pass)
3430 :     //Create password hash
3431 :     rotwtf(pass,6)
3432 :     //Register shared SteamID
3433 :     formatex(query,99,"insert into %splayers (steam_id,password) values (^"%s^",'shared')",DB_PREFIX,sid)
3434 :     SQL_ThreadQuery(DB_TUPLE,"reg_handler",query,data,43)
3435 :     //Register user/pass
3436 :     data[1]=1
3437 :     formatex(query,99,"insert into %splayers (user_name,password,alias) values (^"%s^",^"%s^",^"%s^")",DB_PREFIX,user,pass,name)
3438 :     SQL_ThreadQuery(DB_TUPLE,"reg_handler",query,data,43)
3439 :     }
3440 :     }
3441 :     else client_print(id,print_console,"[Climb] Registration Error: Can't Register; Stats not enabled.")
3442 :     }
3443 :     return PLUGIN_HANDLED
3444 :     }
3445 :    
3446 :     public auto_reg(id)
3447 :     {
3448 :     new query[100],sid[26],name[33],data[43]
3449 :     data[0]=id
3450 :     data[1]=2
3451 :     get_user_authid(id,sid,25)
3452 :     get_user_name(id,name,32)
3453 :     formatex(query,99,"insert into %splayers (steam_id,alias) values (^"%s^",^"%s^")",DB_PREFIX,sid,name)
3454 :     SQL_ThreadQuery(DB_TUPLE,"reg_handler",query,data,43)
3455 :     return PLUGIN_HANDLED
3456 :     }
3457 :    
3458 :     public reg_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3459 :     {
3460 :     new id=data[0]
3461 :     if( !query_failed( failstate, error, errnum) )
3462 :     {
3463 :     new flag=data[1],user[21],pass[21]
3464 :     format(user,20,data[2])
3465 :     format(pass,20,data[22])
3466 :    
3467 :     if(flag==0)client_print(id,print_console,"[Climb] Recorded shared SteamID.")
3468 :     else if(flag==1){
3469 :     client_print(id,print_console,"[Climb] Registration Successful.")
3470 :    
3471 :     new cmd[50]
3472 :     formatex(cmd,49,"login %s %s",user,pass)
3473 :     client_cmd(id,cmd)
3474 :     }
3475 :     else if(flag==2){
3476 : ian 19 timer[id][TMR_CFLAGS]+=CF_JUST_REGD
3477 : ian 1 client_cmd(id,"login")
3478 :     }
3479 :     }
3480 :     else client_print(id,print_chat,"[Climb] DB Registration Error: Please notify a server admin.")
3481 :     return PLUGIN_HANDLED
3482 :     }
3483 :    
3484 :     public highscores(id)
3485 : ian 23 {
3486 : ian 1 if( !CLIMB_SAVE ) return clmsg( id, "Stats not enabled.")
3487 :    
3488 :     new hsurl[150], mapname[33]
3489 :     get_pcvar_string( p_stats_hsurl, hsurl, 149 )
3490 :     get_mapname( mapname, 32 )
3491 :     if( strlen( hsurl ) )
3492 :     {
3493 :     format( hsurl, 149, hsurl, mapname )
3494 :     show_motd( id, hsurl, "High Scores" )
3495 :     return PLUGIN_HANDLED
3496 :     }
3497 :     if( get_systime() - ts_hscore > 10 )
3498 :     {
3499 :     new query[501], data[1]
3500 :     data[0] = id
3501 : ian 41 //old
3502 :     //select distinct p.alias, s.fin_time, s.cps, s.gcs, g.fin_cnt, s.boosts, s.wpns, s.score from climb_scores s join climb_players p on s.user_id = p.user_id join (select user_id, min(score) minscore, count(*) fin_cnt from climb_scores where map_name="clintmo_longjumper" group by user_id, wpns) g on p.user_id=g.user_id where map_name="clintmo_longjumper" and s.score=g.minscore order by s.score limit 20
3503 :     //new
3504 :     //select p.alias, s.fin_time, s.cps, s.gcs, g.fin_cnt, s.boosts, s.wpns, s.score, s.score_id from climb_scores s join climb_players p on s.user_id = p.user_id join (select user_id, min(score) minscore, count(*) fin_cnt, score_id from climb_scores where map_name="clintmo_longjumper" group by user_id, wpns) g on g.score_id=s.score_id order by s.score limit 20
3505 : ian 1 formatex( query, 500,
3506 : ian 41 //"select distinct p.alias, s.fin_time, s.cps, s.gcs, g.fin_cnt, s.boosts, s.wpns, s.score from %sscores s join %splayers p on s.user_id = p.user_id join (select user_id, min(score) minscore, count(*) fin_cnt from %sscores where map_name=^"%s^" group by user_id, wpns) g on p.user_id=g.user_id where map_name=^"%s^" and s.score=g.minscore order by s.score limit 20",
3507 :     //DB_PREFIX, DB_PREFIX, DB_PREFIX, mapname, mapname )
3508 :     "select p.alias, s.fin_time, s.cps, s.gcs, g.fin_cnt, s.boosts, s.wpns, s.score, s.score_id from %sscores s join %splayers p on s.user_id = p.user_id join (select user_id, min(score) minscore, count(*) fin_cnt, score_id from %sscores where map_name=^"%s^" group by user_id, wpns) g on g.score_id=s.score_id order by s.score limit 20",
3509 :     DB_PREFIX, DB_PREFIX, DB_PREFIX, mapname )
3510 : ian 32
3511 : ian 1 SQL_ThreadQuery( DB_TUPLE, "hs_handler", query, data, 1 )
3512 :     ts_hscore = get_systime()
3513 :     }
3514 :     else
3515 :     {
3516 :     if( has_hscores )
3517 :     show_motd( id, HSCORES_PATH, "High Scores" )
3518 :     else
3519 :     {
3520 :     new msg[101]
3521 :     format( msg, 100, "^x04[Climb] No stats available for the current map." )
3522 :     return saytext( id, id, msg )
3523 :     }
3524 :     }
3525 :    
3526 :     return PLUGIN_HANDLED
3527 :     }
3528 :    
3529 :     public hs_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3530 :     {
3531 :     if( !query_failed( failstate, error, errnum) )
3532 :     {
3533 :     new id=data[0],msg[101],num=SQL_NumResults(query)
3534 :     if(!num){
3535 :     format(msg,100,"^x04[Climb] No stats available for the current map.")
3536 :     return saytext(id,id,msg)
3537 :     }
3538 :    
3539 :     has_hscores = true
3540 :    
3541 :     new fh = fopen( HSCORES_PATH, "w" )
3542 :    
3543 :     fprintf( fh, "<link rel=stylesheet href=http://ian.cammarata.us/sb><table><tr><td id=a>" )
3544 :     fprintf( fh, "<pre># Name Time Wpn/CP/GC/Boost Fin</pre>" )
3545 :     fprintf( fh, "</td></tr><tr id=b><td></td></tr><tr><td><pre>" )
3546 :    
3547 :     new name[NAMELEN+2], line[151], written_len, btime_str[20]
3548 :     for( new i = 1; i <= num; i++ )
3549 :     {
3550 :     SQL_ReadResult( query, 0, name, NAMELEN )
3551 :     sb_add_tabs( name, NAMELEN+2 )
3552 :    
3553 :    
3554 : ian 23 format( btime_str, 19, "%d/%d/%d/%d",
3555 :     SQL_ReadResult( query, 6 ),
3556 :     SQL_ReadResult( query, 2 ),
3557 :     SQL_ReadResult( query, 3 ),
3558 :     SQL_ReadResult( query, 5 )
3559 :     )
3560 : ian 1 sb_add_tabs( btime_str, 19 )
3561 :    
3562 : ian 32 new Float:fTmp
3563 :     SQL_ReadResult( query, 1, fTmp )
3564 :    
3565 : ian 1 formatex( line, 150,\
3566 :     "%s%d %s%s %s %d%s",
3567 : ian 22 i % 2 ? NULLSTR : "<div>",
3568 : ian 1 i, htmlspecialchars( name ),
3569 : ian 32 parsetime( floatround( fTmp * 10 ) ),
3570 : ian 1 btime_str,
3571 :     SQL_ReadResult( query, 4 ),
3572 : ian 22 i % 2 ? NULLSTR : "</div>" )
3573 : ian 1 written_len += strlen( line )
3574 :     if( written_len > 1263 ) break
3575 :     fprintf( fh, line )
3576 :     SQL_NextRow( query )
3577 :     }
3578 :    
3579 :     //1530-150-117=1263
3580 :     new cust_msg[33]
3581 :     get_pcvar_string( p_stats_msg, cust_msg, 32 )
3582 :     if( !strlen( cust_msg ) ) formatex( cust_msg, 32, "Climb %s", VERSION )
3583 :     fprintf( fh, "</pre></td></tr><tr id=d><td></td></tr><tr><td id=e></td></tr><tr>" )
3584 :     fprintf( fh, "<td id=a>%s</td></tr></table>", cust_msg )
3585 :     fclose( fh )
3586 :    
3587 :     show_motd( id, HSCORES_PATH, "High Scores" )
3588 :     }
3589 :     return PLUGIN_HANDLED
3590 :     }
3591 :    
3592 :     public climb_dbwho(id,level,cid)
3593 :     {
3594 :     if(cmd_access(id,level,cid,0))
3595 :     {
3596 :     console_print(id,"^n# DB ID (<0=Not in DB), Name")
3597 :    
3598 :     new players[32],count,name[21],id2
3599 :     get_players( players, count, "ch" )
3600 :     for( new i=0; i<count; i++ )
3601 :     {
3602 :     id2=players[i]
3603 :     get_user_name(id2,name,20)
3604 : ian 19 console_print(id,"# %d, %s",timer[id2][TMR_DBUSER],name)
3605 : ian 1 }
3606 :     console_print( id, "%d Players", count )
3607 :     }
3608 :     return PLUGIN_HANDLED
3609 :     }
3610 :    
3611 :     public climb_dbmap( id, level, cid )
3612 :     {
3613 :     if( cmd_access( id, level, cid, 0 ) )
3614 :     {
3615 :     new mapname[33]
3616 :     if( read_argc()>1 )read_argv( 1, mapname, 32 )
3617 :     if( !strlen(mapname) )get_mapname( mapname, 32 )
3618 :    
3619 :     new query[501], data[1]
3620 :     data[0]=id
3621 :    
3622 :     formatex( query, 500,
3623 :     "select distinct p.alias, s.score_id, s.fin_time, s.cps, s.gcs, s.boosts, s.wpns from %sscores s join %splayers p on s.user_id = p.user_id join (select user_id, min(score) minscore, count(*) fin_cnt from %sscores where map_name=^"%s^" group by user_id, wpns) g on p.user_id=g.user_id where map_name=^"%s^" and s.score=g.minscore order by s.score limit 20",
3624 :     DB_PREFIX, DB_PREFIX, DB_PREFIX, mapname, mapname )
3625 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbmap_handler", query, data, 1 )
3626 :     }
3627 :     return PLUGIN_HANDLED
3628 :     }
3629 :    
3630 :     public climb_dbmap_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3631 :     {
3632 :     if( !query_failed( failstate, error, errnum) )
3633 :     {
3634 :     new id=data[0]
3635 :     new count=SQL_NumResults( query )
3636 :     if( count )
3637 :     {
3638 :     new name[21]
3639 :     console_print( id, "^n# Alias, Score ID, Time, cps/gcs/boosts, Scout" )
3640 :     for( new i=0; i<count; i++ )
3641 :     {
3642 :     SQL_ReadResult( query, 0, name, 20 )
3643 :     console_print( id, "# %s, %d, %d, %d/%d/%d, %s",\
3644 :     name,\
3645 :     SQL_ReadResult( query, 1 ),\
3646 :     SQL_ReadResult( query, 2 ),\
3647 :     SQL_ReadResult( query, 3 ),\
3648 :     SQL_ReadResult( query, 4 ),\
3649 :     SQL_ReadResult( query, 5 ),\
3650 :     SQL_ReadResult( query, 6 )?"y":"n")
3651 :     SQL_NextRow( query )
3652 :     }
3653 :     console_print( id, "%d Result(s)", count )
3654 :     }
3655 :     else console_print( id, "Query returned no results." )
3656 :     }
3657 :     return PLUGIN_HANDLED
3658 :     }
3659 :    
3660 :     public climb_dbuser( id, level, cid )
3661 :     {
3662 :     if( cmd_access( id, level, cid, 1 ) )
3663 :     {
3664 :     new db_user_id[10]
3665 :     read_argv( 1, db_user_id, 9 )
3666 :    
3667 :     new query[250], data[1]
3668 :     data[0]=id
3669 :    
3670 :     formatex( query, 249,\
3671 :     "select map_name, score_id, fin_time, cps, gcs, boosts, wpns from %sscores where user_id=%d;",\
3672 :     DB_PREFIX, str_to_num( db_user_id ) )
3673 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbuser_handler", query, data, 1 )
3674 :     }
3675 :     return PLUGIN_HANDLED
3676 :     }
3677 :    
3678 :     public climb_dbuser_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3679 :     {
3680 :     if( !query_failed( failstate, error, errnum ) )
3681 :     {
3682 :     new id=data[0]
3683 :     new count=SQL_NumResults( query )
3684 :     if( count )
3685 :     {
3686 :     new name[21]
3687 :     console_print(id,"^n# Map, Score ID, Time, cps/gcs/boosts, Scout")
3688 :     for( new i=0; i<count; i++ )
3689 :     {
3690 :     SQL_ReadResult( query, 0, name, 20 )
3691 :     console_print( id, "# %s, %d, %d, %d/%d/%d, %s",\
3692 :     name,\
3693 :     SQL_ReadResult(query,1),\
3694 :     SQL_ReadResult(query,2),\
3695 :     SQL_ReadResult(query,3),\
3696 :     SQL_ReadResult(query,4),\
3697 :     SQL_ReadResult(query,5),\
3698 :     SQL_ReadResult(query,6) ? "y" : "n" )
3699 :     SQL_NextRow( query )
3700 :     }
3701 :     console_print( id, "%d Result(s)", count )
3702 :     }
3703 :     else console_print( id, "Query returned no results.")
3704 :     }
3705 :     return PLUGIN_HANDLED
3706 :     }
3707 :    
3708 :     public climb_dbdelete( id, level, cid )
3709 :     {
3710 :     if(cmd_access(id,level,cid,1))
3711 :     {
3712 :     new db_user_id[10]
3713 :     read_argv( 1, db_user_id, 9 )
3714 :    
3715 :     new query[250], data[2], del_id
3716 :     data[1]=del_id=str_to_num( db_user_id )
3717 :     data[0]=id
3718 :    
3719 :     if(db_last_del_id!=del_id)
3720 :     {//First time show data to be deleted and ask if they're sure.
3721 :     formatex( query, 249,\
3722 :     "select p.alias, s.map_name, s.fin_time, s.cps, s.gcs, s.boosts, s.wpns from %sscores s, %splayers p where p.user_id=s.user_id and s.score_id=%d;",\
3723 :     DB_PREFIX, DB_PREFIX, del_id )
3724 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbdelete_verify", query, data, 2 )
3725 :     }
3726 :     else
3727 :     {//Second time execute the delete
3728 :     formatex( query, 249,\
3729 :     "delete from %sscores where score_id=%d;",\
3730 :     DB_PREFIX, del_id )
3731 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbdelete_handler", query, data, 2 )
3732 :     db_last_del_id=0
3733 :     }
3734 :     }
3735 :     return PLUGIN_HANDLED
3736 :     }
3737 :    
3738 :     //For nightly builds
3739 :     public climb_dbrecalc( id, level, cid )
3740 :     {
3741 :     if( cmd_access( id, level, cid, 0 ) )
3742 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler",
3743 :     "update %sscores set score = ( ( (boosts>0) * 1000000 ) + ( (cps>0) * 100000 ) + ( wpns * 10000 ) + fin_time )",
3744 :     DB_PREFIX )
3745 :     return PLUGIN_HANDLED
3746 :     }
3747 :    
3748 :     public climb_dbdelete_verify( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3749 :     {
3750 :     if( !query_failed( failstate, error, errnum ) )
3751 :     {
3752 :     new id=data[0]
3753 :     new del_id=data[1]
3754 :     new count=SQL_NumResults( query )
3755 :     if( count )
3756 :     {
3757 :     new name[21],map[33]
3758 :     console_print( id, "^n# Name, Map, Time, cps/gcs/boosts, Scout" )
3759 :    
3760 :     SQL_ReadResult( query, 0, name, 20 )
3761 :     SQL_ReadResult( query, 1, map, 32 )
3762 :     console_print( id, "# %s, %s, %d, %d/%d/%d, %s",\
3763 :     name,\
3764 :     map,\
3765 :     SQL_ReadResult(query,2),\
3766 :     SQL_ReadResult(query,3),\
3767 :     SQL_ReadResult(query,4),\
3768 :     SQL_ReadResult(query,5),\
3769 :     SQL_ReadResult(query,6) ? "y" : "n" )
3770 :    
3771 :     console_print( id, "%d Result(s)", count )//debug
3772 :     console_print( id, "If you're sure you want to delete this record, execute the command again." )
3773 :     db_last_del_id=del_id
3774 :     }
3775 :     else console_print( id, "No record exists with given DB Score ID." )
3776 :     }
3777 :     return PLUGIN_HANDLED
3778 :     }
3779 :    
3780 :     public climb_dbdelete_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3781 :     {
3782 :     new id=data[0]
3783 :     if( !query_failed( failstate, error, errnum ) )
3784 :     console_print( id, "Record has been deleted." )
3785 :     else console_print( id, "Record could not be deleted." )
3786 :     return PLUGIN_HANDLED
3787 :     }
3788 :    
3789 :     public query_failed( failstate, error[], errnum )
3790 :     {
3791 :     if( failstate == TQUERY_CONNECT_FAILED )
3792 :     {
3793 :     log_amx( "Climb: Couldn't connect to database: %s", error )
3794 :     return 1
3795 :     }
3796 :     else if( failstate == TQUERY_QUERY_FAILED )
3797 :     {
3798 :     log_amx( "Climb: Query failed: %s", error )
3799 :     return 1
3800 :     }
3801 :    
3802 :     if( errnum )
3803 :     {
3804 :     log_amx( "Climb: Query Error: %s", error )
3805 :     return 1
3806 :     }
3807 :    
3808 :     return 0
3809 :     }
3810 :     ////////////////////////////////////////////////////////////////////////////////
3811 :     // End: Database functions
3812 :     ////////////////////////////////////////////////////////////////////////////////
3813 : ian 37 //Simple Password Encryption
3814 :     public rotwtf( string[], out_len )//I should replace this with md5 since it's available now
3815 :     {
3816 :     new len = strlen( string ), str[99], cnt = 0, tok = len - 1
3817 : ian 1 copy( str, out_len, string )
3818 :     for( new index=0; index<11; index++ )
3819 :     {
3820 :     if('a' <= string[index] <= 'z')
3821 :     str[index]=( str[index]-'a'+string[tok]+index )
3822 :     else if('A' <= str[index] <= 'Z')
3823 :     str[index]=( str[index]-'A'+string[tok]+index )
3824 :     else if( '0' <= str[index] <= '9' )
3825 :     str[index]=( str[index]-'0'+string[tok]+index )
3826 :     switch( cnt ){
3827 :     case 0:str[index]=str[index]%26+'a'
3828 :     case 1:str[index]=str[index]%26+'A'
3829 :     case 2:str[index]=str[index]%10+'0'
3830 :     }
3831 :     tok--
3832 :     if( tok<0 )tok=len-1
3833 :     cnt++
3834 :     if( cnt==3 )cnt=0
3835 :     }
3836 :     copy( string, out_len, str )
3837 :     return PLUGIN_HANDLED
3838 :     }
3839 :    
3840 :     public plugin_end()
3841 :     {
3842 :     if( CLIMB_SAVE )SQL_FreeHandle( DB_TUPLE )
3843 :     if( get_pcvar_num( p_auto ) )
3844 :     {
3845 :     set_pcvar_num( p_climb, 0 )
3846 :     set_pcvar_num( p_teambalance, TEAM_BALANCE_OLD )
3847 :     set_pcvar_num( p_limitteams, LIMIT_TEAMS_OLD )
3848 :     }
3849 :     return PLUGIN_CONTINUE
3850 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4