├── .gitignore ├── README.md ├── configs ├── playerstats.cfg └── sql-init-scripts │ └── mysql │ └── playerstats.sql ├── connect_announce.png ├── gamedata └── smlib_colors.games.txt ├── player_join.png ├── player_rank.png ├── player_rank_extras.png ├── plugins └── l4d2_simpleplayerstats.smx ├── ranks_ingame.png ├── 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 └── l4d2_simpleplayerstats.sp └── top_players.png /.gitignore: -------------------------------------------------------------------------------- 1 | /scripting/*.smx 2 | releases 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### **Simple In-Game Player Statistics Plugin for Left 4 Dead 2** 2 | 3 | ### Features 4 | 5 | - This plugin records statistics gathered from human players. The following statistics are currently being recorded: 6 | 7 | Basic Statistics (Default) 8 | 9 | | Name | Team | Description | 10 | | ------------------ | -------- | ------------------------------------------------------------ | 11 | | Survivors Kils | Infected | Number of times an infected has killed a survivor | 12 | | Survivors Incapped | Infected | Number of times an infected player has incapped a survivor | 13 | | Infected Kills | Survivor | Number of times a survivor has killed a Special Infected | 14 | | Infected Headshots | Survivor | Number of times a survivor killed a Special Infected by Headshot | 15 | 16 | Extra Statistics for the more skilled (Disabled by default) 17 | 18 | | Name | Team | Description | 19 | | ---------------------- | -------- | ------------------------------------------------------------ | 20 | | Hunter Skeet (Sniper) | Survivor | Number of hunters skeeted with sniper by a survivor. Counts only 1 tap heashots | 21 | | Hunter Skeet (SG) | Survivor | Number of hunters skeeted with shotgun by a survivor | 22 | | Hunter Skeet (Melee) | Survivor | Number of hunters skeeted with melee by a survivor | 23 | | Tank Rock Skeets | Survivor | Number rocks skeeted by a survivor | 24 | | Witch Crown (Standard) | Survivor | Number of standard witch crowns by a survivor (up close) | 25 | | Witch Crown (Draw) | Survivor | Number of witch draw crowns by a survivor | 26 | | Boomer Pops | Survivor | Number of boomer pops by a survivor | 27 | | Charger Levels | Survivor | Number of chargers leveled by a survivor | 28 | | Smoker Tongue Cuts | Survivor | Number of smoker tongues cut by a survivor | 29 | | Hunter Deadstops | Survivor | Number of hunter deadstops by a survivor | 30 | | Quad Booms | Infected | Number of times survivors have been quad boomed (all 4 boomed) | 31 | | 25 Hunter Pounces | Infected | Number of 25 point hunter pounces | 32 | | Death Charges | Infected | Number of times a charger has death charged a survivor | 33 | | Tank Rock Hits | Infected | Number of times a tank rocked a survivor | 34 | 35 | 36 | 37 | - A customizable connect announce when a player joins displaying the current ranking/steam id/total points of the user. This feature also supports colour coded messages. 38 | 39 | ![Connect Announce](connect_announce.png) 40 | 41 | - A display panel showing the player statistics of a user. This can be triggered by issuing `sm_rank` on the console or by typing `!rank`in chat. 42 | 43 | ![Player Rank (Basic)](player_rank.png) 44 | 45 | - A display panel showing additional stats (disabled by default) 46 | 47 | ![Player Ranks (Extras)](player_rank_extras.png) 48 | 49 | - A display panel showing the top N players sorted by their ranking. This feature also allows the the requesting player to be able to view other player's statistics/ranking on the server. 50 | 51 | ![Top N Players](top_players.png) 52 | 53 | - A display panel showing the ranks of the players currently present in the server 54 | 55 | ![Ranks of all players in-game](ranks_ingame.png) 56 | 57 | - A points and ranking system is also implemented and can be further customized by modifying the point multipliers from the plugin configuration file (`playerstats.cfg`) 58 | 59 | ### Requirements 60 | 61 | - Sourcemod 1.7 above 62 | - [Skill Detect Plugin](https://github.com/SirPlease/ZoneMod/raw/master/addons/sourcemod/plugins/optional/zonemod/l4d2_skill_detect.smx). This is only required if you need the extra statistics enabled 63 | - A working database system (mysql) 64 | 65 | ### Installation 66 | 67 | Download the [latest](https://github.com/sourcemod-plugins/l4d2-player-stats/releases) version from the repository and extract the contents to the root of the left 4 dead 2 server installation directory. 68 | 69 | ### Configuration 70 | 71 | #### Database Configuration 72 | 73 | 1. Create and setup the appropriate users/credentials/privileges on your MySQL/MariaDB database system. 74 | 75 | 2. Import the [provided SQL script](https://github.com/sourcemod-plugins/l4d2-player-stats/blob/master/configs/sql-init-scripts/mysql/playerstats.sql) (under `/configs/sql-init-scripts/mysql/playerstats.sql`\) into your MySQL/MariaDB system. 76 | 77 | 3. Open `databases.cfg` file from `addons/sourcemod/configs` and add a new section named `playerstats`. 78 | 79 | Example: 80 | 81 | ``` 82 | "playerstats" 83 | { 84 | "host" "" 85 | "driver" "mysql" 86 | "database" "" 87 | "user" "" 88 | "pass" "" 89 | //"timeout" "0" 90 | //"port" "0" 91 | } 92 | ``` 93 | 94 | #### Plugin Configuration 95 | 96 | The plugin can be further customized through the `playerstats.cfg` file located under `addons/sourcemod/configs/`. The default entries will look like this: 97 | 98 | > *REMEMBER*: After you have edited the StatModifiers section, you need to run the command `sm_pstats_reload sync` to update the values on the database 99 | 100 | ``` 101 | "PlayerStats" { 102 | "StatModifiers" 103 | { 104 | "survivor_killed" "1.0" 105 | "survivor_incapped" "1.0" 106 | "infected_killed" "1.0" 107 | "infected_headshot" "1.0" 108 | "skeet_hunter_sniper" "1.0" 109 | "skeet_hunter_shotgun" "1.0" 110 | "skeet_hunter_melee" "1.0" 111 | "skeet_tank_rock" "1.0" 112 | "witch_crown_standard" "1.0" 113 | "witch_crown_draw" "1.0" 114 | "boomer_pop" "1.0" 115 | "charger_level" "1.0" 116 | "smoker_tongue_cut" "1.0" 117 | "hunter_dead_stop" "1.0" 118 | "boomer_quad" "1.0" 119 | "hunter_twenty_five" "1.0" 120 | "death_charge" "1.0" 121 | "tank_rock_hits" "1.0" 122 | } 123 | "StatPanels" 124 | { 125 | "title_rank_player" "Player Stats" 126 | "title_rank_topn" "Top {top_player_count} Players" 127 | "title_rank_ingame" "In-Game Player Ranks" 128 | "title_rank_extras" "Extra Player Stats" 129 | } 130 | "ConnectAnnounce" 131 | { 132 | "format" "{N}Player '{G}{last_known_alias}{N}' ({B}{steam_id}{N}) has joined the game ({G}Rank:{N} {i:rank_num}, {G}Points:{N} {f:total_points})" 133 | } 134 | } 135 | ``` 136 | 137 | Connect Announce Output: 138 | 139 | ![Connect Announce Output](connect_announce.png) 140 | 141 | 142 | 143 | > **Note:** You can reload the configuration with the `sm_pstats_reload` command. This command can also synchronize the point modifiers to the STATS_SKILLS table by passing the `sync` argument (e.g. `sm_pstats_reload sync`). 144 | 145 | 146 | 147 | ##### Configuration Sections 148 | 149 | | Section Name | Description | 150 | | --------------- | ------------------------------------------------------------ | 151 | | StatModifiers | This section contains the modifiers for the point system. These values affects the total points of the user. For example, if a player killed 10 special infected by headshot (infected_headshot) and the point modifier is 2.5 the total points for the number of infected headshots would be 25 (10 * 2.5). | 152 | | StatPanels | This section allows you to customize/add title headers to each of the available display panels. | 153 | | ConnectAnnounce | This section allows you to customize the the format of the player connect announce feature. Formatting rules are explained below. | 154 | 155 | #### Connect Announce Formatting Rules 156 | 157 | **Colour Tags** 158 | 159 | > Note: Some colour tags might NOT work for Left 4 Dead 2 160 | 161 | | Tag | Color | 162 | | ----- | -------------------------------------- | 163 | | {N} | Default/normal | 164 | | {O} | Orange | 165 | | {R} | Red | 166 | | {RB} | Red/Blue | 167 | | {B} | Blue (green if no player on blue team) | 168 | | {BR} | Blue/Red | 169 | | {T} | Teamcolor | 170 | | {L} | Lightgreen | 171 | | {GRA} | Grey (green if no spectator) | 172 | | {G} | Green | 173 | | {OG} | Olive | 174 | | {BLA} | Black | 175 | 176 | **Special Tags** 177 | 178 | Some tags are prefixed with "d", "i" or "f". These prefixes are necessary to identify the type of the data so the plugin will be able to interpret it correctly when read from the database. Non-prefixed tags are strings by default. 179 | 180 | Tag Prefix 181 | 182 | | Prefix | Type | 183 | | ------ | ------------------------------------ | 184 | | i | Integer Number | 185 | | d | Date/Time (Not yet working properly) | 186 | | f | Decimal/Floating Point Number | 187 | 188 | | Tag | Description | 189 | | --------------------- | --------------------------------------------------- | 190 | | {steam_id} | Steam ID | 191 | | {last_known_alias} | Last known alias or name of the player | 192 | | {d:last_join_date} | Last join date on the server | 193 | | {i:survivor_killed} | Number of Survivors Killed (As Infected) | 194 | | {i:survivor_incapped} | Number of Survivors Incapped (As Infected) | 195 | | {i:infected_killed} | Number of Infected Killed (As Survivor) | 196 | | {i:infected_headshot} | Number of Infected Killed by Headshot (As Survivor) | 197 | | {f:total_points} | Total Points (Sum of everything) | 198 | | {i:rank_num} | Current Ranking | 199 | 200 | Extra Tags (needs pstats_extras_enabled to be set) 201 | 202 | | Name | Description | 203 | | ------------------------ | ------------------------------------------------------------ | 204 | | {i:skeet_hunter_sniper} | Number of hunters skeeted with sniper by a survivor | 205 | | {i:skeet_hunter_shotgun} | Number of hunters skeeted with shotgun by a survivor | 206 | | {i:skeet_hunter_melee} | Number of hunters skeeted with melee by a survivor | 207 | | {i:skeet_tank_rock} | Number rocks skeeted by a survivor | 208 | | {i:witch_crown_standard} | Number of standard witch crowns by a survivor | 209 | | {i:witch_crown_draw} | Number of draw crowns by a survivor | 210 | | {i:boomer_pop} | Number of boomer pops by a survivor | 211 | | {i:charger_level} | Number of charger levels by a survivor | 212 | | {i:smoker_tongue_cut} | Number of smoker tongue cuts by a survivor | 213 | | {i:hunter_dead_stop} | Number of hunter deadstops by a survivor | 214 | | {i:boomer_quad} | Number of times survivors have been quad boomed (all 4 boomed) | 215 | | {i:hunter_twenty_five} | Number of 25 point hunter pounces | 216 | | {i:death_charge} | Number of times a charger has death charged a survivor | 217 | | {i:tank_rock_hits} | Number of times a tank rocked a survivor | 218 | 219 | 220 | 221 | ------ 222 | 223 | ### ConVars 224 | 225 | | Name | Description | Default value | Min Value | Max Value | 226 | | ------------------------ | ------------------------------------------------------------ | :------------ | --------- | --------- | 227 | | pstats_enabled | Enable/Disable this plugin | 1 | 0 | 1 | 228 | | pstats_debug_enabled | Enable debug messages (for debugging purposes only) | 0 | 0 | 1 | 229 | | pstats_versus_exclusive | If set, the plugin will only work for versus gamemodes | 1 | 0 | 1 | 230 | | pstats_record_bots | Sets whether we should record bots. By default only human players are recorded. | 0 | 0 | 1 | 231 | | pstats_menu_timeout | The timeout value for the player stats panel | 30 (seconds) | 3 | 9999 | 232 | | pstats_max_top_players | The max top N players to display | 10 | 10 | 50 | 233 | | pstats_extras_enabled | Include extra stats to be recorded | 0 | 0 | 1 | 234 | | pstats_display_type | 1 = Display points, 2 = Display the count, 3 = Both points and count | 2 | 1 | 3 | 235 | | pstats_show_rank_onjoin | If set, player rank will be displayed to the user on the start of each map | 1 | 0 | 1 | 236 | | pstats_cannounce_enabled | If set, connect announce will be displayed to chat when a player joins | 1 | 0 | 1 | 237 | 238 | ### Commands 239 | 240 | > **Note**: These commands can also be invoked from chat (e.g. `!rank`, `!top 10`, `!ranks`, `!pstats_reload`) 241 | 242 | | Name | Description | Parameters | Permission | Parameter Description | 243 | | ---------------- | ------------------------------------------------------------ | ---------- | ------------ | -------------------------------------- | 244 | | sm_rank | Display the current stats & ranking of the requesting player. A panel will be displayed to the player. | None | Anyone | None | 245 | | sm_top | Display the top N players. A menu panel will be displayed to the requesting player | Number | Anyone | The number of players to be displayed. | 246 | | sm_ranks | Display the ranks of the players currently playing in the server. A menu panel will be displayed to the requesting player. | Number | Anyone | None | 247 | | sm_pstats_reload | Reloads plugin configuration. This is useful if you have modified the `playerstats.cfg` file. 'This command also synchronizes the modifier values set from the configuration file to the database. This is quite an expensive operation, so please only use this command when necessary. | None | Admin (Root) | None | 248 | | sm_hidestats | Allows a player to prevent other players from viewing his/her extra statistics. | Number | Anyone | 1 = hide, 0 = unhide | 249 | 250 | -------------------------------------------------------------------------------- /configs/playerstats.cfg: -------------------------------------------------------------------------------- 1 | // ============================================================= 2 | // Color Codes: 3 | // ============================================================= 4 | // 5 | // {N} = default/normal 6 | // {O} = orange 7 | // {R} = red 8 | // {RB} = red/blue 9 | // {B} = blue (green if no player on blue team) 10 | // {BR} = blue/red 11 | // {T} = teamcolor 12 | // {L} = lightgreen 13 | // {GRA} = grey (green if no spectator) 14 | // {G} = green 15 | // {OG} = olive 16 | // {BLA} = black 17 | // 18 | // 19 | // ============================================================= 20 | // Connect Announce Keywords 21 | // ============================================================= 22 | // 23 | // Note: Make sure no spaces are in between the type identifiers 24 | // e.g. 25 | // { i: survivor_killed } = wrong 26 | // {i:survivor_killed} = correct 27 | // 28 | // {steam_id} : Steam ID 29 | // {last_known_alias} : Last Known Name 30 | // {d:last_join_date} : Last Join Date 31 | // {i:survivor_killed} : Number of Survivors Killed (As Infected) 32 | // {i:survivor_incapped} : Number of Survivors Incapped (As Infected) 33 | // {i:infected_killed} : Number of Infected Killed (As Survivor) 34 | // {i:infected_headshot} : Number of Infected Killed by Headshot (As Survivor) 35 | // {f:total_points} : Total Points (Sum of everything) 36 | // {i:rank_num} : Current Ranking 37 | // 38 | // Extra stats (applicable only if enabled): 39 | // 40 | // {i:skeet_hunter_sniper} : Number of hunters skeeted with sniper by a survivor 41 | // {i:skeet_hunter_shotgun} : Number of hunters skeeted with shotgun by a survivor 42 | // {i:skeet_hunter_melee} : Number of hunters skeeted with melee by a survivor 43 | // {i:skeet_tank_rock} : Number rocks skeeted by a survivor 44 | // {i:witch_crown_standard} : Number of standard witch crowns by a survivor 45 | // {i:witch_crown_draw} : Number of draw crowns by a survivor 46 | // {i:boomer_pop} : Number of boomer pops by a survivor 47 | // {i:charger_level} : Number of charger levels by a survivor 48 | // {i:smoker_tongue_cut} : Number of smoker tongue cuts by a survivor 49 | // {i:hunter_dead_stop} : Number of hunter deadstops by a survivor 50 | // {i:boomer_quad} : Number of times survivors have been quad boomed (all 4 boomed) 51 | // {i:hunter_twenty_five} : Number of 25 point hunter pounces 52 | // {i:death_charge} : Number of times a charger has death charged a survivor 53 | // {i:tank_rock_hits} : Number of times a tank rocked a survivor 54 | // 55 | // ============================================================= 56 | 57 | "PlayerStats" { 58 | "StatModifiers" 59 | { 60 | "survivor_killed" "1.0" 61 | "survivor_incapped" "1.0" 62 | "infected_killed" "1.0" 63 | "infected_headshot" "1.0" 64 | "skeet_hunter_sniper" "1.0" 65 | "skeet_hunter_shotgun" "1.0" 66 | "skeet_hunter_melee" "1.0" 67 | "skeet_tank_rock" "1.0" 68 | "witch_crown_standard" "1.0" 69 | "witch_crown_draw" "1.0" 70 | "boomer_pop" "1.0" 71 | "charger_level" "1.0" 72 | "smoker_tongue_cut" "1.0" 73 | "hunter_dead_stop" "1.0" 74 | "boomer_quad" "1.0" 75 | "hunter_twenty_five" "1.0" 76 | "death_charge" "1.0" 77 | "tank_rock_hits" "1.0" 78 | } 79 | "StatPanels" 80 | { 81 | "title_rank_player" "Player Stats" 82 | "title_rank_topn" "Top {top_player_count} Players" 83 | "title_rank_ingame" "In-Game Player Ranks" 84 | "title_rank_extras" "Extra Player Stats" 85 | } 86 | "ConnectAnnounce" 87 | { 88 | "format" "{N}Player '{G}{last_known_alias}{N}' ({B}{steam_id}{N}) has joined the game ({G}Rank:{N} #{i:rank_num}, {G}Points:{N} {f:total_points})" 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /configs/sql-init-scripts/mysql/playerstats.sql: -------------------------------------------------------------------------------- 1 | DELIMITER // 2 | CREATE FUNCTION IF NOT EXISTS `APPLY_MODIFIER`( 3 | `name` VARCHAR(50), 4 | `value` INT 5 | ) RETURNS double 6 | BEGIN 7 | DECLARE modifier FLOAT; 8 | 9 | SELECT s.modifier INTO modifier FROM STATS_SKILLS s WHERE s.name = name; 10 | 11 | IF modifier IS NULL 12 | THEN 13 | SELECT 1.0 INTO modifier; 14 | END IF; 15 | 16 | RETURN value * modifier; 17 | END// 18 | DELIMITER ; 19 | 20 | CREATE TABLE IF NOT EXISTS `STATS_PLAYERS` ( 21 | `steam_id` varchar(64) NOT NULL, 22 | `last_known_alias` varchar(255) DEFAULT NULL, 23 | `last_join_date` timestamp NULL DEFAULT current_timestamp(), 24 | `hide_extra_stats` tinyint(4) DEFAULT 0, 25 | `survivor_killed` int(10) unsigned NOT NULL DEFAULT 0, 26 | `survivor_incapped` int(10) unsigned DEFAULT 0, 27 | `infected_killed` int(10) unsigned NOT NULL DEFAULT 0, 28 | `infected_headshot` int(10) unsigned NOT NULL DEFAULT 0, 29 | `skeet_hunter_sniper` int(11) NOT NULL DEFAULT 0, 30 | `skeet_hunter_shotgun` int(11) NOT NULL DEFAULT 0, 31 | `skeet_hunter_melee` int(11) NOT NULL DEFAULT 0, 32 | `skeet_tank_rock` int(11) NOT NULL DEFAULT 0, 33 | `witch_crown_standard` int(11) NOT NULL DEFAULT 0, 34 | `witch_crown_draw` int(11) NOT NULL DEFAULT 0, 35 | `boomer_pop` int(11) NOT NULL DEFAULT 0, 36 | `charger_level` int(11) NOT NULL DEFAULT 0, 37 | `smoker_tongue_cut` int(11) NOT NULL DEFAULT 0, 38 | `hunter_dead_stop` int(11) NOT NULL DEFAULT 0, 39 | `boomer_quad` int(11) NOT NULL DEFAULT 0, 40 | `hunter_twenty_five` int(11) NOT NULL DEFAULT 0, 41 | `death_charge` int(11) NOT NULL DEFAULT 0, 42 | `tank_rock_hits` int(11) NOT NULL DEFAULT 0, 43 | `create_date` timestamp NOT NULL DEFAULT current_timestamp(), 44 | PRIMARY KEY (`steam_id`) 45 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 46 | 47 | CREATE TABLE IF NOT EXISTS `STATS_SKILLS` ( 48 | `name` varchar(50) NOT NULL, 49 | `modifier` float DEFAULT NULL, 50 | `update_date` timestamp NULL DEFAULT current_timestamp(), 51 | PRIMARY KEY (`name`) 52 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 53 | 54 | CREATE VIEW IF NOT EXISTS `STATS_VW_PLAYER_RANKS` AS select `b`.`steam_id` AS `steam_id`,`b`.`last_known_alias` AS `last_known_alias`,date_format(`b`.`last_join_date`,'%Y-%m-%d %h:%i:%s %p') AS `last_join_date`,`b`.`survivor_killed` AS `survivor_killed`,`b`.`survivor_incapped` AS `survivor_incapped`,`b`.`infected_killed` AS `infected_killed`,`b`.`infected_headshot` AS `infected_headshot`,round(`b`.`total_points`,2) AS `total_points`,`b`.`rank_num` AS `rank_num`,date_format(`b`.`create_date`,'%Y-%m-%d %h:%i:%s %p') AS `create_date` from (select `s`.`steam_id` AS `steam_id`,`s`.`last_known_alias` AS `last_known_alias`,`s`.`last_join_date` AS `last_join_date`,`s`.`survivor_killed` AS `survivor_killed`,`s`.`survivor_incapped` AS `survivor_incapped`,`s`.`infected_killed` AS `infected_killed`,`s`.`infected_headshot` AS `infected_headshot`,`APPLY_MODIFIER`('survivor_incapped',`s`.`survivor_incapped`) + `APPLY_MODIFIER`('survivor_killed',`s`.`survivor_killed`) + `APPLY_MODIFIER`('infected_killed',`s`.`infected_killed`) + `APPLY_MODIFIER`('infected_headshot',`s`.`infected_headshot`) AS `total_points`,row_number() over ( order by `s`.`survivor_incapped` + `s`.`survivor_killed` + `s`.`infected_headshot` + `s`.`infected_killed` desc,`s`.`create_date`) AS `rank_num`,`s`.`create_date` AS `create_date` from `STATS_PLAYERS` `s`) `b`; 55 | 56 | CREATE VIEW IF NOT EXISTS `STATS_VW_PLAYER_RANKS_EXTRAS` AS select `b`.`steam_id` AS `steam_id`,`b`.`last_known_alias` AS `last_known_alias`,date_format(`b`.`last_join_date`,'%Y-%m-%d %h:%i:%s %p') AS `last_join_date`,`b`.`survivor_killed` AS `survivor_killed`,`b`.`survivor_incapped` AS `survivor_incapped`,`b`.`infected_killed` AS `infected_killed`,`b`.`infected_headshot` AS `infected_headshot`,`b`.`skeet_hunter_sniper` AS `skeet_hunter_sniper`,`b`.`skeet_hunter_shotgun` AS `skeet_hunter_shotgun`,`b`.`skeet_hunter_melee` AS `skeet_hunter_melee`,`b`.`skeet_tank_rock` AS `skeet_tank_rock`,`b`.`witch_crown_standard` AS `witch_crown_standard`,`b`.`witch_crown_draw` AS `witch_crown_draw`,`b`.`boomer_pop` AS `boomer_pop`,`b`.`charger_level` AS `charger_level`,`b`.`smoker_tongue_cut` AS `smoker_tongue_cut`,`b`.`hunter_dead_stop` AS `hunter_dead_stop`,`b`.`boomer_quad` AS `boomer_quad`,`b`.`hunter_twenty_five` AS `hunter_twenty_five`,`b`.`death_charge` AS `death_charge`,`b`.`tank_rock_hits` AS `tank_rock_hits`,`b`.`total_points` AS `total_points`,`b`.`rank_num` AS `rank_num`,date_format(`b`.`create_date`,'%Y-%m-%d %h:%i:%s %p') AS `create_date` from (select `s`.`steam_id` AS `steam_id`,`s`.`last_known_alias` AS `last_known_alias`,`s`.`last_join_date` AS `last_join_date`,`s`.`survivor_killed` AS `survivor_killed`,`s`.`survivor_incapped` AS `survivor_incapped`,`s`.`infected_killed` AS `infected_killed`,`s`.`infected_headshot` AS `infected_headshot`,`s`.`skeet_hunter_sniper` AS `skeet_hunter_sniper`,`s`.`skeet_hunter_shotgun` AS `skeet_hunter_shotgun`,`s`.`skeet_hunter_melee` AS `skeet_hunter_melee`,`s`.`skeet_tank_rock` AS `skeet_tank_rock`,`s`.`witch_crown_standard` AS `witch_crown_standard`,`s`.`witch_crown_draw` AS `witch_crown_draw`,`s`.`boomer_pop` AS `boomer_pop`,`s`.`charger_level` AS `charger_level`,`s`.`smoker_tongue_cut` AS `smoker_tongue_cut`,`s`.`hunter_dead_stop` AS `hunter_dead_stop`,`s`.`boomer_quad` AS `boomer_quad`,`s`.`hunter_twenty_five` AS `hunter_twenty_five`,`s`.`death_charge` AS `death_charge`,`s`.`tank_rock_hits` AS `tank_rock_hits`,`APPLY_MODIFIER`('survivor_incapped',`s`.`survivor_incapped`) + `APPLY_MODIFIER`('survivor_killed',`s`.`survivor_killed`) + `APPLY_MODIFIER`('infected_killed',`s`.`infected_killed`) + `APPLY_MODIFIER`('infected_headshot',`s`.`infected_headshot`) + `APPLY_MODIFIER`('skeet_hunter_sniper',`s`.`skeet_hunter_sniper`) + `APPLY_MODIFIER`('skeet_hunter_shotgun',`s`.`skeet_hunter_shotgun`) + `APPLY_MODIFIER`('skeet_hunter_melee',`s`.`skeet_hunter_melee`) + `APPLY_MODIFIER`('skeet_tank_rock',`s`.`skeet_tank_rock`) + `APPLY_MODIFIER`('witch_crown_standard',`s`.`witch_crown_standard`) + `APPLY_MODIFIER`('witch_crown_draw',`s`.`witch_crown_draw`) + `APPLY_MODIFIER`('boomer_pop',`s`.`boomer_pop`) + `APPLY_MODIFIER`('charger_level',`s`.`charger_level`) + `APPLY_MODIFIER`('smoker_tongue_cut',`s`.`smoker_tongue_cut`) + `APPLY_MODIFIER`('hunter_dead_stop',`s`.`hunter_dead_stop`) + `APPLY_MODIFIER`('boomer_quad',`s`.`boomer_quad`) + `APPLY_MODIFIER`('hunter_twenty_five',`s`.`hunter_twenty_five`) + `APPLY_MODIFIER`('death_charge',`s`.`death_charge`) + `APPLY_MODIFIER`('tank_rock_hits',`s`.`tank_rock_hits`) AS `total_points`,row_number() over ( order by `s`.`survivor_incapped` + `s`.`survivor_killed` + `s`.`infected_headshot` + `s`.`infected_killed` + `s`.`skeet_hunter_sniper` + `s`.`skeet_hunter_shotgun` + `s`.`skeet_hunter_melee` + `s`.`skeet_tank_rock` + `s`.`witch_crown_standard` + `s`.`witch_crown_draw` + `s`.`boomer_pop` + `s`.`charger_level` + `s`.`smoker_tongue_cut` + `s`.`hunter_dead_stop` + `s`.`boomer_quad` + `s`.`hunter_twenty_five` + `s`.`death_charge` + `s`.`tank_rock_hits` desc,`s`.`create_date`) AS `rank_num`,`s`.`create_date` AS `create_date` from `STATS_PLAYERS` `s`) `b`; 57 | -------------------------------------------------------------------------------- /connect_announce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcemod-plugins/l4d2-player-stats/acfd4df5048977a9fce74db89820c93d8adcaaa4/connect_announce.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /player_join.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcemod-plugins/l4d2-player-stats/acfd4df5048977a9fce74db89820c93d8adcaaa4/player_join.png -------------------------------------------------------------------------------- /player_rank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcemod-plugins/l4d2-player-stats/acfd4df5048977a9fce74db89820c93d8adcaaa4/player_rank.png -------------------------------------------------------------------------------- /player_rank_extras.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcemod-plugins/l4d2-player-stats/acfd4df5048977a9fce74db89820c93d8adcaaa4/player_rank_extras.png -------------------------------------------------------------------------------- /plugins/l4d2_simpleplayerstats.smx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcemod-plugins/l4d2-player-stats/acfd4df5048977a9fce74db89820c93d8adcaaa4/plugins/l4d2_simpleplayerstats.smx -------------------------------------------------------------------------------- /ranks_ingame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcemod-plugins/l4d2-player-stats/acfd4df5048977a9fce74db89820c93d8adcaaa4/ranks_ingame.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /top_players.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcemod-plugins/l4d2-player-stats/acfd4df5048977a9fce74db89820c93d8adcaaa4/top_players.png --------------------------------------------------------------------------------