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

Annotation of /climb.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (view) (download)

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

Contact
ViewVC Help
Powered by ViewVC 1.0.4