├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── gamedata └── smlib_colors.games.txt └── scripting ├── include ├── smlib.inc └── smlib │ ├── arrays.inc │ ├── clients.inc │ ├── colors.inc │ ├── concommands.inc │ ├── convars.inc │ ├── crypt.inc │ ├── debug.inc │ ├── dynarrays.inc │ ├── edicts.inc │ ├── effects.inc │ ├── entities.inc │ ├── files.inc │ ├── game.inc │ ├── general.inc │ ├── math.inc │ ├── menus.inc │ ├── server.inc │ ├── sql.inc │ ├── strings.inc │ ├── teams.inc │ ├── vehicles.inc │ ├── weapons.inc │ └── world.inc └── tests ├── test_colors.sp ├── test_compile-all.sh └── test_compile-all.sp /.gitignore: -------------------------------------------------------------------------------- 1 | *.smx 2 | 3 | ## generic files to ignore 4 | *~ 5 | *.lock 6 | *.DS_Store 7 | *.swp 8 | *.out 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | env: 4 | - SMVERSION=1.6 5 | - SMVERSION=1.7 6 | - SMVERSION=1.8 7 | 8 | matrix: 9 | fast_finish: true 10 | allow_failures: 11 | - env: SMVERSION=1.7 12 | - env: SMVERSION=1.8 13 | 14 | before_install: 15 | - sudo apt-get update 16 | - sudo apt-get install gcc-multilib lib32stdc++6 lib32z1 lynx 17 | 18 | script: 19 | - ./scripting/tests/test_compile-all.sh 20 | 21 | notifications: 22 | email: false 23 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution guidelines 2 | 3 | 4 | **Index of contents** 5 | * What chances do I have to add new code to smlib ? 6 | * Through pull requests 7 | * Write/Push access (direct committing) 8 | * General rules 9 | * Checklist before submitting pull requests / committing new code 10 | * Consistent code style 11 | * smlib code style example 12 | 13 | ## What chances do I have to add new code to smlib ? 14 | 15 | ### Through pull requests 16 | 17 | If you have a Github account, you can make one. 18 | This will require you to fork this project to your own user first, Do/commit the changes there and create a new pull request from the master branch of your smlib repository to here. 19 | 20 | [Here is a more detailled description on how to do it.](https://help.github.com/articles/using-pull-requests) 21 | 22 | Also: read the rest of this document first. 23 | 24 | ### Write/Push access (direct committing) 25 | 26 | We give people push access who have already done some successful pull requests. 27 | 28 | [Create an issue](https://github.com/bcserv/smlib/issues/new), if you feel you would be a good team member/contributor. 29 | 30 | ## General rules 31 | 32 | * Only add game-independent code (try to find the lowest common denominator between games), if a feature is only supported by one game, create a new file/namespace for this specific game 33 | * Use a (to this project) consistent code style 34 | * Don't add code that uses virtual offsets/function signatures/symbols (we don't want to maintain them) 35 | * Write long, self-explaining function/variable names. 36 | * If you add code from other people, don't forget to mention that in a function annotation or comment 37 | * Document all functions with annotations (have a look at other functions) 38 | * Comment your code (That's also useful for yourself, you will forget about things after some time) 39 | * Add used function `#include` dependencies at top to ensure single smlib include files can be included in plugins without having to include the whole `` 40 | * If you are working on a bigger feature in smlib, that will require multiple commits to be made, consider creating a new feature branch ("feature-yourfeaturename") and make a pull request when you are done to merge it with the master 41 | * Write re-usable, capsulated, readable, clean code 42 | * Don't use the function "ServerCommand", unless you have a really really really good reason to do so. 43 | * Don't add code that messes with the client's settings (ie. console command hacks) 44 | 45 | 46 | ## Checklist before submitting pull requests / committing new code 47 | 48 | * Rules: read? 49 | * Consistent code style 50 | * Documentation written (function annotations, comments) 51 | * Add new functions to test_compile-all.sp to make sure the even compile without warnings. 52 | * Write a summary of what you did into the first commit message line, and more detailed information into the next lines. 53 | * Avoid pushing merge commits (within the same branch), they pollute the histoy. Use "git rebase" to stack commits. [Here](http://randyfay.com/content/simpler-rebasing-avoiding-unintentional-merge-commits) is a good tutorial. 54 | 55 | ## Consistent code style 56 | 57 | * We use tabs for intendation 58 | * We use whitespace for aligning code in-line 59 | * Use long, self-explaining variable/function names 60 | * ALWAYS use `{` `}` brackets 61 | * Don't use abbrevations anywhere in function/variable names etc., except they are well-known (like "HTTP") 62 | * Use newlines to group your code into logical parts 63 | * Write names in [camelCase](https://www.google.at/?q=camelCase) 64 | * Make a line break if the line is already too long (we don't have a specific width) 65 | 66 | ### smlib code style example 67 | ```sourcepawn 68 | /** 69 | * Returns the index for the first occurance of the given value. 70 | * If the value cannot be found, -1 will be returned. 71 | * 72 | * @param hard Set this to true to slap the players hard. 73 | * @return True if the slapping was successful, false otherwise 74 | */ 75 | function SlapAllPlayers(bool:hard=true) 76 | { // Function opening bracket on next line 77 | var var1 = 1; // Variables start with a lower case letter 78 | var anotherVar2 = 2; 79 | 80 | for (new client=1; client <= MaxClients; client++) { // for, while, do, switch etc. brackets on same line 81 | 82 | if () { // if, else brackets on same line 83 | // Some code 84 | } 85 | else { 86 | // Some code 87 | } 88 | } 89 | } 90 | ``` 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **This project is not actively maintained anymore, please fork this** 2 | 3 | # smlib 4 | [![Build Status](https://travis-ci.org/bcserv/smlib.svg)](https://travis-ci.org/bcserv/smlib) 5 | 6 | Function Stock Library for Sourcemod with over 350 functions. 7 | 8 | **URL:** http://www.sourcemodplugins.org/smlib/ 9 | 10 | **Discussion:** https://forums.alliedmods.net/showthread.php?t=148387 11 | 12 | **Contribution guidelines:** [CONTRIBUTING.md](CONTRIBUTING.md) 13 | -------------------------------------------------------------------------------- /gamedata/smlib_colors.games.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * SMLib Colors Definitions (used by smlib/colors.inc) 3 | * http://www.sourcemodplugins.org/pages/smlib/ 4 | * 5 | * Note: This file is only needed if you need to have to override the default color settings 6 | * and doesn't need to be distributed 7 | * The settings below are already hardcoded into smlib. 8 | * 9 | * Valid colors are: 10 | * 11 | * "normal", // Normal 12 | * "orange", // Orange 13 | * "red", // Red 14 | * "redblue", // Red, Blue 15 | * "blue", // Blue 16 | * "bluered", // Blue, Red 17 | * "team", // Team 18 | * "lightgreen", // Light green 19 | * "gray", // GRAy 20 | * "green", // Green 21 | * "olivegreen", // Olive green 22 | * "black" // BLAck 23 | * 24 | * Valid keyvalues are: 25 | * 26 | * color_code Color Code (1 - 8) 27 | * color_alternative Defines the index of alternative color (see the chatColorInfo array in colors.inc) 28 | * color_supported Set to "true" if the color is supported, "false" otherwise. 29 | * color_subjecttype (see ChatColorSubjectType enum in colors.inc, any value higher than 0 defines a team color) 30 | */ 31 | 32 | "Games" 33 | { 34 | /* Default */ 35 | "#default" 36 | { 37 | "Keys" 38 | { 39 | "lightgreen_supported" "false" 40 | "gray_supported" "false" 41 | "black_supported" "false" 42 | } 43 | } 44 | 45 | /* Counter-Strike: Source */ 46 | "cstrike" 47 | { 48 | "Keys" 49 | { 50 | "lightgreen_supported" "true" 51 | "gray_supported" "true" 52 | } 53 | } 54 | 55 | /* Team Fortress 2 */ 56 | "tf" 57 | { 58 | "Keys" 59 | { 60 | "lightgreen_supported" "true" 61 | "gray_supported" "true" 62 | "black_supported" "true" 63 | 64 | "gray_code" "1" 65 | "gray_subjecttype" "-3" 66 | } 67 | } 68 | 69 | /* Half Life 2: Deathmatch */ 70 | "hl2dm" 71 | { 72 | "Keys" 73 | { 74 | "lightgreen_supported" "true" 75 | "gray_supported" "true" 76 | "black_supported" "true" 77 | 78 | "red_subjecttype" "3" 79 | "redblue_subjecttype" "3" 80 | "blue_subjecttype" "2" 81 | "bluered_subjecttype" "2" 82 | } 83 | } 84 | 85 | /* Day of Defeat: Source */ 86 | "dod" 87 | { 88 | "Keys" 89 | { 90 | "lightgreen_supported" "true" 91 | "gray_supported" "true" 92 | "black_supported" "true" 93 | // Team colors are automatically recognized as unsupported if there is no SayText2 94 | } 95 | } 96 | 97 | /* Left 4 Dead */ 98 | "left4dead" 99 | { 100 | "Keys" 101 | { 102 | "lightgreen_supported" "true" 103 | "gray_supported" "false" 104 | 105 | "orange_code" "4" 106 | "green_code" "5" 107 | } 108 | } 109 | 110 | /* Left 4 Dead 2 */ 111 | "left4dead2" 112 | { 113 | "Keys" 114 | { 115 | "lightgreen_supported" "true" 116 | "gray_supported" "true" 117 | 118 | "orange_code" "4" 119 | "green_code" "5" 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /scripting/include/smlib.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_included 2 | #endinput 3 | #endif 4 | #define _smlib_included 5 | 6 | #define SMLIB_VERSION "0.9.7" 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | //#include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | -------------------------------------------------------------------------------- /scripting/include/smlib/arrays.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_array_included 2 | #endinput 3 | #endif 4 | #define _smlib_array_included 5 | 6 | #include 7 | 8 | /** 9 | * Returns the index for the first occurance of the given value. 10 | * If the value cannot be found, -1 will be returned. 11 | * 12 | * @param array Static Array. 13 | * @param size Size of the Array. 14 | * @param value Value to search for. 15 | * @param start Optional: Offset where to start (0 - (size-1)). 16 | * @return Array index, or -1 if the value couldn't be found. 17 | */ 18 | stock Array_FindValue(any:array[], size, any:value, start=0) 19 | { 20 | if (start < 0) { 21 | start = 0; 22 | } 23 | 24 | for (new i=start; i < size; i++) { 25 | 26 | if (array[i] == value) { 27 | return i; 28 | } 29 | } 30 | 31 | return -1; 32 | } 33 | 34 | /** 35 | * Searchs for the first occurance of a string in the array. 36 | * If the value cannot be located, -1 will be returned. 37 | * 38 | * @param array Static Array. 39 | * @param size Size of the Array. 40 | * @param value String to search for. 41 | * @param start Optional: Offset where to start(0 - (size-1)). 42 | * @return Array index, or -1 if the value couldn't be found. 43 | */ 44 | stock Array_FindString(const String:array[][], size, const String:str[], bool:caseSensitive=true, start=0) 45 | { 46 | if (start < 0) { 47 | start = 0; 48 | } 49 | 50 | for (new i=start; i < size; i++) { 51 | 52 | if (StrEqual(array[i], str, caseSensitive)) { 53 | return i; 54 | } 55 | } 56 | 57 | return -1; 58 | } 59 | 60 | /** 61 | * Returns the Index of the Lowest value in the array 62 | * 63 | * @param array Static Array. 64 | * @param size Size of the Array. 65 | * @param start Optional: Offset where to start (0 - (size-1)). 66 | * @return Array index. 67 | */ 68 | stock Array_FindLowestValue(any:array[], size, start=0) 69 | { 70 | if (start < 0) { 71 | start = 0; 72 | } 73 | 74 | new any:value = array[start]; 75 | new any:tempValue; 76 | new x = start; 77 | 78 | for (new i=start; i < size; i++) { 79 | 80 | tempValue = array[i]; 81 | 82 | if (tempValue < value) { 83 | value = tempValue; 84 | x = i; 85 | } 86 | 87 | } 88 | 89 | return x; 90 | } 91 | 92 | /** 93 | * Returns the Index of the Highest value in the array 94 | * 95 | * @param array Static Array. 96 | * @param size Size of the Array. 97 | * @param start Optional: Offset where to start (0 - (size-1)). 98 | * @return Array index. 99 | */ 100 | stock Array_FindHighestValue(any:array[], size, start=0) 101 | { 102 | if (start < 0) { 103 | start = 0; 104 | } 105 | 106 | new any:value = array[start]; 107 | new any:tempValue; 108 | new x = start; 109 | 110 | for (new i=start; i < size; i++) { 111 | 112 | tempValue = array[i]; 113 | 114 | if (tempValue > value) { 115 | value = tempValue; 116 | x = i; 117 | } 118 | 119 | } 120 | 121 | return x; 122 | } 123 | 124 | /** 125 | * Fills an array with a given value in a 1 dimensional static array. 126 | * You can specify the amount of cells to be written. 127 | * 128 | * @param array Static Array. 129 | * @param size Number of cells to write (eg. the array's size) 130 | * @param value Fill value. 131 | * @param start Optional: Offset where to start (0 - (size-1)). 132 | * @noreturn 133 | */ 134 | stock Array_Fill(any:array[], size, any:value, start=0) 135 | { 136 | if (start < 0) { 137 | start = 0; 138 | } 139 | 140 | for (new i=start; i < size; i++) { 141 | array[i] = value; 142 | } 143 | } 144 | 145 | /** 146 | * Copies a 1 dimensional static array. 147 | * 148 | * @param array Static Array to copy from. 149 | * @param newArray New Array to copy to. 150 | * @param size Size of the array (or number of cells to copy) 151 | * @noreturn 152 | */ 153 | stock Array_Copy(const any:array[], any:newArray[], size) 154 | { 155 | for (new i=0; i < size; i++) { 156 | newArray[i] = array[i]; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /scripting/include/smlib/colors.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_colors_included 2 | #endinput 3 | #endif 4 | #define _smlib_colors_included 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define CHATCOLOR_NOSUBJECT -2 11 | #define SMLIB_COLORS_GAMEDATAFILE "smlib_colors.games" 12 | 13 | enum ChatColorSubjectType 14 | { 15 | ChatColorSubjectType_none = -3, 16 | 17 | // Subject/Team colors 18 | ChatColorSubjectType_player = -2, 19 | ChatColorSubjectType_undefined = -1, 20 | ChatColorSubjectType_world = 0 21 | // Anything higher is a specific team 22 | } 23 | 24 | enum ChatColorInfo 25 | { 26 | ChatColorInfo_Code, 27 | ChatColorInfo_Alternative, 28 | bool:ChatColorInfo_Supported, 29 | ChatColorSubjectType:ChatColorInfo_SubjectType 30 | }; 31 | 32 | enum ChatColor 33 | { 34 | ChatColor_Normal, 35 | ChatColor_Orange, 36 | ChatColor_Red, 37 | ChatColor_RedBlue, 38 | ChatColor_Blue, 39 | ChatColor_BlueRed, 40 | ChatColor_Team, 41 | ChatColor_Lightgreen, 42 | ChatColor_Gray, 43 | ChatColor_Green, 44 | ChatColor_Olivegreen, 45 | ChatColor_Black 46 | } 47 | 48 | static String:chatColorTags[][] = { 49 | "N", // Normal 50 | "O", // Orange 51 | "R", // Red 52 | "RB", // Red, Blue 53 | "B", // Blue 54 | "BR", // Blue, Red 55 | "T", // Team 56 | "L", // Light green 57 | "GRA", // GRAy 58 | "G", // Green 59 | "OG", // Olive green 60 | "BLA" // BLAck 61 | }; 62 | 63 | static String:chatColorNames[][] = { 64 | "normal", // Normal 65 | "orange", // Orange 66 | "red", // Red 67 | "redblue", // Red, Blue 68 | "blue", // Blue 69 | "bluered", // Blue, Red 70 | "team", // Team 71 | "lightgreen", // Light green 72 | "gray", // GRAy 73 | "green", // Green 74 | "olivegreen", // Olive green 75 | "black" // BLAck 76 | }; 77 | 78 | static chatColorInfo[][ChatColorInfo] = 79 | { 80 | // Code , alternative , Is Supported? Chat color subject type Color name 81 | { '\x01', -1/* None */ , true, ChatColorSubjectType_none, }, // Normal 82 | { '\x01', 0 /* None */ , true, ChatColorSubjectType_none, }, // Orange 83 | { '\x03', 9 /* Green */ , true, ChatColorSubjectType:2 }, // Red 84 | { '\x03', 4 /* Blue */ , true, ChatColorSubjectType:2 }, // Red, Blue 85 | { '\x03', 9 /* Green */ , true, ChatColorSubjectType:3 }, // Blue 86 | { '\x03', 2 /* Red */ , true, ChatColorSubjectType:3 }, // Blue, Red 87 | { '\x03', 9 /* Green */ , true, ChatColorSubjectType_player }, // Team 88 | { '\x03', 9 /* Green */ , true, ChatColorSubjectType_world }, // Light green 89 | { '\x03', 9 /* Green */ , true, ChatColorSubjectType_undefined},// GRAy 90 | { '\x04', 0 /* Normal*/ , true, ChatColorSubjectType_none }, // Green 91 | { '\x05', 9 /* Green */ , true, ChatColorSubjectType_none }, // Olive green 92 | { '\x06', 9 /* Green */ , true, ChatColorSubjectType_none } // BLAck 93 | }; 94 | 95 | static bool:checkTeamPlay = false; 96 | static Handle:mp_teamplay = INVALID_HANDLE; 97 | static bool:isSayText2_supported = true; 98 | static chatSubject = CHATCOLOR_NOSUBJECT; 99 | 100 | /** 101 | * Sets the subject (a client) for the chat color parser. 102 | * Call this before Color_ParseChatText() or Client_PrintToChat(). 103 | * 104 | * @param client Client Index/Subject 105 | * @noreturn 106 | */ 107 | stock Color_ChatSetSubject(client) 108 | { 109 | chatSubject = client; 110 | } 111 | 112 | /** 113 | * Gets the subject used for the chat color parser. 114 | * 115 | * @return Client Index/Subject, or CHATCOLOR_NOSUBJECT if none 116 | */ 117 | stock Color_ChatGetSubject() 118 | { 119 | return chatSubject; 120 | } 121 | 122 | /** 123 | * Clears the subject used for the chat color parser. 124 | * Call this after Color_ParseChatText(). 125 | * 126 | * @noreturn 127 | */ 128 | stock Color_ChatClearSubject() 129 | { 130 | chatSubject = CHATCOLOR_NOSUBJECT; 131 | } 132 | 133 | /** 134 | * Parses a chat string and converts all color tags to color codes. 135 | * This is a very powerful function that works recursively over the color information 136 | * table. The support colors are hardcoded, but can be overriden for each game by 137 | * creating the file gamedata/smlib_colors.games.txt. 138 | * 139 | * @param str Chat String 140 | * @param subject Output Buffer 141 | * @param size Output Buffer size 142 | * @return Returns a value for the subject 143 | */ 144 | stock Color_ParseChatText(const String:str[], String:buffer[], size) 145 | { 146 | new 147 | bool:inBracket = false, 148 | x = 0, x_buf = 0, x_tag = 0, 149 | subject = CHATCOLOR_NOSUBJECT; 150 | 151 | decl 152 | String:sTag[10] = "", // This should be able to hold "\x08RRGGBBAA"\0 153 | String:colorCode[10] = "", // This should be able to hold "\x08RRGGBBAA"\0 154 | String:currentColor[10] = "\x01"; // Initialize with normal color 155 | 156 | size--; 157 | 158 | // Every chat message has to start with a 159 | // color code, otherwise it will ignore all colors. 160 | buffer[x_buf++] = '\x01'; 161 | 162 | while (str[x] != '\0') { 163 | 164 | if (size == x_buf) { 165 | break; 166 | } 167 | 168 | new character = str[x++]; 169 | 170 | if (inBracket) { 171 | // We allow up to 9 characters in the tag (#RRGGBBAA) 172 | if (character == '}' || x_tag > 9) { 173 | inBracket = false; 174 | sTag[x_tag] = '\0'; 175 | x_tag = 0; 176 | 177 | if (character == '}') { 178 | Color_TagToCode(sTag, subject, colorCode); 179 | 180 | if (colorCode[0] == '\0') { 181 | // We got an unknown tag, ignore this 182 | // and forward it to the buffer. 183 | 184 | // Terminate buffer with \0 so Format can handle it. 185 | buffer[x_buf] = '\0'; 186 | x_buf = Format(buffer, size, "%s{%s}", buffer, sTag); 187 | 188 | // We 'r done here 189 | continue; 190 | } 191 | else if (!StrEqual(colorCode, currentColor)) { 192 | // If we are already using this color, 193 | // we don't need to set it again. 194 | 195 | // Write the color code to our buffer. 196 | // x_buf will be increased by the number of cells written. 197 | x_buf += strcopy(buffer[x_buf], size - x_buf, colorCode); 198 | 199 | // Remember the current color. 200 | strcopy(currentColor, sizeof(currentColor), colorCode); 201 | } 202 | } 203 | else { 204 | // If the tag character limit exceeds 9, 205 | // we have to do something. 206 | 207 | // Terminate buffer with \0 so Format can handle it. 208 | buffer[x_buf] = '\0'; 209 | x_buf = Format(buffer, size, "%s{%s%c", buffer, sTag, character); 210 | } 211 | } 212 | else if (character == '{' && !x_tag) { 213 | buffer[x_buf++] = '{'; 214 | inBracket = false; 215 | } 216 | else { 217 | sTag[x_tag++] = character; 218 | } 219 | } 220 | else if (character == '{') { 221 | inBracket = true; 222 | } 223 | else { 224 | buffer[x_buf++] = character; 225 | } 226 | } 227 | 228 | // Write remaining text to the buffer, 229 | // if we have been inside brackets. 230 | if (inBracket) { 231 | buffer[x_buf] = '\0'; 232 | x_buf = Format(buffer, size, "%s{%s", buffer, sTag); 233 | } 234 | 235 | buffer[x_buf] = '\0'; 236 | 237 | return subject; 238 | } 239 | 240 | /** 241 | * Converts a chat color tag to its code character. 242 | * 243 | * @param tag Color Tag String. 244 | * @param subject Subject variable to pass 245 | * @param result The result as character sequence (string). This will be \0 if the tag is unkown. 246 | * @noreturn 247 | */ 248 | stock Color_TagToCode(const String:tag[], &subject=-1, String:result[10]) 249 | { 250 | // Check if the tag starts with a '#'. 251 | // We will handle it has RGB(A)-color code then. 252 | if (tag[0] == '#') { 253 | new length_tag = strlen(tag); 254 | switch (length_tag - 1) { 255 | // #RGB -> \07RRGGBB 256 | case 3: { 257 | FormatEx( 258 | result, sizeof(result), "\x07%c%c%c%c%c%c", 259 | tag[1], tag[1], tag[2], tag[2], tag[3], tag[3] 260 | ); 261 | } 262 | // #RGBA -> \08RRGGBBAA 263 | case 4: { 264 | FormatEx( 265 | result, sizeof(result), "\x08%c%c%c%c%c%c%c%c", 266 | tag[1], tag[1], tag[2], tag[2], tag[3], tag[3], tag[4], tag[4] 267 | ); 268 | } 269 | // #RRGGBB -> \07RRGGBB 270 | case 6: { 271 | FormatEx(result, sizeof(result), "\x07%s", tag[1]); 272 | } 273 | // #RRGGBBAA -> \08RRGGBBAA 274 | case 8: { 275 | FormatEx(result, sizeof(result), "\x08%s", tag[1]); 276 | } 277 | default: { 278 | result[0] = '\0'; 279 | } 280 | } 281 | 282 | return; 283 | } 284 | else { 285 | // Try to handle this string as color name 286 | new n = Array_FindString(chatColorTags, sizeof(chatColorTags), tag); 287 | 288 | // Check if this tag is invalid 289 | if (n == -1) { 290 | result[0] = '\0'; 291 | return; 292 | } 293 | 294 | // Check if the color is actually supported 'n stuff. 295 | Color_GetChatColorInfo(n, subject); 296 | 297 | result[0] = chatColorInfo[n][ChatColorInfo_Code]; 298 | result[1] = '\0'; 299 | } 300 | 301 | return; 302 | } 303 | 304 | /** 305 | * Strips all color control characters in a string. 306 | * The Output buffer can be the same as the input buffer. 307 | * Original code by Psychonic, thanks. 308 | * 309 | * @param input Input String. 310 | * @param output Output String. 311 | * @param size Max Size of the Output string 312 | * @noreturn 313 | */ 314 | stock Color_StripFromChatText(const String:input[], String:output[], size) 315 | { 316 | new x = 0; 317 | for (new i=0; input[i] != '\0'; i++) { 318 | 319 | if (x+1 == size) { 320 | break; 321 | } 322 | 323 | new character = input[i]; 324 | 325 | if (character > 0x08) { 326 | output[x++] = character; 327 | } 328 | } 329 | 330 | output[x] = '\0'; 331 | } 332 | 333 | /** 334 | * Checks the gamename and sets default values. 335 | * For example if some colors are supported, or 336 | * if a game uses another color code for a specific color. 337 | * All those hardcoded default values can be overriden in 338 | * smlib's color gamedata file. 339 | * 340 | * @noreturn 341 | */ 342 | static stock Color_ChatInitialize() 343 | { 344 | static initialized = false; 345 | 346 | if (initialized) { 347 | return; 348 | } 349 | 350 | initialized = true; 351 | 352 | decl String:gameFolderName[32]; 353 | GetGameFolderName(gameFolderName, sizeof(gameFolderName)); 354 | 355 | chatColorInfo[ChatColor_Black][ChatColorInfo_Supported] = false; 356 | 357 | if (strncmp(gameFolderName, "left4dead", 9, false) != 0 && 358 | !StrEqual(gameFolderName, "cstrike", false) && 359 | !StrEqual(gameFolderName, "tf", false)) 360 | { 361 | chatColorInfo[ChatColor_Lightgreen][ChatColorInfo_Supported]= false; 362 | chatColorInfo[ChatColor_Gray][ChatColorInfo_Supported] = false; 363 | } 364 | 365 | if (StrEqual(gameFolderName, "tf", false)) { 366 | chatColorInfo[ChatColor_Black][ChatColorInfo_Supported] = true; 367 | 368 | chatColorInfo[ChatColor_Gray][ChatColorInfo_Code] = '\x01'; 369 | chatColorInfo[ChatColor_Gray][ChatColorInfo_SubjectType] = ChatColorSubjectType_none; 370 | } 371 | else if (strncmp(gameFolderName, "left4dead", 9, false) == 0) { 372 | chatColorInfo[ChatColor_Red][ChatColorInfo_SubjectType] = ChatColorSubjectType:3; 373 | chatColorInfo[ChatColor_RedBlue][ChatColorInfo_SubjectType] = ChatColorSubjectType:3; 374 | chatColorInfo[ChatColor_Blue][ChatColorInfo_SubjectType] = ChatColorSubjectType:2; 375 | chatColorInfo[ChatColor_BlueRed][ChatColorInfo_SubjectType] = ChatColorSubjectType:2; 376 | 377 | chatColorInfo[ChatColor_Orange][ChatColorInfo_Code] = '\x04'; 378 | chatColorInfo[ChatColor_Green][ChatColorInfo_Code] = '\x05'; 379 | } 380 | else if (StrEqual(gameFolderName, "hl2mp", false)) { 381 | chatColorInfo[ChatColor_Red][ChatColorInfo_SubjectType] = ChatColorSubjectType:3; 382 | chatColorInfo[ChatColor_RedBlue][ChatColorInfo_SubjectType] = ChatColorSubjectType:3; 383 | chatColorInfo[ChatColor_Blue][ChatColorInfo_SubjectType] = ChatColorSubjectType:2; 384 | chatColorInfo[ChatColor_BlueRed][ChatColorInfo_SubjectType] = ChatColorSubjectType:2; 385 | chatColorInfo[ChatColor_Black][ChatColorInfo_Supported] = true; 386 | 387 | checkTeamPlay = true; 388 | } 389 | else if (StrEqual(gameFolderName, "dod", false)) { 390 | chatColorInfo[ChatColor_Gray][ChatColorInfo_Code] = '\x01'; 391 | chatColorInfo[ChatColor_Gray][ChatColorInfo_SubjectType] = ChatColorSubjectType_none; 392 | 393 | chatColorInfo[ChatColor_Black][ChatColorInfo_Supported] = true; 394 | chatColorInfo[ChatColor_Orange][ChatColorInfo_Supported] = false; 395 | } 396 | 397 | if (GetUserMessageId("SayText2") == INVALID_MESSAGE_ID) { 398 | isSayText2_supported = false; 399 | } 400 | 401 | decl String:path_gamedata[PLATFORM_MAX_PATH]; 402 | BuildPath(Path_SM, path_gamedata, sizeof(path_gamedata), "gamedata/%s.txt", SMLIB_COLORS_GAMEDATAFILE); 403 | 404 | if (FileExists(path_gamedata)) { 405 | new Handle:gamedata = INVALID_HANDLE; 406 | 407 | if ((gamedata = LoadGameConfigFile(SMLIB_COLORS_GAMEDATAFILE)) != INVALID_HANDLE) { 408 | 409 | decl String:keyName[32], String:buffer[6]; 410 | 411 | for (new i=0; i < sizeof(chatColorNames); i++) { 412 | 413 | Format(keyName, sizeof(keyName), "%s_code", chatColorNames[i]); 414 | if (GameConfGetKeyValue(gamedata, keyName, buffer, sizeof(buffer))) { 415 | chatColorInfo[i][ChatColorInfo_Code] = StringToInt(buffer); 416 | } 417 | 418 | Format(keyName, sizeof(keyName), "%s_alternative", chatColorNames[i]); 419 | if (GameConfGetKeyValue(gamedata, keyName, buffer, sizeof(buffer))) { 420 | chatColorInfo[i][ChatColorInfo_Alternative] = buffer[0]; 421 | } 422 | 423 | Format(keyName, sizeof(keyName), "%s_supported", chatColorNames[i]); 424 | if (GameConfGetKeyValue(gamedata, keyName, buffer, sizeof(buffer))) { 425 | chatColorInfo[i][ChatColorInfo_Supported] = StrEqual(buffer, "true"); 426 | } 427 | 428 | Format(keyName, sizeof(keyName), "%s_subjecttype", chatColorNames[i]); 429 | if (GameConfGetKeyValue(gamedata, keyName, buffer, sizeof(buffer))) { 430 | chatColorInfo[i][ChatColorInfo_SubjectType] = ChatColorSubjectType:StringToInt(buffer); 431 | } 432 | } 433 | 434 | if (GameConfGetKeyValue(gamedata, "checkteamplay", buffer, sizeof(buffer))) { 435 | checkTeamPlay = StrEqual(buffer, "true"); 436 | } 437 | 438 | CloseHandle(gamedata); 439 | } 440 | } 441 | 442 | mp_teamplay = FindConVar("mp_teamplay"); 443 | } 444 | 445 | /** 446 | * Checks if the passed color index is actually supported 447 | * for the current game. If not, the index will be overwritten 448 | * The color resolving works recursively until a valid color is found. 449 | * 450 | * @param index 451 | * @param subject A client index or CHATCOLOR_NOSUBJECT 452 | * @noreturn 453 | */ 454 | static stock Color_GetChatColorInfo(&index, &subject=CHATCOLOR_NOSUBJECT) 455 | { 456 | Color_ChatInitialize(); 457 | 458 | if (index == -1) { 459 | index = 0; 460 | } 461 | 462 | while (!chatColorInfo[index][ChatColorInfo_Supported]) { 463 | 464 | new alternative = chatColorInfo[index][ChatColorInfo_Alternative]; 465 | 466 | if (alternative == -1) { 467 | index = 0; 468 | break; 469 | } 470 | 471 | index = alternative; 472 | } 473 | 474 | if (index == -1) { 475 | index = 0; 476 | } 477 | 478 | new newSubject = CHATCOLOR_NOSUBJECT; 479 | new ChatColorSubjectType:type = chatColorInfo[index][ChatColorInfo_SubjectType]; 480 | 481 | switch (type) { 482 | 483 | case ChatColorSubjectType_none: { 484 | } 485 | case ChatColorSubjectType_player: { 486 | newSubject = chatSubject; 487 | } 488 | case ChatColorSubjectType_undefined: { 489 | newSubject = -1; 490 | } 491 | case ChatColorSubjectType_world: { 492 | newSubject = 0; 493 | } 494 | default: { 495 | 496 | if (!checkTeamPlay || GetConVarBool(mp_teamplay)) { 497 | 498 | if (subject > 0 && subject <= MaxClients) { 499 | 500 | if (GetClientTeam(subject) == _:type) { 501 | newSubject = subject; 502 | } 503 | } 504 | else if (subject == CHATCOLOR_NOSUBJECT) { 505 | new client = Team_GetAnyClient(_:type); 506 | 507 | if (client != -1) { 508 | newSubject = client; 509 | } 510 | } 511 | } 512 | } 513 | } 514 | 515 | if (type > ChatColorSubjectType_none && 516 | ((subject != CHATCOLOR_NOSUBJECT && subject != newSubject) || newSubject == CHATCOLOR_NOSUBJECT || !isSayText2_supported)) 517 | { 518 | index = chatColorInfo[index][ChatColorInfo_Alternative]; 519 | newSubject = Color_GetChatColorInfo(index, subject); 520 | } 521 | 522 | // Only set the subject if there is no subject set already. 523 | if (subject == CHATCOLOR_NOSUBJECT) { 524 | subject = newSubject; 525 | } 526 | 527 | return newSubject; 528 | } 529 | -------------------------------------------------------------------------------- /scripting/include/smlib/concommands.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_concommands_included 2 | #endinput 3 | #endif 4 | #define _smlib_concommands_included 5 | 6 | #include 7 | #include 8 | 9 | /** 10 | * Checks if a ConCommand has one or more flags set. 11 | * 12 | * @param command ConCommand name. 13 | * @param flags Flags to check. 14 | * @return True if flags are set, false otherwise. 15 | */ 16 | stock bool:ConCommand_HasFlags(const String:command[], const flags) 17 | { 18 | return bool:(GetCommandFlags(command) & flags); 19 | } 20 | 21 | /** 22 | * Adds one or more flags to a ConCommand. 23 | * 24 | * @param command ConCommand name. 25 | * @param flags Flags to add. 26 | * @noreturn 27 | */ 28 | stock ConCommand_AddFlags(const String:command[], const flags) 29 | { 30 | new newFlags = GetCommandFlags(command); 31 | newFlags |= flags; 32 | SetCommandFlags(command, newFlags); 33 | } 34 | 35 | /** 36 | * Removes one ore more flags from a ConCommand. 37 | * 38 | * @param command ConCommand name. 39 | * @param flags Flags to remove 40 | * @noreturn 41 | */ 42 | stock ConCommand_RemoveFlags(const String:command[], const flags) 43 | { 44 | new newFlags = GetCommandFlags(command); 45 | newFlags &= ~flags; 46 | SetCommandFlags(command, newFlags); 47 | } 48 | -------------------------------------------------------------------------------- /scripting/include/smlib/convars.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_convars_included 2 | #endinput 3 | #endif 4 | #define _smlib_convars_included 5 | 6 | #include 7 | 8 | /** 9 | * Checks if a ConVar has one or more flags set. 10 | * 11 | * @param convar ConVar Handle. 12 | * @param flags Flags to check. 13 | * @return True if flags are set, false otherwise. 14 | */ 15 | stock bool:Convar_HasFlags(Handle:convar, flags) 16 | { 17 | return bool:(GetConVarFlags(convar) & flags); 18 | } 19 | 20 | /** 21 | * Adds one or more flags to a ConVar. 22 | * 23 | * @param convar ConVar Handle. 24 | * @param flags Flags to add. 25 | * @noreturn 26 | */ 27 | stock Convar_AddFlags(Handle:convar, flags) 28 | { 29 | new newFlags = GetConVarFlags(convar); 30 | newFlags |= flags; 31 | SetConVarFlags(convar, newFlags); 32 | } 33 | 34 | /** 35 | * Removes one ore more flags from a ConVar. 36 | * 37 | * @param convar ConVar Handle. 38 | * @param flags Flags to remove 39 | * @noreturn 40 | */ 41 | stock Convar_RemoveFlags(Handle:convar, flags) 42 | { 43 | new newFlags = GetConVarFlags(convar); 44 | newFlags &= ~flags; 45 | SetConVarFlags(convar, newFlags); 46 | } 47 | 48 | /** 49 | * Checks if a String is a valid ConVar or 50 | * Console Command name. 51 | * 52 | * @param name String Name. 53 | * @return True if the name specified is a valid ConVar or console command name, false otherwise. 54 | */ 55 | stock bool:Convar_IsValidName(const String:name[]) 56 | { 57 | if (name[0] == '\0') { 58 | return false; 59 | } 60 | 61 | new n=0; 62 | while (name[n] != '\0') { 63 | 64 | if (!IsValidConVarChar(name[n])) { 65 | return false; 66 | } 67 | 68 | n++; 69 | } 70 | 71 | return true; 72 | } 73 | -------------------------------------------------------------------------------- /scripting/include/smlib/crypt.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_crypt_included 2 | #endinput 3 | #endif 4 | #define _smlib_crypt_included 5 | 6 | #include 7 | 8 | /********************************************************************************** 9 | * 10 | * Base64 Encoding/Decoding Functions 11 | * All Credits to to SirLamer & ScriptCoderPro 12 | * Taken from http://forums.alliedmods.net/showthread.php?t=101764 13 | * 14 | ***********************************************************************************/ 15 | 16 | // The Base64 encoding table 17 | static const String:base64_sTable[] = 18 | // 0000000000111111111122222222223333333333444444444455555555556666 19 | // 0123456789012345678901234567890123456789012345678901234567890123 20 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 21 | 22 | // The Base64 decoding table 23 | static const base64_decodeTable[] = { 24 | // 0 1 2 3 4 5 6 7 8 9 25 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 9 26 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10 - 19 27 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20 - 29 28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 30 - 39 29 | 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, // 40 - 49 30 | 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, // 50 - 59 31 | 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, // 60 - 69 32 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 70 - 79 33 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 80 - 89 34 | 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, // 90 - 99 35 | 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // 100 - 109 36 | 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, // 110 - 119 37 | 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, // 120 - 129 38 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 130 - 139 39 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 140 - 149 40 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 150 - 159 41 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160 - 169 42 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170 - 179 43 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 180 - 189 44 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 190 - 199 45 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 200 - 209 46 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 210 - 219 47 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 220 - 229 48 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 230 - 239 49 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 240 - 249 50 | 0, 0, 0, 0, 0, 0 // 250 - 256 51 | }; 52 | 53 | /* 54 | * For some reason the standard demands a string in 24-bit (3 character) intervals. 55 | * This fill character is used to identify unused bytes at the end of the string. 56 | */ 57 | static const base64_cFillChar = '='; 58 | 59 | // The conversion characters between the standard and URL-compliance Base64 protocols 60 | static const String:base64_mime_chars[] = "+/="; 61 | static const String:base64_url_chars[] = "-_."; 62 | 63 | /* 64 | * Encodes a string or binary data into Base64 65 | * 66 | * @param sString The input string or binary data to be encoded. 67 | * @param sResult The storage buffer for the Base64-encoded result. 68 | * @param len The maximum length of the storage buffer, in characters/bytes. 69 | * @param sourcelen (optional): The number of characters or length in bytes to be read from the input source. 70 | * This is not needed for a text string, but is important for binary data since there is no end-of-line character. 71 | * @return The length of the written Base64 string, in bytes. 72 | */ 73 | stock Crypt_Base64Encode(const String:sString[], String:sResult[], len, sourcelen=0) 74 | { 75 | new nLength; // The string length to be read from the input 76 | new resPos; // The string position in the result buffer 77 | 78 | // If the read length was specified, use it; otherwise, pull the string length from the input. 79 | if (sourcelen > 0) { 80 | nLength = sourcelen; 81 | } 82 | else { 83 | nLength = strlen(sString); 84 | } 85 | 86 | // Loop through and generate the Base64 encoded string 87 | // NOTE: This performs the standard encoding process. Do not manipulate the logic within this loop. 88 | for (new nPos = 0; nPos < nLength; nPos++) { 89 | new cCode; 90 | 91 | cCode = (sString[nPos] >> 2) & 0x3f; 92 | 93 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", base64_sTable[cCode]); 94 | 95 | cCode = (sString[nPos] << 4) & 0x3f; 96 | if (++nPos < nLength) { 97 | cCode |= (sString[nPos] >> 4) & 0x0f; 98 | } 99 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", base64_sTable[cCode]); 100 | 101 | if ( nPos < nLength ) { 102 | cCode = (sString[nPos] << 2) & 0x3f; 103 | if (++nPos < nLength) { 104 | cCode |= (sString[nPos] >> 6) & 0x03; 105 | } 106 | 107 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", base64_sTable[cCode]); 108 | } 109 | else { 110 | nPos++; 111 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", base64_cFillChar); 112 | } 113 | 114 | if (nPos < nLength) { 115 | cCode = sString[nPos] & 0x3f; 116 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", base64_sTable[cCode]); 117 | } 118 | else { 119 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", base64_cFillChar); 120 | } 121 | } 122 | 123 | return resPos; 124 | } 125 | 126 | 127 | /* 128 | * Decodes a Base64 string. 129 | * 130 | * @param sString The input string in compliant Base64 format to be decoded. 131 | * @param sResult The storage buffer for the decoded text strihg or binary data. 132 | * @param len The maximum length of the storage buffer, in characters/bytes. 133 | * @return The length of the decoded data, in bytes. 134 | */ 135 | stock Crypt_Base64Decode(const String:sString[], String:sResult[], len) 136 | { 137 | new nLength = strlen(sString); // The string length to be read from the input 138 | new resPos; // The string position in the result buffer 139 | 140 | // Loop through and generate the Base64 encoded string 141 | // NOTE: This performs the standard encoding process. Do not manipulate the logic within this loop. 142 | for (new nPos = 0; nPos < nLength; nPos++) { 143 | 144 | new c, c1; 145 | 146 | c = base64_decodeTable[sString[nPos++]]; 147 | c1 = base64_decodeTable[sString[nPos]]; 148 | 149 | c = (c << 2) | ((c1 >> 4) & 0x3); 150 | 151 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", c); 152 | 153 | if (++nPos < nLength) { 154 | 155 | c = sString[nPos]; 156 | 157 | if (c == base64_cFillChar) 158 | break; 159 | 160 | c = base64_decodeTable[sString[nPos]]; 161 | c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf); 162 | 163 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", c1); 164 | } 165 | 166 | if (++nPos < nLength) { 167 | 168 | c1 = sString[nPos]; 169 | 170 | if (c1 == base64_cFillChar) 171 | break; 172 | 173 | c1 = base64_decodeTable[sString[nPos]]; 174 | c = ((c << 6) & 0xc0) | c1; 175 | 176 | resPos += FormatEx(sResult[resPos], len - resPos, "%c", c); 177 | } 178 | } 179 | 180 | return resPos; 181 | } 182 | 183 | 184 | /* 185 | * Converts a standards-compliant Base64 string to the commonly accepted URL-compliant alternative. 186 | * Note: The result will be the same length as the input string as long as the output buffer is large enough. 187 | * 188 | * @param sString The standards-compliant Base64 input string to converted. 189 | * @param sResult The storage buffer for the URL-compliant result. 190 | * @param len The maximum length of the storage buffer in characters/bytes. 191 | * @return Number of cells written. 192 | */ 193 | stock Crypt_Base64MimeToUrl(const String:sString[], String:sResult[], len) 194 | { 195 | new chars_len = sizeof(base64_mime_chars); // Length of the two standards vs. URL character lists 196 | new nLength; // The string length to be read from the input 197 | new temp_char; // Buffer character 198 | 199 | nLength = strlen(sString); 200 | 201 | new String:sTemp[nLength+1]; // Buffer string 202 | 203 | // Loop through string 204 | for (new i = 0; i < nLength; i++) { 205 | temp_char = sString[i]; 206 | 207 | for (new j = 0; j < chars_len; j++) { 208 | 209 | if(temp_char == base64_mime_chars[j]) { 210 | temp_char = base64_url_chars[j]; 211 | break; 212 | } 213 | } 214 | 215 | sTemp[i] = temp_char; 216 | } 217 | 218 | sTemp[nLength] = '\0'; 219 | 220 | return strcopy(sResult, len, sTemp); 221 | } 222 | 223 | /* 224 | * Base64UrlToMime(String:sResult[], len, const String:sString[], sourcelen) 225 | * Converts a URL-compliant Base64 string to the standards-compliant version. 226 | * Note: The result will be the same length as the input string as long as the output buffer is large enough. 227 | * 228 | * @param sString The URL-compliant Base64 input string to converted. 229 | * @param sResult The storage buffer for the standards-compliant result. 230 | * @param len The maximum length of the storage buffer in characters/bytes. 231 | * @return Number of cells written. 232 | */ 233 | stock Crypt_Base64UrlToMime(const String:sString[], String:sResult[], len) 234 | { 235 | new chars_len = sizeof(base64_mime_chars); // Length of the two standards vs. URL character lists 236 | new nLength; // The string length to be read from the input 237 | new temp_char; // Buffer character 238 | 239 | nLength = strlen(sString); 240 | 241 | new String:sTemp[nLength+1]; // Buffer string 242 | 243 | // Loop through string 244 | for (new i = 0; i < nLength; i++) { 245 | temp_char = sString[i]; 246 | for (new j = 0; j < chars_len; j++) { 247 | if (temp_char == base64_url_chars[j]) { 248 | temp_char = base64_mime_chars[j]; 249 | break; 250 | } 251 | } 252 | 253 | sTemp[i] = temp_char; 254 | } 255 | 256 | sTemp[nLength] = '\0'; 257 | 258 | return strcopy(sResult, len, sTemp); 259 | } 260 | 261 | /********************************************************************************** 262 | * 263 | * MD5 Encoding Functions 264 | * All Credits go to sslice 265 | * RSA Data Security, Inc. MD5 Message Digest Algorithm 266 | * Taken from http://forums.alliedmods.net/showthread.php?t=67683 267 | * 268 | ***********************************************************************************/ 269 | 270 | /* 271 | * Calculate the md5 hash of a string. 272 | * 273 | * @param str Input String 274 | * @param output Output String Buffer 275 | * @param maxlen Size of the Output String Buffer 276 | * @noreturn 277 | */ 278 | stock Crypt_MD5(const String:str[], String:output[], maxlen) 279 | { 280 | decl x[2]; 281 | decl buf[4]; 282 | decl input[64]; 283 | new i, ii; 284 | 285 | new len = strlen(str); 286 | 287 | // MD5Init 288 | x[0] = x[1] = 0; 289 | buf[0] = 0x67452301; 290 | buf[1] = 0xefcdab89; 291 | buf[2] = 0x98badcfe; 292 | buf[3] = 0x10325476; 293 | 294 | // MD5Update 295 | new update[16]; 296 | 297 | update[14] = x[0]; 298 | update[15] = x[1]; 299 | 300 | new mdi = (x[0] >>> 3) & 0x3F; 301 | 302 | if ((x[0] + (len << 3)) < x[0]) { 303 | x[1] += 1; 304 | } 305 | 306 | x[0] += len << 3; 307 | x[1] += len >>> 29; 308 | 309 | new c = 0; 310 | while (len--) { 311 | input[mdi] = str[c]; 312 | mdi += 1; 313 | c += 1; 314 | 315 | if (mdi == 0x40) { 316 | 317 | for (i = 0, ii = 0; i < 16; ++i, ii += 4) 318 | { 319 | update[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii]; 320 | } 321 | 322 | // Transform 323 | MD5Transform(buf, update); 324 | 325 | mdi = 0; 326 | } 327 | } 328 | 329 | // MD5Final 330 | new padding[64] = { 331 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 332 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 333 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 334 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 335 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 336 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 337 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 338 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 339 | }; 340 | 341 | new inx[16]; 342 | inx[14] = x[0]; 343 | inx[15] = x[1]; 344 | 345 | mdi = (x[0] >>> 3) & 0x3F; 346 | 347 | len = (mdi < 56) ? (56 - mdi) : (120 - mdi); 348 | update[14] = x[0]; 349 | update[15] = x[1]; 350 | 351 | mdi = (x[0] >>> 3) & 0x3F; 352 | 353 | if ((x[0] + (len << 3)) < x[0]) { 354 | x[1] += 1; 355 | } 356 | 357 | x[0] += len << 3; 358 | x[1] += len >>> 29; 359 | 360 | c = 0; 361 | while (len--) { 362 | input[mdi] = padding[c]; 363 | mdi += 1; 364 | c += 1; 365 | 366 | if (mdi == 0x40) { 367 | 368 | for (i = 0, ii = 0; i < 16; ++i, ii += 4) { 369 | update[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii]; 370 | } 371 | 372 | // Transform 373 | MD5Transform(buf, update); 374 | 375 | mdi = 0; 376 | } 377 | } 378 | 379 | for (i = 0, ii = 0; i < 14; ++i, ii += 4) { 380 | inx[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii]; 381 | } 382 | 383 | MD5Transform(buf, inx); 384 | 385 | new digest[16]; 386 | for (i = 0, ii = 0; i < 4; ++i, ii += 4) { 387 | digest[ii] = (buf[i]) & 0xFF; 388 | digest[ii + 1] = (buf[i] >>> 8) & 0xFF; 389 | digest[ii + 2] = (buf[i] >>> 16) & 0xFF; 390 | digest[ii + 3] = (buf[i] >>> 24) & 0xFF; 391 | } 392 | 393 | FormatEx(output, maxlen, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 394 | digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], digest[6], digest[7], 395 | digest[8], digest[9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]); 396 | } 397 | 398 | static stock MD5Transform_FF(&a, &b, &c, &d, x, s, ac) 399 | { 400 | a += (((b) & (c)) | ((~b) & (d))) + x + ac; 401 | a = (((a) << (s)) | ((a) >>> (32-(s)))); 402 | a += b; 403 | } 404 | 405 | static stock MD5Transform_GG(&a, &b, &c, &d, x, s, ac) 406 | { 407 | a += (((b) & (d)) | ((c) & (~d))) + x + ac; 408 | a = (((a) << (s)) | ((a) >>> (32-(s)))); 409 | a += b; 410 | } 411 | 412 | static stock MD5Transform_HH(&a, &b, &c, &d, x, s, ac) 413 | { 414 | a += ((b) ^ (c) ^ (d)) + x + ac; 415 | a = (((a) << (s)) | ((a) >>> (32-(s)))); 416 | a += b; 417 | } 418 | 419 | static stock MD5Transform_II(&a, &b, &c, &d, x, s, ac) 420 | { 421 | a += ((c) ^ ((b) | (~d))) + x + ac; 422 | a = (((a) << (s)) | ((a) >>> (32-(s)))); 423 | a += b; 424 | } 425 | 426 | static stock MD5Transform(buf[], input[]){ 427 | new a = buf[0]; 428 | new b = buf[1]; 429 | new c = buf[2]; 430 | new d = buf[3]; 431 | 432 | MD5Transform_FF(a, b, c, d, input[0], 7, 0xd76aa478); 433 | MD5Transform_FF(d, a, b, c, input[1], 12, 0xe8c7b756); 434 | MD5Transform_FF(c, d, a, b, input[2], 17, 0x242070db); 435 | MD5Transform_FF(b, c, d, a, input[3], 22, 0xc1bdceee); 436 | MD5Transform_FF(a, b, c, d, input[4], 7, 0xf57c0faf); 437 | MD5Transform_FF(d, a, b, c, input[5], 12, 0x4787c62a); 438 | MD5Transform_FF(c, d, a, b, input[6], 17, 0xa8304613); 439 | MD5Transform_FF(b, c, d, a, input[7], 22, 0xfd469501); 440 | MD5Transform_FF(a, b, c, d, input[8], 7, 0x698098d8); 441 | MD5Transform_FF(d, a, b, c, input[9], 12, 0x8b44f7af); 442 | MD5Transform_FF(c, d, a, b, input[10], 17, 0xffff5bb1); 443 | MD5Transform_FF(b, c, d, a, input[11], 22, 0x895cd7be); 444 | MD5Transform_FF(a, b, c, d, input[12], 7, 0x6b901122); 445 | MD5Transform_FF(d, a, b, c, input[13], 12, 0xfd987193); 446 | MD5Transform_FF(c, d, a, b, input[14], 17, 0xa679438e); 447 | MD5Transform_FF(b, c, d, a, input[15], 22, 0x49b40821); 448 | 449 | MD5Transform_GG(a, b, c, d, input[1], 5, 0xf61e2562); 450 | MD5Transform_GG(d, a, b, c, input[6], 9, 0xc040b340); 451 | MD5Transform_GG(c, d, a, b, input[11], 14, 0x265e5a51); 452 | MD5Transform_GG(b, c, d, a, input[0], 20, 0xe9b6c7aa); 453 | MD5Transform_GG(a, b, c, d, input[5], 5, 0xd62f105d); 454 | MD5Transform_GG(d, a, b, c, input[10], 9, 0x02441453); 455 | MD5Transform_GG(c, d, a, b, input[15], 14, 0xd8a1e681); 456 | MD5Transform_GG(b, c, d, a, input[4], 20, 0xe7d3fbc8); 457 | MD5Transform_GG(a, b, c, d, input[9], 5, 0x21e1cde6); 458 | MD5Transform_GG(d, a, b, c, input[14], 9, 0xc33707d6); 459 | MD5Transform_GG(c, d, a, b, input[3], 14, 0xf4d50d87); 460 | MD5Transform_GG(b, c, d, a, input[8], 20, 0x455a14ed); 461 | MD5Transform_GG(a, b, c, d, input[13], 5, 0xa9e3e905); 462 | MD5Transform_GG(d, a, b, c, input[2], 9, 0xfcefa3f8); 463 | MD5Transform_GG(c, d, a, b, input[7], 14, 0x676f02d9); 464 | MD5Transform_GG(b, c, d, a, input[12], 20, 0x8d2a4c8a); 465 | 466 | MD5Transform_HH(a, b, c, d, input[5], 4, 0xfffa3942); 467 | MD5Transform_HH(d, a, b, c, input[8], 11, 0x8771f681); 468 | MD5Transform_HH(c, d, a, b, input[11], 16, 0x6d9d6122); 469 | MD5Transform_HH(b, c, d, a, input[14], 23, 0xfde5380c); 470 | MD5Transform_HH(a, b, c, d, input[1], 4, 0xa4beea44); 471 | MD5Transform_HH(d, a, b, c, input[4], 11, 0x4bdecfa9); 472 | MD5Transform_HH(c, d, a, b, input[7], 16, 0xf6bb4b60); 473 | MD5Transform_HH(b, c, d, a, input[10], 23, 0xbebfbc70); 474 | MD5Transform_HH(a, b, c, d, input[13], 4, 0x289b7ec6); 475 | MD5Transform_HH(d, a, b, c, input[0], 11, 0xeaa127fa); 476 | MD5Transform_HH(c, d, a, b, input[3], 16, 0xd4ef3085); 477 | MD5Transform_HH(b, c, d, a, input[6], 23, 0x04881d05); 478 | MD5Transform_HH(a, b, c, d, input[9], 4, 0xd9d4d039); 479 | MD5Transform_HH(d, a, b, c, input[12], 11, 0xe6db99e5); 480 | MD5Transform_HH(c, d, a, b, input[15], 16, 0x1fa27cf8); 481 | MD5Transform_HH(b, c, d, a, input[2], 23, 0xc4ac5665); 482 | 483 | MD5Transform_II(a, b, c, d, input[0], 6, 0xf4292244); 484 | MD5Transform_II(d, a, b, c, input[7], 10, 0x432aff97); 485 | MD5Transform_II(c, d, a, b, input[14], 15, 0xab9423a7); 486 | MD5Transform_II(b, c, d, a, input[5], 21, 0xfc93a039); 487 | MD5Transform_II(a, b, c, d, input[12], 6, 0x655b59c3); 488 | MD5Transform_II(d, a, b, c, input[3], 10, 0x8f0ccc92); 489 | MD5Transform_II(c, d, a, b, input[10], 15, 0xffeff47d); 490 | MD5Transform_II(b, c, d, a, input[1], 21, 0x85845dd1); 491 | MD5Transform_II(a, b, c, d, input[8], 6, 0x6fa87e4f); 492 | MD5Transform_II(d, a, b, c, input[15], 10, 0xfe2ce6e0); 493 | MD5Transform_II(c, d, a, b, input[6], 15, 0xa3014314); 494 | MD5Transform_II(b, c, d, a, input[13], 21, 0x4e0811a1); 495 | MD5Transform_II(a, b, c, d, input[4], 6, 0xf7537e82); 496 | MD5Transform_II(d, a, b, c, input[11], 10, 0xbd3af235); 497 | MD5Transform_II(c, d, a, b, input[2], 15, 0x2ad7d2bb); 498 | MD5Transform_II(b, c, d, a, input[9], 21, 0xeb86d391); 499 | 500 | buf[0] += a; 501 | buf[1] += b; 502 | buf[2] += c; 503 | buf[3] += d; 504 | } 505 | 506 | /********************************************************************************** 507 | * 508 | * RC4 Encoding Functions 509 | * All Credits go to SirLamer and Raydan 510 | * Taken from http://forums.alliedmods.net/showthread.php?t=101834 511 | * 512 | ***********************************************************************************/ 513 | 514 | /* 515 | * Encrypts a text string using RC4. 516 | * Note: This function is NOT binary safe. 517 | * Use EncodeRC4Binary to encode binary data. 518 | * 519 | * @param input The source data to be encrypted. 520 | * @param pwd The password/key used to encode and decode the data. 521 | * @param output The encoded result. 522 | * @param maxlen The maximum length of the output buffer. 523 | * 524 | * @noreturn 525 | */ 526 | stock Crypt_RC4Encode(const String:input[], const String:pwd[], String:output[], maxlen) 527 | { 528 | decl pwd_len,str_len,i,j,a,k; 529 | decl key[256]; 530 | decl box[256]; 531 | decl tmp; 532 | 533 | pwd_len = strlen(pwd); 534 | str_len = strlen(input); 535 | 536 | if (pwd_len > 0 && str_len > 0) { 537 | 538 | for (i=0; i < 256; i++) { 539 | key[i] = pwd[i%pwd_len]; 540 | box[i]=i; 541 | } 542 | 543 | i=0; j=0; 544 | 545 | for (; i < 256; i++) { 546 | j = (j + box[i] + key[i]) % 256; 547 | tmp = box[i]; 548 | box[i] = box[j]; 549 | box[j] = tmp; 550 | } 551 | 552 | i=0; j=0; a=0; 553 | 554 | for (; i < str_len; i++) { 555 | a = (a + 1) % 256; 556 | j = (j + box[a]) % 256; 557 | tmp = box[a]; 558 | box[a] = box[j]; 559 | box[j] = tmp; 560 | k = box[((box[a] + box[j]) % 256)]; 561 | FormatEx(output[2*i], maxlen-2*i, "%02x", input[i] ^ k); 562 | } 563 | } 564 | } 565 | 566 | /* 567 | * Encrypts binary data using RC4. 568 | * 569 | * @param input The source data to be encrypted. 570 | * @param str_len The length of the source data. 571 | * @param pwd The password/key used to encode and decode the data. 572 | * @param output The encoded result. 573 | * @param maxlen The maximum length of the output buffer. 574 | * @noreturn 575 | */ 576 | stock Crypt_RC4EncodeBinary(const String:input[], str_len, const String:pwd[], String:output[], maxlen) 577 | { 578 | decl pwd_len,i,j,a,k; 579 | decl key[256]; 580 | decl box[256]; 581 | decl tmp; 582 | 583 | pwd_len = strlen(pwd); 584 | 585 | if (pwd_len > 0 && str_len > 0) { 586 | 587 | for(i=0;i<256;i++) { 588 | key[i] = pwd[i%pwd_len]; 589 | box[i]=i; 590 | } 591 | 592 | i=0; j=0; 593 | 594 | for (; i < 256; i++) { 595 | j = (j + box[i] + key[i]) % 256; 596 | tmp = box[i]; 597 | box[i] = box[j]; 598 | box[j] = tmp; 599 | } 600 | 601 | i=0; j=0; a=0; 602 | 603 | if (str_len+1 > maxlen) { 604 | str_len = maxlen - 1; 605 | } 606 | 607 | for(; i < str_len; i++) { 608 | a = (a + 1) % 256; 609 | j = (j + box[a]) % 256; 610 | tmp = box[a]; 611 | box[a] = box[j]; 612 | box[j] = tmp; 613 | k = box[((box[a] + box[j]) % 256)]; 614 | FormatEx(output[i], maxlen-i, "%c", input[i] ^ k); 615 | } 616 | 617 | /* 618 | * i = number of written bits (remember increment occurs at end of for loop, and THEN it fails the loop condition) 619 | * Since we're working with binary data, the calling function should not depend on the escape 620 | * character, but putting it here prevents crashes in case someone tries to read the data like a string 621 | */ 622 | output[i] = '\0'; 623 | 624 | return i; 625 | } 626 | else { 627 | return -1; 628 | } 629 | } 630 | -------------------------------------------------------------------------------- /scripting/include/smlib/debug.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_debug_included 2 | #endinput 3 | #endif 4 | #define _smlib_debug_included 5 | 6 | #include 7 | 8 | /** 9 | * Prints the values of a static Float-Array to the server console. 10 | * 11 | * @param array Static Float-Array. 12 | * @param size Size of the Array. 13 | * @noreturn 14 | */ 15 | stock Debug_FloatArray(const Float:array[], size=3) 16 | { 17 | new String:output[64] = ""; 18 | 19 | for (new i=0; i < size; ++i) { 20 | 21 | if (i > 0 && i < size) { 22 | StrCat(output, sizeof(output), ", "); 23 | 24 | } 25 | 26 | Format(output, sizeof(output), "%s%f", output, array[i]); 27 | } 28 | 29 | PrintToServer("[DEBUG] Vector[%d] = { %s }", size, output); 30 | } 31 | -------------------------------------------------------------------------------- /scripting/include/smlib/dynarrays.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_dynarray_included 2 | #endinput 3 | #endif 4 | #define _smlib_dynarray_included 5 | 6 | #include 7 | 8 | /** 9 | * Retrieves a cell value from an array. 10 | * This is a wrapper around the Sourcemod Function GetArrayCell, 11 | * but it casts the result as bool 12 | * 13 | * @param array Array Handle. 14 | * @param index Index in the array. 15 | * @param block Optionally specify which block to read from 16 | * (useful if the blocksize > 0). 17 | * @param asChar Optionally read as a byte instead of a cell. 18 | * @return Value read. 19 | * @error Invalid Handle, invalid index, or invalid block. 20 | */ 21 | stock bool:DynArray_GetBool(Handle:array, index, block=0, bool:asChar=false) 22 | { 23 | return bool:GetArrayCell(array, index, block, asChar); 24 | } 25 | -------------------------------------------------------------------------------- /scripting/include/smlib/edicts.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_edicts_included 2 | #endinput 3 | #endif 4 | #define _smlib_edicts_included 5 | 6 | #include 7 | #include 8 | 9 | /* 10 | * Finds an edict by it's name 11 | * It only finds the first occurence. 12 | * 13 | * @param name Name of the entity you want so search. 14 | * @return Edict Index or INVALID_ENT_REFERENCE if no entity was found. 15 | */ 16 | stock Edict_FindByName(const String:name[]) 17 | { 18 | new maxEntities = GetMaxEntities(); 19 | for (new edict=0; edict < maxEntities; edict++) { 20 | 21 | if (!IsValidEdict(edict)) { 22 | continue; 23 | } 24 | 25 | if (Entity_NameMatches(edict, name)) { 26 | return edict; 27 | } 28 | } 29 | 30 | return INVALID_ENT_REFERENCE; 31 | } 32 | 33 | /* 34 | * Finds an edict by its HammerID. 35 | * The newer version of Valve's Hammer editor 36 | * sets a unique ID for each entity in a map. 37 | * It only finds the first occurence. 38 | * 39 | * @param hammerId Hammer editor ID 40 | * @return Edict Index or INVALID_ENT_REFERENCE if no entity was found. 41 | */ 42 | stock Edict_FindByHammerId(hammerId) 43 | { 44 | new maxEntities = GetMaxEntities(); 45 | for (new edict=0; edict < maxEntities; edict++) { 46 | 47 | if (!IsValidEdict(edict)) { 48 | continue; 49 | } 50 | 51 | if (Entity_GetHammerId(edict) == hammerId) { 52 | return edict; 53 | } 54 | } 55 | 56 | return INVALID_ENT_REFERENCE; 57 | } 58 | 59 | /** 60 | * Searches for the closest edict in relation to the given origin 61 | * 62 | * @param vecOrigin_center 3 dimensional origin array 63 | * @param clientsOnly True if you only want to search for clients 64 | * @param ignoreEntity Ignore this entity 65 | * @return Edict Index or INVALID_ENT_REFERENCE if no entity was found. 66 | */ 67 | stock Edict_GetClosest(Float:vecOrigin_center[3], bool:clientsOnly=false, ignoreEntity=-1) 68 | { 69 | decl Float:vecOrigin_edict[3]; 70 | new Float:smallestDistance = 0.0; 71 | new closestEdict = INVALID_ENT_REFERENCE; 72 | 73 | new maxEntities; 74 | 75 | if (clientsOnly) { 76 | maxEntities = MaxClients; 77 | } 78 | else { 79 | maxEntities = GetMaxEntities(); 80 | } 81 | 82 | for (new edict=1; edict <= maxEntities; edict++) { 83 | 84 | if (!IsValidEdict(edict)) { 85 | continue; 86 | } 87 | 88 | if (ignoreEntity >= 0 && edict == ignoreEntity) { 89 | continue; 90 | } 91 | 92 | if (GetEntSendPropOffs(edict, "m_vecOrigin") == -1) { 93 | continue; 94 | } 95 | 96 | Entity_GetAbsOrigin(edict, vecOrigin_edict); 97 | 98 | new Float:edict_distance = GetVectorDistance(vecOrigin_center, vecOrigin_edict, true); 99 | 100 | if (edict_distance < smallestDistance || smallestDistance == 0.0) { 101 | smallestDistance = edict_distance; 102 | closestEdict = edict; 103 | } 104 | } 105 | 106 | return closestEdict; 107 | } 108 | 109 | /** 110 | * Searches for the closest edict in relation to the given edict. 111 | * 112 | * @param edict Edict index 113 | * @param clientsOnly True if you only want to search for clients 114 | * @return The closest edict or INVALID_ENT_REFERENCE 115 | */ 116 | stock Edict_GetClosestToEdict(edict, bool:clientsOnly=false) 117 | { 118 | decl Float:vecOrigin[3]; 119 | 120 | if (GetEntSendPropOffs(edict, "m_vecOrigin") == -1) { 121 | return INVALID_ENT_REFERENCE; 122 | } 123 | 124 | Entity_GetAbsOrigin(edict, vecOrigin); 125 | 126 | return Edict_GetClosest(vecOrigin, clientsOnly, edict); 127 | } 128 | -------------------------------------------------------------------------------- /scripting/include/smlib/effects.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_effects_included 2 | #endinput 3 | #endif 4 | #define _smlib_effects_included 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | 17 | // Entity Dissolve types 18 | enum DissolveType 19 | { 20 | DISSOLVE_NORMAL = 0, 21 | DISSOLVE_ELECTRICAL, 22 | DISSOLVE_ELECTRICAL_LIGHT, 23 | DISSOLVE_CORE 24 | }; 25 | 26 | /** 27 | * Dissolves a player 28 | * 29 | * @param client Client Index. 30 | * @param dissolveType Dissolve Type, use the DissolveType enum. 31 | * @param magnitude How strongly to push away from the center. 32 | * @return True on success, otherwise false. 33 | */ 34 | stock bool:Effect_DissolveEntity(entity, DissolveType:dissolveType=DISSOLVE_NORMAL, magnitude=1) 35 | { 36 | new env_entity_dissolver = CreateEntityByName("env_entity_dissolver"); 37 | 38 | if (env_entity_dissolver == -1) { 39 | return false; 40 | } 41 | 42 | Entity_PointAtTarget(env_entity_dissolver, entity); 43 | SetEntProp(env_entity_dissolver, Prop_Send, "m_nDissolveType", _:dissolveType); 44 | SetEntProp(env_entity_dissolver, Prop_Send, "m_nMagnitude", magnitude); 45 | AcceptEntityInput(env_entity_dissolver, "Dissolve"); 46 | Entity_Kill(env_entity_dissolver); 47 | 48 | return true; 49 | } 50 | 51 | /** 52 | * Dissolves a player's Ragdoll 53 | * 54 | * @param client Client Index. 55 | * @param dissolveType Dissolve Type, use the DissolveType enum. 56 | * @return True on success, otherwise false. 57 | */ 58 | stock bool:Effect_DissolvePlayerRagDoll(client, DissolveType:dissolveType=DISSOLVE_NORMAL) 59 | { 60 | new m_hRagdoll = GetEntPropEnt(client, Prop_Send, "m_hRagdoll"); 61 | 62 | if (m_hRagdoll == -1) { 63 | return false; 64 | } 65 | 66 | return Effect_DissolveEntity(m_hRagdoll, dissolveType); 67 | } 68 | 69 | functag EffectCallback public(entity, any:data); 70 | 71 | /** 72 | * Fades an entity in our out. 73 | * You can specifiy a callback function which will get called 74 | * when the fade is finished. 75 | * Important: The callback will be called if it is passed, 76 | * no matter if the entity is still valid or not. That means you 77 | * have to check if the entity is valid yourself. 78 | * 79 | * @param entity Entity Index. 80 | * @param fadeOut Optional: Fade the entity out (true) or in (false). 81 | * @param kill Optional: If to kill the entity when the fade is finished. 82 | * @param fast Optional: Fade the entity fast (~0.7 secs) or slow (~3 secs) 83 | * @param callback Optional: You can specify a callback Function that will get called when the fade is finished. 84 | * @param data Optional: You can pass any data to the callback. 85 | * @return True on success, otherwise false. 86 | */ 87 | stock Effect_Fade(entity, fadeOut=true, kill=false, fast=true, EffectCallback:callback=INVALID_FUNCTION, any:data=0) 88 | { 89 | new Float:timerTime = 0.0; 90 | 91 | if (fast) { 92 | timerTime = 0.6; 93 | 94 | if (fadeOut) { 95 | SetEntityRenderFx(entity, RENDERFX_FADE_FAST); 96 | } 97 | else { 98 | SetEntityRenderFx(entity, RENDERFX_SOLID_FAST); 99 | } 100 | } 101 | else { 102 | timerTime = 3.0; 103 | 104 | if (fadeOut) { 105 | SetEntityRenderFx(entity, RENDERFX_FADE_SLOW); 106 | } 107 | else { 108 | SetEntityRenderFx(entity, RENDERFX_SOLID_SLOW); 109 | } 110 | } 111 | 112 | ChangeEdictState(entity, GetEntSendPropOffs(entity, "m_nRenderFX", true)); 113 | 114 | if (kill || callback != INVALID_FUNCTION) { 115 | new Handle:dataPack = INVALID_HANDLE; 116 | CreateDataTimer(timerTime, _smlib_Timer_Effect_Fade, dataPack, TIMER_FLAG_NO_MAPCHANGE | TIMER_DATA_HNDL_CLOSE); 117 | 118 | WritePackCell(dataPack, EntIndexToEntRef(entity)); 119 | WritePackCell(dataPack, kill); 120 | #if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 7 121 | WritePackFunction(dataPack, callback); 122 | #else 123 | WritePackCell(dataPack, _:callback); 124 | #endif 125 | WritePackCell(dataPack, data); 126 | ResetPack(dataPack); 127 | } 128 | } 129 | 130 | /** 131 | * Fades the entity in. 132 | * A wrapper function around Effect_Fade(). 133 | * 134 | * @param entity Entity Index. 135 | * @param fast Optional: Fade the entity fast (~0.7 secs) or slow (~3 secs) 136 | * @param callback Optional: You can specify a callback Function that will get called when the fade is finished. 137 | * @param data Optional: You can pass any data to the callback. 138 | * @return True on success, otherwise false. 139 | */ 140 | stock Effect_FadeIn(entity, fast=true, EffectCallback:callback=INVALID_FUNCTION, any:data=0) 141 | { 142 | Effect_Fade(entity, false, false, fast, callback, data); 143 | } 144 | 145 | /** 146 | * Fades the entity out. 147 | * A wrapper function around Effect_Fade(). 148 | * 149 | * @param entity Entity Index. 150 | * @param fadeOut Optional: Fade the entity out (true) or in (false). 151 | * @param kill Optional: If to kill the entity when the fade is finished. 152 | * @param fast Optional: Fade the entity fast (~0.7 secs) or slow (~3 secs) 153 | * @param callback Optional: You can specify a callback Function that will get called when the fade is finished. 154 | * @param data Optional: You can pass any data to the callback. 155 | * @return True on success, otherwise false. 156 | */ 157 | stock Effect_FadeOut(entity, kill=false, fast=true, EffectCallback:callback=INVALID_FUNCTION, any:data=0) 158 | { 159 | Effect_Fade(entity, true, kill, fast, callback, data); 160 | } 161 | 162 | public Action:_smlib_Timer_Effect_Fade(Handle:Timer, Handle:dataPack) 163 | { 164 | new entity = ReadPackCell(dataPack); 165 | new kill = ReadPackCell(dataPack); 166 | #if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 7 167 | new Function:callback = ReadPackFunction(dataPack); 168 | #else 169 | new Function:callback = Function:ReadPackCell(dataPack); 170 | #endif 171 | new any:data = any:ReadPackCell(dataPack); 172 | 173 | if (callback != INVALID_FUNCTION) { 174 | Call_StartFunction(INVALID_HANDLE, callback); 175 | Call_PushCell(entity); 176 | Call_PushCell(data); 177 | Call_Finish(); 178 | } 179 | 180 | if (kill && IsValidEntity(entity)) { 181 | Entity_Kill(entity); 182 | } 183 | 184 | return Plugin_Stop; 185 | } 186 | 187 | /** 188 | * Sends a boxed beam effect to one player. 189 | * 190 | * Ported from eventscripts vecmath library. 191 | * 192 | * @param client The client to show the box to. 193 | * @param bottomCorner One bottom corner of the box. 194 | * @param upperCorner One upper corner of the box. 195 | * @param modelIndex Precached model index. 196 | * @param haloIndex Precached model index. 197 | * @param startFrame Initital frame to render. 198 | * @param frameRate Beam frame rate. 199 | * @param life Time duration of the beam. 200 | * @param width Initial beam width. 201 | * @param endWidth Final beam width. 202 | * @param fadeLength Beam fade time duration. 203 | * @param amplitude Beam amplitude. 204 | * @param color Color array (r, g, b, a). 205 | * @param speed Speed of the beam. 206 | * @noreturn 207 | */ 208 | stock Effect_DrawBeamBoxToClient( 209 | client, 210 | const Float:bottomCorner[3], 211 | const Float:upperCorner[3], 212 | modelIndex, 213 | haloIndex, 214 | startFrame=0, 215 | frameRate=30, 216 | Float:life=5.0, 217 | Float:width=5.0, 218 | Float:endWidth=5.0, 219 | fadeLength=2, 220 | Float:amplitude=1.0, 221 | const color[4]={ 255, 0, 0, 255 }, 222 | speed=0 223 | ) { 224 | new clients[1]; 225 | clients[0] = client; 226 | Effect_DrawBeamBox(clients, 1, bottomCorner, upperCorner, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 227 | } 228 | 229 | /** 230 | * Sends a boxed beam effect to all players. 231 | * 232 | * Ported from eventscripts vecmath library. 233 | * 234 | * @param bottomCorner One bottom corner of the box. 235 | * @param upperCorner One upper corner of the box. 236 | * @param modelIndex Precached model index. 237 | * @param haloIndex Precached model index. 238 | * @param startFrame Initital frame to render. 239 | * @param frameRate Beam frame rate. 240 | * @param life Time duration of the beam. 241 | * @param width Initial beam width. 242 | * @param endWidth Final beam width. 243 | * @param fadeLength Beam fade time duration. 244 | * @param amplitude Beam amplitude. 245 | * @param color Color array (r, g, b, a). 246 | * @param speed Speed of the beam. 247 | * @noreturn 248 | */ 249 | stock Effect_DrawBeamBoxToAll( 250 | const Float:bottomCorner[3], 251 | const Float:upperCorner[3], 252 | modelIndex, 253 | haloIndex, 254 | startFrame=0, 255 | frameRate=30, 256 | Float:life=5.0, 257 | Float:width=5.0, 258 | Float:endWidth=5.0, 259 | fadeLength=2, 260 | Float:amplitude=1.0, 261 | const color[4]={ 255, 0, 0, 255 }, 262 | speed=0 263 | ) 264 | { 265 | new clients[MaxClients]; 266 | new numClients = Client_Get(clients, CLIENTFILTER_INGAME); 267 | 268 | Effect_DrawBeamBox(clients, numClients, bottomCorner, upperCorner, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 269 | } 270 | 271 | /** 272 | * Sends a boxed beam effect to a list of players. 273 | * 274 | * Ported from eventscripts vecmath library. 275 | * 276 | * @param clients An array of clients to show the box to. 277 | * @param numClients Number of players in the array. 278 | * @param bottomCorner One bottom corner of the box. 279 | * @param upperCorner One upper corner of the box. 280 | * @param modelIndex Precached model index. 281 | * @param haloIndex Precached model index. 282 | * @param startFrame Initital frame to render. 283 | * @param frameRate Beam frame rate. 284 | * @param life Time duration of the beam. 285 | * @param width Initial beam width. 286 | * @param endWidth Final beam width. 287 | * @param fadeLength Beam fade time duration. 288 | * @param amplitude Beam amplitude. 289 | * @param color Color array (r, g, b, a). 290 | * @param speed Speed of the beam. 291 | * @noreturn 292 | */ 293 | stock Effect_DrawBeamBox( 294 | clients[], 295 | numClients, 296 | const Float:bottomCorner[3], 297 | const Float:upperCorner[3], 298 | modelIndex, 299 | haloIndex, 300 | startFrame=0, 301 | frameRate=30, 302 | Float:life=5.0, 303 | Float:width=5.0, 304 | Float:endWidth=5.0, 305 | fadeLength=2, 306 | Float:amplitude=1.0, 307 | const color[4]={ 255, 0, 0, 255 }, 308 | speed=0 309 | ) { 310 | // Create the additional corners of the box 311 | decl Float:corners[8][3]; 312 | 313 | for (new i=0; i < 4; i++) { 314 | Array_Copy(bottomCorner, corners[i], 3); 315 | Array_Copy(upperCorner, corners[i+4], 3); 316 | } 317 | 318 | corners[1][0] = upperCorner[0]; 319 | corners[2][0] = upperCorner[0]; 320 | corners[2][1] = upperCorner[1]; 321 | corners[3][1] = upperCorner[1]; 322 | corners[4][0] = bottomCorner[0]; 323 | corners[4][1] = bottomCorner[1]; 324 | corners[5][1] = bottomCorner[1]; 325 | corners[7][0] = bottomCorner[0]; 326 | 327 | // Draw all the edges 328 | 329 | // Horizontal Lines 330 | // Bottom 331 | for (new i=0; i < 4; i++) { 332 | new j = ( i == 3 ? 0 : i+1 ); 333 | TE_SetupBeamPoints(corners[i], corners[j], modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 334 | TE_Send(clients, numClients); 335 | } 336 | 337 | // Top 338 | for (new i=4; i < 8; i++) { 339 | new j = ( i == 7 ? 4 : i+1 ); 340 | TE_SetupBeamPoints(corners[i], corners[j], modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 341 | TE_Send(clients, numClients); 342 | } 343 | 344 | // All Vertical Lines 345 | for (new i=0; i < 4; i++) { 346 | TE_SetupBeamPoints(corners[i], corners[i+4], modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 347 | TE_Send(clients, numClients); 348 | } 349 | } 350 | 351 | 352 | /** 353 | * Sends a boxed beam effect to one player. 354 | * 355 | * Ported from eventscripts vecmath library. 356 | * 357 | * @param client The client to show the box to. 358 | * @param origin Origin/center of the box. 359 | * @param mins Min size Vector 360 | * @param maxs Max size Vector 361 | * @param angles Angles used to rotate the box. 362 | * @param modelIndex Precached model index. 363 | * @param haloIndex Precached model index. 364 | * @param startFrame Initital frame to render. 365 | * @param frameRate Beam frame rate. 366 | * @param life Time duration of the beam. 367 | * @param width Initial beam width. 368 | * @param endWidth Final beam width. 369 | * @param fadeLength Beam fade time duration. 370 | * @param amplitude Beam amplitude. 371 | * @param color Color array (r, g, b, a). 372 | * @param speed Speed of the beam. 373 | * @noreturn 374 | */ 375 | stock Effect_DrawBeamBoxRotatableToClient( 376 | client, 377 | const Float:origin[3], 378 | const Float:mins[3], 379 | const Float:maxs[3], 380 | const Float:angles[3], 381 | modelIndex, 382 | haloIndex, 383 | startFrame=0, 384 | frameRate=30, 385 | Float:life=5.0, 386 | Float:width=5.0, 387 | Float:endWidth=5.0, 388 | fadeLength=2, 389 | Float:amplitude=1.0, 390 | const color[4]={ 255, 0, 0, 255 }, 391 | speed=0 392 | ) { 393 | new clients[1]; 394 | clients[0] = client; 395 | Effect_DrawBeamBoxRotatable(clients, 1, origin, mins, maxs, angles, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 396 | } 397 | 398 | 399 | 400 | /** 401 | * Sends a boxed beam effect to all players. 402 | * 403 | * Ported from eventscripts vecmath library. 404 | * 405 | * @param origin Origin/center of the box. 406 | * @param mins Min size Vector 407 | * @param maxs Max size Vector 408 | * @param angles Angles used to rotate the box. 409 | * @param modelIndex Precached model index. 410 | * @param haloIndex Precached model index. 411 | * @param startFrame Initital frame to render. 412 | * @param frameRate Beam frame rate. 413 | * @param life Time duration of the beam. 414 | * @param width Initial beam width. 415 | * @param endWidth Final beam width. 416 | * @param fadeLength Beam fade time duration. 417 | * @param amplitude Beam amplitude. 418 | * @param color Color array (r, g, b, a). 419 | * @param speed Speed of the beam. 420 | * @noreturn 421 | */ 422 | stock Effect_DrawBeamBoxRotatableToAll( 423 | const Float:origin[3], 424 | const Float:mins[3], 425 | const Float:maxs[3], 426 | const Float:angles[3], 427 | modelIndex, 428 | haloIndex, 429 | startFrame=0, 430 | frameRate=30, 431 | Float:life=5.0, 432 | Float:width=5.0, 433 | Float:endWidth=5.0, 434 | fadeLength=2, 435 | Float:amplitude=1.0, 436 | const color[4]={ 255, 0, 0, 255 }, 437 | speed=0 438 | ) 439 | { 440 | new clients[MaxClients]; 441 | new numClients = Client_Get(clients, CLIENTFILTER_INGAME); 442 | 443 | Effect_DrawBeamBoxRotatable(clients, numClients, origin, mins, maxs, angles, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 444 | } 445 | 446 | /** 447 | * Sends a boxed beam effect to a list of players. 448 | * 449 | * Ported from eventscripts vecmath library. 450 | * 451 | * @param clients An array of clients to show the box to. 452 | * @param numClients Number of players in the array. 453 | * @param origin Origin/center of the box. 454 | * @param mins Min size Vector 455 | * @param maxs Max size Vector 456 | * @param angles Angles used to rotate the box. 457 | * @param modelIndex Precached model index. 458 | * @param haloIndex Precached model index. 459 | * @param startFrame Initital frame to render. 460 | * @param frameRate Beam frame rate. 461 | * @param life Time duration of the beam. 462 | * @param width Initial beam width. 463 | * @param endWidth Final beam width. 464 | * @param fadeLength Beam fade time duration. 465 | * @param amplitude Beam amplitude. 466 | * @param color Color array (r, g, b, a). 467 | * @param speed Speed of the beam. 468 | * @noreturn 469 | */ 470 | stock Effect_DrawBeamBoxRotatable( 471 | clients[], 472 | numClients, 473 | const Float:origin[3], 474 | const Float:mins[3], 475 | const Float:maxs[3], 476 | const Float:angles[3], 477 | modelIndex, 478 | haloIndex, 479 | startFrame=0, 480 | frameRate=30, 481 | Float:life=5.0, 482 | Float:width=5.0, 483 | Float:endWidth=5.0, 484 | fadeLength=2, 485 | Float:amplitude=1.0, 486 | const color[4]={ 255, 0, 0, 255 }, 487 | speed=0 488 | ) { 489 | // Create the additional corners of the box 490 | decl Float:corners[8][3]; 491 | Array_Copy(mins, corners[0], 3); 492 | Math_MakeVector(maxs[0], mins[1], mins[2], corners[1]); 493 | Math_MakeVector(maxs[0], maxs[1], mins[2], corners[2]); 494 | Math_MakeVector(mins[0], maxs[1], mins[2], corners[3]); 495 | Math_MakeVector(mins[0], mins[1], maxs[2], corners[4]); 496 | Math_MakeVector(maxs[0], mins[1], maxs[2], corners[5]); 497 | Array_Copy(maxs, corners[6], 3); 498 | Math_MakeVector(mins[0], maxs[1], maxs[2], corners[7]); 499 | 500 | // Rotate all edges 501 | for (new i=0; i < sizeof(corners); i++) { 502 | Math_RotateVector(corners[i], angles, corners[i]); 503 | } 504 | 505 | // Apply world offset (after rotation) 506 | for (new i=0; i < sizeof(corners); i++) { 507 | AddVectors(origin, corners[i], corners[i]); 508 | } 509 | 510 | // Draw all the edges 511 | // Horizontal Lines 512 | // Bottom 513 | for (new i=0; i < 4; i++) { 514 | new j = ( i == 3 ? 0 : i+1 ); 515 | TE_SetupBeamPoints(corners[i], corners[j], modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 516 | TE_Send(clients, numClients); 517 | } 518 | 519 | // Top 520 | for (new i=4; i < 8; i++) { 521 | new j = ( i == 7 ? 4 : i+1 ); 522 | TE_SetupBeamPoints(corners[i], corners[j], modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 523 | TE_Send(clients, numClients); 524 | } 525 | 526 | // All Vertical Lines 527 | for (new i=0; i < 4; i++) { 528 | TE_SetupBeamPoints(corners[i], corners[i+4], modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, color, speed); 529 | TE_Send(clients, numClients); 530 | } 531 | } 532 | 533 | /** 534 | * Displays the given axis of rotation as beam effect to one player. 535 | * 536 | * @param client The client to show the box to. 537 | * @param origin Origin/center of the box. 538 | * @param angles Angles used to rotate the box. 539 | * @param length The length in each direction. 540 | * @param modelIndex Precached model index. 541 | * @param haloIndex Precached model index. 542 | * @param startFrame Initital frame to render. 543 | * @param frameRate Beam frame rate. 544 | * @param life Time duration of the beam. 545 | * @param width Initial beam width. 546 | * @param endWidth Final beam width. 547 | * @param fadeLength Beam fade time duration. 548 | * @param amplitude Beam amplitude. 549 | * @param color Color array (r, g, b, a). 550 | * @param speed Speed of the beam. 551 | * @noreturn 552 | */ 553 | stock Effect_DrawAxisOfRotationToClient( 554 | client, 555 | const Float:origin[3], 556 | const Float:angles[3], 557 | const Float:length[3], 558 | modelIndex, 559 | haloIndex, 560 | startFrame=0, 561 | frameRate=30, 562 | Float:life=5.0, 563 | Float:width=5.0, 564 | Float:endWidth=5.0, 565 | fadeLength=2, 566 | Float:amplitude=1.0, 567 | speed=0 568 | ) { 569 | new clients[1]; 570 | clients[0] = client; 571 | Effect_DrawAxisOfRotation(clients, 1, origin, angles, length, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, speed); 572 | } 573 | 574 | /** 575 | * Displays the given axis of rotation as beam effect to all players. 576 | * 577 | * @param origin Origin/center of the box. 578 | * @param angles Angles used to rotate the box. 579 | * @param length The length in each direction. 580 | * @param modelIndex Precached model index. 581 | * @param haloIndex Precached model index. 582 | * @param startFrame Initital frame to render. 583 | * @param frameRate Beam frame rate. 584 | * @param life Time duration of the beam. 585 | * @param width Initial beam width. 586 | * @param endWidth Final beam width. 587 | * @param fadeLength Beam fade time duration. 588 | * @param amplitude Beam amplitude. 589 | * @param color Color array (r, g, b, a). 590 | * @param speed Speed of the beam. 591 | * @noreturn 592 | */ 593 | stock Effect_DrawAxisOfRotationToAll( 594 | const Float:origin[3], 595 | const Float:angles[3], 596 | const Float:length[3], 597 | modelIndex, 598 | haloIndex, 599 | startFrame=0, 600 | frameRate=30, 601 | Float:life=5.0, 602 | Float:width=5.0, 603 | Float:endWidth=5.0, 604 | fadeLength=2, 605 | Float:amplitude=1.0, 606 | speed=0 607 | ) 608 | { 609 | new clients[MaxClients]; 610 | new numClients = Client_Get(clients, CLIENTFILTER_INGAME); 611 | 612 | Effect_DrawAxisOfRotation(clients, numClients, origin, angles, length, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, speed); 613 | } 614 | 615 | /** 616 | * Displays the given axis of rotation as beam effect to a list of players. 617 | * 618 | * @param clients An array of clients to show the box to. 619 | * @param numClients Number of players in the array. 620 | * @param origin Origin/center of the box. 621 | * @param angles Angles used to rotate the box. 622 | * @param length The length in each direction. 623 | * @param modelIndex Precached model index. 624 | * @param haloIndex Precached model index. 625 | * @param startFrame Initital frame to render. 626 | * @param frameRate Beam frame rate. 627 | * @param life Time duration of the beam. 628 | * @param width Initial beam width. 629 | * @param endWidth Final beam width. 630 | * @param fadeLength Beam fade time duration. 631 | * @param amplitude Beam amplitude. 632 | * @param color Color array (r, g, b, a). 633 | * @param speed Speed of the beam. 634 | * @noreturn 635 | */ 636 | stock Effect_DrawAxisOfRotation( 637 | clients[], 638 | numClients, 639 | const Float:origin[3], 640 | const Float:angles[3], 641 | const Float:length[3], 642 | modelIndex, 643 | haloIndex, 644 | startFrame=0, 645 | frameRate=30, 646 | Float:life=5.0, 647 | Float:width=5.0, 648 | Float:endWidth=5.0, 649 | fadeLength=2, 650 | Float:amplitude=1.0, 651 | speed=0 652 | ) { 653 | // Create the additional corners of the box 654 | new Float:xAxis[3], Float:yAxis[3], Float:zAxis[3]; 655 | xAxis[0] = length[0]; 656 | yAxis[1] = length[1]; 657 | zAxis[2] = length[2]; 658 | 659 | // Rotate all edges 660 | Math_RotateVector(xAxis, angles, xAxis); 661 | Math_RotateVector(yAxis, angles, yAxis); 662 | Math_RotateVector(zAxis, angles, zAxis); 663 | 664 | // Apply world offset (after rotation) 665 | AddVectors(origin, xAxis, xAxis); 666 | AddVectors(origin, yAxis, yAxis); 667 | AddVectors(origin, zAxis, zAxis); 668 | 669 | // Draw all 670 | TE_SetupBeamPoints(origin, xAxis, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, {255, 0, 0, 255}, speed); 671 | TE_Send(clients, numClients); 672 | 673 | TE_SetupBeamPoints(origin, yAxis, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, {0, 255, 0, 255}, speed); 674 | TE_Send(clients, numClients); 675 | 676 | TE_SetupBeamPoints(origin, zAxis, modelIndex, haloIndex, startFrame, frameRate, life, width, endWidth, fadeLength, amplitude, {0, 0, 255, 255}, speed); 677 | TE_Send(clients, numClients); 678 | } 679 | 680 | 681 | /** 682 | * Creates an env_sprite. 683 | * 684 | * @param origin Origin of the Sprite. 685 | * @param modelIndex Precached model index. 686 | * @param color Color array (r, g, b, a). 687 | * @param scale Scale (Note: many materials ignore a lower value than 0.25). 688 | * @param targetName Targetname of the sprite. 689 | * @param parent Entity Index of this sprite's parent in the movement hierarchy. 690 | * @param renderMode Render mode (use the enum). 691 | * @param renderFx Render fx (use the enum). 692 | * @param glowProxySize Radius size of the glow when to be rendered, if inside a geometry. Ex: a block 2x2x2 units big, if the glowProxySize is between 0.0 and 2.0 the sprite will not be rendered, even if the actual size of the sprite is bigger, everything above 2.0 will render the sprite. Using an abnormal high value will render Sprites trough walls. 693 | * @param frameRate Sprite frame rate. 694 | * @param hdrColorScale Float value to multiply sprite color by when running with HDR. 695 | * @param receiveShadows When false then this prevents the sprite from receiving shadows. 696 | * @return Entity Index of the created Sprite. 697 | */ 698 | stock Effect_EnvSprite( 699 | const Float:origin[3], 700 | modelIndex, 701 | const color[4]={255, 255, 255, 255}, 702 | Float:scale=0.25, 703 | const String:targetName[MAX_NAME_LENGTH]="", 704 | parent=-1, 705 | RenderMode:renderMode=RENDER_WORLDGLOW, 706 | RenderFx:renderFx=RENDERFX_NONE, 707 | Float:glowProxySize=2.0, 708 | Float:framerate=10.0, 709 | Float:hdrColorScale=1.0, 710 | bool:receiveShadows = true 711 | ) { 712 | new entity = Entity_Create("env_sprite"); 713 | 714 | if (entity == INVALID_ENT_REFERENCE) { 715 | return INVALID_ENT_REFERENCE; 716 | } 717 | 718 | DispatchKeyValue (entity, "disablereceiveshadows", (receiveShadows) ? "0" : "1"); 719 | DispatchKeyValueFloat (entity, "framerate", framerate); 720 | DispatchKeyValueFloat (entity, "GlowProxySize", glowProxySize); 721 | DispatchKeyValue (entity, "spawnflags", "1"); 722 | DispatchKeyValueFloat (entity, "HDRColorScale", hdrColorScale); 723 | DispatchKeyValue (entity, "maxdxlevel", "0"); 724 | DispatchKeyValue (entity, "mindxlevel", "0"); 725 | DispatchKeyValueFloat (entity, "scale", scale); 726 | 727 | DispatchSpawn(entity); 728 | 729 | SetEntityRenderMode(entity, renderMode); 730 | SetEntityRenderColor(entity, color[0], color[1], color[2], color[3]); 731 | SetEntityRenderFx(entity, renderFx); 732 | 733 | Entity_SetName(entity, targetName); 734 | Entity_SetModelIndex(entity, modelIndex); 735 | Entity_SetAbsOrigin(entity, origin); 736 | 737 | if (parent != -1) { 738 | Entity_SetParent(entity, parent); 739 | } 740 | 741 | return entity; 742 | } 743 | -------------------------------------------------------------------------------- /scripting/include/smlib/files.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_files_included 2 | #endinput 3 | #endif 4 | #define _smlib_files_included 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /** 11 | * Gets the Base name of a path. 12 | * Examples: 13 | * blub.txt -> "blub.txt" 14 | * /sourcemod/extensions/example.ext.so -> "example.ext.so" 15 | * 16 | * @param path File path 17 | * @param buffer String buffer array 18 | * @param size Size of string buffer 19 | * @noreturn 20 | */ 21 | stock bool:File_GetBaseName(const String:path[], String:buffer[], size) 22 | { 23 | if (path[0] == '\0') { 24 | buffer[0] = '\0'; 25 | return; 26 | } 27 | 28 | new pos_start = FindCharInString(path, '/', true); 29 | 30 | if (pos_start == -1) { 31 | pos_start = FindCharInString(path, '\\', true); 32 | } 33 | 34 | pos_start++; 35 | 36 | strcopy(buffer, size, path[pos_start]); 37 | } 38 | 39 | /** 40 | * Gets the Directory of a path (without the file name). 41 | * Does not work with "." as the path. 42 | * Examples: 43 | * blub.txt -> "blub.txt" 44 | * /sourcemod/extensions/example.ext.so -> "example.ext.so" 45 | * 46 | * @param path File path 47 | * @param buffer String buffer array 48 | * @param size Size of string buffer 49 | * @noreturn 50 | */ 51 | stock bool:File_GetDirName(const String:path[], String:buffer[], size) 52 | { 53 | if (path[0] == '\0') { 54 | buffer[0] = '\0'; 55 | return; 56 | } 57 | 58 | new pos_start = FindCharInString(path, '/', true); 59 | 60 | if (pos_start == -1) { 61 | pos_start = FindCharInString(path, '\\', true); 62 | 63 | if (pos_start == -1) { 64 | buffer[0] = '\0'; 65 | return; 66 | } 67 | } 68 | 69 | strcopy(buffer, size, path); 70 | buffer[pos_start] = '\0'; 71 | } 72 | 73 | /** 74 | * Gets the File name of a path. 75 | * blub.txt -> "blub" 76 | * /sourcemod/extensions/example.ext.so -> "example.ext" 77 | * 78 | * @param path File path 79 | * @param buffer String buffer array 80 | * @param size Size of string buffer 81 | * @noreturn 82 | */ 83 | stock bool:File_GetFileName(const String:path[], String:buffer[], size) 84 | { 85 | if (path[0] == '\0') { 86 | buffer[0] = '\0'; 87 | return; 88 | } 89 | 90 | File_GetBaseName(path, buffer, size); 91 | 92 | new pos_ext = FindCharInString(buffer, '.', true); 93 | 94 | if (pos_ext != -1) { 95 | buffer[pos_ext] = '\0'; 96 | } 97 | } 98 | 99 | /** 100 | * Gets the Extension of a file. 101 | * Examples: 102 | * blub.inc.txt -> "txt" 103 | * /sourcemod/extensions/example.ext.so -> "so" 104 | * 105 | * @param path Path String 106 | * @param buffer String buffer array 107 | * @param size Max length of string buffer 108 | * @noreturn 109 | */ 110 | stock File_GetExtension(const String:path[], String:buffer[], size) 111 | { 112 | new extpos = FindCharInString(path, '.', true); 113 | 114 | if (extpos == -1) { 115 | buffer[0] = '\0'; 116 | return; 117 | } 118 | 119 | strcopy(buffer, size, path[++extpos]); 120 | } 121 | 122 | /** 123 | * Adds a path to the downloadables network string table. 124 | * This can be a file or directory and also works recursed. 125 | * You can optionally specify file extensions that should be ignored. 126 | * Bz2 and ztmp are automatically ignored. 127 | * It only adds files that actually exist. 128 | * You can also specify a wildcard * after the ., very useful for models. 129 | * This forces a client to download the file if they do not already have it. 130 | * 131 | * @param path Path String 132 | * @param recursive Whether to do recursion or not. 133 | * @param ignoreExts Optional: 2 dimensional String array.You can define it like this: new String:ignore[][] = { ".ext1", ".ext2" }; 134 | * @param size This should be set to the number of file extensions in the ignoreExts array (sizeof(ignore) for the example above) 135 | * @noreturn 136 | */ 137 | 138 | // Damn you SourcePawn :( I didn't want to 139 | new String:_smlib_empty_twodimstring_array[][] = { { '\0' } }; 140 | stock File_AddToDownloadsTable(const String:path[], bool:recursive=true, const String:ignoreExts[][]=_smlib_empty_twodimstring_array, size=0) 141 | { 142 | if (path[0] == '\0') { 143 | return; 144 | } 145 | 146 | if (FileExists(path)) { 147 | 148 | new String:fileExtension[5]; 149 | File_GetExtension(path, fileExtension, sizeof(fileExtension)); 150 | 151 | if (StrEqual(fileExtension, "bz2", false) || StrEqual(fileExtension, "ztmp", false)) { 152 | return; 153 | } 154 | 155 | if (Array_FindString(ignoreExts, size, fileExtension) != -1) { 156 | return; 157 | } 158 | 159 | decl String:path_new[PLATFORM_MAX_PATH]; 160 | strcopy(path_new, sizeof(path_new), path); 161 | ReplaceString(path_new, sizeof(path_new), "//", "/"); 162 | 163 | AddFileToDownloadsTable(path_new); 164 | } 165 | else if (recursive && DirExists(path)) { 166 | 167 | decl String:dirEntry[PLATFORM_MAX_PATH]; 168 | new Handle:__dir = OpenDirectory(path); 169 | 170 | while (ReadDirEntry(__dir, dirEntry, sizeof(dirEntry))) { 171 | 172 | if (StrEqual(dirEntry, ".") || StrEqual(dirEntry, "..")) { 173 | continue; 174 | } 175 | 176 | Format(dirEntry, sizeof(dirEntry), "%s/%s", path, dirEntry); 177 | File_AddToDownloadsTable(dirEntry, recursive, ignoreExts, size); 178 | } 179 | 180 | CloseHandle(__dir); 181 | } 182 | else if (FindCharInString(path, '*', true)) { 183 | 184 | new String:fileExtension[4]; 185 | File_GetExtension(path, fileExtension, sizeof(fileExtension)); 186 | 187 | if (StrEqual(fileExtension, "*")) { 188 | 189 | decl 190 | String:dirName[PLATFORM_MAX_PATH], 191 | String:fileName[PLATFORM_MAX_PATH], 192 | String:dirEntry[PLATFORM_MAX_PATH]; 193 | 194 | File_GetDirName(path, dirName, sizeof(dirName)); 195 | File_GetFileName(path, fileName, sizeof(fileName)); 196 | StrCat(fileName, sizeof(fileName), "."); 197 | 198 | new Handle:__dir = OpenDirectory(dirName); 199 | while (ReadDirEntry(__dir, dirEntry, sizeof(dirEntry))) { 200 | 201 | if (StrEqual(dirEntry, ".") || StrEqual(dirEntry, "..")) { 202 | continue; 203 | } 204 | 205 | if (strncmp(dirEntry, fileName, strlen(fileName)) == 0) { 206 | Format(dirEntry, sizeof(dirEntry), "%s/%s", dirName, dirEntry); 207 | File_AddToDownloadsTable(dirEntry, recursive, ignoreExts, size); 208 | } 209 | } 210 | 211 | CloseHandle(__dir); 212 | } 213 | } 214 | 215 | return; 216 | } 217 | 218 | 219 | /* 220 | * Adds all files/paths in the given text file to the download table. 221 | * Recursive mode enabled, see File_AddToDownloadsTable() 222 | * Comments are allowed ! Supported comment types are ; // # 223 | * 224 | * @param path Path to the .txt file. 225 | * @noreturn 226 | */ 227 | stock File_ReadDownloadList(const String:path[]) 228 | { 229 | new Handle:file = OpenFile(path, "r"); 230 | 231 | if (file == INVALID_HANDLE) { 232 | return; 233 | } 234 | 235 | new String:buffer[PLATFORM_MAX_PATH]; 236 | while (!IsEndOfFile(file)) { 237 | ReadFileLine(file, buffer, sizeof(buffer)); 238 | 239 | new pos; 240 | pos = StrContains(buffer, "//"); 241 | if (pos != -1) { 242 | buffer[pos] = '\0'; 243 | } 244 | 245 | pos = StrContains(buffer, "#"); 246 | if (pos != -1) { 247 | buffer[pos] = '\0'; 248 | } 249 | 250 | pos = StrContains(buffer, ";"); 251 | if (pos != -1) { 252 | buffer[pos] = '\0'; 253 | } 254 | 255 | TrimString(buffer); 256 | 257 | if (buffer[0] == '\0') { 258 | continue; 259 | } 260 | 261 | File_AddToDownloadsTable(buffer); 262 | } 263 | 264 | CloseHandle(file); 265 | } 266 | 267 | /* 268 | * Attempts to load a translation file and optionally unloads the plugin if the file 269 | * doesn't exist (also prints an error message). 270 | * 271 | * @param file Filename of the translations file (eg. .phrases). 272 | * @param setFailState If true, it sets the failstate if the translations file doesn't exist 273 | * @return True on success, false otherwise (only if setFailState is set to false) 274 | */ 275 | stock File_LoadTranslations(const String:file[], setFailState=true) 276 | { 277 | decl String:path[PLATFORM_MAX_PATH]; 278 | 279 | BuildPath(Path_SM, path, sizeof(path), "translations/%s", file); 280 | 281 | if (FileExists(path)) { 282 | LoadTranslations(file); 283 | return true; 284 | } 285 | 286 | Format(path,sizeof(path), "%s.txt", path); 287 | 288 | if (!FileExists(path)) { 289 | 290 | if (setFailState) { 291 | SetFailState("Unable to locate translation file (%s).", path); 292 | } 293 | 294 | return false; 295 | } 296 | 297 | LoadTranslations(file); 298 | 299 | return true; 300 | } 301 | 302 | /* 303 | * Reads the contents of a given file into a string buffer in binary mode. 304 | * 305 | * @param path Path to the file 306 | * @param buffer String buffer 307 | * @param size If -1, reads until a null terminator is encountered in the file. Otherwise, read_count bytes are read into the buffer provided. In this case the buffer is not explicitly null terminated, and the buffer will contain any null terminators read from the file. 308 | * @return Number of characters written to the buffer, or -1 if an error was encountered. 309 | */ 310 | stock File_ToString(const String:path[], String:buffer[], size) 311 | { 312 | new Handle:file = OpenFile(path, "rb"); 313 | 314 | if (file == INVALID_HANDLE) { 315 | buffer[0] = '\0'; 316 | return -1; 317 | } 318 | 319 | new num_bytes_written = ReadFileString(file, buffer, size); 320 | CloseHandle(file); 321 | 322 | return num_bytes_written; 323 | } 324 | 325 | /* 326 | * Writes a string into a file in binary mode. 327 | * 328 | * @param file Path to the file 329 | * @param str String to write 330 | * @return True on success, false otherwise 331 | */ 332 | stock bool:File_StringToFile(const String:path[], String:str[]) 333 | { 334 | new Handle:file = OpenFile(path, "wb"); 335 | 336 | if (file == INVALID_HANDLE) { 337 | return false; 338 | } 339 | 340 | new bool:success = WriteFileString(file, str, false); 341 | CloseHandle(file); 342 | 343 | return success; 344 | } 345 | 346 | /* 347 | * Copies file source to destination 348 | * Based on code of javalia: 349 | * http://forums.alliedmods.net/showthread.php?t=159895 350 | * 351 | * @param source Input file 352 | * @param destination Output file 353 | */ 354 | stock bool:File_Copy(const String:source[], const String:destination[]) 355 | { 356 | new Handle:file_source = OpenFile(source, "rb"); 357 | 358 | if (file_source == INVALID_HANDLE) { 359 | return false; 360 | } 361 | 362 | new Handle:file_destination = OpenFile(destination, "wb"); 363 | 364 | if (file_destination == INVALID_HANDLE) { 365 | CloseHandle(file_source); 366 | return false; 367 | } 368 | 369 | new buffer[32]; 370 | new cache; 371 | 372 | while (!IsEndOfFile(file_source)) { 373 | cache = ReadFile(file_source, buffer, 32, 1); 374 | WriteFile(file_destination, buffer, cache, 1); 375 | } 376 | 377 | CloseHandle(file_source); 378 | CloseHandle(file_destination); 379 | 380 | return true; 381 | } 382 | 383 | /* 384 | * Recursively copies (the content) of a directory or file specified 385 | * by "path" to "destination". 386 | * Note that because of Sourcemod API limitations this currently does not 387 | * takeover the file permissions (it leaves them default). 388 | * Links will be resolved. 389 | * 390 | * @param path Source path 391 | * @param destination Destination directory (This can only be a directory) 392 | * @param stop_on_error Optional: Set to true to stop on error (ie can't read a file) 393 | * @param dirMode Optional: File mode for directories that will be created (Default = 0755), don't forget to convert FROM octal 394 | */ 395 | stock bool:File_CopyRecursive(const String:path[], const String:destination[], bool:stop_on_error=false, dirMode=493) 396 | { 397 | if (FileExists(path)) { 398 | return File_Copy(path, destination); 399 | } 400 | else if (DirExists(path)) { 401 | return Sub_File_CopyRecursive(path, destination, stop_on_error, FileType_Directory, dirMode); 402 | } 403 | else { 404 | return false; 405 | } 406 | } 407 | 408 | static stock bool:Sub_File_CopyRecursive(const String:path[], const String:destination[], bool:stop_on_error=false, FileType:fileType, dirMode) 409 | { 410 | if (fileType == FileType_File) { 411 | return File_Copy(path, destination); 412 | } 413 | else if (fileType == FileType_Directory) { 414 | 415 | if (!CreateDirectory(destination, dirMode) && stop_on_error) { 416 | return false; 417 | } 418 | 419 | new Handle:directory = OpenDirectory(path); 420 | 421 | if (directory == INVALID_HANDLE) { 422 | return false; 423 | } 424 | 425 | decl 426 | String:source_buffer[PLATFORM_MAX_PATH], 427 | String:destination_buffer[PLATFORM_MAX_PATH]; 428 | new FileType:type; 429 | 430 | while (ReadDirEntry(directory, source_buffer, sizeof(source_buffer), type)) { 431 | 432 | if (StrEqual(source_buffer, "..") || StrEqual(source_buffer, ".")) { 433 | continue; 434 | } 435 | 436 | Format(destination_buffer, sizeof(destination_buffer), "%s/%s", destination, source_buffer); 437 | Format(source_buffer, sizeof(source_buffer), "%s/%s", path, source_buffer); 438 | 439 | if (type == FileType_File) { 440 | File_Copy(source_buffer, destination_buffer); 441 | } 442 | else if (type == FileType_Directory) { 443 | 444 | if (!File_CopyRecursive(source_buffer, destination_buffer, stop_on_error, dirMode) && stop_on_error) { 445 | CloseHandle(directory); 446 | return false; 447 | } 448 | } 449 | } 450 | 451 | CloseHandle(directory); 452 | } 453 | else if (fileType == FileType_Unknown) { 454 | return false; 455 | } 456 | 457 | return true; 458 | } 459 | -------------------------------------------------------------------------------- /scripting/include/smlib/game.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_game_included 2 | #endinput 3 | #endif 4 | #define _smlib_game_included 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /* 11 | * End's the game and displays the scoreboard with intermission time. 12 | * 13 | * @noparam 14 | * @return True on success, false otherwise 15 | */ 16 | stock bool:Game_End() 17 | { 18 | new game_end = FindEntityByClassname(-1, "game_end"); 19 | 20 | if (game_end == -1) { 21 | game_end = CreateEntityByName("game_end"); 22 | 23 | if (game_end == -1) { 24 | ThrowError("Unable to find or create entity \"game_end\""); 25 | } 26 | } 27 | 28 | return AcceptEntityInput(game_end, "EndGame"); 29 | } 30 | 31 | /* 32 | * End's the current round, allows specifying the winning 33 | * team and more. 34 | * This function currently works in TF2 only (it uses the game_round_win entity). 35 | * 36 | * @param team The winning Team, pass 0 for Sudden Death mode (no winning team) 37 | * @param forceMapReset If to force the map to reset during the force respawn after the round is over. 38 | * @param switchTeams If to switch the teams when the game is going to be reset. 39 | * @return True on success, false otherwise 40 | */ 41 | stock bool:Game_EndRound(team=0, bool:forceMapReset=false, bool:switchTeams=false) 42 | { 43 | new game_round_win = FindEntityByClassname(-1, "game_round_win"); 44 | 45 | if (game_round_win == -1) { 46 | game_round_win = CreateEntityByName("game_round_win"); 47 | 48 | if (game_round_win == -1) { 49 | ThrowError("Unable to find or create entity \"game_round_win\""); 50 | } 51 | } 52 | 53 | DispatchKeyValue(game_round_win, "TeamNum" , (team ? "true" : "false")); 54 | DispatchKeyValue(game_round_win, "force_map_reset" , (forceMapReset? "true" : "false")); 55 | DispatchKeyValue(game_round_win, "switch_teams" , (switchTeams ? "true" : "false")); 56 | 57 | return AcceptEntityInput(game_round_win, "RoundWin"); 58 | } 59 | -------------------------------------------------------------------------------- /scripting/include/smlib/general.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_general_included 2 | #endinput 3 | #endif 4 | #define _smlib_general_included 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define TIME_TO_TICKS(%1) ( (int)( 0.5 + (float)(%1) / GetTickInterval() ) ) 11 | #define TICKS_TO_TIME(%1) ( GetTickInterval() * %1 ) 12 | #define ROUND_TO_TICKS(%1) ( TICK_INTERVAL * TIME_TO_TICKS( %1 ) ) 13 | 14 | /* 15 | * Precaches the given model. 16 | * It's best to call this OnMapStart(). 17 | * 18 | * @param material Path of the material to precache. 19 | * @return Returns the material index, INVALID_STRING_INDEX on error. 20 | */ 21 | stock PrecacheMaterial(const String:material[]) 22 | { 23 | static materialNames = INVALID_STRING_TABLE; 24 | 25 | if (materialNames == INVALID_STRING_TABLE) { 26 | if ((materialNames = FindStringTable("Materials")) == INVALID_STRING_TABLE) { 27 | return INVALID_STRING_INDEX; 28 | } 29 | } 30 | 31 | new index = FindStringIndex2(materialNames, material); 32 | if (index == INVALID_STRING_INDEX) { 33 | new numStrings = GetStringTableNumStrings(materialNames); 34 | if (numStrings >= GetStringTableMaxStrings(materialNames)) { 35 | return INVALID_STRING_INDEX; 36 | } 37 | 38 | AddToStringTable(materialNames, material); 39 | index = numStrings; 40 | } 41 | 42 | return index; 43 | } 44 | 45 | /* 46 | * Checks if the material is precached. 47 | * 48 | * @param material Path of the material. 49 | * @return True if it is precached, false otherwise. 50 | */ 51 | stock bool:IsMaterialPrecached(const String:material[]) 52 | { 53 | static materialNames = INVALID_STRING_TABLE; 54 | 55 | if (materialNames == INVALID_STRING_TABLE) { 56 | if ((materialNames = FindStringTable("Materials")) == INVALID_STRING_TABLE) { 57 | return false; 58 | } 59 | } 60 | 61 | return (FindStringIndex2(materialNames, material) != INVALID_STRING_INDEX); 62 | } 63 | 64 | /* 65 | * Precaches the given particle system. 66 | * It's best to call this OnMapStart(). 67 | * Code based on Rochellecrab's, thanks. 68 | * 69 | * @param particleSystem Name of the particle system to precache. 70 | * @return Returns the particle system index, INVALID_STRING_INDEX on error. 71 | */ 72 | stock PrecacheParticleSystem(const String:particleSystem[]) 73 | { 74 | static particleEffectNames = INVALID_STRING_TABLE; 75 | 76 | if (particleEffectNames == INVALID_STRING_TABLE) { 77 | if ((particleEffectNames = FindStringTable("ParticleEffectNames")) == INVALID_STRING_TABLE) { 78 | return INVALID_STRING_INDEX; 79 | } 80 | } 81 | 82 | new index = FindStringIndex2(particleEffectNames, particleSystem); 83 | if (index == INVALID_STRING_INDEX) { 84 | new numStrings = GetStringTableNumStrings(particleEffectNames); 85 | if (numStrings >= GetStringTableMaxStrings(particleEffectNames)) { 86 | return INVALID_STRING_INDEX; 87 | } 88 | 89 | AddToStringTable(particleEffectNames, particleSystem); 90 | index = numStrings; 91 | } 92 | 93 | return index; 94 | } 95 | 96 | /* 97 | * Checks if the particle system is precached. 98 | * 99 | * @param material Name of the particle system 100 | * @return True if it is precached, false otherwise. 101 | */ 102 | stock bool:IsParticleSystemPrecached(const String:particleSystem[]) 103 | { 104 | static particleEffectNames = INVALID_STRING_TABLE; 105 | 106 | if (particleEffectNames == INVALID_STRING_TABLE) { 107 | if ((particleEffectNames = FindStringTable("ParticleEffectNames")) == INVALID_STRING_TABLE) { 108 | return false; 109 | } 110 | } 111 | 112 | return (FindStringIndex2(particleEffectNames, particleSystem) != INVALID_STRING_INDEX); 113 | } 114 | 115 | /* 116 | * Searches for the index of a given string in a string table. 117 | * 118 | * @param table String table name. 119 | * @param str String to find. 120 | * @return String index if found, INVALID_STRING_INDEX otherwise. 121 | */ 122 | stock FindStringIndexByTableName(const String:table[], const String:str[]) 123 | { 124 | new tableIndex = INVALID_STRING_TABLE; 125 | if ((tableIndex = FindStringTable("ParticleEffectNames")) == INVALID_STRING_TABLE) { 126 | return INVALID_STRING_INDEX; 127 | } 128 | 129 | return FindStringIndex2(tableIndex, str); 130 | } 131 | 132 | /* 133 | * Rewrite of FindStringIndex, because in my tests 134 | * FindStringIndex failed to work correctly. 135 | * Searches for the index of a given string in a string table. 136 | * 137 | * @param tableidx A string table index. 138 | * @param str String to find. 139 | * @return String index if found, INVALID_STRING_INDEX otherwise. 140 | */ 141 | stock FindStringIndex2(tableidx, const String:str[]) 142 | { 143 | decl String:buf[1024]; 144 | 145 | new numStrings = GetStringTableNumStrings(tableidx); 146 | for (new i=0; i < numStrings; i++) { 147 | ReadStringTable(tableidx, i, buf, sizeof(buf)); 148 | 149 | if (StrEqual(buf, str)) { 150 | return i; 151 | } 152 | } 153 | 154 | return INVALID_STRING_INDEX; 155 | } 156 | 157 | /* 158 | * Converts a long IP to a dotted format String. 159 | * 160 | * @param ip IP Long 161 | * @param buffer String Buffer (size = 16) 162 | * @param size String Buffer size 163 | * @noreturn 164 | */ 165 | stock LongToIP(ip, String:buffer[], size) 166 | { 167 | Format( 168 | buffer, size, 169 | "%d.%d.%d.%d", 170 | (ip >> 24) & 0xFF, 171 | (ip >> 16) & 0xFF, 172 | (ip >> 8 ) & 0xFF, 173 | ip & 0xFF 174 | ); 175 | } 176 | 177 | /* 178 | * Converts a dotted format String IP to a long. 179 | * 180 | * @param ip IP String 181 | * @return Long IP 182 | */ 183 | stock IPToLong(const String:ip[]) 184 | { 185 | decl String:pieces[4][4]; 186 | 187 | if (ExplodeString(ip, ".", pieces, sizeof(pieces), sizeof(pieces[])) != 4) { 188 | return 0; 189 | } 190 | 191 | return ( 192 | StringToInt(pieces[0]) << 24 | 193 | StringToInt(pieces[1]) << 16 | 194 | StringToInt(pieces[2]) << 8 | 195 | StringToInt(pieces[3]) 196 | ); 197 | } 198 | 199 | static localIPRanges[] = 200 | { 201 | 10 << 24, // 10. 202 | 127 << 24 | 1 , // 127.0.0.1 203 | 127 << 24 | 16 << 16, // 127.16. 204 | 192 << 24 | 168 << 16, // 192.168. 205 | }; 206 | 207 | /* 208 | * Checks whether an IP is a private/internal IP 209 | * 210 | * @param ip IP Long 211 | * @return True if the IP is local, false otherwise. 212 | */ 213 | stock bool:IsIPLocal(ip) 214 | { 215 | new range, bits, move, bool:matches; 216 | 217 | for (new i=0; i < sizeof(localIPRanges); i++) { 218 | 219 | range = localIPRanges[i]; 220 | matches = true; 221 | 222 | for (new j=0; j < 4; j++) { 223 | move = j * 8; 224 | bits = (range >> move) & 0xFF; 225 | 226 | if (bits && bits != ((ip >> move) & 0xFF)) { 227 | matches = false; 228 | } 229 | } 230 | 231 | if (matches) { 232 | return true; 233 | } 234 | } 235 | 236 | return false; 237 | } 238 | 239 | /* 240 | * Closes the given hindle and sets it to INVALID_HANDLE. 241 | * 242 | * @param handle handle 243 | * @noreturn 244 | */ 245 | stock ClearHandle(&Handle:handle) 246 | { 247 | if (handle != INVALID_HANDLE) { 248 | CloseHandle(handle); 249 | handle = INVALID_HANDLE; 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /scripting/include/smlib/math.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_math_included 2 | #endinput 3 | #endif 4 | #define _smlib_math_included 5 | 6 | #include 7 | 8 | #define SIZE_OF_INT 2147483647 // without 0 9 | #define INT_MAX_DIGITS 10 10 | 11 | #define GAMEUNITS_TO_METERS 0.01905 12 | #define METERS_TO_GAMEUNITS 52.49343832020997 13 | #define METERS_TO_FEET 3.2808399 14 | #define FEET_TO_METERS 0.3048 15 | #define KILOMETERS_TO_MILES 0.62137 16 | 17 | enum VecAngle 18 | { 19 | ANG_ALPHA, 20 | ANG_BETA, 21 | ANG_GAMMA 22 | } 23 | 24 | /** 25 | * Makes a negative integer number to a positive integer number. 26 | * This is faster than Sourcemod's native FloatAbs() for integers. 27 | * Use FloatAbs() for Float numbers. 28 | * 29 | * @param number A number that can be positive or negative. 30 | * @return Positive number. 31 | */ 32 | stock Math_Abs(value) 33 | { 34 | return (value ^ (value >> 31)) - (value >> 31); 35 | } 36 | 37 | /** 38 | * Checks if 2 vectors are equal. 39 | * You can specfiy a tolerance, which is the maximum distance at which vectors are considered equals 40 | * 41 | * @param vec1 First vector (3 dim array) 42 | * @param vec2 Second vector (3 dim array) 43 | * @param tolerance If you want to check that those vectors are somewhat even. 0.0 means they are 100% even if this function returns true. 44 | * @return True if vectors are equal, false otherwise. 45 | */ 46 | stock bool:Math_VectorsEqual(Float:vec1[3], Float:vec2[3], Float:tolerance=0.0) 47 | { 48 | new Float:distance = GetVectorDistance(vec1, vec2, true); 49 | 50 | return distance <= (tolerance * tolerance); 51 | } 52 | 53 | /** 54 | * Sets the given value to min 55 | * if the value is smaller than the given. 56 | * 57 | * @param value Value 58 | * @param min Min Value used as lower border 59 | * @return Correct value not lower than min 60 | */ 61 | stock any:Math_Min(any:value, any:min) 62 | { 63 | if (value < min) { 64 | value = min; 65 | } 66 | 67 | return value; 68 | } 69 | 70 | /** 71 | * Sets the given value to max 72 | * if the value is greater than the given. 73 | * 74 | * @param value Value 75 | * @param max Max Value used as upper border 76 | * @return Correct value not upper than max 77 | */ 78 | stock any:Math_Max(any:value, any:max) 79 | { 80 | if (value > max) { 81 | value = max; 82 | } 83 | 84 | return value; 85 | } 86 | 87 | /** 88 | * Makes sure a value is within a certain range and 89 | * returns the value. 90 | * If the value is outside the range it is set to either 91 | * min or max, if it is inside the range it will just return 92 | * the specified value. 93 | * 94 | * @param value Value 95 | * @param min Min value used as lower border 96 | * @param max Max value used as upper border 97 | * @return Correct value not lower than min and not greater than max. 98 | */ 99 | stock any:Math_Clamp(any:value, any:min, any:max) 100 | { 101 | value = Math_Min(value, min); 102 | value = Math_Max(value, max); 103 | 104 | return value; 105 | } 106 | 107 | /* 108 | * Checks if the value is within the given bounds (min & max). 109 | * 110 | * @param value The value you want to check. 111 | * @param min The lower border. 112 | * @param max The upper border. 113 | * @return True if the value is within bounds (bigger or equal min / smaller or equal max), false otherwise. 114 | */ 115 | stock bool:Math_IsInBounds(any:value, any:min, any:max) 116 | { 117 | if (value < min || value > max) { 118 | return false; 119 | } 120 | 121 | return true; 122 | } 123 | 124 | /** 125 | * Let's the specified value "overflow" if it is outside the given limit. 126 | * This is like with integers when it reaches a value above the max possible 127 | * integer size. 128 | * 129 | * @param value Value 130 | * @param min Min value used as lower border 131 | * @param max Max value used as upper border 132 | * @return Overflowed number 133 | */ 134 | stock any:Math_Overflow(any:value, any:min, any:max) 135 | { 136 | return (value % max) + min; 137 | } 138 | 139 | /** 140 | * Returns a random, uniform Integer number in the specified (inclusive) range. 141 | * This is safe to use multiple times in a function. 142 | * The seed is set automatically for each plugin. 143 | * Rewritten by MatthiasVance, thanks. 144 | * 145 | * @param min Min value used as lower border 146 | * @param max Max value used as upper border 147 | * @return Random Integer number between min and max 148 | */ 149 | stock Math_GetRandomInt(min, max) 150 | { 151 | new random = GetURandomInt(); 152 | 153 | if (random == 0) { 154 | random++; 155 | } 156 | 157 | return RoundToCeil(float(random) / (float(SIZE_OF_INT) / float(max - min + 1))) + min - 1; 158 | } 159 | 160 | /** 161 | * Returns a random, uniform Float number in the specified (inclusive) range. 162 | * This is safe to use multiple times in a function. 163 | * The seed is set automatically for each plugin. 164 | * 165 | * @param min Min value used as lower border 166 | * @param max Max value used as upper border 167 | * @return Random Float number between min and max 168 | */ 169 | stock Float:Math_GetRandomFloat(Float:min, Float:max) 170 | { 171 | return (GetURandomFloat() * (max - min)) + min; 172 | } 173 | 174 | /** 175 | * Gets the percentage of amount in all as Integer where 176 | * amount and all are numbers and amount usually 177 | * is a subset of all. 178 | * 179 | * @param value Integer value 180 | * @param all Integer value 181 | * @return An Integer value between 0 and 100 (inclusive). 182 | */ 183 | stock Math_GetPercentage(value, all) { 184 | return RoundToNearest((float(value) / float(all)) * 100.0); 185 | } 186 | 187 | /** 188 | * Gets the percentage of amount in all as Float where 189 | * amount and all are numbers and amount usually 190 | * is a subset of all. 191 | * 192 | * @param value Float value 193 | * @param all Float value 194 | * @return A Float value between 0.0 and 100.0 (inclusive). 195 | */ 196 | stock Float:Math_GetPercentageFloat(Float:value, Float:all) { 197 | return (value / all) * 100.0; 198 | } 199 | 200 | /* 201 | * Moves the start vector on a direct line to the end vector by the given scale. 202 | * Note: If scale is 0.0 the output will be the same as the start vector and if scale is 1.0 the output vector will be the same as the end vector. 203 | * Exmaple usage: Move an entity to another entity but only 12 units: Vector_MoveVector(entity1Origin,entity2Origin,(12.0 / GetVectorDistance(entity1Origin,entity2Origin)),newEntity1Origin); now only teleport your entity to newEntity1Origin. 204 | * 205 | * @param start The start vector where the imagined line starts. 206 | * @param end The end vector where the imagined line ends. 207 | * @param scale The position on the line 0.0 is the start 1.0 is the end. 208 | * @param output Output vector 209 | * @noreturn 210 | */ 211 | stock Math_MoveVector(const Float:start[3], const Float:end[3], Float:scale, Float:output[3]) 212 | { 213 | SubtractVectors(end,start,output); 214 | ScaleVector(output,scale); 215 | AddVectors(start,output,output); 216 | } 217 | 218 | /** 219 | * Puts x, y and z into a vector. 220 | * 221 | * @param x Float value. 222 | * @param y Float value. 223 | * @param z Float value. 224 | * @param result Output vector. 225 | * @noreturn 226 | */ 227 | stock Math_MakeVector(const Float:x, const Float:y, const Float:z, Float:result[3]) 228 | { 229 | result[0] = x; 230 | result[1] = y; 231 | result[2] = z; 232 | } 233 | 234 | /** 235 | * Rotates a vector around its zero-point. 236 | * Note: As example you can rotate mins and maxs of an entity and then add its origin to mins and maxs to get its bounding box in relation to the world and its rotation. 237 | * When used with players use the following angle input: 238 | * angles[0] = 0.0; 239 | * angles[1] = 0.0; 240 | * angles[2] = playerEyeAngles[1]; 241 | * 242 | * @param vec Vector to rotate. 243 | * @param angles How to rotate the vector. 244 | * @param result Output vector. 245 | * @noreturn 246 | */ 247 | stock Math_RotateVector(const Float:vec[3], const Float:angles[3], Float:result[3]) 248 | { 249 | // First the angle/radiant calculations 250 | decl Float:rad[3]; 251 | // I don't really know why, but the alpha, beta, gamma order of the angles are messed up... 252 | // 2 = xAxis 253 | // 0 = yAxis 254 | // 1 = zAxis 255 | rad[0] = DegToRad(angles[2]); 256 | rad[1] = DegToRad(angles[0]); 257 | rad[2] = DegToRad(angles[1]); 258 | 259 | // Pre-calc function calls 260 | new Float:cosAlpha = Cosine(rad[0]); 261 | new Float:sinAlpha = Sine(rad[0]); 262 | new Float:cosBeta = Cosine(rad[1]); 263 | new Float:sinBeta = Sine(rad[1]); 264 | new Float:cosGamma = Cosine(rad[2]); 265 | new Float:sinGamma = Sine(rad[2]); 266 | 267 | // 3D rotation matrix for more information: http://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions 268 | new Float:x = vec[0], Float:y = vec[1], Float:z = vec[2]; 269 | new Float:newX, Float:newY, Float:newZ; 270 | newY = cosAlpha*y - sinAlpha*z; 271 | newZ = cosAlpha*z + sinAlpha*y; 272 | y = newY; 273 | z = newZ; 274 | 275 | newX = cosBeta*x + sinBeta*z; 276 | newZ = cosBeta*z - sinBeta*x; 277 | x = newX; 278 | z = newZ; 279 | 280 | newX = cosGamma*x - sinGamma*y; 281 | newY = cosGamma*y + sinGamma*x; 282 | x = newX; 283 | y = newY; 284 | 285 | // Store everything... 286 | result[0] = x; 287 | result[1] = y; 288 | result[2] = z; 289 | } 290 | 291 | /** 292 | * Converts Source Game Units to metric Meters 293 | * 294 | * @param units Float value 295 | * @return Meters as Float value. 296 | */ 297 | stock Float:Math_UnitsToMeters(Float:units) 298 | { 299 | return (units * GAMEUNITS_TO_METERS); 300 | } 301 | 302 | /** 303 | * Converts Source Game Units to Meters 304 | * 305 | * @param units Float value 306 | * @return Feet as Float value. 307 | */ 308 | stock Float:Math_UnitsToFeet(Float:units) 309 | { 310 | return (Math_UnitsToMeters(units) * METERS_TO_FEET); 311 | } 312 | 313 | /** 314 | * Converts Source Game Units to Centimeters 315 | * 316 | * @param units Float value 317 | * @return Centimeters as Float value. 318 | */ 319 | stock Float:Math_UnitsToCentimeters(Float:units) 320 | { 321 | return (Math_UnitsToMeters(units) * 100.0); 322 | } 323 | 324 | /** 325 | * Converts Source Game Units to Kilometers 326 | * 327 | * @param units Float value 328 | * @return Kilometers as Float value. 329 | */ 330 | stock Float:Math_UnitsToKilometers(Float:units) 331 | { 332 | return (Math_UnitsToMeters(units) / 1000.0); 333 | } 334 | 335 | /** 336 | * Converts Source Game Units to Miles 337 | * 338 | * @param units Float value 339 | * @return Miles as Float value. 340 | */ 341 | stock Float:Math_UnitsToMiles(Float:units) 342 | { 343 | return (Math_UnitsToKilometers(units) * KILOMETERS_TO_MILES); 344 | } 345 | -------------------------------------------------------------------------------- /scripting/include/smlib/menus.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_menus_included 2 | #endinput 3 | #endif 4 | #define _smlib_menus_included 5 | 6 | #include 7 | #include 8 | 9 | /** 10 | * Adds an option to a menu with a String display but an integer 11 | * identifying the option. 12 | * 13 | * @param menu Handle to the menu 14 | * @param value Integer value for the option 15 | * @param display Display text for the menu 16 | * @noreturn 17 | */ 18 | stock Menu_AddIntItem(Handle:menu, any:value, String:display[]) 19 | { 20 | decl String:buffer[INT_MAX_DIGITS + 1]; 21 | IntToString(value, buffer, sizeof(buffer)); 22 | AddMenuItem(menu, buffer, display); 23 | } 24 | 25 | /** 26 | * Retrieves an integer-value choice from a menu, where the 27 | * menu's information strings were created as integers. 28 | * 29 | * @param menu Handle to the menu 30 | * @param param2 The item position selected from the menu. 31 | * @return Integer choice from the menu, or 0 if the integer could not be parsed. 32 | */ 33 | stock any:Menu_GetIntItem(Handle:menu, any:param2) 34 | { 35 | decl String:buffer[INT_MAX_DIGITS + 1]; 36 | GetMenuItem(menu, param2, buffer, sizeof(buffer)); 37 | return StringToInt(buffer); 38 | } 39 | -------------------------------------------------------------------------------- /scripting/include/smlib/server.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_server_included 2 | #endinput 3 | #endif 4 | #define _smlib_server_included 5 | 6 | #include 7 | #include 8 | 9 | /* 10 | * Gets the server's public/external (default) or 11 | * private/local (usually server's behind a NAT) IP. 12 | * If your server is behind a NAT Router, you need the SteamTools 13 | * extension available at http://forums.alliedmods.net/showthread.php?t=129763 14 | * to get the public IP. has to be included BEFORE . 15 | * If the server is not behind NAT, the public IP is the same as the private IP. 16 | * 17 | * @param public Set to true to retrieve the server's public/external IP, false otherwise. 18 | * @return Long IP or 0 if the IP couldn't be retrieved. 19 | */ 20 | stock Server_GetIP(bool:public_=true) 21 | { 22 | new ip = 0; 23 | 24 | static Handle:cvHostip = INVALID_HANDLE; 25 | 26 | if (cvHostip == INVALID_HANDLE) { 27 | cvHostip = FindConVar("hostip"); 28 | MarkNativeAsOptional("Steam_GetPublicIP"); 29 | } 30 | 31 | if (cvHostip != INVALID_HANDLE) { 32 | ip = GetConVarInt(cvHostip); 33 | } 34 | 35 | if (ip != 0 && IsIPLocal(ip) == public_) { 36 | ip = 0; 37 | } 38 | 39 | #if defined _steamtools_included 40 | if (ip == 0) { 41 | if (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "Steam_GetPublicIP") == FeatureStatus_Available) { 42 | decl octets[4]; 43 | Steam_GetPublicIP(octets); 44 | 45 | ip = 46 | octets[0] << 24 | 47 | octets[1] << 16 | 48 | octets[2] << 8 | 49 | octets[3]; 50 | 51 | if (IsIPLocal(ip) == public_) { 52 | ip = 0; 53 | } 54 | } 55 | } 56 | #endif 57 | 58 | return ip; 59 | } 60 | 61 | /* 62 | * Gets the server's public/external (default) or 63 | * private/local (usually server's behind a NAT) as IP String in dotted format. 64 | * If your server is behind a NAT Router, you need the SteamTools 65 | * extension available at http://forums.alliedmods.net/showthread.php?t=129763 66 | * to get the public IP. has to be included BEFORE . 67 | * If the public IP couldn't be found, an empty String is returned. 68 | * If the server is not behind NAT, the public IP is the same as the private IP. 69 | * 70 | * @param buffer String buffer (size=16) 71 | * @param size String buffer size. 72 | * @param public Set to true to retrieve the server's public/external IP, false otherwise. 73 | * @return True on success, false otherwise. 74 | */ 75 | stock bool:Server_GetIPString(String:buffer[], size, bool:public_=true) 76 | { 77 | new ip; 78 | 79 | if ((ip = Server_GetIP(public_)) == 0) { 80 | buffer[0] = '\0'; 81 | return false; 82 | } 83 | 84 | LongToIP(ip, buffer, size); 85 | 86 | return true; 87 | } 88 | 89 | /* 90 | * Gets the server's local port. 91 | * 92 | * @noparam 93 | * @return The server's port, 0 if there is no port. 94 | */ 95 | stock Server_GetPort() 96 | { 97 | static Handle:cvHostport = INVALID_HANDLE; 98 | 99 | if (cvHostport == INVALID_HANDLE) { 100 | cvHostport = FindConVar("hostport"); 101 | } 102 | 103 | if (cvHostport == INVALID_HANDLE) { 104 | return 0; 105 | } 106 | 107 | new port = GetConVarInt(cvHostport); 108 | 109 | return port; 110 | } 111 | 112 | /* 113 | * Gets the server's hostname 114 | * 115 | * @param hostname String buffer 116 | * @param size String buffer size 117 | * @return True on success, false otherwise. 118 | */ 119 | stock bool:Server_GetHostName(String:buffer[], size) 120 | { 121 | static Handle:cvHostname = INVALID_HANDLE; 122 | 123 | if (cvHostname == INVALID_HANDLE) { 124 | cvHostname = FindConVar("hostname"); 125 | } 126 | 127 | if (cvHostname == INVALID_HANDLE) { 128 | buffer[0] = '\0'; 129 | return false; 130 | } 131 | 132 | GetConVarString(cvHostname, buffer, size); 133 | 134 | return true; 135 | } 136 | -------------------------------------------------------------------------------- /scripting/include/smlib/sql.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_sql_included 2 | #endinput 3 | #endif 4 | #define _smlib_sql_included 5 | 6 | #include 7 | #include 8 | 9 | /** 10 | * Executes a threaded SQL Query (See: SQL_TQuery) 11 | * This function supports the printf Syntax. 12 | * 13 | * 14 | * @param database A database Handle. 15 | * @param callback Callback; database is in "owner" and the query Handle is passed in "hndl". 16 | * @param data Extra data value to pass to the callback. 17 | * @param format Query string, printf syntax supported 18 | * @param priority Priority queue to use 19 | * @param ... Variable number of format parameters. 20 | * @noreturn 21 | */ 22 | stock SQL_TQueryF(Handle:database, SQLTCallback:callback, any:data, DBPriority:priority=DBPrio_Normal, const String:format[], any:...) { 23 | 24 | if (database == INVALID_HANDLE) { 25 | ThrowError("[SMLIB] Error: Invalid database handle."); 26 | return; 27 | } 28 | 29 | decl String:query[16384]; 30 | VFormat(query, sizeof(query), format, 6); 31 | 32 | SQL_TQuery(database, callback, query, data, priority); 33 | } 34 | 35 | /** 36 | * Fetches an integer from a field in the current row of a result set (See: SQL_FetchInt) 37 | * 38 | * @param query A query (or statement) Handle. 39 | * @param field The field index (starting from 0). 40 | * @param result Optional variable to store the status of the return value. 41 | * @return An integer value. 42 | * @error Invalid query Handle or field index, invalid 43 | * type conversion requested from the database, 44 | * or no current result set. 45 | */ 46 | stock SQL_FetchIntByName(Handle:query, String:fieldName[], &DBResult:result=DBVal_Error) { 47 | 48 | new fieldNum; 49 | SQL_FieldNameToNum(query, fieldName, fieldNum); 50 | 51 | return SQL_FetchInt(query, fieldNum, result); 52 | } 53 | 54 | /** 55 | * Fetches a bool from a field in the current row of a result set (See: SQL_FetchInt) 56 | * 57 | * @param query A query (or statement) Handle. 58 | * @param field The field index (starting from 0). 59 | * @param result Optional variable to store the status of the return value. 60 | * @return A bool value. 61 | * @error Invalid query Handle or field index, invalid 62 | * type conversion requested from the database, 63 | * or no current result set. 64 | */ 65 | stock bool:SQL_FetchBoolByName(Handle:query, String:fieldName[], &DBResult:result=DBVal_Error) { 66 | 67 | return bool:SQL_FetchIntByName(query, fieldName, result); 68 | } 69 | 70 | /** 71 | * Fetches a float from a field in the current row of a result set. (See: SQL_FetchFloat) 72 | * 73 | * @param query A query (or statement) Handle. 74 | * @param field The field index (starting from 0). 75 | * @param result Optional variable to store the status of the return value. 76 | * @return A float value. 77 | * @error Invalid query Handle or field index, invalid 78 | * type conversion requested from the database, 79 | * or no current result set. 80 | */ 81 | stock Float:SQL_FetchFloatByName(Handle:query, String:fieldName[], &DBResult:result=DBVal_Error) { 82 | 83 | new fieldNum; 84 | SQL_FieldNameToNum(query, fieldName, fieldNum); 85 | 86 | return SQL_FetchFloat(query, fieldNum, result); 87 | } 88 | 89 | /** 90 | * Fetches a string from a field in the current row of a result set. (See: SQL_FetchString) 91 | * 92 | * @param query A query (or statement) Handle. 93 | * @param field The field index (starting from 0). 94 | * @param buffer String buffer. 95 | * @param maxlength Maximum size of the string buffer. 96 | * @param result Optional variable to store the status of the return value. 97 | * @return Number of bytes written. 98 | * @error Invalid query Handle or field index, invalid 99 | * type conversion requested from the database, 100 | * or no current result set. 101 | */ 102 | stock SQL_FetchStringByName(Handle:query, String:fieldName[], String:buffer[], maxlength, &DBResult:result=DBVal_Error) { 103 | 104 | new fieldNum; 105 | SQL_FieldNameToNum(query, fieldName, fieldNum); 106 | 107 | return SQL_FetchString(query, fieldNum, buffer, maxlength, result); 108 | } 109 | -------------------------------------------------------------------------------- /scripting/include/smlib/strings.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_strings_included 2 | #endinput 3 | #endif 4 | #define _smlib_strings_included 5 | 6 | #include 7 | #include 8 | 9 | /** 10 | * Checks if the string is numeric. 11 | * This correctly handles + - . in the String. 12 | * 13 | * @param str String to check. 14 | * @return True if the String is numeric, false otherwise.. 15 | */ 16 | stock bool:String_IsNumeric(const String:str[]) 17 | { 18 | new x=0; 19 | new dotsFound=0; 20 | new numbersFound=0; 21 | 22 | if (str[x] == '+' || str[x] == '-') { 23 | x++; 24 | } 25 | 26 | while (str[x] != '\0') { 27 | 28 | if (IsCharNumeric(str[x])) { 29 | numbersFound++; 30 | } 31 | else if (str[x] == '.') { 32 | dotsFound++; 33 | 34 | if (dotsFound > 1) { 35 | return false; 36 | } 37 | } 38 | else { 39 | return false; 40 | } 41 | 42 | x++; 43 | } 44 | 45 | if (!numbersFound) { 46 | return false; 47 | } 48 | 49 | return true; 50 | } 51 | 52 | /** 53 | * Trims a string by removing the specified chars from beginning and ending. 54 | * Removes all ' ', '\t', '\r', '\n' characters by default. 55 | * The Output String can be the same as the Input String. 56 | * 57 | * @param str Input String. 58 | * @param output Output String (Can be the as the input). 59 | * @param size Size of the output String. 60 | * @param chars Characters to remove. 61 | * @noreturn 62 | */ 63 | stock String_Trim(const String:str[], String:output[], size, const String:chrs[]=" \t\r\n") 64 | { 65 | new x=0; 66 | while (str[x] != '\0' && FindCharInString(chrs, str[x]) != -1) { 67 | x++; 68 | } 69 | 70 | x = strcopy(output, size, str[x]); 71 | x--; 72 | 73 | while (x >= 0 && FindCharInString(chrs, output[x]) != -1) { 74 | x--; 75 | } 76 | 77 | output[++x] = '\0'; 78 | } 79 | 80 | /** 81 | * Removes a list of strings from a string. 82 | * 83 | * @param buffer Input/Ourput buffer. 84 | * @param removeList A list of strings which should be removed from buffer. 85 | * @param size Number of Strings in the List. 86 | * @param caseSensitive If true, comparison is case sensitive. If false (default), comparison is case insensitive. 87 | * @noreturn 88 | */ 89 | stock String_RemoveList(String:buffer[], String:removeList[][], size, bool:caseSensitive=false) 90 | { 91 | for (new i=0; i < size; i++) { 92 | ReplaceString(buffer, SIZE_OF_INT, removeList[i], "", caseSensitive); 93 | } 94 | } 95 | 96 | /** 97 | * Converts the whole String to lower case. 98 | * Only works with alphabetical characters (not ÖÄÜ) because Sourcemod suxx ! 99 | * The Output String can be the same as the Input String. 100 | * 101 | * @param input Input String. 102 | * @param output Output String. 103 | * @param size Max Size of the Output string 104 | * @noreturn 105 | */ 106 | stock String_ToLower(const String:input[], String:output[], size) 107 | { 108 | size--; 109 | 110 | new x=0; 111 | while (input[x] != '\0' && x < size) { 112 | 113 | output[x] = CharToLower(input[x]); 114 | 115 | x++; 116 | } 117 | 118 | output[x] = '\0'; 119 | } 120 | 121 | /** 122 | * Converts the whole String to upper case. 123 | * Only works with alphabetical characters (not öäü) because Sourcemod suxx ! 124 | * The Output String can be the same as the Input String. 125 | * 126 | * @param input Input String. 127 | * @param output Output String. 128 | * @param size Max Size of the Output string 129 | * @noreturn 130 | */ 131 | stock String_ToUpper(const String:input[], String:output[], size) 132 | { 133 | size--; 134 | 135 | new x=0; 136 | while (input[x] != '\0' && x < size) { 137 | 138 | output[x] = CharToUpper(input[x]); 139 | 140 | x++; 141 | } 142 | 143 | output[x] = '\0'; 144 | } 145 | 146 | /** 147 | * Generates a random string. 148 | * 149 | * 150 | * @param buffer String Buffer. 151 | * @param size String Buffer size (must be length+1) 152 | * @param length Number of characters being generated. 153 | * @param chrs String for specifying the characters used for random character generation. 154 | * By default it will use all letters of the alphabet (upper and lower) and all numbers. 155 | * If you pass an empty String, it will use all readable ASCII characters (33 - 126) 156 | * @noreturn 157 | */ 158 | stock String_GetRandom(String:buffer[], size, length=32, const String:chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234556789") 159 | { 160 | new random, len; 161 | size--; 162 | 163 | if (chrs[0] != '\0') { 164 | len = strlen(chrs) - 1; 165 | } 166 | 167 | new n = 0; 168 | while (n < length && n < size) { 169 | 170 | if (chrs[0] == '\0') { 171 | random = Math_GetRandomInt(33, 126); 172 | buffer[n] = random; 173 | } 174 | else { 175 | random = Math_GetRandomInt(0, len); 176 | buffer[n] = chrs[random]; 177 | } 178 | 179 | n++; 180 | } 181 | 182 | buffer[length] = '\0'; 183 | } 184 | 185 | /** 186 | * Checks if string str starts with subString. 187 | * 188 | * 189 | * @param str String to check 190 | * @param subString Sub-String to check in str 191 | * @return True if str starts with subString, false otherwise. 192 | */ 193 | stock bool:String_StartsWith(const String:str[], const String:subString[]) 194 | { 195 | new n = 0; 196 | while (subString[n] != '\0') { 197 | 198 | if (str[n] == '\0' || str[n] != subString[n]) { 199 | return false; 200 | } 201 | 202 | n++; 203 | } 204 | 205 | return true; 206 | } 207 | 208 | /** 209 | * Checks if string str ends with subString. 210 | * 211 | * 212 | * @param str String to check 213 | * @param subString Sub-String to check in str 214 | * @return True if str ends with subString, false otherwise. 215 | */ 216 | stock bool:String_EndsWith(const String:str[], const String:subString[]) 217 | { 218 | new n_str = strlen(str) - 1; 219 | new n_subString = strlen(subString) - 1; 220 | 221 | if(n_str < n_subString) { 222 | return false; 223 | } 224 | 225 | while (n_str != 0 && n_subString != 0) { 226 | 227 | if (str[n_str--] != subString[n_subString--]) { 228 | return false; 229 | } 230 | } 231 | 232 | return true; 233 | } 234 | -------------------------------------------------------------------------------- /scripting/include/smlib/teams.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_teams_included 2 | #endinput 3 | #endif 4 | #define _smlib_teams_included 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define MAX_TEAMS 32 // Max number of teams in a game 11 | #define MAX_TEAM_NAME_LENGTH 32 // Max length of a team's name 12 | 13 | // Team Defines 14 | #define TEAM_INVALID -1 15 | #define TEAM_UNASSIGNED 0 16 | #define TEAM_SPECTATOR 1 17 | #define TEAM_ONE 2 18 | #define TEAM_TWO 3 19 | #define TEAM_THREE 4 20 | #define TEAM_FOUR 5 21 | 22 | /* 23 | * If one team is empty its assumed single team mode is enabled and the game won't start. 24 | * 25 | * @noparam 26 | * @return True if one team is empty, false otherwise. 27 | */ 28 | stock bool:Team_HaveAllPlayers(bool:countFakeClients=true) { 29 | 30 | new teamCount = GetTeamCount(); 31 | for (new i=2; i < teamCount; i++) { 32 | 33 | if (Team_GetClientCount(i, ((countFakeClients) ? CLIENTFILTER_ALL : CLIENTFILTER_NOBOTS)) == 0) { 34 | return false; 35 | } 36 | } 37 | 38 | return true; 39 | } 40 | 41 | /* 42 | * Returns the client count of the players in a team. 43 | * 44 | * @param team Team Index. 45 | * @param flags Client Filter Flags (Use the CLIENTFILTER_ constants). 46 | * @return Client count in the server. 47 | */ 48 | stock Team_GetClientCount(team, flags=0) 49 | { 50 | flags |= CLIENTFILTER_INGAME; 51 | 52 | new numClients = 0; 53 | for (new client=1; client <= MaxClients; client++) { 54 | 55 | if (!Client_MatchesFilter(client, flags)) { 56 | continue; 57 | } 58 | 59 | if (GetClientTeam(client) == team) { 60 | numClients++; 61 | } 62 | } 63 | 64 | return numClients; 65 | } 66 | 67 | /* 68 | * Returns the client counts of the first two teams (eg.: Terrorists - Counter). 69 | * Use this function for optimization if you have to get the counts of both teams, 70 | * otherwise use Team_GetClientCount(). 71 | * 72 | * @param team1 Pass an integer variable by reference 73 | * @param team2 Pass an integer variable by reference 74 | * @param flags Client Filter Flags (Use the CLIENTFILTER_ constants). 75 | * @noreturn 76 | */ 77 | stock Team_GetClientCounts(&team1=0, &team2=0, flags=0) 78 | { 79 | flags |= CLIENTFILTER_INGAME; 80 | 81 | for (new client=1; client <= MaxClients; client++) { 82 | 83 | if (!Client_MatchesFilter(client, flags)) { 84 | continue; 85 | } 86 | 87 | if (GetClientTeam(client) == TEAM_ONE) { 88 | team1++; 89 | } 90 | else if (GetClientTeam(client) == TEAM_TWO) { 91 | team2++; 92 | } 93 | } 94 | } 95 | 96 | /* 97 | * Gets the name of a team. 98 | * Don't call this before OnMapStart() 99 | * 100 | * @param index Team Index. 101 | * @param str String buffer 102 | * @param size String Buffer Size 103 | * @return True on success, false otherwise 104 | */ 105 | stock bool:Team_GetName(index, String:str[], size) 106 | { 107 | new edict = Team_GetEdict(index); 108 | 109 | if (edict == -1) { 110 | str[0] = '\0'; 111 | return false; 112 | } 113 | 114 | GetEntPropString(edict, Prop_Send, "m_szTeamname", str, size); 115 | 116 | return true; 117 | } 118 | 119 | /* 120 | * Changes a team's name. 121 | * Use this carefully ! 122 | * Only set the teamname OnMapStart() or OnEntityCreated() 123 | * when no players are ingame, otherwise it can crash the server. 124 | * 125 | * @param index Team Index. 126 | * @param name New Name String 127 | * @return True on success, false otherwise 128 | */ 129 | stock bool:Team_SetName(index, const String:name[]) 130 | { 131 | new edict = Team_GetEdict(index); 132 | 133 | if (edict == -1) { 134 | return false; 135 | } 136 | 137 | SetEntPropString(edict, Prop_Send, "m_szTeamname", name); 138 | ChangeEdictState(edict, GetEntSendPropOffs(edict, "m_szTeamname", true)); 139 | 140 | return true; 141 | } 142 | 143 | /* 144 | * Changes a team's score. 145 | * Don't use this before OnMapStart(). 146 | * 147 | * @param index Team Index. 148 | * @return Team Score or -1 if the team is not valid. 149 | */ 150 | stock Team_GetScore(index) 151 | { 152 | new edict = Team_GetEdict(index); 153 | 154 | if (edict == -1) { 155 | return -1; 156 | } 157 | 158 | return GetEntProp(edict, Prop_Send, "m_iScore"); 159 | } 160 | 161 | /* 162 | * Changes a team's score. 163 | * Don't use this before OnMapStart(). 164 | * 165 | * @param index Team Index. 166 | * @param score Score value. 167 | * @return True on success, false otherwise 168 | */ 169 | stock bool:Team_SetScore(index, score) 170 | { 171 | new edict = Team_GetEdict(index); 172 | 173 | if (edict == -1) { 174 | return false; 175 | } 176 | 177 | SetEntProp(edict, Prop_Send, "m_iScore", score); 178 | 179 | ChangeEdictState(edict, GetEntSendPropOffs(edict, "m_iScore", true)); 180 | 181 | return true; 182 | } 183 | 184 | /* 185 | * Gets a team's edict (*team_manager) Team Index. 186 | * Don't call this before OnMapStart() 187 | * 188 | * @param edict Edict 189 | * @return Team Index 190 | */ 191 | stock Team_EdictGetNum(edict) 192 | { 193 | return GetEntProp(edict, Prop_Send, "m_iTeamNum"); 194 | } 195 | 196 | /* 197 | * Check's whether the index is a valid team index or not. 198 | * Don't call this before OnMapStart() 199 | * 200 | * @param index Index. 201 | * @return True if the Index is a valid team, false otherwise. 202 | */ 203 | stock bool:Team_IsValid(index) 204 | { 205 | return (Team_GetEdict(index) != -1); 206 | } 207 | 208 | /* 209 | * Gets a team's edict (team_manager) Team Index. 210 | * Don't call this before OnMapStart() 211 | * 212 | * @param index Edict 213 | * @return Team Index 214 | */ 215 | stock Team_EdictIsValid(edict) 216 | { 217 | return GetEntProp(edict, Prop_Send, "m_iTeamNum"); 218 | } 219 | 220 | /* 221 | * Gets a team's edict (team_manager). 222 | * This function caches found team edicts. 223 | * Don't call this before OnMapStart() 224 | * 225 | * @param index Team Index. 226 | * @return Team edict or -1 if not found 227 | */ 228 | stock Team_GetEdict(index) 229 | { 230 | static teams[MAX_TEAMS] = { INVALID_ENT_REFERENCE, ... }; 231 | 232 | if (index < 0 || index > MAX_TEAMS) { 233 | return -1; 234 | } 235 | 236 | new edict = teams[index]; 237 | if (Entity_IsValid(edict)) { 238 | return edict; 239 | } 240 | 241 | new bool:foundTeamManager = false; 242 | 243 | new maxEntities = GetMaxEntities(); 244 | for (new entity=MaxClients+1; entity < maxEntities; entity++) { 245 | 246 | if (!IsValidEntity(entity)) { 247 | continue; 248 | } 249 | 250 | if (Entity_ClassNameMatches(entity, "team_manager", true)) { 251 | foundTeamManager = true; 252 | } 253 | // Do not continue when no team managers are found anymore (for optimization) 254 | else if (foundTeamManager) { 255 | return -1; 256 | } 257 | else { 258 | continue; 259 | } 260 | 261 | new num = Team_EdictGetNum(entity); 262 | 263 | if (num >= 0 && num <= MAX_TEAMS) { 264 | teams[num] = EntIndexToEntRef(entity); 265 | } 266 | 267 | if (num == index) { 268 | return entity; 269 | } 270 | } 271 | 272 | return -1; 273 | } 274 | 275 | /* 276 | * Trys to find a client in the specified team. 277 | * This function is NOT random, it returns the first 278 | * or the cached player (Use Client_GetRandom() instead). 279 | * 280 | * @param index Team Index. 281 | * @return Client Index or -1 if no client was found in the specified team. 282 | */ 283 | stock Team_GetAnyClient(index) 284 | { 285 | static client_cache[MAX_TEAMS] = -1; 286 | new client; 287 | 288 | if (index > 0) { 289 | client = client_cache[index]; 290 | 291 | if (client > 0 && client <= MaxClients) { 292 | 293 | if (IsClientInGame(client) && GetClientTeam(client) == index) { 294 | return client; 295 | } 296 | } 297 | else { 298 | client = -1; 299 | } 300 | } 301 | 302 | for (client=1; client <= MaxClients; client++) { 303 | 304 | if (!IsClientInGame(client)) { 305 | continue; 306 | } 307 | 308 | if (GetClientTeam(client) != index) { 309 | continue; 310 | } 311 | 312 | client_cache[index] = client; 313 | 314 | return client; 315 | } 316 | 317 | return -1; 318 | } 319 | -------------------------------------------------------------------------------- /scripting/include/smlib/vehicles.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_vehicles_included 2 | #endinput 3 | #endif 4 | #define _smlib_vehicles_included 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /** 12 | * Returns the vehicle's driver. 13 | * If there is no driver in the vehicle, -1 is returned. 14 | * 15 | * @param vehicle Entity index. 16 | * @return Client index, or -1 if there is no driver. 17 | */ 18 | stock Vehicle_GetDriver(vehicle) 19 | { 20 | new m_hVehicle = GetEntPropEnt(vehicle, Prop_Send, "m_hPlayer"); 21 | 22 | return m_hVehicle; 23 | } 24 | 25 | /** 26 | * Returns whether there is a driver in the vehicle or not. 27 | * 28 | * @param vehicle Entity index. 29 | * @return True if the vehicle has a driver, false otherwise 30 | */ 31 | stock bool:Vehicle_HasDriver(vehicle) 32 | { 33 | return !(Vehicle_GetDriver(vehicle) == -1); 34 | } 35 | 36 | /** 37 | * Kicks the driver ouf of the vehicle 38 | * 39 | * @param vehicle Entity index. 40 | * @return True on success, false otherwise. 41 | */ 42 | stock bool:Vehicle_ExitDriver(vehicle) 43 | { 44 | if (!Vehicle_HasDriver(vehicle)) { 45 | return false; 46 | } 47 | 48 | return AcceptEntityInput(vehicle, "ExitVehicle"); 49 | } 50 | 51 | /** 52 | * Start's the vehicle's engine 53 | * 54 | * @param vehicle Entity index. 55 | * @return True on success, false otherwise. 56 | */ 57 | stock bool:Vehicle_TurnOn(vehicle) 58 | { 59 | 60 | return AcceptEntityInput(vehicle, "TurnOn"); 61 | } 62 | 63 | /** 64 | * Shuts down the vehicle's engine 65 | * 66 | * @param vehicle Entity index. 67 | * @return True on success, false otherwise. 68 | */ 69 | stock bool:Vehicle_TurnOff(vehicle) 70 | { 71 | 72 | return AcceptEntityInput(vehicle, "TurnOff"); 73 | } 74 | 75 | /** 76 | * Locks the vehicle. 77 | * 78 | * @param vehicle Entity index. 79 | * @return True on success, false otherwise. 80 | */ 81 | stock bool:Vehicle_Lock(vehicle) 82 | { 83 | 84 | return AcceptEntityInput(vehicle, "Lock"); 85 | } 86 | 87 | /** 88 | * Unlocks the vehicle. 89 | * 90 | * @param vehicle Entity index. 91 | * @return True on success, false otherwise. 92 | */ 93 | stock bool:Vehicle_Unlock(vehicle) 94 | { 95 | 96 | return AcceptEntityInput(vehicle, "Unlock"); 97 | } 98 | 99 | /** 100 | * Returns wether the entity is a valid vehicle or not. 101 | * 102 | * @param vehicle Entity index. 103 | * @return True if it is a valid vehicle, false otherwise. 104 | */ 105 | stock bool:Vehicle_IsValid(vehicle) 106 | { 107 | if (!Entity_IsValid(vehicle)) { 108 | return false; 109 | } 110 | 111 | return Entity_ClassNameMatches(vehicle, "prop_vehicle", true); 112 | } 113 | 114 | /** 115 | * Reads the vehicle script from a vehicle. 116 | * This script contains all the vehicle settings like its speed 117 | * and that stuff. 118 | * 119 | * @param vehicle Entity index. 120 | * @param buffer String Buffer. 121 | * @param size String Buffer size. 122 | * @noreturn 123 | */ 124 | stock bool:Vehicle_GetScript(vehicle, String:buffer[], size) 125 | { 126 | GetEntPropString(vehicle, Prop_Data, "m_vehicleScript", buffer, size); 127 | } 128 | 129 | /** 130 | * Sets the script of a vehicle. 131 | * This script contains all the vehicle settings like its speed 132 | * and that stuff. 133 | * 134 | * @param vehicle Entity index. 135 | * @param buffer Vehicle Script path. 136 | * @noreturn 137 | */ 138 | stock bool:Vehicle_SetScript(vehicle, String:script[]) 139 | { 140 | DispatchKeyValue(vehicle, "vehiclescript", script); 141 | } 142 | -------------------------------------------------------------------------------- /scripting/include/smlib/weapons.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_weapons_included 2 | #endinput 3 | #endif 4 | #define _smlib_weapons_included 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define MAX_WEAPON_OFFSET 64 11 | #define MAX_WEAPON_SLOTS 6 // hud item selection slots 12 | #define MAX_WEAPON_POSITIONS 20 // max number of items within a slot 13 | #define MAX_WEAPONS 48 // Max number of weapons availabl 14 | #define WEAPON_NOCLIP -1 // clip sizes set to this tell the weapon it doesn't use a clip 15 | #define MAX_AMMO_TYPES 32 16 | #define MAX_AMMO_SLOTS 32 // not really slots 17 | 18 | #define MAX_WEAPON_STRING 80 19 | #define MAX_WEAPON_PREFIX 16 20 | #define MAX_WEAPON_AMMO_NAME 32 21 | 22 | /* 23 | * Gets the owner (usually a client) of the weapon 24 | * 25 | * @param weapon Weapon Entity. 26 | * @return Owner of the weapon or INVALID_ENT_REFERENCE if the weapon has no owner. 27 | */ 28 | stock Weapon_GetOwner(weapon) 29 | { 30 | return GetEntPropEnt(weapon, Prop_Data, "m_hOwner"); 31 | } 32 | 33 | /* 34 | * Sets the owner (usually a client) of the weapon 35 | * 36 | * @param weapon Weapon Entity. 37 | * @param entity Entity Index. 38 | * @noreturn 39 | */ 40 | stock Weapon_SetOwner(weapon, entity) 41 | { 42 | SetEntPropEnt(weapon, Prop_Data, "m_hOwner", entity); 43 | } 44 | 45 | /* 46 | * Checks whether the entity is a valid weapon or not. 47 | * 48 | * @param weapon Weapon Entity. 49 | * @return True if the entity is a valid weapon, false otherwise. 50 | */ 51 | stock Weapon_IsValid(weapon) 52 | { 53 | if (!IsValidEdict(weapon)) { 54 | return false; 55 | } 56 | 57 | return Entity_ClassNameMatches(weapon, "weapon_", true); 58 | } 59 | 60 | /* 61 | * Create's a weapon and spawns it in the world at the specified location. 62 | * 63 | * @param className Classname String of the weapon to spawn 64 | * @param absOrigin Absolute Origin Vector where to spawn the weapon. 65 | * @param absAngles Absolute Angles Vector. 66 | * @return Weapon Index of the created weapon or INVALID_ENT_REFERENCE on error. 67 | */ 68 | stock Weapon_Create(const String:className[], Float:absOrigin[3], Float:absAngles[3]) 69 | { 70 | new weapon = Entity_Create(className); 71 | 72 | if (weapon == INVALID_ENT_REFERENCE) { 73 | return INVALID_ENT_REFERENCE; 74 | } 75 | 76 | Entity_SetAbsOrigin(weapon, absOrigin); 77 | Entity_SetAbsAngles(weapon, absAngles); 78 | 79 | DispatchSpawn(weapon); 80 | 81 | return weapon; 82 | } 83 | 84 | /* 85 | * Create's a weapon and spawns it in the world at the specified location. 86 | * 87 | * @param className Classname String of the weapon to spawn 88 | * @param absOrigin Absolute Origin Vector where to spawn the weapon. 89 | * @param absAngles Absolute Angles Vector. 90 | * @return Weapon Index of the created weapon or INVALID_ENT_REFERENCE on error. 91 | */ 92 | stock Weapon_CreateForOwner(client, const String:className[]) 93 | { 94 | decl Float:absOrigin[3], Float:absAngles[3]; 95 | Entity_GetAbsOrigin(client, absOrigin); 96 | Entity_GetAbsAngles(client, absAngles); 97 | 98 | new weapon = Weapon_Create(className, absOrigin, absAngles); 99 | 100 | if (weapon == INVALID_ENT_REFERENCE) { 101 | return INVALID_ENT_REFERENCE; 102 | } 103 | 104 | Entity_SetOwner(weapon, client); 105 | 106 | return weapon; 107 | } 108 | 109 | /* 110 | * Gets the weapon's subtype. 111 | * The subtype is only used when a player has multiple weapons of the same type. 112 | * 113 | * @param weapon Weapon Entity. 114 | * @return Subtype of the weapon. 115 | */ 116 | stock Weapon_GetSubType(weapon) 117 | { 118 | return GetEntProp(weapon, Prop_Data, "m_iSubType"); 119 | } 120 | 121 | /* 122 | * Is the weapon currently reloading ? 123 | * 124 | * @param weapon Weapon Entity. 125 | * @return True if weapon is currently reloading, false if not. 126 | */ 127 | stock bool:Weapon_IsReloading(weapon) 128 | { 129 | return bool:GetEntProp(weapon, Prop_Data, "m_bInReload"); 130 | } 131 | 132 | /* 133 | * Weapon m_iState 134 | */ 135 | #define WEAPON_IS_ONTARGET 0x40 136 | #define WEAPON_NOT_CARRIED 0 // Weapon is on the ground 137 | #define WEAPON_IS_CARRIED_BY_PLAYER 1 // This client is carrying this weapon. 138 | #define WEAPON_IS_ACTIVE 2 // This client is carrying this weapon and it's the currently held weapon 139 | 140 | /* 141 | * Get's the state of the weapon. 142 | * This returns whether the weapon is currently carried by a client, 143 | * if it is active and if it is on a target. 144 | * 145 | * @param weapon Weapon Entity. 146 | * @return Weapon State. 147 | */ 148 | stock Weapon_GetState(weapon) 149 | { 150 | return GetEntProp(weapon, Prop_Data, "m_iState"); 151 | } 152 | 153 | /* 154 | * Returns whether the weapon can fire primary ammo under water. 155 | * 156 | * @param weapon Weapon Entity. 157 | * @return True or False. 158 | */ 159 | stock bool:Weapon_FiresUnderWater(weapon) 160 | { 161 | return bool:GetEntProp(weapon, Prop_Data, "m_bFiresUnderwater"); 162 | } 163 | 164 | /* 165 | * Sets if the weapon can fire primary ammo under water. 166 | * 167 | * @param weapon Weapon Entity. 168 | * @param can True or False. 169 | * @noreturn 170 | */ 171 | stock Weapon_SetFiresUnderWater(weapon, bool:can=true) 172 | { 173 | SetEntProp(weapon, Prop_Data, "m_bFiresUnderwater", _:can); 174 | } 175 | 176 | /* 177 | * Returns whether the weapon can fire secondary ammo under water. 178 | * 179 | * @param weapon Weapon Entity. 180 | * @return True or False. 181 | */ 182 | stock bool:Weapon_FiresUnderWaterAlt(weapon) 183 | { 184 | return bool:GetEntProp(weapon, Prop_Data, "m_bAltFiresUnderwater"); 185 | } 186 | 187 | /* 188 | * Sets if the weapon can fire secondary ammo under water. 189 | * 190 | * @param weapon Weapon Entity. 191 | * @param can True or False. 192 | * @noreturn 193 | */ 194 | stock Weapon_SetFiresUnderWaterAlt(weapon, bool:can=true) 195 | { 196 | SetEntProp(weapon, Prop_Data, "m_bAltFiresUnderwater", _:can); 197 | } 198 | 199 | /* 200 | * Gets the primary ammo Type (int offset) 201 | * 202 | * @param weapon Weapon Entity. 203 | * @return Primary ammo type value. 204 | */ 205 | stock Weapon_GetPrimaryAmmoType(weapon) 206 | { 207 | return GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType"); 208 | } 209 | 210 | /* 211 | * Sets the primary ammo Type (int offset) 212 | * 213 | * @param weapon Weapon Entity. 214 | * @param type Primary ammo type value. 215 | */ 216 | stock Weapon_SetPrimaryAmmoType(weapon,type) 217 | { 218 | SetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType", type); 219 | } 220 | 221 | /* 222 | * Gets the secondary ammo Type (int offset) 223 | * 224 | * @param weapon Weapon Entity. 225 | * @return Secondary ammo type value. 226 | */ 227 | stock Weapon_GetSecondaryAmmoType(weapon) 228 | { 229 | return GetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoType"); 230 | } 231 | 232 | /* 233 | * Sets the secondary ammo Type (int offset) 234 | * 235 | * @param weapon Weapon Entity. 236 | * @param type Secondary ammo type value. 237 | */ 238 | stock Weapon_SetSecondaryAmmoType(weapon,type) 239 | { 240 | SetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoType", type); 241 | } 242 | 243 | /* 244 | * Gets the primary clip count of a weapon. 245 | * 246 | * @param weapon Weapon Entity. 247 | * @return Primary Clip count. 248 | */ 249 | stock Weapon_GetPrimaryClip(weapon) 250 | { 251 | return GetEntProp(weapon, Prop_Data, "m_iClip1"); 252 | } 253 | 254 | /* 255 | * Sets the primary clip count of a weapon. 256 | * 257 | * @param weapon Weapon Entity. 258 | * @param value Clip Count value. 259 | */ 260 | stock Weapon_SetPrimaryClip(weapon, value) 261 | { 262 | SetEntProp(weapon, Prop_Data, "m_iClip1", value); 263 | } 264 | 265 | /* 266 | * Gets the secondary clip count of a weapon. 267 | * 268 | * @param weapon Weapon Entity. 269 | * @return Secondy Clip count. 270 | */ 271 | stock Weapon_GetSecondaryClip(weapon) 272 | { 273 | return GetEntProp(weapon, Prop_Data, "m_iClip2"); 274 | } 275 | 276 | /* 277 | * Sets the secondary clip count of a weapon. 278 | * 279 | * @param weapon Weapon Entity. 280 | * @param value Clip Count value. 281 | */ 282 | stock Weapon_SetSecondaryClip(weapon, value) 283 | { 284 | SetEntProp(weapon, Prop_Data, "m_iClip2", value); 285 | } 286 | 287 | /* 288 | * Sets the primary & secondary clip count of a weapon. 289 | * 290 | * @param weapon Weapon Entity. 291 | * @param primary Primary Clip Count value. 292 | * @param secondary Primary Clip Count value. 293 | */ 294 | stock Weapon_SetClips(weapon, primary, secondary) 295 | { 296 | Weapon_SetPrimaryClip(weapon, primary); 297 | Weapon_SetSecondaryClip(weapon, secondary); 298 | } 299 | 300 | /* 301 | * Gets the primary ammo count of a weapon. 302 | * This is only used when the weapon is not carried 303 | * by a player to give a player ammo when he picks up 304 | * the weapon. 305 | * 306 | * @param weapon Weapon Entity. 307 | * @return Primary Ammo Count. 308 | */ 309 | stock Weapon_GetPrimaryAmmoCount(weapon) 310 | { 311 | return GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount"); 312 | } 313 | 314 | /* 315 | * Sets the primary ammo count of a weapon. 316 | * This is only used when the weapon is not carried 317 | * by a player to give a player ammo when he picks up 318 | * the weapon. 319 | * 320 | * @param weapon Weapon Entity. 321 | * @param value Primary Ammo Count. 322 | * @noreturn 323 | */ 324 | stock Weapon_SetPrimaryAmmoCount(weapon, value) 325 | { 326 | SetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount", value); 327 | } 328 | 329 | /* 330 | * Gets the secondary ammo count of a weapon. 331 | * This is only used when the weapon is not carried 332 | * by a player to give a player ammo when he picks up 333 | * the weapon. 334 | * 335 | * @param weapon Weapon Entity. 336 | * @return Secondary Ammo Count. 337 | */ 338 | stock Weapon_GetSecondaryAmmoCount(weapon) 339 | { 340 | return GetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoCount"); 341 | } 342 | 343 | /* 344 | * Sets the secodary ammo count of a weapon. 345 | * This is only used when the weapon is not carried 346 | * by a player to give a player ammo when he picks up 347 | * the weapon. 348 | * 349 | * @param weapon Weapon Entity. 350 | * @param value Secondary Ammo Count. 351 | * @noreturn 352 | */ 353 | stock Weapon_SetSecondaryAmmoCount(weapon, value) 354 | { 355 | SetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoCount", value); 356 | } 357 | 358 | /* 359 | * Sets both, the primary & the secondary ammo count of a weapon. 360 | * This is only used when the weapon is not carried 361 | * by a player to give a player ammo when he picks up 362 | * the weapon. 363 | * 364 | * @param weapon Weapon Entity. 365 | * @value primary Primary Ammo Count. 366 | * @value secondary Secondary Ammo Count. 367 | * @noreturn 368 | */ 369 | stock Weapon_SetAmmoCounts(weapon, primary, secondary) 370 | { 371 | Weapon_SetPrimaryAmmoCount(weapon, primary); 372 | Weapon_SetSecondaryAmmoCount(weapon, secondary); 373 | } 374 | 375 | /* 376 | * Gets the Model Index of the weapon's view model. 377 | * 378 | * @param weapon Weapon Entity. 379 | * @return View Model Index. 380 | */ 381 | stock Weapon_GetViewModelIndex(weapon) 382 | { 383 | return GetEntProp(weapon, Prop_Data, "m_nViewModelIndex"); 384 | } 385 | 386 | /* 387 | * Sets the Model Index of the weapon's view model. 388 | * You can get the Model Index by precaching a model with PrecacheModel(). 389 | * 390 | * @param weapon Weapon Entity. 391 | * @param index Model Index. 392 | * @noreturn 393 | */ 394 | stock Weapon_SetViewModelIndex(weapon, index) 395 | { 396 | SetEntProp(weapon, Prop_Data, "m_nViewModelIndex", index); 397 | ChangeEdictState(weapon, FindDataMapInfo(weapon, "m_nViewModelIndex")); 398 | } 399 | -------------------------------------------------------------------------------- /scripting/include/smlib/world.inc: -------------------------------------------------------------------------------- 1 | #if defined _smlib_world_included 2 | #endinput 3 | #endif 4 | #define _smlib_world_included 5 | 6 | #include 7 | 8 | /* 9 | * Gets the world's max size 10 | * 11 | * @param vec Vector buffer 12 | * @noreturn 13 | */ 14 | stock World_GetMaxs(Float:vec[3]) { 15 | 16 | GetEntPropVector(0, Prop_Data, "m_WorldMaxs", vec); 17 | } 18 | -------------------------------------------------------------------------------- /scripting/tests/test_colors.sp: -------------------------------------------------------------------------------- 1 | 2 | // enforce semicolons after each code statement 3 | #pragma semicolon 1 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define PLUGIN_VERSION "0.1" 10 | 11 | 12 | 13 | /***************************************************************** 14 | 15 | 16 | P L U G I N I N F O 17 | 18 | 19 | *****************************************************************/ 20 | 21 | public Plugin:myinfo = { 22 | name = "smlib - color tests", 23 | author = "Berni", 24 | description = "", 25 | version = PLUGIN_VERSION, 26 | url = "http://www.sourcemodplugins.org" 27 | } 28 | 29 | 30 | 31 | /***************************************************************** 32 | 33 | 34 | G L O B A L V A R S 35 | 36 | 37 | *****************************************************************/ 38 | 39 | // ConVar Handles 40 | 41 | // Misc 42 | 43 | 44 | 45 | /***************************************************************** 46 | 47 | 48 | F O R W A R D P U B L I C S 49 | 50 | 51 | *****************************************************************/ 52 | 53 | public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) 54 | { 55 | MarkNativeAsOptional("GetUserMessageType"); 56 | return APLRes_Success; 57 | } 58 | 59 | public OnPluginStart() 60 | { 61 | Client_PrintToChatAll(false, "Loading plugin test-colors compiled on %s %s", __DATE__, __TIME__); 62 | RegAdminCmd("sm_testcolors", Command_TestColors, ADMFLAG_ROOT); 63 | } 64 | 65 | 66 | 67 | /**************************************************************** 68 | 69 | 70 | C A L L B A C K F U N C T I O N S 71 | 72 | 73 | ****************************************************************/ 74 | 75 | public Action:Command_TestColors(client, args) 76 | { 77 | decl String:arguments[255]; 78 | 79 | GetCmdArgString(arguments, sizeof(arguments)); 80 | Client_PrintToChat(client, true, "%s", arguments); 81 | 82 | return Plugin_Handled; 83 | } 84 | 85 | 86 | 87 | /***************************************************************** 88 | 89 | 90 | P L U G I N F U N C T I O N S 91 | 92 | 93 | *****************************************************************/ 94 | -------------------------------------------------------------------------------- /scripting/tests/test_compile-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Bash immediate exit and verbosity 4 | set -ev 5 | 6 | SMPATTERN="http:.*sourcemod-.*-linux\..*" 7 | SMURL="http://www.sourcemod.net/smdrop/$SMVERSION/" 8 | SMPACKAGE=`lynx -dump "$SMURL" | egrep -o "$SMPATTERN" | tail -1` 9 | TEST_SCRIPT="tests/test_compile-all.sp" 10 | 11 | wget $SMPACKAGE 12 | tar -xzf $(basename "$SMPACKAGE") 13 | cp -R scripting/ addons/sourcemod/ 14 | cd addons/sourcemod/scripting/ 15 | chmod +x spcomp 16 | 17 | # Semicolon fix for Sourcemod include file (hack) 18 | sed -i 's/^\tnew i, len/\tnew i, len;/' ./include/string.inc 19 | 20 | # Verify all functions stocks have been added to the test file 21 | functions=$(grep -oP --color=never --no-filename '^(?!static\s+)stock\s*(\w+:)?\K\w+(?=\()' include/smlib/*.inc) 22 | 23 | # Temporarily disable bash immediate exit 24 | set +e 25 | while read -r function; do 26 | grep -Fq "$function" "$TEST_SCRIPT" 27 | exit_code=$? 28 | 29 | if [[ $exit_code != 0 ]]; then 30 | echo "[ERROR] Stock function \"$function\" not found in \"$TEST_SCRIPT\". Please add it." 31 | exit 1 32 | fi 33 | done <<< "$functions" 34 | set -e 35 | 36 | 37 | ./spcomp "$TEST_SCRIPT" 38 | 39 | ls *.smx 40 | -------------------------------------------------------------------------------- /scripting/tests/test_compile-all.sp: -------------------------------------------------------------------------------- 1 | /************************************************** 2 | * 3 | * SMLIB Testing Suite 4 | * 5 | * ************************************************ 6 | * 7 | * Warning: This plugin is only for testing if all 8 | * function stocks are compile-able without any 9 | * errors/warnings, do not load this on a production 10 | * server or it will likely crash it. 11 | * 12 | */ 13 | 14 | // enforce semicolons after each code statement 15 | #pragma semicolon 1 16 | 17 | #include 18 | #include 19 | 20 | #define PLUGIN_VERSION "1.0" 21 | 22 | 23 | 24 | /***************************************************************** 25 | 26 | 27 | P L U G I N I N F O 28 | 29 | 30 | *****************************************************************/ 31 | 32 | public Plugin:myinfo = { 33 | name = "smlib Testing Suite", 34 | author = "Berni, Chanz", 35 | description = "Plugin by Berni", 36 | version = PLUGIN_VERSION, 37 | url = "" 38 | } 39 | 40 | 41 | 42 | /***************************************************************** 43 | 44 | 45 | G L O B A L V A R S 46 | 47 | 48 | *****************************************************************/ 49 | 50 | // ConVar Handles 51 | 52 | // Misc 53 | 54 | 55 | 56 | /***************************************************************** 57 | 58 | 59 | F O R W A R D P U B L I C S 60 | 61 | 62 | *****************************************************************/ 63 | 64 | public OnPluginStart() { 65 | 66 | new arr[1], String:arr_str[1][1], arr_4[4]; 67 | decl Float:vec[3]; 68 | decl String:buf[1], String:buf_10[10], String:twoDimStrArr[1][1]; 69 | new variable; 70 | new Handle:handle; 71 | 72 | // File: arrays.inc 73 | Array_FindValue(arr, sizeof(arr), 1); 74 | Array_FindString(arr_str, sizeof(arr_str), ""); 75 | Array_FindLowestValue(arr, sizeof(arr)); 76 | Array_FindHighestValue(arr, sizeof(arr)); 77 | Array_Fill(arr, sizeof(arr), 0); 78 | Array_Copy(arr, arr, 1); 79 | 80 | // File: clients.inc 81 | Client_SetHideHud(0, 0); 82 | Client_IsValid(0); 83 | Client_IsIngame(0); 84 | Client_IsIngameAuthorized(0); 85 | Client_FindBySteamId(""); 86 | Client_FindByName(""); 87 | Client_GetObserverMode(0); 88 | Client_SetObserverMode(0, Obs_Mode:0); 89 | Client_GetObserverLastMode(0); 90 | Client_SetObserverLastMode(0, Obs_Mode:0); 91 | Client_GetViewOffset(0, vec); 92 | Client_SetViewOffset(0, vec); 93 | Client_GetObserverTarget(0); 94 | Client_SetObserverTarget(0, 0); 95 | Client_GetFOV(0); 96 | Client_SetFOV(0, 0); 97 | Client_DrawViewModel(0); 98 | Client_SetDrawViewModel(0, true); 99 | Client_SetThirdPersonMode(0); 100 | Client_IsInThirdPersonMode(0); 101 | Client_ScreenFade(0, 0, 0); 102 | Client_GetClones(0, arr); 103 | Client_IsOnLadder(0); 104 | Client_GetWaterLevel(0); 105 | Client_GetSuitSprintPower(0); 106 | Client_SetSuitSprintPower(0, 0.0); 107 | Client_GetCount(); 108 | Client_GetFakePing(0); 109 | Client_GetClosestToClient(0); 110 | Client_GetLastPlaceName(0, buf, sizeof(buf)); 111 | Client_GetScore(0); 112 | Client_SetScore(0, 0); 113 | Client_GetDeaths(0); 114 | Client_SetDeaths(0, 0); 115 | Client_GetArmor(0); 116 | Client_SetArmor(0, 0); 117 | Client_GetSuitPower(0); 118 | Client_SetSuitPower(0, 0.0); 119 | Client_GetActiveDevices(0); 120 | Client_GetNextDecalTime(0); 121 | Client_CanSprayDecal(0); 122 | Client_GetVehicle(0); 123 | Client_IsInVehicle(0); 124 | Client_RemoveAllDecals(0); 125 | Client_ExitVehicle(0); 126 | Client_RawAudio(0, 0, ""); 127 | Client_RawAudioToAll(0, ""); 128 | Client_Impulse(0, 0); 129 | Client_GetWeaponsOffset(0); 130 | Client_GetActiveWeapon(0); 131 | Client_GetActiveWeaponName(0, buf, sizeof(buf)); 132 | Client_SetActiveWeapon(0, 0); 133 | Client_ChangeWeapon(0, ""); 134 | Client_ChangeToLastWeapon(0); 135 | Client_GetLastActiveWeapon(0); 136 | Client_GetLastActiveWeaponName(0, buf, sizeof(buf)); 137 | Client_SetLastActiveWeapon(0, 0); 138 | Client_EquipWeapon(0, 0); 139 | Client_DetachWeapon(0, 0); 140 | Client_GiveWeapon(0, ""); 141 | Client_GiveWeaponAndAmmo(0, ""); 142 | Client_RemoveWeapon(0, ""); 143 | Client_RemoveAllWeapons(0, ""); 144 | Client_HasWeapon(0, ""); 145 | Client_GetWeapon(0, ""); 146 | Client_GetWeaponBySlot(0, 0); 147 | Client_GetDefaultWeapon(0); 148 | Client_GetDefaultWeaponName(0, buf, sizeof(buf)); 149 | Client_GetFirstWeapon(0); 150 | Client_GetWeaponCount(0); 151 | Client_IsReloading(0); 152 | Client_SetWeaponClipAmmo(0, ""); 153 | Client_GetWeaponPlayerAmmo(0, ""); 154 | Client_GetWeaponPlayerAmmoEx(0, 0); 155 | Client_SetWeaponPlayerAmmo(0, ""); 156 | Client_SetWeaponPlayerAmmoEx(0, 0); 157 | Client_SetWeaponAmmo(0, ""); 158 | Client_GetNextWeapon(0, variable); 159 | Client_PrintHintText(0, ""); 160 | Client_PrintHintTextToAll(""); 161 | Client_PrintKeyHintText(0, ""); 162 | Client_PrintKeyHintTextToAll(""); 163 | Client_PrintToChatRaw(0, ""); 164 | Client_PrintToChat(0, false, ""); 165 | Client_PrintToChatAll(false, ""); 166 | Client_PrintToChatEx({ 0 }, 0, false, ""); 167 | Client_Shake(0); 168 | Client_IsAdmin(0); 169 | Client_HasAdminFlags(0); 170 | Client_IsInAdminGroup(0, ""); 171 | Client_IsLookingAtWall(0); 172 | Client_GetClass(0); 173 | Client_SetClass(0, 0); 174 | Client_GetButtons(0); 175 | Client_SetButtons(0, 0); 176 | Client_AddButtons(0, 0); 177 | Client_RemoveButtons(0, 0); 178 | Client_ClearButtons(0); 179 | Client_HasButtons(0, 0); 180 | Client_GetChangedButtons(0); 181 | Client_SetMaxSpeed(0, 0.0); 182 | Client_SetScreenOverlay(0, ""); 183 | Client_SetScreenOverlayForAll(""); 184 | Client_Mute(0); 185 | Client_UnMute(0); 186 | Client_IsMuted(0); 187 | Client_PrintToConsole(0, ""); 188 | Client_Print(0, ClientHudPrint:0, ""); 189 | Client_PrintToChatExclude(0); 190 | Client_Reply(0, ""); 191 | Client_MatchesFilter(0, 0); 192 | Client_Get({ 0 }, 0); 193 | Client_GetRandom(0); 194 | Client_GetNext(0); 195 | Client_GetMapTime(0); 196 | Client_GetMoney(0); 197 | Client_SetMoney(0, 0); 198 | Client_GetObservers(0, { 0 }); 199 | Client_GetPlayersInRadius(0, arr, 0.0); 200 | Client_GetNextObserver(0); 201 | Client_GetPlayerManager(); 202 | Client_SetPing(0, 0); 203 | Client_PrintToTopExclude(0); 204 | Client_PrintToTopRaw(0,0,0,0,0,0.0,""); 205 | Client_PrintToTop(0,0,0,0,0,0.0,""); 206 | Client_PrintToTopAll(0,0,0,0,0.0,""); 207 | Client_PrintToTopEx({ 0 },1,0,0,0,0,0.0,""); 208 | Client_ShowScoreboard(0); 209 | 210 | // File: colors.inc 211 | Color_ChatSetSubject(0); 212 | Color_ChatGetSubject(); 213 | Color_ChatClearSubject(); 214 | Color_ParseChatText("", "", 0); 215 | Color_TagToCode("", variable, buf_10); 216 | Color_StripFromChatText("", "", 0); 217 | 218 | // File: convars.inc 219 | ConCommand_HasFlags("", 0); 220 | ConCommand_AddFlags("", 0); 221 | ConCommand_RemoveFlags("", 0); 222 | 223 | // File: convars.inc 224 | Convar_HasFlags(INVALID_HANDLE, 0); 225 | Convar_AddFlags(INVALID_HANDLE, 0); 226 | Convar_RemoveFlags(INVALID_HANDLE, 0); 227 | Convar_IsValidName(""); 228 | 229 | // File: crypt.inc 230 | Crypt_Base64Encode("", buf, sizeof(buf)); 231 | Crypt_Base64Decode("", buf, sizeof(buf)); 232 | Crypt_Base64MimeToUrl("", buf, sizeof(buf)); 233 | Crypt_Base64UrlToMime("", buf, sizeof(buf)); 234 | Crypt_MD5("", buf, sizeof(buf)); 235 | Crypt_RC4Encode("", "", buf, sizeof(buf)); 236 | Crypt_RC4EncodeBinary("", 0, "", buf, sizeof(buf)); 237 | 238 | // File: debug.inc 239 | Debug_FloatArray(vec); 240 | 241 | // File: dynarrays.inc 242 | DynArray_GetBool(INVALID_HANDLE, 0); 243 | 244 | // File: edicts.inc 245 | Edict_FindByName(""); 246 | Edict_FindByHammerId(0); 247 | Edict_GetClosest(vec); 248 | Edict_GetClosestToEdict(0); 249 | 250 | // File: effects.inc 251 | Effect_DissolveEntity(0); 252 | Effect_DissolvePlayerRagDoll(0); 253 | Effect_Fade(0); 254 | Effect_FadeIn(0); 255 | Effect_FadeOut(0); 256 | Effect_DrawBeamBox(arr, 1, NULL_VECTOR, NULL_VECTOR, 0, 0); 257 | Effect_DrawBeamBoxToAll(NULL_VECTOR, NULL_VECTOR, 0, 0); 258 | Effect_DrawBeamBoxToClient(0, NULL_VECTOR, NULL_VECTOR, 0, 0); 259 | Effect_DrawBeamBoxRotatableToClient(0, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, 0, 0); 260 | Effect_DrawBeamBoxRotatableToAll(NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, 0, 0); 261 | Effect_DrawBeamBoxRotatable(arr, 1, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, 0, 0); 262 | Effect_DrawAxisOfRotationToClient(0, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, 0, 0); 263 | Effect_DrawAxisOfRotationToAll(NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, 0, 0); 264 | Effect_DrawAxisOfRotation(arr, 1, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR, 0, 0); 265 | Effect_EnvSprite(NULL_VECTOR,0); 266 | 267 | // File: entities.inc 268 | Entity_IsValid(0); 269 | Entity_FindByName(""); 270 | Entity_FindByHammerId(0); 271 | Entity_FindByClassName(0, ""); 272 | Entity_ClassNameMatches(0, ""); 273 | Entity_NameMatches(0, ""); 274 | Entity_GetName(0, buf, sizeof(buf)); 275 | Entity_SetName(0, ""); 276 | Entity_GetClassName(0, buf, sizeof(buf)); 277 | Entity_SetClassName(0, ""); 278 | Entity_GetTargetName(0, buf, sizeof(buf)); 279 | Entity_SetTargetName(0, ""); 280 | Entity_GetGlobalName(0, buf, sizeof(buf)); 281 | Entity_SetGlobalName(0, ""); 282 | Entity_GetParentName(0, buf, sizeof(buf)); 283 | Entity_SetParentName(0, ""); 284 | Entity_GetHammerId(0); 285 | Entity_GetRadius(0); 286 | Entity_SetRadius(0, 0.0); 287 | Entity_GetMinSize(0, vec); 288 | Entity_SetMinSize(0, vec); 289 | Entity_GetMaxSize(0, vec); 290 | Entity_SetMaxSize(0, vec); 291 | Entity_SetMinMaxSize(0, vec, vec); 292 | Entity_GetSpawnFlags(0); 293 | Entity_SetSpawnFlags(0, 0); 294 | Entity_AddSpawnFlags(0, 0); 295 | Entity_RemoveSpawnFlags(0, 0); 296 | Entity_ClearSpawnFlags(0); 297 | Entity_HasSpawnFlags(0, 0); 298 | Entity_GetEFlags(0); 299 | Entity_SetEFlags(0, Entity_Flags:0); 300 | Entity_AddEFlags(0, Entity_Flags:0); 301 | Entity_RemoveEFlags(0, Entity_Flags:0); 302 | Entity_HasEFlags(0, Entity_Flags:0); 303 | Entity_MarkSurrBoundsDirty(0); 304 | Entity_GetFlags(0); 305 | Entity_SetFlags(0, 0); 306 | Entity_AddFlags(0, 0); 307 | Entity_RemoveFlags(0, 0); 308 | Entity_ToggleFlag(0, 0); 309 | Entity_ClearFlags(0); 310 | Entity_GetSolidFlags(0); 311 | Entity_SetSolidFlags(0, SolidFlags_t:0); 312 | Entity_AddSolidFlags(0, SolidFlags_t:0); 313 | Entity_RemoveSolidFlags(0, SolidFlags_t:0); 314 | Entity_ClearSolidFlags(0); 315 | Entity_SolidFlagsSet(0, SolidFlags_t:0); 316 | Entity_GetSolidType(0); 317 | Entity_SetSolidType(0, SolidType_t:0); 318 | Entity_IsSolid(0); 319 | Entity_GetModel(0, buf, sizeof(buf)); 320 | Entity_SetModel(0, ""); 321 | Entity_GetModelIndex(0); 322 | Entity_SetModelIndex(0, 0); 323 | Entity_SetMaxSpeed(0, 0.0); 324 | Entity_GetCollisionGroup(0); 325 | Entity_SetCollisionGroup(0, Collision_Group_t:0); 326 | Entity_GetAbsOrigin(0, vec); 327 | Entity_SetAbsOrigin(0, vec); 328 | Entity_GetAbsAngles(0, vec); 329 | Entity_SetAbsAngles(0, vec); 330 | Entity_GetLocalVelocity(0, vec); 331 | Entity_SetLocalVelocity(0, vec); 332 | Entity_GetBaseVelocity(0, vec); 333 | Entity_SetBaseVelocity(0, vec); 334 | Entity_GetAbsVelocity(0, vec); 335 | Entity_SetAbsVelocity(0, vec); 336 | Entity_IsLocked(0); 337 | Entity_Lock(0); 338 | Entity_UnLock(0); 339 | Entity_GetHealth(0); 340 | Entity_SetHealth(0, 0); 341 | Entity_GetMaxHealth(0); 342 | Entity_SetMaxHealth(0, 0); 343 | Entity_AddHealth(0, 0); 344 | Entity_GetDistance(0, 0); 345 | Entity_GetDistanceOrigin(0, vec); 346 | Entity_InRange(0, 0, 0.0); 347 | Entity_EnableMotion(0); 348 | Entity_DisableMotion(0); 349 | Entity_Freeze(0); 350 | Entity_UnFreeze(0); 351 | Entity_PointAtTarget(0, 0); 352 | Entity_PointHurtAtTarget(0, 0); 353 | Entity_IsPlayer(0); 354 | Entity_Create(""); 355 | Entity_Kill(0); 356 | Entity_KillAllByClassName(""); 357 | Entity_GetOwner(0); 358 | Entity_SetOwner(0, 0); 359 | Entity_GetGroundEntity(0); 360 | Entity_Hurt(0, 0); 361 | Entity_GetParent(0); 362 | Entity_ClearParent(0); 363 | Entity_SetParent(0, 0); 364 | Entity_ChangeOverTime(0, 0.1, INVALID_FUNCTION); 365 | Entity_GetNextChild(0); 366 | Entity_GetMoveDirection(0,NULL_VECTOR); 367 | Entity_SetMoveDirection(0,NULL_VECTOR); 368 | Entity_GetForceClose(0); 369 | Entity_SetForceClose(0,true); 370 | Entity_GetSpeed(0); 371 | Entity_SetSpeed(0,0.0); 372 | Entity_GetBlockDamage(0); 373 | Entity_SetBlockDamage(0,0.0); 374 | Entity_IsDisabled(0); 375 | Entity_Disable(0); 376 | Entity_Enable(0); 377 | Entity_SetTakeDamage(0,0); 378 | Entity_GetTakeDamage(0); 379 | Entity_SetMinHealthDamage(0,0); 380 | Entity_GetMinHealthDamage(0); 381 | Entity_GetRenderColor(0, arr_4); 382 | Entity_SetRenderColor(0, 0, 0, 0, 0); 383 | Entity_AddOutput(0, ""); 384 | Entity_TakeHealth(0, 0); 385 | 386 | // File: files.inc 387 | File_GetBaseName("", buf, sizeof(buf)); 388 | File_GetDirName("", buf, sizeof(buf)); 389 | File_GetFileName("", buf, sizeof(buf)); 390 | File_GetExtension("", buf, sizeof(buf)); 391 | File_AddToDownloadsTable(""); 392 | File_ReadDownloadList(""); 393 | File_LoadTranslations(""); 394 | File_ToString("", "", 0); 395 | File_StringToFile("", ""); 396 | File_Copy("", ""); 397 | File_CopyRecursive("", ""); 398 | 399 | // File: game.inc 400 | Game_End(); 401 | Game_EndRound(); 402 | 403 | // File: general.inc 404 | PrecacheMaterial(""); 405 | IsMaterialPrecached(""); 406 | PrecacheParticleSystem(""); 407 | IsParticleSystemPrecached(""); 408 | FindStringIndexByTableName("", ""); 409 | FindStringIndex2(0, ""); 410 | LongToIP(0, buf, sizeof(buf)); 411 | IPToLong(""); 412 | IsIPLocal(0); 413 | ClearHandle(handle); 414 | 415 | // File: math.inc 416 | Math_Abs(0); 417 | Math_VectorsEqual(vec, vec); 418 | Math_Min(0, 0); 419 | Math_Max(0, 0); 420 | Math_Clamp(0, 0, 0); 421 | Math_IsInBounds(0, 0, 0); 422 | Math_GetRandomInt(0, 0); 423 | Math_GetRandomFloat(0.0, 0.0); 424 | Math_GetPercentage(0, 0); 425 | Math_GetPercentageFloat(0.0, 0.0); 426 | Math_MoveVector(vec, vec, 0.0, vec); 427 | Math_UnitsToMeters(0.0); 428 | Math_UnitsToFeet(0.0); 429 | Math_UnitsToCentimeters(0.0); 430 | Math_UnitsToKilometers(0.0); 431 | Math_UnitsToMiles(0.0); 432 | Math_RotateVector(vec, vec, vec); 433 | Math_MakeVector(0.0, 0.0, 0.0, vec); 434 | Math_Overflow(0, 0, 0); 435 | 436 | // File: menus.inc 437 | Menu_AddIntItem(INVALID_HANDLE, 0, ""); 438 | Menu_GetIntItem(INVALID_HANDLE, 0); 439 | 440 | // File: server.inc 441 | Server_GetIP(); 442 | Server_GetIPString(buf, sizeof(buf)); 443 | Server_GetPort(); 444 | Server_GetHostName(buf, sizeof(buf)); 445 | 446 | // File: sql.inc 447 | SQL_TQueryF(INVALID_HANDLE, INVALID_FUNCTION, 0, DBPrio_Normal, ""); 448 | SQL_FetchIntByName(INVALID_HANDLE, ""); 449 | SQL_FetchBoolByName(INVALID_HANDLE, ""); 450 | SQL_FetchFloatByName(INVALID_HANDLE, ""); 451 | SQL_FetchStringByName(INVALID_HANDLE, "", buf, sizeof(buf)); 452 | 453 | // File: strings.inc 454 | String_IsNumeric(""); 455 | String_Trim("", buf, sizeof(buf)); 456 | String_RemoveList(buf, twoDimStrArr, sizeof(twoDimStrArr)); 457 | String_ToLower(buf, buf, sizeof(buf)); 458 | String_ToUpper(buf, buf, sizeof(buf)); 459 | String_GetRandom(buf, sizeof(buf)); 460 | String_StartsWith("", ""); 461 | String_EndsWith("", ""); 462 | 463 | // File: teams.inc 464 | Team_HaveAllPlayers(); 465 | Team_GetClientCount(0); 466 | Team_GetClientCounts(variable, variable); 467 | Team_GetName(0, buf, sizeof(buf)); 468 | Team_SetName(0, ""); 469 | Team_GetScore(0); 470 | Team_SetScore(0, 0); 471 | Team_EdictGetNum(0); 472 | Team_IsValid(0); 473 | Team_EdictIsValid(0); 474 | Team_GetEdict(0); 475 | Team_GetAnyClient(0); 476 | 477 | // File: 0s.inc 478 | Vehicle_GetDriver(0); 479 | Vehicle_HasDriver(0); 480 | Vehicle_ExitDriver(0); 481 | Vehicle_TurnOn(0); 482 | Vehicle_TurnOff(0); 483 | Vehicle_Lock(0); 484 | Vehicle_Unlock(0); 485 | Vehicle_IsValid(0); 486 | Vehicle_GetScript(0, buf, sizeof(buf)); 487 | Vehicle_SetScript(0, ""); 488 | 489 | // File: 0s.inc 490 | Weapon_GetOwner(0); 491 | Weapon_SetOwner(0, 0); 492 | Weapon_IsValid(0); 493 | Weapon_Create("", vec, vec); 494 | Weapon_CreateForOwner(0, ""); 495 | Weapon_GetSubType(0); 496 | Weapon_IsReloading(0); 497 | Weapon_GetState(0); 498 | Weapon_FiresUnderWater(0); 499 | Weapon_SetFiresUnderWater(0); 500 | Weapon_FiresUnderWaterAlt(0); 501 | Weapon_SetFiresUnderWaterAlt(0); 502 | Weapon_GetPrimaryAmmoType(0); 503 | Weapon_GetSecondaryAmmoType(0); 504 | Weapon_SetSecondaryAmmoType(0,0); 505 | Weapon_SetPrimaryAmmoType(0,0); 506 | Weapon_GetPrimaryClip(0); 507 | Weapon_SetPrimaryClip(0, 0); 508 | Weapon_GetSecondaryClip(0); 509 | Weapon_SetSecondaryClip(0, 0); 510 | Weapon_SetClips(0, 0, 0); 511 | Weapon_GetPrimaryAmmoCount(0); 512 | Weapon_SetPrimaryAmmoCount(0, 0); 513 | Weapon_GetSecondaryAmmoCount(0); 514 | Weapon_SetSecondaryAmmoCount(0, 0); 515 | Weapon_SetAmmoCounts(0, 0, 0); 516 | Weapon_GetViewModelIndex(0); 517 | Weapon_SetViewModelIndex(0, 0); 518 | 519 | // File: world.inc 520 | World_GetMaxs(vec); 521 | } 522 | 523 | 524 | 525 | /**************************************************************** 526 | 527 | 528 | C A L L B A C K F U N C T I O N S 529 | 530 | 531 | ****************************************************************/ 532 | 533 | 534 | 535 | 536 | 537 | /***************************************************************** 538 | 539 | 540 | P L U G I N F U N C T I O N S 541 | 542 | 543 | *****************************************************************/ 544 | --------------------------------------------------------------------------------