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

Annotation of /climb.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (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 24 new const VERSION[ ] = "a3.7.3 Nov 18 16:34 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 24 new wpn_name[17]
1252 :     get_weaponname( wpn, wpn_name,16 )
1253 :     new wpn_id = find_ent_by_owner( -1, wpn_name, id )
1254 : ian 22 if( !wpn_id ) return PLUGIN_CONTINUE
1255 :    
1256 :     new clip = get_msg_arg_int( 3 )
1257 :     new maxammo = 2
1258 :    
1259 :     //Force silencer w/o animation
1260 :     if( wpn == CSW_USP || wpn == CSW_M4A1 || wpn == CSW_TMP )
1261 : ian 1 {
1262 : ian 22 if( wpn != CSW_TMP ) cs_set_weapon_silen( wpn_id, 1, 0 )
1263 :     maxammo = 10
1264 : ian 1
1265 : ian 22 //Unlimited ammo for VIPs
1266 :     if( get_user_flags(id) & VIP )
1267 : ian 1 {
1268 : ian 22 cs_set_weapon_ammo( wpn_id, 12 )
1269 :     if( clip != 12 )return PLUGIN_HANDLED
1270 :     set_msg_arg_int( 3, ARG_BYTE, 12 )
1271 :     return PLUGIN_CONTINUE
1272 : ian 1 }
1273 :     }
1274 :    
1275 : ian 22 //Set clip and backpack ammo
1276 :     cs_set_user_bpammo( id, wpn, maxammo - clip )
1277 :     if( clip > maxammo )
1278 :     {
1279 :     set_msg_arg_int( 3, ARG_BYTE, maxammo )
1280 :     cs_set_weapon_ammo( wpn_id, maxammo )
1281 :     }
1282 :    
1283 : ian 1 return PLUGIN_CONTINUE
1284 :     }
1285 :    
1286 :     public rank_mod_update( id )
1287 : ian 22 {
1288 : ian 1 new rank, maxspeed = pev( id, pev_maxspeed )
1289 :     switch( maxspeed )
1290 :     {
1291 :     case 210:
1292 :     rank = 0
1293 :     case 220:
1294 :     rank = 1
1295 :     case 230:
1296 :     rank = 2
1297 :     case 235:
1298 :     rank = 3
1299 :     case 240:
1300 :     rank = 4
1301 :     case 245:
1302 :     rank = 5
1303 :     case 250:
1304 :     rank = 6
1305 :     case 260:
1306 :     rank = 7
1307 :     }
1308 :    
1309 : ian 19 if( rank > timer[id][TMR_CNTWPN] )
1310 :     timer[id][TMR_CNTWPN] = rank
1311 : ian 1
1312 :     new msg[100]
1313 :     format( msg, 99, "Weapon Max Speed: %d^nRank Modifier: %d", maxspeed, rank )
1314 :     clmsg( id, msg )
1315 :     }
1316 :    
1317 :     public get_weapon_name( wpn_rank, ret_name[], len )
1318 :     {
1319 :     new name[21]
1320 :     switch( wpn_rank )
1321 :     {
1322 :     case 0:
1323 :     name = "AWP"
1324 :     case 1:
1325 :     name = "Para"
1326 :     case 2:
1327 :     name = "M4A1"
1328 :     case 3:
1329 :     name = "SG552"
1330 :     case 4:
1331 :     name = "Famas"
1332 :     case 5:
1333 :     name = "P90"
1334 :     case 6:
1335 :     name = "USP"
1336 :     case 7:
1337 :     name = "Scout"
1338 :     }
1339 :     formatex( ret_name, len, name )
1340 :     }
1341 :    
1342 :     public DeathMsg( )
1343 :     {//Respawn client when they die unless switching to spec
1344 :     if( get_pcvar_num( p_climb ) )
1345 :     {
1346 :     new id = read_data(2)
1347 :     set_entity_flags( id, FL_FROZEN, 0 )//Unfreeze in case of switch to spectator.
1348 :     new ida[1]
1349 :     ida[0]=id
1350 :     if(task_exists(100+id))remove_task(100+id)
1351 :     if(isct(id)){
1352 :     set_task(0.2,"respawn_task",100+id,ida,1)
1353 :     }
1354 :     }
1355 :     return PLUGIN_HANDLED
1356 :     }
1357 :    
1358 :     public respawn_task(ida[]){//used by death_msg function
1359 :     new id=ida[0]
1360 :     if( !get_user_team( id ) || is_climber_alive( id ) || !isct( id ) )
1361 :     return PLUGIN_HANDLED
1362 :     //cs_user_spawn(id)
1363 :     climb_user_spawn( id, 0 )
1364 :     return PLUGIN_HANDLED
1365 :     }
1366 :    
1367 :     public frespawn( id )
1368 :     {
1369 :     stop(id)
1370 :     if( is_climber_alive( id ) ) teleport( id, spawn_tp_orig )
1371 : ian 19 else if( !check_timeout( id, time_stamps[id][TS_SPAWN], SPAWN_TIMEOUT ) )
1372 : ian 1 {
1373 :     //if( get_user_team ( id ) == 3 ) cs_set_user_team( id, 2 )
1374 :     //cs_user_spawn( id )
1375 :     climb_user_spawn( id )
1376 :     }
1377 :     return PLUGIN_HANDLED
1378 :     }
1379 :    
1380 :     public tp_start_btn( id )
1381 :     {
1382 :     if ( !is_climber_alive( id ) )
1383 :     {
1384 :     //if( get_user_team ( id ) == 3 ) cs_set_user_team( id, 2 )
1385 :     //cs_user_spawn( id )
1386 :     climb_user_spawn( id )
1387 :     }
1388 :     if( teleport( id, start_tp_orig ) ) return
1389 :     clmsg( id, "This map doesn't have a start button." )
1390 :     }
1391 :    
1392 :     stock climb_user_spawn( id, give_wpns = 1 )
1393 :     {
1394 :     cs_user_spawn( id )
1395 :    
1396 :     set_pev( id, pev_movetype, MOVETYPE_WALK )
1397 :     set_pev( id, pev_solid, SOLID_BBOX )
1398 :     set_pev( id, pev_effects, 0 )
1399 :     set_pev( id, pev_deadflag, DEAD_NO )
1400 :     set_pev( id, pev_takedamage, DAMAGE_AIM )
1401 :     set_pev( id, pev_health, 100 )
1402 :    
1403 :     cs_set_user_team( id, 2 )
1404 :    
1405 :     if( give_wpns )
1406 :     {
1407 :     give_item( id, "weapon_knife" )
1408 :     give_item( id, "weapon_usp" )
1409 :     }
1410 :     }
1411 :    
1412 :     public ResetHUD( id )
1413 :     {//Spawned
1414 :     if( get_pcvar_num( p_climb ) )
1415 :     {
1416 :     if( !is_user_bot( id ) && !is_user_hltv( id ) )
1417 :     {
1418 :     flight_icons( id )//redraw flashlight hud icons
1419 :     set_msg_block( SVC_STATUSICON, 2 )//Block buy menu
1420 :    
1421 :     if( is_climber_alive( id ) )
1422 :     {
1423 :     //set_pev( id, pev_movetype, MOVETYPE_WALK )
1424 :     //cs_set_user_team( id, 2 )
1425 :    
1426 :     heal( id )
1427 :     sfexec( id, 1 )//Execute commands from start/finish config
1428 :     if( get_user_flags( id ) & VIP ) cs_set_user_scoreattrib( id, 4 )//Show admin as VIP on Scoreboard.
1429 :    
1430 : ian 19 if( timer[id][TMR_CFLAGS] & CF_PAUSE )
1431 : ian 1 {//If they are paused tp to pause spot and freeze them again.
1432 :     new Float:coords[3]
1433 :     for( new i=0; i<3; i++ ) coords[i] = origins[ id - 1 ][ ORIG_PAUS + i ]
1434 :     teleport( id, coords )
1435 :     cl_pause( id )
1436 :     }
1437 :    
1438 :     //Teleport to cp, start, or primary spawn position
1439 :     else if( origins[ id - 1 ][ 0 ] || origins[ id - 1][ 1 ] || origins[ id - 1 ][ 2 ]) gocheck( id )
1440 :     else if( !teleport( id, start_tp_orig ) ) teleport( id, spawn_tp_orig )
1441 :     }
1442 :     }
1443 :     sortcssb( )
1444 :     }
1445 :     else set_msg_block( SVC_STATUSICON, 0 )
1446 :     }
1447 :    
1448 :     public run_tasks( )
1449 :     {
1450 :     updatebot( )
1451 :     check_cvars( )
1452 :     }
1453 :    
1454 :     public updatebot( )
1455 :     {
1456 :     if(get_pcvar_num(p_climb))
1457 :     {
1458 :     //new players[32], cl
1459 :     //get_players( players, cl, "ach" )
1460 :     new id = find_player( "i" )
1461 :     //if(0<cl<3&&!id){
1462 :     new cl = get_playersnum( )
1463 :     if( cl < MAXPLAYERS - 2 && !id )
1464 :     {
1465 :     //Start borrowed code : from Space Headed's AMXX Bot(bot_api.sma) v0.5.1
1466 :     new name[32]
1467 :     format( name, 31, "Climb v%s", VERSION )
1468 :     id = engfunc( EngFunc_CreateFakeClient, name )
1469 :     if( pev_valid( id ) )
1470 :     {
1471 :     engfunc( EngFunc_FreeEntPrivateData, id )
1472 :     dllfunc( MetaFunc_CallGameEntity, "player", id )
1473 :     set_user_info( id, "rate", "3500" )
1474 :     set_user_info( id, "cl_updaterate", "25" )
1475 :     set_user_info( id, "cl_lw", "1" )
1476 :     set_user_info( id, "cl_lc", "1" )
1477 :     set_user_info( id, "cl_dlmax", "128" )
1478 :     set_user_info( id, "cl_righthand", "1" )
1479 :     set_user_info( id, "_vgui_menus", "0" )
1480 :     set_user_info( id, "_ah", "0" )
1481 :     set_user_info( id, "dm", "0" )
1482 :     set_user_info( id, "tracker", "0" )
1483 :     set_user_info( id, "friends", "0" )
1484 :     set_user_info( id, "*bot", "1" )
1485 :     set_pev( id, pev_flags, pev( id, pev_flags ) | FL_FAKECLIENT )
1486 :     set_pev( id, pev_colormap, id )
1487 :    
1488 :     new msg[128]
1489 :     dllfunc( DLLFunc_ClientConnect, id, name, "127.0.0.1", msg )
1490 :     dllfunc( DLLFunc_ClientPutInServer, id )
1491 :     engfunc( EngFunc_RunPlayerMove, id, Float:{0.0,0.0,0.0}, 0.0, 0.0, 0.0, 0, 0, 76 )
1492 :     //End borrowed code
1493 :    
1494 :     cs_set_user_team( id, 2 )
1495 :     cs_user_spawn( id )
1496 :     }
1497 :     }
1498 :     //else if(cl>2&&id)server_cmd("kick #%d",get_user_userid(id))
1499 :     else if( cl == MAXPLAYERS - 1 && id )
1500 :     {
1501 :     set_entity_visibility( id, 1 )
1502 :     server_cmd( "kick #%d", get_user_userid( id ) )
1503 :     }
1504 :     else if( is_user_bot( id ) && id )
1505 :     {
1506 :     set_entity_visibility( id, 0 )
1507 :     entity_set_int( id, EV_INT_solid, SOLID_NOT )
1508 :     set_pev( id, pev_takedamage, DAMAGE_NO )
1509 :     entity_set_vector( id, EV_VEC_origin, Float:{999999,999999,999999} )
1510 :     call_think( id )
1511 :     }
1512 :     }
1513 :     }
1514 :    
1515 :     public check_cvars( )
1516 :     {
1517 :     static bool:nodraw
1518 :     if( get_pcvar_num( p_water_nodraw ) && !nodraw )
1519 :     {
1520 :     new ent = find_ent_by_class( -1, "func_water" )
1521 :     while( ent > 0 )
1522 :     {
1523 :     set_entity_visibility( ent, 0 )
1524 :     ent = find_ent_by_class( ent, "func_water" )
1525 :     }
1526 :     nodraw = true
1527 :     }
1528 :     else if( !get_pcvar_num( p_water_nodraw ) && nodraw )
1529 :     {
1530 :     new ent = find_ent_by_class( -1, "func_water" )
1531 :     while( ent > 0 )
1532 :     {
1533 :     set_entity_visibility( ent, 1 )
1534 :     ent = find_ent_by_class( ent, "func_water" )
1535 :     }
1536 :     nodraw = false
1537 :     }
1538 :     }
1539 :    
1540 :     //Calculate a timeout, returns time remaining on timeout
1541 :     stock check_timeout( id, &checktime, freq = 1, curtime = -1, nowrite = 0 )
1542 :     {
1543 :     if( curtime < 0 ) curtime = get_systime( )
1544 :    
1545 :     new dif = checktime - curtime
1546 :     if( dif > 3600 ) checktime = curtime + freq
1547 :    
1548 :     if( curtime >= checktime )
1549 :     {
1550 :     if( !nowrite ) checktime = curtime + freq
1551 :     return 0
1552 :     }
1553 :    
1554 :     new msg[76]
1555 :     if( id > 0)
1556 :     {
1557 :     format( msg, 75, "You must wait %d more seconds to use this command again.", dif )
1558 :     clmsg( id, msg )
1559 :     }
1560 :    
1561 :     return dif
1562 :     }
1563 :    
1564 : ian 23 stock change_boost( id, newboost, silent = 0 )
1565 : ian 1 {//Change Boost flags
1566 : ian 23 if( !( cvar_enabled( id, p_boost, silent ) && isalive( id ) ) && notpaused( id ) ) return PLUGIN_HANDLED
1567 : ian 1
1568 :     new msg[151], rmflag, cflags = timer[ id - 1 ][ TMR_CFLAGS ]
1569 :     if( cflags & CF_SOLID )
1570 :     {
1571 :     if( task_exists( 150 + id ) ) remove_task( 150 + id )
1572 :     rmflag = CF_SOLID
1573 :     msg = "Solid Boost Disabled.^n"
1574 :     }
1575 :     else if( cflags & CF_SUPER_JUMP )
1576 :     {
1577 :     rmflag = CF_SUPER_JUMP
1578 :     msg = "Super Jump Disabled.^n"
1579 :     }
1580 :     else if( cflags & CF_DOUBLE_JUMP)
1581 :     {
1582 :     rmflag = CF_DOUBLE_JUMP
1583 :     msg = "Double Jump Disabled.^n"
1584 :     }
1585 :     if( rmflag > 0 ) timer[ id - 1 ][ TMR_CFLAGS ] -= rmflag
1586 :     if( !( rmflag & newboost ) && \
1587 : ian 23 !check_timeout( id, time_stamps[id][TS_BOOST], BOOST_TIMEOUT, ( cflags & CF_START ? timer[id][TMR_CNTTME] / 10 : get_systime() ) ) )
1588 : ian 1 {
1589 :     if( newboost == CF_SOLID )
1590 :     {
1591 :     format( msg, 150, "%sSolid Boost Enabled.", msg )
1592 :     new ida[1]
1593 :     ida[0] = id
1594 :     set_task( 15.0, "solid_boost_timer", 150 + id, ida, 1 )
1595 :     if( timer[ id - 1 ][ TMR_CFLAGS ] & CF_START ) timer[ id - 1 ][ TMR_CNTBST ]++
1596 :     }
1597 :     if( newboost == CF_SUPER_JUMP ) format( msg, 150, "%sSuper Jump Enabled.", msg )
1598 :     if( newboost == CF_DOUBLE_JUMP ) format( msg, 150, "%sDouble Jump Enabled.", msg )
1599 :     timer[ id - 1 ][ TMR_CFLAGS ] |= newboost
1600 :     }
1601 :     if(strlen(msg))clmsg(id,msg)
1602 :     return PLUGIN_HANDLED
1603 :     }
1604 :    
1605 :     //Task to auto disable solid boost after timeout
1606 :     public solid_boost_timer( ida[] )
1607 :     change_boost( ida[0], CF_SOLID )
1608 :    
1609 :     /*public server_frame( )
1610 :     {//Semi-clip
1611 :     if( get_pcvar_num( p_climb ) )
1612 :     {
1613 :     new players[32], bool:skip[32], num, i, j
1614 :     new Float:orig_i[3], Float:orig_j[3]
1615 :     new Float:vel_i[3], Float:vel_iz[3]
1616 :     new id_i, id_j, cflags_i, cflags_j
1617 :     get_players( players, num, "ac" )
1618 :     for( i = 0; i < num; i++ )
1619 :     {
1620 :     id_i = players[i]
1621 : ian 19 cflags_i = timer[id_i][TMR_CFLAGS]
1622 : ian 1
1623 :     if( !( cflags_i & CF_PAUSE ) )
1624 :     {
1625 :     entity_get_vector( id_i, EV_VEC_origin, orig_i )
1626 :     entity_get_vector( id_i, EV_VEC_velocity, vel_i )
1627 :    
1628 :     vel_iz[0] = vel_i[0] > 0 ? -70.0 : 70.0
1629 :     vel_iz[1] = vel_i[1] > 0 ? -70.0 : 70.0
1630 :     vel_iz[2] = vel_i[2] > 0 ? -120.0 : 120.0
1631 :    
1632 :     if( !vel_i[0] ) vel_i[0] = vel_iz[0] * -1
1633 :     if( !vel_i[1] ) vel_i[1] = vel_iz[1] * -1
1634 :     if( !vel_i[2] ) vel_i[2] = vel_iz[2] * -1
1635 :    
1636 :     for( j=0; j<num; j++ )
1637 :     {
1638 :     if( i != j )
1639 :     {
1640 :     id_j = players[j]
1641 : ian 19 cflags_j = timer[id_j][TMR_CFLAGS]
1642 : ian 1
1643 :     if( ( !( cflags_i & CF_SOLID && cflags_j & CF_SOLID ) || skip[i] ) && !( cflags_j & CF_PAUSE ) )
1644 :     {
1645 :     entity_get_vector( id_j, EV_VEC_origin, orig_j )
1646 :    
1647 :     if( is_between_f( orig_j[0], orig_i[0] + vel_iz[0], orig_i[0] + vel_i[0] ) &&
1648 :     is_between_f( orig_j[1], orig_i[1] + vel_iz[1], orig_i[1] + vel_i[1] ) &&
1649 :     is_between_f( orig_j[2], orig_i[2] + vel_iz[2], orig_i[2] + vel_i[2] ) )
1650 :     {
1651 :     unsolid( id_i )
1652 :     unsolid( id_j )
1653 :     skip[i] = true
1654 :     skip[j] = true
1655 :     //maybe reset j first time i runs this, to unsolid anyone they might be boosting with
1656 :     }
1657 :     }
1658 :     }
1659 :     }
1660 :     if( !skip[i] ) solid( id_i )
1661 :     }
1662 :     }
1663 :     }
1664 :     return PLUGIN_CONTINUE
1665 :     }*/
1666 :     public server_frame( )
1667 :     {
1668 :     if( !get_pcvar_num(p_climb) )
1669 :     return PLUGIN_CONTINUE
1670 :    
1671 :     sc_fcount++
1672 :     if( sc_fcount > 9 ) sc_fcount = 0
1673 :    
1674 :     //Semi-clip
1675 :     new players[32],num,i,j,Float:c1[3],Float:c2[3]
1676 :     new Float:c1z[3],Float:c2z[3]
1677 :     new id_i,id_j,cflags_i,cflags_j
1678 :     get_players(players,num,"ac")
1679 :     //new Float:c1d[3],Float:c2d[3],xyadd,zadd
1680 :     for(i=0;i<num;i++){
1681 :     id_i=players[i]
1682 : ian 19 cflags_i=timer[id_i][TMR_CFLAGS]
1683 : ian 1 if(!(cflags_i&CF_PAUSE)){
1684 :     //solid(players[i])
1685 :     entity_get_vector(id_i,EV_VEC_origin,c1)
1686 :     //entity_get_vector(players[i],EV_VEC_velocity,c1d)
1687 :     c1z[2]=c1[2]
1688 :     c1[2]=0.0
1689 :     for(j=0;j<num;j++){
1690 :     id_j=players[j]
1691 : ian 19 cflags_j=timer[id_j][TMR_CFLAGS]
1692 : ian 1 if(!(cflags_j&CF_SOLID)&&i!=j){
1693 :     entity_get_vector(id_j,EV_VEC_origin,c2)
1694 :     //entity_get_vector(players[j],EV_VEC_velocity,c2d)
1695 :     c2z[2]=c2[2]
1696 :     c2[2]=0.0
1697 :     if(vector_distance(c1,c2)<90&&vector_distance(c1z,c2z)<110){
1698 :     if(!(cflags_i&CF_SOLID&&cflags_j&CF_SOLID)){//&&vector_distance(c1,c2)>25&&vector_distance(c1z,c2z)>30)){
1699 :     unsolid(id_i)
1700 :     unsolid(id_j)
1701 :     j=num
1702 :     }
1703 :     }
1704 :     }
1705 :     if(j+1==num)solid(id_i)
1706 :     }
1707 :     }
1708 :     }
1709 :     return PLUGIN_CONTINUE
1710 :     }
1711 :    
1712 :     stock bool:is_between_f( Float:mid, Float:a, Float:b )
1713 :     {
1714 :     if( a < b && ( a < mid < b ) ) return true
1715 :     if( a > b && ( a > mid > b ) ) return true
1716 :     return false
1717 :     }
1718 :    
1719 :     stock Float:vector_z_distance_f( Float:vec1[3], Float:vec2[3] )
1720 :     {
1721 :     return Float:floatsqroot( ( vec1[2] - vec2[2] ) ^ 2.0 )
1722 :     }
1723 :    
1724 :     stock Float:vector_xy_distance_f( Float:vec1[3], Float:vec2[3] )
1725 :     {
1726 :     return Float:floatsqroot( ( ( vec1[0] - vec2[0] ) ^ 2.0 ) + ( ( vec1[1] - vec2[1] ) ^ 2.0 ) )
1727 :     }
1728 :    
1729 :     public client_PreThink( id )
1730 :     {
1731 :     if( !get_pcvar_num( p_climb ) || is_user_bot( id ) || !is_climber_alive( id ) )
1732 :     return PLUGIN_CONTINUE
1733 :    
1734 : ian 19 if( sclip[id] && sc_fcount == 9 ) entity_set_int( id, EV_INT_solid, SOLID_BBOX )
1735 : ian 1
1736 :     //Detect button use. Replicated from HL SDK
1737 :     if( get_user_button( id ) & IN_USE && !( get_user_oldbutton( id ) & IN_USE ) )
1738 :     {
1739 :     new entlist[3], count
1740 :     count = find_sphere_class( id, "func_button", 64.0, entlist, 3 )
1741 :     if( count )
1742 :     {
1743 :     new Float:orig[3]
1744 :     for( new i = 0; i < count; i++ )
1745 :     {
1746 :     get_brush_entity_origin( entlist[i], orig )
1747 :     if( is_in_viewcone( id, orig ) ) button_used( id, entlist[i] )
1748 :     }
1749 :     }
1750 :     }
1751 :    
1752 : ian 19 new cflags = timer[id][TMR_CFLAGS]
1753 : ian 1
1754 :     //Double and super jump boosts
1755 :     if( get_pcvar_num( p_boost ) )
1756 :     {
1757 :     new bool:onground = false
1758 :     if( get_entity_flags( id ) & FL_ONGROUND ) onground = true
1759 :     if( get_user_button( id ) & IN_JUMP )
1760 :     {
1761 :     if( cflags & CF_SUPER_JUMP && onground )
1762 :     {
1763 : ian 19 entity_get_vector( id, EV_VEC_velocity, post_think_vel[id] )
1764 :     if( post_think_vel[id][0] != 0.0 || post_think_vel[id][1] != 0.0)
1765 : ian 1 {
1766 : ian 19 velocity_by_aim( id, 400, post_think_vel[id] )
1767 :     if( post_think_vel[id][2] < 250.0) post_think_vel[id][2] = 250.0
1768 :     if( post_think_vel[id][2] > 350.0) post_think_vel[id][2] = 350.0
1769 : ian 1 }
1770 : ian 19 else post_think_vel[id] = Float:{0.0,0.0,0.0}
1771 : ian 1 }
1772 :     else if( cflags & CF_DOUBLE_JUMP )
1773 :     {
1774 :     if( !onground && !(get_user_oldbutton( id ) & IN_JUMP ) )
1775 :     {
1776 : ian 19 entity_get_vector( id, EV_VEC_velocity, post_think_vel[id] )
1777 :     float_clamp( post_think_vel[id][0], -150.0, 150.0 )
1778 :     float_clamp( post_think_vel[id][1], -150.0, 150.0 )
1779 :     if( is_finished( id ) || post_think_vel[id][2] > -500 ) post_think_vel[id][2] = 250.0
1780 :     else post_think_vel[id] = Float:{ 0.0, 0.0, 0.0 }
1781 : ian 1 }
1782 :     }
1783 :     }
1784 :     }
1785 :    
1786 :     //Prevent drowning
1787 :     // waterlevel 0 - not in water
1788 :     // waterlevel 1 - feet in water
1789 :     // waterlevel 2 - waist in water
1790 :     // waterlevel 3 - head in water
1791 :     if( pev( id, pev_waterlevel ) == 3 ) set_pev( id, pev_waterlevel, 2 )
1792 :    
1793 :     new button = pev( id, pev_button )
1794 :     new oldbutton = pev( id, pev_oldbuttons )
1795 :    
1796 :     //If measure flag is set, call measure function
1797 :     if( !( oldbutton & IN_ATTACK ) && button & IN_ATTACK )
1798 :     if( cflags & CF_MEASURE ) do_measure( id )
1799 :     else if( cflags & CF_MEASURE2 ) do_measure2( id, 1 )
1800 :    
1801 :     //Knife attack timeout
1802 :     new wpn, clip, ammo
1803 :     wpn = get_user_weapon( id, clip, ammo )
1804 :     if( wpn == CSW_KNIFE )
1805 :     {
1806 :    
1807 :     if( button & IN_ATTACK || button & IN_ATTACK2 )
1808 : ian 19 if( check_timeout( 0, time_stamps[id][TS_KNIFE], KNIFE_TIMEOUT ) )
1809 : ian 1 set_pev( id, pev_button, pev( id, pev_button ) & ~IN_ATTACK_EITHER )
1810 :     }
1811 :     return PLUGIN_CONTINUE
1812 :     }
1813 :    
1814 :     public client_PostThink(id)
1815 :     {
1816 :     if( !( get_pcvar_num(p_climb) && get_pcvar_num(p_boost) && is_climber_alive( id ) ) || is_user_bot(id) )
1817 :     return PLUGIN_CONTINUE
1818 :    
1819 : ian 19 if( sclip[id] ) entity_set_int( id, EV_INT_solid, SOLID_NOT )
1820 : ian 1
1821 : ian 19 if( _:get_distance( _:post_think_vel[id], { 0, 0, 0 } ) )
1822 : ian 1 {
1823 : ian 19 entity_set_vector( id, EV_VEC_velocity, post_think_vel[id] )
1824 :     post_think_vel[id] = Float:{ 0.0, 0.0, 0.0 }
1825 :     if( timer[id][TMR_CFLAGS] & CF_START )
1826 : ian 1 {
1827 : ian 19 timer[id][TMR_CNTBST]++ //Increment client boost count
1828 : ian 1 change_boost( id, CF_NULL )
1829 :     }
1830 :     else if( !is_finished(id) )change_boost( id, CF_NULL )
1831 :     }
1832 :    
1833 :     //Store pause data
1834 : ian 19 if( !( timer[id][TMR_CFLAGS] & CF_PAUSE ) )
1835 : ian 1 {
1836 :     new Float:coords[3]
1837 :     entity_get_vector( id, EV_VEC_origin, coords )
1838 : ian 19 for( new i=0; i<3; i++ ) origins[id][ORIG_PAUS+i] = coords[i]
1839 :     origins[id][ORIG_PAUS+3] = entity_get_float( id, EV_FL_gravity )
1840 : ian 1 }
1841 :     return PLUGIN_CONTINUE
1842 :     }
1843 :    
1844 :     public button_used( id, button )
1845 :     {
1846 :     new btn_type = 0
1847 :     for( new i = 0; i < ST_BTN_CNT || i < FN_BTN_CNT; i++ )
1848 :     {
1849 :     if( i < ST_BTN_CNT )
1850 :     if( button == ST_BTNS[i] )
1851 :     {
1852 :     btn_type = 1
1853 :     break
1854 :     }
1855 :     if( i < FN_BTN_CNT )
1856 :     if( button == FN_BTNS[i] )
1857 :     {
1858 :     btn_type = 2
1859 :     break
1860 :     }
1861 :     }
1862 :    
1863 : ian 19 //new cflags = timer[id][TMR_CFLAGS]
1864 : ian 1
1865 :     if( btn_type == 1 )//Start Button
1866 :     {
1867 :     new Float:orig[3], bool:need_respawn = true //Float:view[3]
1868 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START ) need_respawn = false
1869 : ian 1
1870 : ian 19 for( new i = 0; i < 48; i++ ) origins[id][i] = 0.0 //Erase checkpoints
1871 : ian 1
1872 :     //Set all associated variables
1873 : ian 23 timer[id][TMR_CNTTME] = 0
1874 : ian 19 timer[id][TMR_CNTCPS] = 0
1875 :     timer[id][TMR_CNTGCS] = 0
1876 :     timer[id][TMR_CNTBST] = 0
1877 :     timer[id][TMR_CPPOS] = 0
1878 :     timer[id][TMR_CNTWPN] = 0
1879 :     time_stamps[id][TS_BOOST] = BOOST_TIMEOUT
1880 : ian 23 change_status(id,CF_START)
1881 : ian 1
1882 : ian 19 if( timer[id][TMR_CFLAGS] & CF_COUNTDOWN ) set_countdown_time( id )
1883 : ian 1
1884 :     //Record starting weapon
1885 :     rank_mod_update( id )
1886 :    
1887 :     //Respawn client to clear items.
1888 :     if( need_respawn && get_pcvar_num( p_start_respawn ) )
1889 :     {
1890 :     entity_get_vector( id, EV_VEC_origin, orig )
1891 :     //entity_get_vector( id, EV_VEC_angles, view )
1892 :     cs_user_spawn( id )
1893 :     entity_set_vector( id, EV_VEC_origin, orig )
1894 :     //entity_set_vector( id, EV_VEC_angles, view )
1895 :     delay_duck( id )
1896 : ian 19 //time_stamps[id][TS_SPAWN]=get_systime()
1897 : ian 1 }
1898 :     heal( id )
1899 :     cs_set_user_money( id, get_pcvar_num( p_startmoney ) )
1900 :    
1901 :     //Play random start sound and text messages
1902 :     if( get_pcvar_num( p_sounds ) ) switch( random_num( 0, 2 ) )
1903 :     {
1904 :     case 0:client_cmd( id, "spk barney/beertopside" )
1905 :     case 1:client_cmd( id, "spk scientist/c3a2_sci_portopen" )
1906 :     case 2:client_cmd( id, "spk barney/c1a2_ba_climb" )
1907 :     }
1908 :    
1909 : ian 23 change_boost( id, CF_NULL, SILENT ) //Disable Boosts
1910 : ian 19 //time_stamps[id][TS_BOOST]=0
1911 : ian 1 clmsg(id,"Timer started. Go Go Go!!!")
1912 :     //client_print(id,print_chat,"Timer started. Go Go Go!!!")
1913 :    
1914 :     sfexec( id, 2 ) //Execute commands from start/finish config
1915 :    
1916 :     sortcssb( ) //Update frags to reorder scoreboard
1917 :     }
1918 :     else if( btn_type == 2 )//Finish Button
1919 :     {
1920 : ian 23 if( timer[id][TMR_CFLAGS] & CF_START )
1921 : ian 1 {
1922 : ian 23 new cnttme = timer[id][TMR_CNTTME] / 10
1923 :     new cntbst = timer[id][TMR_CNTBST]
1924 :     new cntcps = timer[id][TMR_CNTCPS]
1925 :     new cntgcs = timer[id][TMR_CNTGCS]
1926 :     new cntwpn = timer[id][TMR_CNTWPN]
1927 :    
1928 : ian 1 //Set client variables
1929 :     change_status( id, CF_STOP )
1930 : ian 19 timer[id][TMR_SESFIN]++
1931 :     timer[id][TMR_MAPFIN]++
1932 : ian 1
1933 :     //Announce to client
1934 :     if( get_pcvar_num( p_sounds ) ) client_cmd( 0, "spk woop" )
1935 :     clmsg( id, "Congratulations 1337 climber." )
1936 :     //client_print(id,print_chat,"Congratulations 1337 climber.")
1937 : ian 23 new name[32], msg[23]
1938 :     formatex( msg, 22, "%s^t%s", getuserstatus( id ), parsetime( timer[id][TMR_CNTTME] ) )
1939 : ian 1 //clmsg(id,msg)
1940 :     //client_print(id,print_chat,msg)
1941 :    
1942 :     new wpn[11]
1943 : ian 23 get_weapon_name( cntwpn, wpn, 10 )
1944 : ian 1
1945 :     //Announce to all
1946 :     get_user_name( id, name, 32 )
1947 : ian 23 client_print( 0, print_chat,
1948 :     "%s^t%s^t(%s/ %d CPS/ %d GCS/ %d Boosts)^tCompleted (%d, %d)",
1949 :     name, msg, wpn, cntcps, cntgcs, cntbst,
1950 :     timer[id][TMR_SESFIN], timer[id][TMR_MAPFIN]
1951 :     )
1952 : ian 1
1953 : ian 23 new cntscore = ( ( ( cntbst > 0 ? 1 : 0 ) * 1000000 ) +
1954 :     ( ( cntcps > 0 ? 1 : 0 ) * 100000 ) +
1955 :     ( cntwpn * 10000 ) +
1956 :     cnttme )
1957 : ian 1
1958 : ian 23 new bstscore = ( ( ( timer[id][TMR_BSTBST] > 0 ? 1 : 0 ) * 1000000 ) +
1959 : ian 19 ( ( timer[id][TMR_BSTCPS] > 0 ? 1 : 0 ) * 100000 ) +
1960 :     ( timer[id][TMR_BSTWPN] * 10000 ) +
1961 : ian 23 timer[id][TMR_BSTTME] / 10 )
1962 : ian 1
1963 : ian 23 if( cntscore < bstscore || bstscore == 0 )
1964 : ian 1 {
1965 : ian 23 timer[id][TMR_BSTTME] = cnttme
1966 :     timer[id][TMR_BSTCPS] = cntcps
1967 :     timer[id][TMR_BSTGCS] = cntgcs
1968 :     timer[id][TMR_BSTBST] = cntbst
1969 :     timer[id][TMR_BSTWPN] = cntwpn
1970 : ian 1 }
1971 :    
1972 :     sfexec( id, 2 )//Execute commands from start/finish config
1973 :    
1974 :     if( CLIMB_SAVE ) db_save( id )
1975 :    
1976 :     sortcssb( ) //Update frags to reorder scoreboard
1977 :     }
1978 : ian 19 else if(timer[id][TMR_CFLAGS]&CF_STOP&&timer[id][TMR_SESFIN]==0){
1979 : ian 1 //change_status(id,CF_FINISH)
1980 : ian 19 timer[id][TMR_SESFIN]++
1981 : ian 1 new msg[100]="Congratulations, you finished! But you didn't start the timer. :("
1982 :     clmsg(id,msg)
1983 :     client_print(id,print_chat,msg)
1984 :     //Execute commands from start/finish config
1985 :     sfexec(id,2)
1986 :     //If stats save enabled warn unregistered clients to register
1987 :     //if(CLIMB_SAVE)regwarn(id)
1988 :     }
1989 :     heal(id)
1990 :     }
1991 :     return PLUGIN_HANDLED
1992 :     }
1993 :    
1994 :     //Execute commands from start/finish config
1995 :     public sfexec(id,clevent){
1996 : ian 19 new clstat[3],cflags=timer[id][TMR_CFLAGS]
1997 :     /*switch(timer[id][TMR_CFLAGS]){
1998 : ian 1 case TMR_CFLAGS_STOP: clstat="ns"
1999 :     case TMR_CFLAGS_STRT: clstat="st"
2000 :     case TMR_CFLAGS_FNSH: clstat="fn"
2001 :     }*/
2002 :     if(is_finished(id))clstat="fn"
2003 :     else if(cflags&CF_STOP)clstat="ns"
2004 :     else if(cflags&CF_START)clstat="st"
2005 : ian 19 //else if(timer[id][TMR_CFLAGS]&CF_FINISH)clstat="fn"
2006 :     //if(equal(clstat,"ns")&&(get_user_flags(id)&VIP||timer[id][TMR_SESFIN]>0))clstat="fn"
2007 : ian 1
2008 :     for(new i=0;i<sfcount;i++){
2009 :     new cmdstat[3],cmdevent[2],cmdtype[3],cmd[60],idtype[5]
2010 :     parse(sfactions[i],cmdstat,2,cmdevent,1,cmdtype,2,cmd,sizeof(cmd)-1,idtype,4)
2011 :     if((equali(cmdstat,clstat)||equali(cmdstat,"ay"))&&str_to_num(cmdevent)&clevent){
2012 :     if(equali(cmdtype,"sc")){
2013 :     if(equali(idtype,"uid"))format(cmd,sizeof(cmd)-1,cmd,get_user_userid(id))
2014 :     else{
2015 :     new name[24]
2016 :     get_user_name(id,name,sizeof(name)-1)
2017 :     format(name,sizeof(name),"^"%s^"",name)
2018 :     format(cmd,sizeof(cmd)-1,cmd,name)
2019 :     client_print(id,print_chat,cmd)
2020 :     }
2021 :     server_cmd(cmd)
2022 :     }
2023 :     else{
2024 :     client_cmd(id,cmd)
2025 :     }
2026 :     }
2027 :     }
2028 :     return PLUGIN_HANDLED
2029 :     }
2030 :    
2031 :     //Update frags to reorder scoreboard
2032 :     public sortcssb( )
2033 :     {
2034 :     new players[32], num, id
2035 :     get_players_ordered( players, num )
2036 :     for( new i = 0 ; i < num; i++ )
2037 :     {
2038 :     id = players[i]
2039 :     set_user_frags( id, 0 )
2040 :     cs_set_user_deaths( id, i + 1 )
2041 :    
2042 :     message_begin( MSG_ALL, SVC_TEAMINFO )
2043 :     write_byte( id )
2044 :     write_string( "CT" )
2045 :     message_end( )
2046 :     }
2047 :    
2048 :     //Show bot as spectator on scoreboard
2049 :     message_begin( MSG_ALL, SVC_TEAMINFO )
2050 :     write_byte( find_player( "i" ) )
2051 :     write_string( "SPECTATOR" )
2052 :     message_end( )
2053 :     }
2054 :    
2055 :     //Returns array of client id's sorted by climb time
2056 :     public get_players_ordered( players[32], &num )
2057 :     {
2058 :     get_players( players, num, "ch" )
2059 :    
2060 :     new i, id, pdata[32][3] //{ status, score, id }
2061 :     for( i = 0; i < num; i++ )
2062 :     {//Fill player data sorting array
2063 :     id = players[i]
2064 :     pdata[i][2] = id
2065 :    
2066 : ian 19 if( timer[id][TMR_BSTTME] )
2067 : ian 1 {//Has high score
2068 :     pdata[i][0] = 0
2069 : ian 19 pdata[i][1] = ( ( ( timer[id][TMR_BSTBST] > 0 ? 1 : 0 ) * 1000000 ) +
2070 :     ( ( timer[id][TMR_BSTCPS] > 0 ? 1 : 0 ) * 100000 ) +
2071 :     ( timer[id][TMR_BSTWPN] * 10000 ) +
2072 : ian 23 timer[id][TMR_BSTTME] / 10 )
2073 : ian 1 }
2074 : ian 19 else if( timer[id][TMR_CFLAGS] & CF_START || timer[id][TMR_CFLAGS] & CF_PAUSE )
2075 : ian 1 {//Has time but no high score
2076 :     pdata[i][0] = 1
2077 : ian 19 pdata[i][1] = ( ( ( timer[id][TMR_CNTBST] > 0 ? 1 : 0 ) * 1000000 ) +
2078 :     ( ( timer[id][TMR_CNTCPS] > 0 ? 1 : 0 ) * 100000 ) +
2079 :     ( timer[id][TMR_CNTWPN] * 10000 ) +
2080 : ian 23 timer[id][TMR_CNTTME] / 10 )
2081 : ian 1 }
2082 :     else pdata[i][0] = 2 //No time or high score
2083 :     }
2084 :    
2085 :     SortStrings( pdata, num )
2086 :     for( i = 0; i < num; i++ )
2087 :     players[i] = pdata[i][2]
2088 :     }
2089 :    
2090 :     /*public get_limit(){
2091 :     //if(get_pcvar_num(p_webmod))
2092 :     //return 0
2093 :     new url[100]
2094 :     get_pcvar_string(p_stats_url,url,99)
2095 :     if(strlen(url))
2096 :     return false
2097 :     return true
2098 :     }*/
2099 :    
2100 :     /*public get_url( id, file[] )
2101 :     {
2102 :     new url[100]
2103 :     get_pcvar_string( p_stats_url, url, 99 )
2104 :     //if(get_pcvar_num(p_webmod)){
2105 :     // new ip[10],iip[33],eip[33],port[10]
2106 :     // get_user_ip(id,ip,9)
2107 :     // get_pcvar_string(p_ip_internal,iip,32)
2108 :     // get_pcvar_string(p_ip_external,eip,32)
2109 :     // get_pcvar_string(p_port,port,9)
2110 :     // if(equal(ip,"192.168.",8))format(url,99,"http://%s:%s/%s",iip,port,file)
2111 :     // else format(url,99,"http://%s:%s/%s",eip,port,file)
2112 :     //}
2113 :     if( strlen( url ) ) format( url, 99, "%sclimb_scores.html", url )
2114 :     return url
2115 :     }*/
2116 :    
2117 :     stock sb_add_tabs( str[], size)
2118 :     {
2119 :     new len = strlen( str )// > 7 ? 1 : 2
2120 :     add( str[len], size, "^t")
2121 :     if( len < 8 ) add( str[len+1], size, "^t")
2122 :     }
2123 :    
2124 :     public climbscores( id )
2125 :     {//Show scoreboard
2126 : ian 23 if( !get_pcvar_num( p_climb ) ) return PLUGIN_HANDLED
2127 :    
2128 :     if( get_systime() - ts_score > 2 )
2129 : ian 1 {
2130 : ian 23 new fh = fopen( SCORES_PATH, "w" )
2131 :    
2132 :     //Header-8 cols: #, name, status, time, sct/cp/gc/boost, Best, cp/gc/boost, Completed
2133 :     fprintf( fh, "<link rel=stylesheet href=http://ian.cammarata.us/sb><table><tr><td id=a>" )
2134 :     fprintf( fh, "<pre># Name Status Time Wpn/CP/GC/Bst Best ... Fin</pre>" )
2135 :     fprintf( fh, "</td></tr><tr id=b><td></td></tr><tr><td><pre>" )
2136 :    
2137 :     new line[251], name[NAMELEN+2], players[32], num, tid, written_len
2138 :     new ctime, cwpn, ccp, cgc, cbst
2139 :     new btime, bwpn, bcp, bgc, bbst
2140 :     new ctime_str[20], btime_str[20]
2141 :    
2142 :     get_players_ordered( players, num )
2143 :    
2144 : ian 24 for( new i = 0; i < num; i++ )
2145 : ian 1 {
2146 : ian 23 tid = players[i]
2147 : ian 1
2148 : ian 23 get_user_name( tid, name, NAMELEN)
2149 :     sb_add_tabs( name, NAMELEN+2 )
2150 : ian 1
2151 : ian 23 ctime = timer[tid][TMR_CNTTME]
2152 :     cwpn = timer[tid][TMR_CNTWPN]
2153 :     ccp = timer[tid][TMR_CNTCPS]
2154 :     cgc = timer[tid][TMR_CNTGCS]
2155 :     cbst = timer[tid][TMR_CNTBST]
2156 :     format( ctime_str, 19, "%d/%d/%d/%d", cwpn, ccp, cgc, cbst )
2157 :     sb_add_tabs( ctime_str, 19 )
2158 : ian 1
2159 : ian 23 btime = timer[tid][TMR_BSTTME]
2160 :     bwpn = timer[tid][TMR_BSTWPN]
2161 :     bcp = timer[tid][TMR_BSTCPS]
2162 :     bgc = timer[tid][TMR_BSTGCS]
2163 :     bbst = timer[tid][TMR_BSTBST]
2164 :     format( btime_str, 19, "%d/%d/%d/%d", bwpn, bcp, bgc, bbst )
2165 :     sb_add_tabs( btime_str, 19 )
2166 : ian 1
2167 : ian 23 formatex( line, 250,
2168 :     "%s%d %s%s %s %s%s %s%d%s",
2169 :     i % 2 ? NULLSTR : "<div>",
2170 :     i, htmlspecialchars( name ),
2171 :     getuserstatus( tid ),
2172 :     parsetime( ctime ), ctime_str,
2173 :     parsetime( btime ), btime_str,
2174 :     timer[tid][TMR_MAPFIN],
2175 :     i % 2 ? NULLSTR : "</div>" )
2176 :     written_len += strlen( line )
2177 :     //if( limit && written_len > ( 1263 - strlen( cust_msg ) ) ) break
2178 :     if( written_len > 1263 ) break
2179 :     fprintf( fh, line )
2180 : ian 1 }
2181 : ian 23 //1530-150-117=1263
2182 :     new cust_msg[33]
2183 :     get_pcvar_string( p_stats_msg, cust_msg, 32 )
2184 :     if( !strlen( cust_msg ) ) formatex( cust_msg, 32, "Climb %s", VERSION )
2185 :     fprintf( fh, "</pre></td></tr><tr id=d><td></td></tr><tr><td id=e></td></tr><tr>" )
2186 :     fprintf( fh, "<td id=a>%s</td></tr></table>", cust_msg )
2187 :     fclose( fh )
2188 :     ts_score = get_systime()
2189 : ian 1 }
2190 : ian 23
2191 :     show_motd( id, SCORES_PATH, "Current Scores" )
2192 :    
2193 : ian 1 return PLUGIN_HANDLED
2194 :     }
2195 :    
2196 : ian 23 //Convert seconds to time string with zero padded seconds field
2197 :     public parsetime( decisec )
2198 :     {
2199 :     new timestr[11], mins, sec, dec, decstr[3]
2200 :    
2201 :     sec = decisec / 10
2202 :     dec = decisec % 10
2203 :     mins = sec / 60
2204 :     sec = sec % 60
2205 :     if( dec ) formatex( decstr, 2, ".%d", dec )
2206 :     formatex( timestr, 10, "%d:%s%d%s", mins, sec < 10 ? "0" : NULLSTR , sec, decstr )
2207 : ian 1 return timestr
2208 :     }
2209 :    
2210 :     public hudtime( )
2211 :     {//Set clock on HUD to current climb time
2212 :     if( !get_pcvar_num( p_climb ) ) return
2213 :    
2214 :     new id, players[32], num, cltime, cflags
2215 :     get_players( players, num, "ach" )
2216 :     for( new i = 0; i < num; i++ )
2217 :     {
2218 :     id = players[i]
2219 : ian 19 cflags = timer[id][TMR_CFLAGS]
2220 : ian 23 cltime = timer[id][TMR_CNTTME] / 10 + 1
2221 : ian 1 if( cflags & CF_PAUSE )
2222 :     {
2223 :     clmsg( id, "PAUSED - say '/unpause' to resume." )
2224 :     cl_pause( id )
2225 :     }
2226 :    
2227 : ian 23 if( !( cflags & CF_COUNTDOWN ) || ( timer[id][TMR_BSTTME] >= timer[id][TMR_CNTTME] ) )
2228 : ian 1 hudtime_msg( id, cltime )
2229 :     else if( cflags & CF_PAUSE )
2230 : ian 23 hudtime_msg( id, timer[id][TMR_BSTTME] / 10 - cltime + 1 )
2231 : ian 1
2232 : ian 19 for( new j = 1; j <= spec_ids[id][0]; j++ )
2233 :     hudtime_msg( spec_ids[id][j], cltime )
2234 : ian 1 }
2235 :     }
2236 :    
2237 :     public toggle_countdown( id )
2238 :     {
2239 :     //Toggle countdown flag and print message
2240 : ian 19 timer[id][TMR_CFLAGS] ^= CF_COUNTDOWN
2241 :     if( timer[id][TMR_CFLAGS] & CF_COUNTDOWN )
2242 : ian 1 {
2243 :     if( set_countdown_time( id ) )
2244 :     clmsg( id, "Countdown enabled." )
2245 :     }
2246 :     else
2247 :     clmsg( id, "Countdown disabled." )
2248 :     }
2249 :    
2250 :     public bool:set_countdown_time( id )
2251 :     {
2252 : ian 23 new bsttme = timer[id][TMR_BSTTME] / 10
2253 :     if( bsttme > 0 )
2254 : ian 1 {
2255 : ian 19 new cflags = timer[id][TMR_CFLAGS]
2256 : ian 1 if( cflags & CF_START || cflags & CF_PAUSE )
2257 : ian 23 hudtime_msg( id, bsttme - timer[id][TMR_CNTTME] / 10 )
2258 : ian 1 return true
2259 :     }
2260 :     clmsg( id, "Countdown disabled: No high score available." )
2261 : ian 19 timer[id][TMR_CFLAGS] ^= CF_COUNTDOWN
2262 : ian 1 return false
2263 :     }
2264 :    
2265 :     public hudtime_msg( id, cltime )
2266 :     {
2267 :     message_begin( MSG_ONE, SVC_ROUNDTIME, _, id )
2268 :     write_short( cltime )
2269 :     message_end( )
2270 :     }
2271 :    
2272 :     public getuserstatus( id )
2273 :     {//Return string describing user status
2274 : ian 19 new msg[12], cflags = timer[id][TMR_CFLAGS]
2275 : ian 1 msg = "PAUSED"
2276 : ian 19 if( cflags & CF_STOP && timer[id][TMR_SESFIN] > 0 )
2277 : ian 1 msg = "Finished"
2278 :     else if( cflags & CF_STOP )
2279 :     msg = "Not Started"
2280 :     else if( cflags & CF_START )
2281 :     msg = "Climbing"
2282 :     //else if( cflags & CF_PAUSE ) msg = "PAUSED"
2283 :     //return "PAUSED"
2284 :     return msg
2285 :     }
2286 :    
2287 :     stock clmsg( id, msg[] )
2288 :     {//Show Hud Message
2289 :     set_hudmessage( get_pcvar_num( p_msg_r ), get_pcvar_num( p_msg_g ), get_pcvar_num( p_msg_b ),
2290 :     get_pcvar_float( p_msg_x ), get_pcvar_float( p_msg_y ), 0, 0.0, 5.0, 0.5, 0.5, 4 )
2291 :     show_hudmessage( id, msg )
2292 :    
2293 :     //Show to spectators
2294 : ian 19 for( new i = 1; i <= spec_ids[id][0]; i++ )
2295 :     show_hudmessage( spec_ids[id][i], msg )
2296 : ian 1
2297 :     return PLUGIN_HANDLED
2298 :     }
2299 :     //Fill spectator data array used for msg replication
2300 :     public spec_update(){
2301 :     if(get_pcvar_num(p_climb)){
2302 :     new players[32],num,id,id2,i
2303 : ian 19 for(i=1;i<33;i++)spec_ids[i][0]=0
2304 : ian 1 get_players(players,num,"bch")
2305 :     for(i=0;i<num;i++){
2306 :     id=players[i]
2307 :     id2=pev(id,pev_iuser2)
2308 :     if(id2){
2309 : ian 19 spec_ids[id2][0]++
2310 :     spec_ids[id2][spec_ids[id2][0]]=id
2311 : ian 1 }
2312 :     }
2313 :     }
2314 :     return PLUGIN_HANDLED
2315 :     }
2316 :     //Make client solid
2317 :     public solid(id)
2318 :     {
2319 :     set_user_rendering(id,kRenderFxNone,0,0,0,kRenderNormal,255)
2320 :     entity_set_int(id,EV_INT_solid,SOLID_BBOX)
2321 : ian 19 sclip[id]=false
2322 : ian 1 return PLUGIN_CONTINUE
2323 :     }
2324 :     //Make client unsolid
2325 :     public unsolid(id)
2326 :     {
2327 :     if(get_pcvar_num(p_render))set_user_rendering(id,kRenderFxHologram,0,0,0,kRenderTransAdd,0)
2328 :     else set_user_rendering(id,kRenderFxPulseSlow,0,0,0,kRenderTransTexture,50)
2329 :     entity_set_int(id,EV_INT_solid,SOLID_NOT)
2330 : ian 19 sclip[id]=true
2331 : ian 1 return PLUGIN_CONTINUE
2332 :     }
2333 :     ////////////////////////////////////////////////////////////////////////////////
2334 :     // Start: Functions for use in if statements
2335 :     ////////////////////////////////////////////////////////////////////////////////
2336 :     public is_climber_alive( id )
2337 :     {
2338 :     new movetype = pev( id, pev_movetype )
2339 :     if( movetype == MOVETYPE_WALK || movetype == MOVETYPE_FLY )
2340 :     return 1
2341 :     return 0
2342 :     }
2343 :    
2344 :     public playersolid( id )
2345 :     {
2346 :     if(entity_get_int(id,EV_INT_solid)==SOLID_BBOX)return 1
2347 :     return 0
2348 :     }
2349 :    
2350 :     public isct(id){//Used in IF statements a lot
2351 :     if(get_user_team(id)==2)return 1
2352 :     return 0
2353 :     }
2354 :    
2355 :     public is_finished( id )
2356 :     {
2357 : ian 19 new cflags = timer[id][TMR_CFLAGS]
2358 :     if( cflags & CF_STOP && ( get_user_flags( id ) & VIP || timer[id][TMR_SESFIN] > 0 ) )
2359 : ian 1 return 1
2360 :     return 0
2361 :     }
2362 :    
2363 :     public isalive(id){//Use in IF statements to automatically print error if false
2364 :     if( is_climber_alive( id ) )return 1
2365 :     clmsg(id,"You must be alive to execute this command.")
2366 :     return 0
2367 :     }
2368 :    
2369 :     public notpaused(id){//Use in IF statements to automatically print error if false
2370 : ian 19 if(!(timer[id][TMR_CFLAGS]&CF_PAUSE))return 1
2371 : ian 1 clmsg(id,"You can't execute this command while paused.")
2372 :     return 0
2373 :     }
2374 :    
2375 :     /*public regwarn(id){
2376 : ian 19 if(timer[id][TMR_DBUSER]<1){
2377 : ian 1 saytext(id,id,"^x04You must register/login for your stats to save. Say /climbhelp for more info.")
2378 :     return 1
2379 :     }
2380 :     return 0
2381 :     }*/
2382 :     ////////////////////////////////////////////////////////////////////////////////
2383 :     // End: Functions for use in if statements
2384 :     ////////////////////////////////////////////////////////////////////////////////
2385 :     // Start: Auto Heal functions
2386 :     ////////////////////////////////////////////////////////////////////////////////
2387 : ian 22 public Health( id )
2388 :     {//Called when client takes damage
2389 : ian 1 new ida[1]
2390 : ian 22 ida[0] = id
2391 :     set_task( 0.1, "damage_handle", _, ida, 1 )
2392 : ian 1 }
2393 :    
2394 :     public damage_handle( ida[1] )
2395 :     {//Damage hander, delayed to provide HUD consistency
2396 :     new id = ida[0]
2397 :     if( get_pcvar_num( p_climb )&& is_climber_alive( id ) )
2398 :     {
2399 :     new chp = get_user_health( id )
2400 :     if( chp != hp )
2401 :     {
2402 :     heal( id )
2403 :     /*new wpn, atk = get_user_attacker( id, wpn )
2404 :    
2405 :     //Heal hp immediately
2406 :     if( ( atk == 0 || ( id == atk && wpn == 0) ) && !task_exists( 50 + id ) )
2407 :     heal(id)
2408 :    
2409 :     //Heal delayed
2410 :     else
2411 :     {
2412 :     if( task_exists( 50 + id ) ) remove_task( 50 + id )
2413 :     set_task( 5.0, "task_heal", 50 + id, ida, 1 )
2414 :    
2415 :     //Fix hp display at 0
2416 :     if( chp == 256 ) set_user_health( id, 257 )
2417 :     }*/
2418 :     }
2419 :     else if( task_exists( 50 + id ) ) remove_task( 50 + id )
2420 :     }
2421 :     return PLUGIN_HANDLED
2422 :     }
2423 :    
2424 :     public task_heal(ida[]){//Heal client to predetermined HP required by map
2425 :     heal(ida[0])
2426 :     return PLUGIN_HANDLED
2427 :     }
2428 :    
2429 :     public heal(id){
2430 :     if( is_climber_alive( id ) )
2431 :     {
2432 :     if(is_finished(id))set_user_health(id,511)
2433 :     else if(hp)set_user_health(id,hp)
2434 :     else if(get_user_health(id)>100)set_user_health(id,100)
2435 :     }
2436 :     }
2437 :     ////////////////////////////////////////////////////////////////////////////////
2438 :     // End: Auto Heal functions
2439 :     ////////////////////////////////////////////////////////////////////////////////
2440 :     // Start: Multiplay Bunny Hop functions
2441 :     ////////////////////////////////////////////////////////////////////////////////
2442 :     public pfn_touch( ent, id )
2443 :     {
2444 :     if( !get_pcvar_num( p_climb ) )
2445 :     return PLUGIN_CONTINUE
2446 :    
2447 :     //Clean up dropped stuff
2448 :     new str[21]
2449 :     entity_get_string( ent, EV_SZ_classname, str, 20 )
2450 :     if( equal( str, "weaponbox" ) || equal( str, "item_thighpack" ) )
2451 :     {
2452 :     remove_entity( ent )
2453 :     return PLUGIN_HANDLED
2454 :     }
2455 :     if( pev_valid( id ) )
2456 :     {
2457 :     entity_get_string( id, EV_SZ_classname, str, 20 )
2458 :     if( equal( str, "weaponbox" ) || equal( str, "item_thighpack" ) )
2459 :     {
2460 :     remove_entity( id )
2461 :     return PLUGIN_HANDLED
2462 :     }
2463 :     }
2464 :     else return PLUGIN_HANDLED
2465 :    
2466 :     if ( !ent || !id )
2467 :     return PLUGIN_CONTINUE
2468 :    
2469 :     //Make sure id is player and ent is object
2470 :     if( 0 < ent <= MAXPLAYERS )
2471 :     {
2472 :     new tmp = id
2473 :     id = ent
2474 :     ent = tmp
2475 :     }
2476 :     else if( !( 0 < id <= MAXPLAYERS ) )
2477 :     return PLUGIN_CONTINUE
2478 :    
2479 :     //Bhop stuff
2480 :     new dpos = door_in_array( ent )
2481 :     if( dpos > -1 )
2482 :     {
2483 :     //Finished can stand on bhop blocks
2484 :     if( is_finished( id ) )
2485 :     return PLUGIN_HANDLED
2486 :    
2487 : ian 19 if( bhop_failid[id] != ent )
2488 : ian 1 {
2489 : ian 19 bhop_failid[id] = ent
2490 :     bhop_fail[id] = false
2491 : ian 1
2492 :     new tskid = TSK_BHOP + id
2493 :     if( task_exists( tskid ) )
2494 :     remove_task( tskid )
2495 :     set_task( 0.2, "bhop_set_fail", tskid )
2496 :     tskid = TSK_CLEAR_FAIL + id
2497 :     if( task_exists( tskid ) )
2498 :     remove_task( tskid )
2499 :     set_task( 0.7, "bhop_clear_fail", tskid )
2500 :     }
2501 : ian 19 else if( bhop_fail[id] )
2502 : ian 1 {
2503 :     teleport( id, door_tp_pos[dpos] )
2504 : ian 19 bhop_failid[id] = 0
2505 :     bhop_fail[id] = false
2506 : ian 1 }
2507 :     return PLUGIN_HANDLED
2508 :     }
2509 :    
2510 :     return PLUGIN_CONTINUE
2511 :     }
2512 :    
2513 :     public door_in_array( door )
2514 :     {
2515 :     for( new i = 0; i < door_count; i++ )
2516 :     if( func_doors[i][0] == door )
2517 :     return i
2518 :     return -1
2519 :     }
2520 :    
2521 :     public bhop_set_fail( tskid )
2522 :     {
2523 : ian 19 bhop_fail[tskid-TSK_BHOP] = true
2524 : ian 1 return PLUGIN_HANDLED
2525 :     }
2526 :    
2527 :     public bhop_clear_fail( tskid )
2528 :     {
2529 :     new id = tskid - TSK_CLEAR_FAIL
2530 : ian 19 bhop_failid[id] = 0
2531 :     bhop_fail[id] = false
2532 : ian 1 return PLUGIN_HANDLED
2533 :     }
2534 :    
2535 :     ////////////////////////////////////////////////////////////////////////////////
2536 :     // End: Multiplay Bunny Hop functions
2537 :     ////////////////////////////////////////////////////////////////////////////////
2538 :    
2539 :     /*public spawn_distance_sort(elem1[],elem2[]){
2540 :     if(elem1[1]<elem2[1])return -1
2541 :     if(elem1[1]>elem2[1])return 1
2542 :     return 0
2543 :     }*/
2544 :    
2545 :     //Future use, to block hook, or detect hook cheaters a.k.a. hookers
2546 :     public phook( id )
2547 :     {
2548 :     hooked[id] = 1
2549 :     return PLUGIN_CONTINUE
2550 :     }
2551 :    
2552 :     public mhook( id )
2553 :     {
2554 :     hooked[id] = 0
2555 :     return PLUGIN_CONTINUE
2556 :     }
2557 :    
2558 :     ////////////////////////////////////////////////////////////////////////////////
2559 :     // Start: Flashlight functions
2560 :     ////////////////////////////////////////////////////////////////////////////////
2561 :     public flight_icons( id )
2562 :     {
2563 : ian 19 if( timer[id][TMR_CFLAGS] & CF_LIGHT_ON )
2564 : ian 1 {
2565 :     if( !task_exists( TSK_FLIGHT + id ) )
2566 :     set_task( 0.1, "flight_msg", TSK_FLIGHT + id, _, _, "b" )
2567 :    
2568 :     message_begin( MSG_ONE, SVC_FLASHLIGHT, _, id )
2569 :     write_byte( 1 )
2570 :     write_byte( 100 )
2571 :     message_end( )
2572 :    
2573 :     message_begin( MSG_ONE, SVC_STATUSICON, _, id )
2574 :     write_byte( 1 ) //on
2575 :     write_string( "flash_beam" )
2576 :     write_byte( get_pcvar_num( p_light_r ) ) //r
2577 :     write_byte( get_pcvar_num( p_light_g ) ) //g
2578 :     write_byte( get_pcvar_num( p_light_b ) ) //b
2579 :     message_end( )
2580 :     }
2581 :     else
2582 :     {
2583 :     message_begin( MSG_ONE, SVC_FLASHLIGHT, _, id )
2584 :     write_byte( 0 )
2585 :     write_byte( 100 )
2586 :     message_end( )
2587 :    
2588 :     message_begin( MSG_ONE, SVC_STATUSICON, _, id )
2589 :     write_byte( 0 ) //off
2590 :     write_string( "flash_beam" )
2591 :     message_end( )
2592 :     }
2593 :     }
2594 :     public tog_flight(id){
2595 :     if(!get_pcvar_num(p_climb))return PLUGIN_CONTINUE
2596 : ian 19 if(!(timer[id][TMR_CFLAGS]&CF_LIGHT_ON)){
2597 :     timer[id][TMR_CFLAGS]+=CF_LIGHT_ON
2598 : ian 1 set_task(0.1,"flight_msg",TSK_FLIGHT+id,_,_,"b")
2599 :     }
2600 : ian 19 else timer[id][TMR_CFLAGS]-=CF_LIGHT_ON
2601 : ian 1 flight_icons(id)
2602 :     return PLUGIN_HANDLED
2603 :     }
2604 :    
2605 :     public flight_msg(tskid){
2606 :     if(get_pcvar_num(p_climb)){
2607 :     new orig[3],id=tskid-TSK_FLIGHT
2608 : ian 19 if(!(timer[id][TMR_CFLAGS]&CF_LIGHT_ON))remove_task(tskid)
2609 : ian 1 get_user_origin(id,orig)
2610 :     message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,_,id)
2611 :     write_byte(TE_DLIGHT)
2612 :     write_coord(orig[0])//x
2613 :     write_coord(orig[1])//y
2614 :     write_coord(orig[2])//z
2615 :     write_byte(60)//radius
2616 :     write_byte(get_pcvar_num(p_light_r))//r
2617 :     write_byte(get_pcvar_num(p_light_g))//g
2618 :     write_byte(get_pcvar_num(p_light_b))//b
2619 :     write_byte(4)//life
2620 :     write_byte(2)//decay
2621 :     message_end()
2622 :     }
2623 :     return PLUGIN_HANDLED
2624 :     }
2625 :     ////////////////////////////////////////////////////////////////////////////////
2626 :     // End: Flashlight functions
2627 :     ////////////////////////////////////////////////////////////////////////////////
2628 :     public teleport( id, Float:orig[3] )
2629 :     {//Used to teleport clients, prevents client collisions and getting stuck
2630 :     //Don't tp if vector is all zeros
2631 :     if( !( orig[0] || orig[1] || orig[2] ) ) return 0
2632 :    
2633 :     new Float:c2[3], player, players[32], num
2634 :     get_players( players, num, "ac" )
2635 :     unsolid( id )
2636 :     for( new i = 0; i < num; i++ )
2637 :     {
2638 :     player = players[i]
2639 :     if( id != player )
2640 :     {
2641 :     entity_get_vector( player, EV_VEC_origin, c2 )
2642 :     if( vector_distance( orig, c2 ) < 90 ) unsolid( player )
2643 :     }
2644 :     }
2645 :     entity_set_vector( id, EV_VEC_velocity, Float:{0.0, 0.0, 0.0} )
2646 :     entity_set_vector( id, EV_VEC_origin, orig )
2647 :     delay_duck( id )
2648 :     return 1
2649 :     }
2650 :    
2651 :     public delay_duck(id){//Used by teleport and timer start respawn, prevents getting stuck
2652 :     new ida[1]
2653 :     ida[0]=id
2654 :     set_task(0.01,"force_duck",_,ida,1)
2655 :     set_entity_flags(ida[0],FL_DUCKING,1)
2656 :     }
2657 :    
2658 :     public force_duck(ida[1]){//Task for delay_duck
2659 :     set_entity_flags(ida[0],FL_DUCKING,1)
2660 :     }
2661 :    
2662 : ian 23 //Used in IF statements to automatically print error if false
2663 :     stock cvar_enabled( id, p_cvar, silent = 0 )
2664 :     {
2665 :     if( get_pcvar_num(p_cvar) == 0 )
2666 :     {
2667 :     if( !silent )
2668 :     {
2669 :     clmsg( id, "This command is disabled." )
2670 :     client_print(id,print_chat,"This command has been disabled by the server administrator.")
2671 :     }
2672 : ian 1 return 0
2673 :     }
2674 :     return 1
2675 :     }
2676 :     ////////////////////////////////////////////////////////////////////////////////
2677 :     // Start: Climb command handling functions
2678 :     ////////////////////////////////////////////////////////////////////////////////
2679 :    
2680 :     public sunglasses( id )
2681 :     {
2682 :     //Toggle flag for this measure and print message
2683 : ian 19 timer[id][TMR_CFLAGS] ^= CF_SUNGLASSES
2684 :     if( timer[id][TMR_CFLAGS] & CF_SUNGLASSES )
2685 : ian 1 {
2686 :     message_begin( MSG_ONE, SVC_SCREENFADE, _, id )
2687 :     write_short( 1 ) //total duration
2688 :     write_short( 0 ) //time it stays one color
2689 :     write_short( 5 ) //fade type
2690 :     write_byte( 0 ) //r
2691 :     write_byte( 0 ) //g
2692 :     write_byte( 0 ) //b
2693 :     write_byte( 127 ) //a
2694 :     message_end( )
2695 :     }
2696 :     else
2697 :     {
2698 :     message_begin( MSG_ONE, SVC_SCREENFADE, _, id )
2699 :     write_short( 1 ) //total duration
2700 :     write_short( 0 ) //time it stays one color
2701 :     write_short( 0 ) //fade type
2702 :     write_byte( 0 ) //r
2703 :     write_byte( 0 ) //g
2704 :     write_byte( 0 ) //b
2705 :     write_byte( 127 ) //a
2706 :     message_end( )
2707 :     }
2708 :     }
2709 :    
2710 :     public give_scout( id )
2711 : ian 19 if( !check_timeout( id, time_stamps[id][TS_WPN], WPN_TIMEOUT ) )
2712 : ian 1 give_item( id, "weapon_scout" )
2713 :    
2714 :     public give_usp( id )
2715 : ian 19 if( !check_timeout( id, time_stamps[id][TS_WPN], WPN_TIMEOUT ) )
2716 : ian 1 give_item( id, "weapon_usp" )
2717 :    
2718 :     public give_weapons( id )
2719 : ian 19 if( !check_timeout( id, time_stamps[id][TS_WPN], WPN_TIMEOUT ) )
2720 : ian 1 {
2721 :     give_item( id, "weapon_awp" )
2722 :     give_item( id, "weapon_m249" )
2723 :     give_item( id, "weapon_m4a1" )
2724 :     give_item( id, "weapon_sg552" )
2725 :     give_item( id, "weapon_famas" )
2726 :     give_item( id, "weapon_p90" )
2727 :     give_item( id, "weapon_usp" )
2728 :     give_item( id, "weapon_scout" )
2729 :     }
2730 :    
2731 :    
2732 :     public help_msg(id)
2733 :     {
2734 :     client_print( id, print_chat, "Say /climbhelp to get help with the Climb kz plugin." )
2735 :     return PLUGIN_CONTINUE
2736 :     }
2737 :    
2738 :     public climb_help(id)
2739 :     if( get_pcvar_num( p_climb ) )
2740 :     show_motd( id, "http://ian.cammarata.us/projects/climb/help/2a3/en/commands?agent=hl", "Climb Plugin Help" )
2741 :    
2742 :     public boost_help(id)
2743 :     if( get_pcvar_num( p_climb ) )
2744 :     show_motd( id, "http://ian.cammarata.us/projects/climb/help/2a3/en/boosts?agent=hl", "Climb Plugin Help" )
2745 :    
2746 :     public goto_player( id )
2747 :     {//Admin command, teleport to client
2748 :     if( is_finished( id ) && get_pcvar_num( p_climb ) )
2749 :     {
2750 :     new tid, arg[24]
2751 :     read_argv( 1, arg, sizeof( arg ) - 1 )
2752 :     tid = cmd_target( tid, arg, 4 )
2753 :     if( tid )
2754 :     {
2755 :     new Float:orig[3]
2756 :     entity_get_vector( tid, EV_VEC_origin, orig )
2757 :     teleport( id, orig )
2758 :     }
2759 :     }
2760 :     return PLUGIN_HANDLED
2761 :     }
2762 :    
2763 :     public spectate( id )
2764 :     {//Client switch to spectator
2765 :     if( get_pcvar_num( p_climb ) && !is_user_bot( id ) && !is_user_hltv( id ) )
2766 :     {
2767 :     if( !is_climber_alive( id ) )
2768 :     {
2769 :     /*
2770 :     cs_set_user_team(id,3)//fixes respawn bug?
2771 :     frespawn( id )
2772 :     */
2773 :    
2774 :     climb_user_spawn( id )
2775 :    
2776 : ian 19 if( timer[id][TMR_CFLAGS] & CF_PAUSE )
2777 : ian 1 {//If they are paused tp to pause spot and freeze them again.
2778 :     new Float:coords[3]
2779 :     for( new i=0; i<3; i++ ) coords[i] = origins[ id - 1 ][ ORIG_PAUS + i ]
2780 :     teleport( id, coords )
2781 :     cl_pause( id )
2782 :     }
2783 :    
2784 :     }
2785 :     else if( get_user_flags( id ) & VIP ? 1 : ( cvar_enabled( id, p_allow_spectators ) ) )
2786 :     {
2787 :     //Move client way outside the map so we don't have to see their retarded model
2788 :     new Float:orig[3]
2789 :     entity_get_vector( id, EV_VEC_origin, orig )
2790 :     entity_set_vector( id, EV_VEC_origin, Float:{ 99999.9, 99999.9, 99999.9 } )
2791 :    
2792 :     //Set a task to move them back to where they were originally
2793 :     new ida[4]
2794 :     ida[0] = id
2795 :     ida[1] = _:orig[0]
2796 :     ida[2] = _:orig[1]
2797 :     ida[3] = _:orig[2]
2798 :     set_task( 0.1, "tsk_spec_tp_back", _, ida, 4 )
2799 :    
2800 :     set_pev( id, pev_movetype, MOVETYPE_NOCLIP )
2801 :     set_pev( id, pev_solid, SOLID_NOT )
2802 :     set_pev( id, pev_effects, EF_NODRAW )
2803 :     set_pev( id, pev_deadflag, DEAD_DEAD )
2804 :     set_pev( id, pev_takedamage, DAMAGE_NO )
2805 :     set_entity_flags( id, FL_FROZEN, 0 )
2806 :    
2807 : ian 19 if( timer[id][TMR_CFLAGS] & CF_START ) change_status( id, CF_PAUSE )
2808 : ian 1 }
2809 :     return PLUGIN_HANDLED
2810 :     }
2811 :     return PLUGIN_CONTINUE
2812 :     }
2813 :    
2814 :     public tsk_spec_tp_back( ida[4] )
2815 :     {
2816 :     new Float:orig[3]
2817 :     orig[0] = Float:ida[1]
2818 :     orig[1] = Float:ida[2]
2819 :     orig[2] = Float:ida[3]
2820 :     entity_set_vector( ida[0], EV_VEC_origin, orig )
2821 :     }
2822 :    
2823 :     public client_command( id )
2824 :     {//Forward to catch all formats for commands
2825 :     if(!get_pcvar_num(p_climb))
2826 :     return PLUGIN_CONTINUE
2827 :     new cmd[21]
2828 :     read_argv(0,cmd,20)
2829 :    
2830 :     //If say command, trim "say", abort if more than one word
2831 :     if(equal(cmd,"say")||equal(cmd,"say_team")){
2832 :     read_argv(1,cmd,20)
2833 :     trim(cmd)
2834 :     if(contain(cmd," ")>-1)return PLUGIN_CONTINUE
2835 :     }
2836 :    
2837 :     //Remove slashes
2838 :     if( equal(cmd,"/",1) || equal(cmd,"\",1) || equal(cmd,".",1) || equal(cmd,"!",1) )
2839 :     copy(cmd,20,cmd[1])
2840 :    
2841 :     //Make a checkpoint
2842 :     if( equali(cmd,"checkpoint") || equali(cmd,"check") || equali(cmd,"cp") )
2843 :     check(id)
2844 :    
2845 :     //Go to checkpoint
2846 :     else if( equali(cmd,"gocheck") || equali(cmd,"gc") || equali(cmd,"tp") || equali(cmd,"tele") )
2847 :     gocheck(id)
2848 :    
2849 :     //Ungocheck
2850 :     else if( equali(cmd,"ungc") || equali(cmd,"ungocheck") )
2851 :     ungocheck(id)
2852 :    
2853 :     //Boost help page
2854 :     else if( equali(cmd,"boost") )
2855 :     boost_help(id)
2856 :    
2857 :     //Solid Boost
2858 :     else if( equali(cmd,"solid") || equali(cmd,"semiclip") )
2859 :     change_boost(id,CF_SOLID)
2860 :    
2861 :     //Jump Boost
2862 :     else if( equali(cmd,"superjump") || equali(cmd,"sjump") || equali(cmd,"sj") || equali(cmd,"longjump") ||\
2863 :     equali(cmd,"ljump") || equali(cmd,"lj") )
2864 :     change_boost(id,CF_SUPER_JUMP)
2865 :    
2866 :     //Double Jump Boost
2867 :     else if( equali(cmd,"doublejump") || equali(cmd,"djump") || equali(cmd,"dj") )
2868 :     change_boost(id,CF_DOUBLE_JUMP)
2869 :    
2870 :     //Cycle CPs reverse
2871 :     else if( equali(cmd,"cp-") || equali(cmd,"stuck") || equali(cmd,"unstuck") )
2872 :     {
2873 :     cp_back( id )
2874 :     return PLUGIN_CONTINUE
2875 :     }
2876 :    
2877 :     //Cycle CPs forward
2878 :     else if( equali(cmd,"cp+") )
2879 :     {
2880 :     cp_forward( id )
2881 :     return PLUGIN_CONTINUE
2882 :     }
2883 :    
2884 :     //Pause
2885 :     else if( equali(cmd,"pause") || equali(cmd,"unpause") )
2886 :     change_status(id,CF_PAUSE)
2887 :    
2888 :     //Stop
2889 :     else if( equali(cmd,"stop") )
2890 :     stop(id)
2891 :    
2892 :     //Time/Scores
2893 :     else if( equali(cmd,"scoreboard") || equali(cmd,"score") || equali(cmd,"scores") )
2894 :     climbscores(id)
2895 :    
2896 :     //High Scores
2897 :     else if( equali(cmd,"top10") || equali(cmd,"top15") || equali(cmd,"top") || equali(cmd,"highscores") ||\
2898 :     equali(cmd,"best") || equali(cmd,"rank") || equali(cmd,"pro15") || equali(cmd,"nub15") )
2899 :     highscores(id)
2900 :    
2901 :     //Respawn
2902 :     else if( equali( cmd, "respawn" ) || equali( cmd, "spawn" ) )
2903 :     frespawn( id )
2904 :    
2905 :     //TP to start button
2906 :     else if( equali( cmd, "restart" ) || equali( cmd, "start" ) || equali( cmd, "reset" ) )
2907 :     tp_start_btn( id )
2908 :    
2909 :     //Spectate
2910 :     else if( equali(cmd,"spectate") || equali(cmd,"spec") )
2911 :     spectate(id)
2912 :    
2913 :     //Get scout
2914 :     else if( equali( cmd, "scout" ) )
2915 :     give_scout( id )
2916 :    
2917 :     //Get usp
2918 :     else if( equali( cmd, "usp" ) )
2919 :     give_usp( id )
2920 :    
2921 :     else if( equali( cmd, "weapons" ) )
2922 :     {
2923 :     give_weapons( id )
2924 :     return PLUGIN_CONTINUE
2925 :     }
2926 :    
2927 :     else if( equali( cmd, "measure" ) )
2928 :     {
2929 :     toggle_measure( id )
2930 :     return PLUGIN_CONTINUE
2931 :     }
2932 :    
2933 :     else if( equali( cmd, "measure2" ) )
2934 :     {
2935 :     toggle_measure2( id )
2936 :     return PLUGIN_CONTINUE
2937 :     }
2938 :    
2939 :     else if( equali( cmd, "countdown" ) || equali( cmd, "countup" ) )
2940 :     {
2941 :     toggle_countdown( id )
2942 :     return PLUGIN_CONTINUE
2943 :     }
2944 :    
2945 :     else if( equali( cmd, "sunglasses" ) )
2946 :     {
2947 :     sunglasses( id )
2948 :     return PLUGIN_CONTINUE
2949 :     }
2950 :    
2951 :     //Climb Help
2952 :     else if( equali( cmd, "climbhelp" ) || equali( cmd, "kzhelp" ) )
2953 :     climb_help( id )
2954 :    
2955 :     //If none of above conditions met, don't block the command
2956 :     else return PLUGIN_CONTINUE
2957 :     return PLUGIN_HANDLED
2958 :     }
2959 :    
2960 :     ////////////////////////////////////////////////////////////////////////////////
2961 :     // End: Climb command handling functions
2962 :     ////////////////////////////////////////////////////////////////////////////////
2963 :     // Start: Measure functions
2964 :     ////////////////////////////////////////////////////////////////////////////////
2965 :    
2966 :     public toggle_measure( id )
2967 :     {
2968 :     //Remove flag for other measure
2969 : ian 19 new cflags = timer[id][TMR_CFLAGS]
2970 :     if( cflags & CF_MEASURE2 ) timer[id][TMR_CFLAGS] = cflags & ~CF_MEASURE2
2971 : ian 1
2972 :     //Toggle flag for this measure and print message
2973 : ian 19 timer[id][TMR_CFLAGS] ^= CF_MEASURE
2974 : ian 1 if( cflags & CF_MEASURE )
2975 :     clmsg( id, "Measure disabled." )
2976 :     else
2977 :     clmsg( id, "Measure enabled, use attack to measure." )
2978 :     }
2979 :    
2980 :     public do_measure( id )
2981 :     {
2982 :     new Float:orig[3], Float:look[3], Float:end[3], Float:ret[3]
2983 :     new Float:ln_st[3], Float:ln_fn[3]
2984 :    
2985 :     entity_get_vector( id, EV_VEC_origin, orig )
2986 :     entity_get_vector( id, EV_VEC_view_ofs, ret )
2987 :     for( new i = 0; i < 3; i++ ) orig[i] += ret[i]
2988 :    
2989 :     velocity_by_aim( id, 1, ret )
2990 :     for( new i = 0; i < 3; i++ ) end[i] = orig[i] + ( ret[i] * 9999 )
2991 :    
2992 :     trace_line( id, orig, end, ln_st )
2993 :     trace_normal( id, orig, end, look )
2994 :    
2995 :     for( new i = 0; i < 3; i++ ) end[i] = ln_st[i] + ( look[i] * 9999 )
2996 :    
2997 :     trace_line( id, ln_st, end, ln_fn )
2998 :    
2999 :     end[0] = ln_st[0] + ( ret[0] * -9999 )
3000 :     end[1] = ln_st[1] + ( ret[1] * -9999 )
3001 :     end[2] = ln_st[2]
3002 :    
3003 :     trace_line( id, ln_st, end, orig )
3004 :    
3005 :     new msg[101]
3006 :     format( msg, 100, "Distance: red %d / blue %d",
3007 :     floatround( vector_distance( ln_st, ln_fn ), floatround_ceil ),
3008 :     floatround( vector_distance( ln_st, orig ), floatround_ceil ) )
3009 :     clmsg( id, msg )
3010 :     console_print( id, msg )
3011 :    
3012 :     message_begin( MSG_ONE, SVC_TEMPENTITY, _, id )
3013 :     write_byte( TE_BEAMPOINTS )
3014 :     write_coord( floatround( ln_st[0] ) )
3015 :     write_coord( floatround( ln_st[1] ) )
3016 :     write_coord( floatround( ln_st[2] ) )
3017 :     write_coord( floatround( ln_fn[0] ) )
3018 :     write_coord( floatround( ln_fn[1] ) )
3019 :     write_coord( floatround( ln_fn[2] ) )
3020 :     write_short( beam_sprite ) // sprite index
3021 :     write_byte( 0 ) // starting frame
3022 :     write_byte( 10 ) // frame rate in 0.1's
3023 :     write_byte( 100 ) // life in 0.1's
3024 :     write_byte( 10 ) // line width in 0.1's
3025 :     write_byte( 2 ) // noise amplitude in 0.01's
3026 :     write_byte( 255 ) // Red
3027 :     write_byte( 0 ) // Green
3028 :     write_byte( 0 ) // Blue
3029 :     write_byte( 127 ) // brightness
3030 :     write_byte( 50 ) // scroll speed in 0.1's
3031 :     message_end( )
3032 :    
3033 :     message_begin( MSG_ONE, SVC_TEMPENTITY, _, id )
3034 :     write_byte( TE_BEAMPOINTS )
3035 :     write_coord( floatround( ln_st[0] ) )
3036 :     write_coord( floatround( ln_st[1] ) )
3037 :     write_coord( floatround( ln_st[2] ) )
3038 :     write_coord( floatround( orig[0] ) )
3039 :     write_coord( floatround( orig[1] ) )
3040 :     write_coord( floatround( orig[2] ) )
3041 :     write_short( beam_sprite ) // sprite index
3042 :     write_byte( 0 ) // starting frame
3043 :     write_byte( 10 ) // frame rate in 0.1's
3044 :     write_byte( 100 ) // life in 0.1's
3045 :     write_byte( 10 ) // line width in 0.1's
3046 :     write_byte( 2 ) // noise amplitude in 0.01's
3047 :     write_byte( 0 ) // Red
3048 :     write_byte( 0 ) // Green
3049 :     write_byte( 255 ) // Blue
3050 :     write_byte( 127 ) // brightness
3051 :     write_byte( 50 ) // scroll speed in 0.1's
3052 :     message_end( )
3053 :     }
3054 :    
3055 :     public toggle_measure2( id )
3056 :     {
3057 :     //Remove flag for other measure
3058 : ian 19 new cflags = timer[id][TMR_CFLAGS]
3059 :     if( cflags & CF_MEASURE ) timer[id][TMR_CFLAGS] = cflags & ~CF_MEASURE
3060 : ian 1
3061 :     //Toggle flag for this measure and print message
3062 : ian 19 timer[id][TMR_CFLAGS] ^= CF_MEASURE2
3063 : ian 1 if( cflags & CF_MEASURE2 )
3064 :     clmsg( id, "Measure 2 disabled." )
3065 :     else
3066 :     clmsg( id, "Measure 2 enabled, use attack to measure." )
3067 :     }
3068 :    
3069 :     public tsk_do_measure2( tskid )
3070 :     do_measure2( tskid - TSK_MEASURE2 )
3071 :    
3072 :     stock do_measure2( id, set = 0 )
3073 :     {
3074 :     new tskid = TSK_MEASURE2 + id
3075 :    
3076 : ian 19 static Float:ln_st_static[33][3]
3077 : ian 1
3078 :     new Float:orig[3], Float:ret[3], Float:end[3]
3079 :    
3080 :     entity_get_vector( id, EV_VEC_origin, orig )
3081 :     entity_get_vector( id, EV_VEC_view_ofs, ret )
3082 :     for( new i = 0; i < 3; i++ ) orig[i] += ret[i]
3083 :    
3084 :     velocity_by_aim( id, 1, ret )
3085 :    
3086 :     for( new i = 0; i < 3; i++ ) end[i] = orig[i] + ( ret[i] * 9999 )
3087 :     trace_line( id, orig, end, ret )
3088 :    
3089 :     new Float:ln_st[3]
3090 : ian 19 ln_st = ln_st_static[id]
3091 : ian 1
3092 :     //If first iteration, save point to static and return
3093 :     if( !( ln_st[0] || ln_st[0] || ln_st[0] ) )
3094 :     {
3095 : ian 19 ln_st_static[id] = ret
3096 : ian 1 set_task( 0.1, "tsk_do_measure2", tskid, _, _, "b" )
3097 :     return
3098 :     }
3099 :    
3100 :     new Float:ln_fn[3], Float:ln_stmid[3], Float:ln_fnmid[3]
3101 :     ln_fn = ret
3102 :    
3103 :     ln_stmid[0] = ln_st[0]
3104 :     ln_stmid[1] = ln_st[1]
3105 :     ln_stmid[2] = ln_fn[2]
3106 :    
3107 :     ln_fnmid[0] = ln_fn[0]
3108 :     ln_fnmid[1] = ln_st[1]
3109 :     ln_fnmid[2] = ln_fn[2]
3110 :    
3111 :     new msg[101]
3112 :     format( msg, 100, "Distance: r %d / g %d / b %d",
3113 :     floatround( vector_distance( ln_st, ln_stmid ), floatround_ceil ),
3114 :     floatround( vector_distance( ln_stmid, ln_fnmid ), floatround_ceil ),
3115 :     floatround( vector_distance( ln_fnmid, ln_fn ), floatround_ceil ) )
3116 :     clmsg( id, msg )
3117 :    
3118 :     new life = 1, dest = MSG_ONE_UNRELIABLE
3119 :     if( set )
3120 :     {
3121 :     life = 125
3122 :     dest = MSG_ONE
3123 :     console_print( id, msg )
3124 :     }
3125 :    
3126 :     message_begin( dest, SVC_TEMPENTITY, _, id )
3127 :     write_byte( TE_BEAMPOINTS )
3128 :     write_coord( floatround( ln_st[0] ) )
3129 :     write_coord( floatround( ln_st[1] ) )
3130 :     write_coord( floatround( ln_st[2] ) )
3131 :     write_coord( floatround( ln_stmid[0] ) )
3132 :     write_coord( floatround( ln_stmid[1] ) )
3133 :     write_coord( floatround( ln_stmid[2] ) )
3134 :     write_short( beam_sprite ) // sprite index
3135 :     write_byte( 0 ) // starting frame
3136 :     write_byte( 10 ) // frame rate in 0.1's
3137 :     write_byte( life ) // life in 0.1's
3138 :     write_byte( 10 ) // line width in 0.1's
3139 :     write_byte( 2 ) // noise amplitude in 0.01's
3140 :     write_byte( 255 ) // Red
3141 :     write_byte( 0 ) // Green
3142 :     write_byte( 0 ) // Blue
3143 :     write_byte( 127 ) // brightness
3144 :     write_byte( 50 ) // scroll speed in 0.1's
3145 :     message_end( )
3146 :    
3147 :     message_begin( dest, SVC_TEMPENTITY, _, id )
3148 :     write_byte( TE_BEAMPOINTS )
3149 :     write_coord( floatround( ln_stmid[0] ) )
3150 :     write_coord( floatround( ln_stmid[1] ) )
3151 :     write_coord( floatround( ln_stmid[2] ) )
3152 :     write_coord( floatround( ln_fnmid[0] ) )
3153 :     write_coord( floatround( ln_fnmid[1] ) )
3154 :     write_coord( floatround( ln_fnmid[2] ) )
3155 :     write_short( beam_sprite ) // sprite index
3156 :     write_byte( 0 ) // starting frame
3157 :     write_byte( 10 ) // frame rate in 0.1's
3158 :     write_byte( life ) // life in 0.1's
3159 :     write_byte( 10 ) // line width in 0.1's
3160 :     write_byte( 2 ) // noise amplitude in 0.01's
3161 :     write_byte( 0 ) // Red
3162 :     write_byte( 255 ) // Green
3163 :     write_byte( 0 ) // Blue
3164 :     write_byte( 127 ) // brightness
3165 :     write_byte( 50 ) // scroll speed in 0.1's
3166 :     message_end( )
3167 :    
3168 :     message_begin( dest, SVC_TEMPENTITY, _, id )
3169 :     write_byte( TE_BEAMPOINTS )
3170 :     write_coord( floatround( ln_fnmid[0] ) )
3171 :     write_coord( floatround( ln_fnmid[1] ) )
3172 :     write_coord( floatround( ln_fnmid[2] ) )
3173 :     write_coord( floatround( ln_fn[0] ) )
3174 :     write_coord( floatround( ln_fn[1] ) )
3175 :     write_coord( floatround( ln_fn[2] ) )
3176 :     write_short( beam_sprite ) // sprite index
3177 :     write_byte( 0 ) // starting frame
3178 :     write_byte( 10 ) // frame rate in 0.1's
3179 :     write_byte( life ) // life in 0.1's
3180 :     write_byte( 10 ) // line width in 0.1's
3181 :     write_byte( 2 ) // noise amplitude in 0.01's
3182 :     write_byte( 0 ) // Red
3183 :     write_byte( 0 ) // Green
3184 :     write_byte( 255 ) // Blue
3185 :     write_byte( 127 ) // brightness
3186 :     write_byte( 50 ) // scroll speed in 0.1's
3187 :     message_end( )
3188 :    
3189 :     //Remove task if flag has been removed
3190 : ian 19 if( task_exists( tskid ) && !( timer[id][TMR_CFLAGS] & CF_MEASURE2 ) ) remove_task( tskid )
3191 : ian 1
3192 :     //If a second point hasn't been set then end here
3193 :     if( !set ) return
3194 :    
3195 :     //If it gets this far it's the second iteration, /*so disable flag and*/ reset static var
3196 : ian 19 //timer[id][TMR_CFLAGS] ^= CF_MEASURE2
3197 :     ln_st_static[id] = Float:{ 0.0, 0.0, 0.0 }
3198 : ian 1 if( task_exists( tskid ) ) remove_task( tskid )
3199 :     }
3200 :    
3201 :     ////////////////////////////////////////////////////////////////////////////////
3202 :     // End: Measure functions
3203 :     ////////////////////////////////////////////////////////////////////////////////
3204 :     // Start: Blocked/Forwarded default CS commands
3205 :     ////////////////////////////////////////////////////////////////////////////////
3206 :     public client_kill( id )
3207 :     {//Block kill, forward to spectate command
3208 :     if( get_pcvar_num( p_climb ) )
3209 :     {
3210 :     spectate( id )
3211 :     return PLUGIN_HANDLED
3212 :     }
3213 :     return PLUGIN_CONTINUE
3214 :     }
3215 :    
3216 :     public block_cmd(id){//Block some commands if climb enabled
3217 :     if(get_pcvar_num(p_climb))return PLUGIN_HANDLED
3218 :     return PLUGIN_CONTINUE
3219 :     }
3220 :    
3221 :     public block_cmd2(id){//Used to block fullupdate always
3222 :     return PLUGIN_HANDLED
3223 :     }
3224 :    
3225 :     public block_jointeam(id){//Block client trying to switch teams
3226 :     if(get_pcvar_num(p_climb)&&isct(id))return PLUGIN_HANDLED
3227 :     return PLUGIN_CONTINUE
3228 :     }
3229 :    
3230 :     public donothing(){//register_clcmd reference this function, but are picked up by the more flexible code in the client_command forward.
3231 :     return PLUGIN_CONTINUE
3232 :     }
3233 :    
3234 :     public menuteam(id){//Connect choose team menu - force client to select CT
3235 :     if(get_pcvar_num(p_climb))client_cmd(id,"slot2")
3236 :     return PLUGIN_CONTINUE
3237 :     }
3238 :    
3239 :     public menuclass(id){//Force client to choose random model
3240 :     if(get_pcvar_num(p_climb)){
3241 :     client_cmd(id,"slot5")
3242 :     }
3243 :     return PLUGIN_CONTINUE
3244 :     }
3245 :    
3246 :     ////////////////////////////////////////////////////////////////////////////////
3247 :     // End: Blocked/Forwarded default CS commands
3248 :     ////////////////////////////////////////////////////////////////////////////////
3249 :     // Start: Database functions
3250 :     ////////////////////////////////////////////////////////////////////////////////
3251 :     public db_init( )
3252 :     {
3253 :    
3254 :     static host[32], user[32], pass[32], name[32], type[12]
3255 :    
3256 :     get_cvar_string( "climb_db_host", host, 31 )
3257 :     get_cvar_string( "climb_db_user", user, 31 )
3258 :     get_cvar_string( "climb_db_pass", pass, 31 )
3259 :     get_cvar_string( "climb_db_name", name, 31 )
3260 :     get_cvar_string( "climb_db_type", type, 11 )
3261 :     get_cvar_string( "climb_db_prefix", DB_PREFIX, 10 )
3262 :     get_cvar_string( "climb_db_serverid", DB_SERVER_ID, 15 )
3263 :    
3264 :     //SQL_SetAffinity(type)
3265 :     DB_TUPLE=SQL_MakeDbTuple(host,user,pass,name)
3266 :    
3267 :     if( !get_cvar_num( "climb_db_exists" ) )
3268 :     {
3269 :     new autoinc[15]="autoincrement"
3270 :     if(equal(type,"mysql"))autoinc="auto_increment"
3271 :     new query[600]
3272 :    
3273 :     formatex( query, 599,
3274 :     "create table if not exists %splayers (\
3275 :     user_id integer primary key %s,\
3276 :     steam_id char(25) unique,\
3277 :     password char(6),\
3278 :     user_name varchar(20) unique,\
3279 :     alias varchar(32) unique,\
3280 :     email varchar(50) unique,\
3281 :     cflags integer)",
3282 :     DB_PREFIX, autoinc )
3283 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler", query )
3284 :    
3285 :     formatex( query, 599,
3286 :     "create table if not exists %sscores (\
3287 :     score_id integer primary key %s,\
3288 :     score integer,\
3289 :     server_ip char(15),\
3290 :     user_id integer,\
3291 :     map_name varchar(32),\
3292 : ian 23 fin_time float,\
3293 : ian 1 cps integer,\
3294 :     gcs integer,\
3295 :     boosts integer,\
3296 :     wpns integer,\
3297 :     server_time_stamp integer)",
3298 :     DB_PREFIX, autoinc )
3299 :     SQL_ThreadQuery(DB_TUPLE,"db_generic_handler",query)
3300 :    
3301 :     formatex( query, 599, "create index scores_score on %sscores (score)", DB_PREFIX )
3302 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler", query )
3303 :    
3304 :     formatex( query, 599,
3305 :     "create table if not exists %ssessions (\
3306 :     steam_id char(25) primary key,\
3307 :     user_id integer unique)",
3308 :     DB_PREFIX )
3309 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler", query )
3310 :    
3311 :     set_cvar_num( "climb_db_exists", 1 )
3312 :     }
3313 :     }
3314 :    
3315 :     public db_generic_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3316 :     return query_failed( failstate, error, errnum )
3317 :    
3318 :     public auto_login(ida[1])
3319 :     {
3320 :     new id=ida[0]
3321 :    
3322 :     //debug
3323 :     new name[33],sid[33],data[2],query[151]
3324 :     get_user_name( id, name, 32 )
3325 :     get_user_authid( id, sid, 32 )
3326 :     //log_amx( "CLIMB: auto_login( %d ) / %s / %s", id, name, sid )
3327 :    
3328 :     data[0] = id
3329 :     data[1] = 2
3330 :     formatex( query, 150,
3331 :     "select user_id, steam_id, password from %splayers where steam_id=^"%s^"",
3332 :     DB_PREFIX, sid )
3333 :     //formatex( data[2], 24, sid)
3334 :     SQL_ThreadQuery( DB_TUPLE, "login_handler", query, data, 2 )
3335 :    
3336 :     //log_amx( "CLIMB: Login Query for id=%d - ^"%s^";", id, query )
3337 :    
3338 :     //return client_cmd( id, "login" )
3339 :     //return db_login( id )
3340 :     }
3341 :    
3342 :     public db_login( id )
3343 :     {
3344 :     //log_amx( "CLIMB: Function entry - login( %d )", id )
3345 :     if( get_pcvar_num( p_climb ) )
3346 :     {
3347 :     if( CLIMB_SAVE )
3348 :     {
3349 :     //log_amx( "CLIMB: Begin login client id=%d.", id )
3350 : ian 19 //log_amx( "CLIMB: timer[id][TMR_DBUSER]=%d.", timer[id][TMR_DBUSER] )
3351 : ian 1
3352 : ian 19 if( timer[id][TMR_DBUSER] > 0 ) //Already logged in
3353 : ian 1 {
3354 :     client_print( id, print_console, "[Climb] Login Error: You are already logged in." )
3355 :     return PLUGIN_HANDLED
3356 :     }
3357 :     new query[151], data[2] //data[28]
3358 :     data[0] = id
3359 :    
3360 :     /*if( read_argc() > 1 ) //Client is logging in with a user/pass
3361 :     {
3362 :     new user[21], pass[21]
3363 :     read_argv( 1, user, 20 )
3364 :     read_argv( 2, pass, 20 )
3365 :     rotwtf( pass, 6 )
3366 :     data[1] = 1
3367 :     formatex( query, 150,
3368 :     "select user_id, steam_id, from %splayers where user_id=^"%s^" and password=^"%s^";",
3369 :     DB_PREFIX, user, pass )
3370 :     //formatex( data[2], 24, user)
3371 :     SQL_ThreadQuery( DB_TUPLE, "login_handler", query, data, 2 )
3372 :     }
3373 :     else //Client is logging in with SteamID
3374 :     {*/
3375 :     new sid[32]
3376 :     get_user_authid( id, sid, 31 )
3377 :     data[1] = 2
3378 :     formatex( query, 150,
3379 :     "select user_id, steam_id, password from %splayers where steam_id=^"%s^"",
3380 :     DB_PREFIX, sid )
3381 :     //formatex( data[2], 24, sid)
3382 :     SQL_ThreadQuery( DB_TUPLE, "login_handler", query, data, 2 )
3383 :    
3384 :     //log_amx( "CLIMB: Login Query for id=%d - ^"%s^";", id, query )
3385 :     //}
3386 :     }
3387 :     else client_print( id, print_console, "[Climb] Login Error: Can't Login; Stats not enabled." )
3388 :     }
3389 :     return PLUGIN_HANDLED
3390 :     }
3391 :    
3392 :     public login_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3393 :     {
3394 :     new id = data[0]
3395 :     //log_amx( "CLIMB: Function entry - login_handler( %d )", id )
3396 :     //If they've disonnected since the login attempt initiated, abort
3397 :     if( !is_user_connected( id ) ) return log_amx( "CLIMB: Login Error id=%d - Client no longer exists.", id )
3398 :    
3399 :     if( SQL_NumResults( query ) < 1 )
3400 :     {
3401 :     //log_amx( "CLIMB: Login Error id=%d - Not a valid account. 0 result returned", id )
3402 :     return client_print( id, print_console, "[Climb] Login Error: Not a valid account." )
3403 :     }
3404 :    
3405 :     if( !query_failed( failstate, error, errnum) )
3406 :     {
3407 :     //If database steamid doesn't match client steamid, abort
3408 :     new db_sid[32], sid[32]
3409 :     SQL_ReadResult( query, 1, db_sid, 31 )
3410 :     get_user_authid( id, sid, 31 )
3411 :     if( !equal( sid, db_sid ) ) return log_amx( "CLIMB: Login Error id=%d - SteamID mismatch.", id )
3412 :    
3413 :     //Fail if steamid login attempt, and steamid is registered as shared
3414 :     if( data[1] == 2 )
3415 :     {
3416 :     new pass[7]
3417 :     SQL_ReadResult( query, 2, pass, 6 )
3418 :     if( equali( pass, "shared" ) )
3419 :     {
3420 :     //log_amx( "CLIMB: Login Error id=%d - Shared SteamID.", id )
3421 :     return client_print( id, print_console,\
3422 :     "[Climb] Login Error: You are using a shared SteamID. Please login with a username and password." )
3423 :     }
3424 :     }
3425 :    
3426 :     //Everything is ok, add db userid to timer info, display login messages
3427 : ian 19 timer[id][TMR_DBUSER] = SQL_ReadResult( query, 0 )
3428 : ian 1 new msg[100]
3429 :     formatex( msg, 99, "[Climb] Login: Success - Account: %s", sid )
3430 :     //log_amx( "CLIMB: Login Success id=%d", id )
3431 :     client_print(id,print_console,msg )
3432 :     format( msg, 99, "^x04%s", msg )
3433 :     saytext( id, id, msg )
3434 :    
3435 :     //If they just registered and logged in, save score, else load score
3436 : ian 19 if( timer[id][TMR_CFLAGS] & CF_JUST_REGD )
3437 : ian 1 {
3438 :     db_save( id )
3439 : ian 19 timer[id][TMR_CFLAGS] -= CF_JUST_REGD
3440 : ian 1 }
3441 :     else db_load(id)
3442 :     }
3443 :     return PLUGIN_HANDLED
3444 :     }
3445 :    
3446 :     /*public logout(id)
3447 :     {
3448 : ian 19 for(new i=0;i<8;i++)origins[id][i]=0.0
3449 :     for(new i=0;i<11;i++)timer[id][i]=0
3450 : ian 1 }*/
3451 :    
3452 :     public db_load( id )
3453 :     {
3454 :     new query[351], mapname[33], data[1]
3455 :     data[0] = id
3456 :     get_mapname( mapname, 32 )
3457 :     /*formatex( query, 149,
3458 :     "select fin_time, cps, gcs, fin_cnt, boosts, wpns from %sscores where user_id=%d and map_name=^"%s^";",
3459 : ian 19 DB_PREFIX, timer[id][TMR_DBUSER], mapname )*/
3460 : ian 1 formatex( query, 350,
3461 :     "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",
3462 : ian 19 DB_PREFIX, DB_PREFIX, mapname, mapname, timer[id][TMR_DBUSER], timer[id][TMR_DBUSER] )
3463 : ian 1 SQL_ThreadQuery( DB_TUPLE, "db_load_handler", query, data, 1 )
3464 :     }
3465 :    
3466 :     public db_load_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3467 :     {
3468 :     new id=data[0]
3469 :     if( !query_failed( failstate, error, errnum) )
3470 :     {
3471 :     new msg[100]
3472 :     if(!SQL_NumResults(query))
3473 :     msg="^x04No stats available for this account on the current map."
3474 :     else
3475 :     {
3476 : ian 23 new mapname[33]
3477 : ian 1 get_mapname(mapname,32)
3478 : ian 23 SQL_ReadResult( query, 0, timer[id][TMR_BSTTME] )
3479 :     timer[id][TMR_BSTTME] *= 10
3480 : ian 19 timer[id][TMR_BSTCPS] = SQL_ReadResult( query, 1 )
3481 :     timer[id][TMR_BSTGCS] = SQL_ReadResult( query, 2 )
3482 :     timer[id][TMR_MAPFIN] = SQL_ReadResult( query, 3 )
3483 :     timer[id][TMR_BSTBST] = SQL_ReadResult( query, 4 )
3484 :     timer[id][TMR_BSTWPN] = SQL_ReadResult( query, 5 )
3485 :     //timer[id][TMR_CFLAGS]+=SQL_ReadResult(query,5)?CF_BSTSCT:0
3486 : ian 1
3487 :     formatex( msg, 99,
3488 :     "^x04Stats loaded for %s - %s^t(%d/ %d CP/%d GC/%d Boost)^tCompleted %d",
3489 : ian 23 mapname, parsetime( timer[id][TMR_BSTTME] ), timer[id][TMR_BSTWPN], timer[id][TMR_BSTCPS],
3490 : ian 19 timer[id][TMR_BSTGCS], timer[id][TMR_BSTBST], timer[id][TMR_MAPFIN] )
3491 : ian 1 }
3492 :     saytext( id, id, msg )
3493 :     }
3494 :     else client_print( id, print_chat, "[Climb] DB Read Error: Please notify a server admin." )
3495 :     return PLUGIN_HANDLED
3496 :     }
3497 :    
3498 :     public db_save( id )
3499 :     {
3500 : ian 23 new user_id = timer[id][TMR_DBUSER]
3501 :    
3502 :     if( user_id < 1 )
3503 : ian 1 {
3504 :     auto_reg( id )
3505 :     return PLUGIN_HANDLED
3506 :     }
3507 : ian 23
3508 : ian 1 new query[351], name[33], data[2]
3509 :     data[0] = id
3510 :     get_mapname( name, 32 )
3511 :     strtolower( name )
3512 :    
3513 : ian 23 new cntbst = timer[id][TMR_CNTBST]
3514 :     new cntcps = timer[id][TMR_CNTCPS]
3515 :     new cntwpn = timer[id][TMR_CNTWPN]
3516 : ian 1
3517 : ian 23 new score = ( ( ( cntbst > 0 ? 1 : 0 ) * 1000000 ) +
3518 :     ( ( cntcps > 0 ? 1 : 0 ) * 100000 ) +
3519 :     ( cntwpn * 10000 ) +
3520 :     timer[id][TMR_CNTTME] / 10 )
3521 : ian 1
3522 :     formatex( query, 350,
3523 : 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)",\
3524 :     DB_PREFIX, DB_SERVER_ID, user_id, name, timer[id][TMR_CNTTME] * 0.1, cntcps, timer[id][TMR_CNTGCS], cntbst, cntwpn, score, get_systime() )
3525 : ian 1 SQL_ThreadQuery(DB_TUPLE,"db_save_handler",query,data,2)
3526 :    
3527 :     data[1] = 0
3528 :     get_user_name( id, name, 32 )
3529 : ian 23 formatex( query, 350, "update %splayers set alias=^"%s^" where user_id=%d;", DB_PREFIX, name, user_id )
3530 : ian 1 SQL_ThreadQuery( DB_TUPLE, "db_name_update_handler", query, data, 2 )
3531 :     return PLUGIN_HANDLED
3532 :     }
3533 :    
3534 :     public db_save_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3535 :     {
3536 :     if( query_failed( failstate, error, errnum ) )
3537 :     {
3538 :     new id=data[0]
3539 :     client_print(id,print_chat,"[Climb] DB Write Error: Could not update your score. Please notify a server admin.")
3540 :     }
3541 :    
3542 :     return PLUGIN_HANDLED
3543 :     }
3544 :    
3545 :     public db_name_update_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3546 :     {
3547 :     if( query_failed( failstate, error, errnum ) )
3548 :     {
3549 :     new id = data[0]
3550 :    
3551 :     if( data[1] > 9 )
3552 :     client_print(id,print_chat,"[Climb] DB Write Error: Could not update your name. Please notify a server admin.")
3553 :     else
3554 :     {
3555 :     new query[250]
3556 :     new data2[2]
3557 :     data2[0] = id
3558 :     data2[1] = data[1] + 1
3559 :    
3560 :    
3561 :     new name[33]
3562 :     get_user_name( id, name, 29 )
3563 :     format( name, 32, "%s(%d)", name, data2[1] )
3564 :    
3565 :     formatex( query, 249,\
3566 :     "update %splayers set alias=^"%s^" where user_id=%d;",\
3567 : ian 19 DB_PREFIX, name, timer[id][TMR_DBUSER] )
3568 : ian 1 SQL_ThreadQuery(DB_TUPLE,"db_name_update_handler",query,data2,2)
3569 :     }
3570 :     }
3571 :    
3572 :     return PLUGIN_HANDLED
3573 :     }
3574 :    
3575 :     public reg(id)
3576 :     {
3577 :     if(get_pcvar_num(p_climb)){
3578 :     if(CLIMB_SAVE){
3579 :     new query[100],sid[26],name[33],data[43]
3580 :     data[0]=id
3581 :     data[1]=0
3582 :     get_user_authid(id,sid,25)
3583 :     get_user_name(id,name,32)
3584 :     //Register user/pass
3585 :     if(read_argc()>1){
3586 :     if(read_argc()!=3){
3587 :     client_print(id,print_console,"[Climb] Registration Error: Invalid number of arguments")
3588 :     return PLUGIN_HANDLED
3589 :     }
3590 :     new user[21],pass[50]
3591 :     //Read password and check length
3592 :     read_argv(2,pass,20)
3593 :     if(strlen(pass)<10){
3594 :     client_print(id,print_console,"[Climb] Registration Error: Password must be at least 10 characters.")
3595 :     return PLUGIN_HANDLED
3596 :     }
3597 :     //Read user
3598 :     read_argv(1,user,20)
3599 :     //Store user/pass in data array to pass to handler for autologin
3600 :     formatex(data[2],20,user)
3601 :     formatex(data[22],20,pass)
3602 :     //Create password hash
3603 :     rotwtf(pass,6)
3604 :     //Register shared SteamID
3605 :     formatex(query,99,"insert into %splayers (steam_id,password) values (^"%s^",'shared')",DB_PREFIX,sid)
3606 :     SQL_ThreadQuery(DB_TUPLE,"reg_handler",query,data,43)
3607 :     //Register user/pass
3608 :     data[1]=1
3609 :     formatex(query,99,"insert into %splayers (user_name,password,alias) values (^"%s^",^"%s^",^"%s^")",DB_PREFIX,user,pass,name)
3610 :     SQL_ThreadQuery(DB_TUPLE,"reg_handler",query,data,43)
3611 :     }
3612 :     }
3613 :     else client_print(id,print_console,"[Climb] Registration Error: Can't Register; Stats not enabled.")
3614 :     }
3615 :     return PLUGIN_HANDLED
3616 :     }
3617 :    
3618 :     public auto_reg(id)
3619 :     {
3620 :     new query[100],sid[26],name[33],data[43]
3621 :     data[0]=id
3622 :     data[1]=2
3623 :     get_user_authid(id,sid,25)
3624 :     get_user_name(id,name,32)
3625 :     formatex(query,99,"insert into %splayers (steam_id,alias) values (^"%s^",^"%s^")",DB_PREFIX,sid,name)
3626 :     SQL_ThreadQuery(DB_TUPLE,"reg_handler",query,data,43)
3627 :     return PLUGIN_HANDLED
3628 :     }
3629 :    
3630 :     public reg_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3631 :     {
3632 :     new id=data[0]
3633 :     if( !query_failed( failstate, error, errnum) )
3634 :     {
3635 :     new flag=data[1],user[21],pass[21]
3636 :     format(user,20,data[2])
3637 :     format(pass,20,data[22])
3638 :    
3639 :     if(flag==0)client_print(id,print_console,"[Climb] Recorded shared SteamID.")
3640 :     else if(flag==1){
3641 :     client_print(id,print_console,"[Climb] Registration Successful.")
3642 :    
3643 :     new cmd[50]
3644 :     formatex(cmd,49,"login %s %s",user,pass)
3645 :     client_cmd(id,cmd)
3646 :     }
3647 :     else if(flag==2){
3648 : ian 19 timer[id][TMR_CFLAGS]+=CF_JUST_REGD
3649 : ian 1 client_cmd(id,"login")
3650 :     }
3651 :     }
3652 :     else client_print(id,print_chat,"[Climb] DB Registration Error: Please notify a server admin.")
3653 :     return PLUGIN_HANDLED
3654 :     }
3655 :    
3656 :     public highscores(id)
3657 : ian 23 {
3658 : ian 1 if( !CLIMB_SAVE ) return clmsg( id, "Stats not enabled.")
3659 :    
3660 :     new hsurl[150], mapname[33]
3661 :     get_pcvar_string( p_stats_hsurl, hsurl, 149 )
3662 :     get_mapname( mapname, 32 )
3663 :     if( strlen( hsurl ) )
3664 :     {
3665 :     format( hsurl, 149, hsurl, mapname )
3666 :     show_motd( id, hsurl, "High Scores" )
3667 :     return PLUGIN_HANDLED
3668 :     }
3669 :     if( get_systime() - ts_hscore > 10 )
3670 :     {
3671 :     new query[501], data[1]
3672 :     data[0] = id
3673 : ian 23
3674 : ian 1 formatex( query, 500,
3675 :     "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",
3676 :     DB_PREFIX, DB_PREFIX, DB_PREFIX, mapname, mapname )
3677 :     SQL_ThreadQuery( DB_TUPLE, "hs_handler", query, data, 1 )
3678 :     ts_hscore = get_systime()
3679 :     }
3680 :     else
3681 :     {
3682 :     if( has_hscores )
3683 :     show_motd( id, HSCORES_PATH, "High Scores" )
3684 :     else
3685 :     {
3686 :     new msg[101]
3687 :     format( msg, 100, "^x04[Climb] No stats available for the current map." )
3688 :     return saytext( id, id, msg )
3689 :     }
3690 :     }
3691 :    
3692 :     return PLUGIN_HANDLED
3693 :     }
3694 :    
3695 :     public hs_handler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
3696 :     {
3697 :     if( !query_failed( failstate, error, errnum) )
3698 :     {
3699 :     new id=data[0],msg[101],num=SQL_NumResults(query)
3700 :     if(!num){
3701 :     format(msg,100,"^x04[Climb] No stats available for the current map.")
3702 :     return saytext(id,id,msg)
3703 :     }
3704 :    
3705 :     has_hscores = true
3706 :    
3707 :     new fh = fopen( HSCORES_PATH, "w" )
3708 :    
3709 :     fprintf( fh, "<link rel=stylesheet href=http://ian.cammarata.us/sb><table><tr><td id=a>" )
3710 :     fprintf( fh, "<pre># Name Time Wpn/CP/GC/Boost Fin</pre>" )
3711 :     fprintf( fh, "</td></tr><tr id=b><td></td></tr><tr><td><pre>" )
3712 :    
3713 :     new name[NAMELEN+2], line[151], written_len, btime_str[20]
3714 :     for( new i = 1; i <= num; i++ )
3715 :     {
3716 :     SQL_ReadResult( query, 0, name, NAMELEN )
3717 :     sb_add_tabs( name, NAMELEN+2 )
3718 :    
3719 :    
3720 : ian 23 format( btime_str, 19, "%d/%d/%d/%d",
3721 :     SQL_ReadResult( query, 6 ),
3722 :     SQL_ReadResult( query, 2 ),
3723 :     SQL_ReadResult( query, 3 ),
3724 :     SQL_ReadResult( query, 5 )
3725 :     )
3726 : ian 1 sb_add_tabs( btime_str, 19 )
3727 :    
3728 :     formatex( line, 150,\
3729 :     "%s%d %s%s %s %d%s",
3730 : ian 22 i % 2 ? NULLSTR : "<div>",
3731 : ian 1 i, htmlspecialchars( name ),
3732 : ian 23 parsetime( SQL_ReadResult( query, 1 ) * 10 ),
3733 : ian 1 btime_str,
3734 :     SQL_ReadResult( query, 4 ),
3735 : ian 22 i % 2 ? NULLSTR : "</div>" )
3736 : ian 1 written_len += strlen( line )
3737 :     if( written_len > 1263 ) break
3738 :     fprintf( fh, line )
3739 :     SQL_NextRow( query )
3740 :     }
3741 :    
3742 :     //1530-150-117=1263
3743 :     new cust_msg[33]
3744 :     get_pcvar_string( p_stats_msg, cust_msg, 32 )
3745 :     if( !strlen( cust_msg ) ) formatex( cust_msg, 32, "Climb %s", VERSION )
3746 :     fprintf( fh, "</pre></td></tr><tr id=d><td></td></tr><tr><td id=e></td></tr><tr>" )
3747 :     fprintf( fh, "<td id=a>%s</td></tr></table>", cust_msg )
3748 :     fclose( fh )
3749 :    
3750 :     show_motd( id, HSCORES_PATH, "High Scores" )
3751 :     }
3752 :     return PLUGIN_HANDLED
3753 :     }
3754 :    
3755 :     public climb_dbwho(id,level,cid)
3756 :     {
3757 :     if(cmd_access(id,level,cid,0))
3758 :     {
3759 :     console_print(id,"^n# DB ID (<0=Not in DB), Name")
3760 :    
3761 :     new players[32],count,name[21],id2
3762 :     get_players( players, count, "ch" )
3763 :     for( new i=0; i<count; i++ )
3764 :     {
3765 :     id2=players[i]
3766 :     get_user_name(id2,name,20)
3767 : ian 19 console_print(id,"# %d, %s",timer[id2][TMR_DBUSER],name)
3768 : ian 1 }
3769 :     console_print( id, "%d Players", count )
3770 :     }
3771 :     return PLUGIN_HANDLED
3772 :     }
3773 :    
3774 :     public climb_dbmap( id, level, cid )
3775 :     {
3776 :     if( cmd_access( id, level, cid, 0 ) )
3777 :     {
3778 :     new mapname[33]
3779 :     if( read_argc()>1 )read_argv( 1, mapname, 32 )
3780 :     if( !strlen(mapname) )get_mapname( mapname, 32 )
3781 :    
3782 :     new query[501], data[1]
3783 :     data[0]=id
3784 :    
3785 :     formatex( query, 500,
3786 :     "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",
3787 :     DB_PREFIX, DB_PREFIX, DB_PREFIX, mapname, mapname )
3788 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbmap_handler", query, data, 1 )
3789 :     }
3790 :     return PLUGIN_HANDLED
3791 :     }
3792 :    
3793 :     public climb_dbmap_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3794 :     {
3795 :     if( !query_failed( failstate, error, errnum) )
3796 :     {
3797 :     new id=data[0]
3798 :     new count=SQL_NumResults( query )
3799 :     if( count )
3800 :     {
3801 :     new name[21]
3802 :     console_print( id, "^n# Alias, Score ID, Time, cps/gcs/boosts, Scout" )
3803 :     for( new i=0; i<count; i++ )
3804 :     {
3805 :     SQL_ReadResult( query, 0, name, 20 )
3806 :     console_print( id, "# %s, %d, %d, %d/%d/%d, %s",\
3807 :     name,\
3808 :     SQL_ReadResult( query, 1 ),\
3809 :     SQL_ReadResult( query, 2 ),\
3810 :     SQL_ReadResult( query, 3 ),\
3811 :     SQL_ReadResult( query, 4 ),\
3812 :     SQL_ReadResult( query, 5 ),\
3813 :     SQL_ReadResult( query, 6 )?"y":"n")
3814 :     SQL_NextRow( query )
3815 :     }
3816 :     console_print( id, "%d Result(s)", count )
3817 :     }
3818 :     else console_print( id, "Query returned no results." )
3819 :     }
3820 :     return PLUGIN_HANDLED
3821 :     }
3822 :    
3823 :     public climb_dbuser( id, level, cid )
3824 :     {
3825 :     if( cmd_access( id, level, cid, 1 ) )
3826 :     {
3827 :     new db_user_id[10]
3828 :     read_argv( 1, db_user_id, 9 )
3829 :    
3830 :     new query[250], data[1]
3831 :     data[0]=id
3832 :    
3833 :     formatex( query, 249,\
3834 :     "select map_name, score_id, fin_time, cps, gcs, boosts, wpns from %sscores where user_id=%d;",\
3835 :     DB_PREFIX, str_to_num( db_user_id ) )
3836 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbuser_handler", query, data, 1 )
3837 :     }
3838 :     return PLUGIN_HANDLED
3839 :     }
3840 :    
3841 :     public climb_dbuser_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3842 :     {
3843 :     if( !query_failed( failstate, error, errnum ) )
3844 :     {
3845 :     new id=data[0]
3846 :     new count=SQL_NumResults( query )
3847 :     if( count )
3848 :     {
3849 :     new name[21]
3850 :     console_print(id,"^n# Map, Score ID, Time, cps/gcs/boosts, Scout")
3851 :     for( new i=0; i<count; i++ )
3852 :     {
3853 :     SQL_ReadResult( query, 0, name, 20 )
3854 :     console_print( id, "# %s, %d, %d, %d/%d/%d, %s",\
3855 :     name,\
3856 :     SQL_ReadResult(query,1),\
3857 :     SQL_ReadResult(query,2),\
3858 :     SQL_ReadResult(query,3),\
3859 :     SQL_ReadResult(query,4),\
3860 :     SQL_ReadResult(query,5),\
3861 :     SQL_ReadResult(query,6) ? "y" : "n" )
3862 :     SQL_NextRow( query )
3863 :     }
3864 :     console_print( id, "%d Result(s)", count )
3865 :     }
3866 :     else console_print( id, "Query returned no results.")
3867 :     }
3868 :     return PLUGIN_HANDLED
3869 :     }
3870 :    
3871 :     public climb_dbdelete( id, level, cid )
3872 :     {
3873 :     if(cmd_access(id,level,cid,1))
3874 :     {
3875 :     new db_user_id[10]
3876 :     read_argv( 1, db_user_id, 9 )
3877 :    
3878 :     new query[250], data[2], del_id
3879 :     data[1]=del_id=str_to_num( db_user_id )
3880 :     data[0]=id
3881 :    
3882 :     if(db_last_del_id!=del_id)
3883 :     {//First time show data to be deleted and ask if they're sure.
3884 :     formatex( query, 249,\
3885 :     "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;",\
3886 :     DB_PREFIX, DB_PREFIX, del_id )
3887 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbdelete_verify", query, data, 2 )
3888 :     }
3889 :     else
3890 :     {//Second time execute the delete
3891 :     formatex( query, 249,\
3892 :     "delete from %sscores where score_id=%d;",\
3893 :     DB_PREFIX, del_id )
3894 :     SQL_ThreadQuery( DB_TUPLE, "climb_dbdelete_handler", query, data, 2 )
3895 :     db_last_del_id=0
3896 :     }
3897 :     }
3898 :     return PLUGIN_HANDLED
3899 :     }
3900 :    
3901 :     //For nightly builds
3902 :     public climb_dbrecalc( id, level, cid )
3903 :     {
3904 :     if( cmd_access( id, level, cid, 0 ) )
3905 :     SQL_ThreadQuery( DB_TUPLE, "db_generic_handler",
3906 :     "update %sscores set score = ( ( (boosts>0) * 1000000 ) + ( (cps>0) * 100000 ) + ( wpns * 10000 ) + fin_time )",
3907 :     DB_PREFIX )
3908 :     return PLUGIN_HANDLED
3909 :     }
3910 :    
3911 :     public climb_dbdelete_verify( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3912 :     {
3913 :     if( !query_failed( failstate, error, errnum ) )
3914 :     {
3915 :     new id=data[0]
3916 :     new del_id=data[1]
3917 :     new count=SQL_NumResults( query )
3918 :     if( count )
3919 :     {
3920 :     new name[21],map[33]
3921 :     console_print( id, "^n# Name, Map, Time, cps/gcs/boosts, Scout" )
3922 :    
3923 :     SQL_ReadResult( query, 0, name, 20 )
3924 :     SQL_ReadResult( query, 1, map, 32 )
3925 :     console_print( id, "# %s, %s, %d, %d/%d/%d, %s",\
3926 :     name,\
3927 :     map,\
3928 :     SQL_ReadResult(query,2),\
3929 :     SQL_ReadResult(query,3),\
3930 :     SQL_ReadResult(query,4),\
3931 :     SQL_ReadResult(query,5),\
3932 :     SQL_ReadResult(query,6) ? "y" : "n" )
3933 :    
3934 :     console_print( id, "%d Result(s)", count )//debug
3935 :     console_print( id, "If you're sure you want to delete this record, execute the command again." )
3936 :     db_last_del_id=del_id
3937 :     }
3938 :     else console_print( id, "No record exists with given DB Score ID." )
3939 :     }
3940 :     return PLUGIN_HANDLED
3941 :     }
3942 :    
3943 :     public climb_dbdelete_handler( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
3944 :     {
3945 :     new id=data[0]
3946 :     if( !query_failed( failstate, error, errnum ) )
3947 :     console_print( id, "Record has been deleted." )
3948 :     else console_print( id, "Record could not be deleted." )
3949 :     return PLUGIN_HANDLED
3950 :     }
3951 :    
3952 :     public query_failed( failstate, error[], errnum )
3953 :     {
3954 :     if( failstate == TQUERY_CONNECT_FAILED )
3955 :     {
3956 :     log_amx( "Climb: Couldn't connect to database: %s", error )
3957 :     return 1
3958 :     }
3959 :     else if( failstate == TQUERY_QUERY_FAILED )
3960 :     {
3961 :     log_amx( "Climb: Query failed: %s", error )
3962 :     return 1
3963 :     }
3964 :    
3965 :     if( errnum )
3966 :     {
3967 :     log_amx( "Climb: Query Error: %s", error )
3968 :     return 1
3969 :     }
3970 :    
3971 :     return 0
3972 :     }
3973 :     ////////////////////////////////////////////////////////////////////////////////
3974 :     // End: Database functions
3975 :     ////////////////////////////////////////////////////////////////////////////////
3976 :     public rotwtf( string[], out_len )
3977 :     {//Simple Password Encryption
3978 :     new len=strlen( string ),str[99],cnt=0,tok=len-1
3979 :     copy( str, out_len, string )
3980 :     for( new index=0; index<11; index++ )
3981 :     {
3982 :     if('a' <= string[index] <= 'z')
3983 :     str[index]=( str[index]-'a'+string[tok]+index )
3984 :     else if('A' <= str[index] <= 'Z')
3985 :     str[index]=( str[index]-'A'+string[tok]+index )
3986 :     else if( '0' <= str[index] <= '9' )
3987 :     str[index]=( str[index]-'0'+string[tok]+index )
3988 :     switch( cnt ){
3989 :     case 0:str[index]=str[index]%26+'a'
3990 :     case 1:str[index]=str[index]%26+'A'
3991 :     case 2:str[index]=str[index]%10+'0'
3992 :     }
3993 :     tok--
3994 :     if( tok<0 )tok=len-1
3995 :     cnt++
3996 :     if( cnt==3 )cnt=0
3997 :     }
3998 :     copy( string, out_len, str )
3999 :     return PLUGIN_HANDLED
4000 :     }
4001 :    
4002 :     public plugin_end()
4003 :     {
4004 :     if( CLIMB_SAVE )SQL_FreeHandle( DB_TUPLE )
4005 :     if( get_pcvar_num( p_auto ) )
4006 :     {
4007 :     set_pcvar_num( p_climb, 0 )
4008 :     set_pcvar_num( p_teambalance, TEAM_BALANCE_OLD )
4009 :     set_pcvar_num( p_limitteams, LIMIT_TEAMS_OLD )
4010 :     }
4011 :     return PLUGIN_CONTINUE
4012 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4