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

Annotation of /climb.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (view) (download)

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

Contact
ViewVC Help
Powered by ViewVC 1.0.4