hl.inc
Original include source with line numbers.
| 1 | /* |
| 2 | * AMX mod X functions for Half-Life |
| 3 | * |
| 4 | * Version 1.1 (last update: 29.07.2010) |
| 5 | * |
| 6 | * http://hl.levshi.ru/forum/ - Russian Half-Life and Adrenaline Gamer Community |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #if defined _hl_included |
| 11 | #endinput |
| 12 | #endif |
| 13 | #define _hl_included |
| 14 | |
| 15 | #include <amxmodx> |
| 16 | #include <fakemeta> |
| 17 | |
| 18 | |
| 19 | #define EXTRAOFFSET 5 |
| 20 | #define EXTRAOFFSET_WEAPONS 4 |
| 21 | #define EXTRAOFFSET_WEAPONBOX 4 |
| 22 | |
| 23 | #define OFFSET_WEAPONID 30 |
| 24 | #define OFFSET_WEAPONCLIP 40 |
| 25 | #define OFFSET_WEAPONBOX 60 |
| 26 | |
| 27 | #define OFFSET_ACTIVEITEM 306 |
| 28 | #define OFFSET_DEATHS 377 |
| 29 | #define OFFSET_HUD 296 |
| 30 | #define OFFSET_LONGJUMP 291 |
| 31 | |
| 32 | #define HL_MAX_TEAMS 10 |
| 33 | |
| 34 | stock static teams[HL_MAX_TEAMS][16] |
| 35 | |
| 36 | enum |
| 37 | { |
| 38 | OFFSET_AMMO_SHOTGUN = 310, |
| 39 | OFFSET_AMMO_9MM, // MP5, GLOCK |
| 40 | OFFSET_AMMO_ARGRENADE, // M-203 |
| 41 | OFFSET_AMMO_PYTHON, |
| 42 | OFFSET_AMMO_URANIUM, // GAUSS, EGON |
| 43 | OFFSET_AMMO_RPG, |
| 44 | OFFSET_AMMO_CROSSBOW, |
| 45 | OFFSET_AMMO_TRIPMINE, |
| 46 | OFFSET_AMMO_SATCHEL, |
| 47 | OFFSET_AMMO_HEGRENADE, // HAND GRENADE |
| 48 | OFFSET_AMMO_SNARK, |
| 49 | OFFSET_AMMO_HORNET |
| 50 | } |
| 51 | |
| 52 | static const _HLW_to_offset[] = |
| 53 | { |
| 54 | 0, 0, OFFSET_AMMO_9MM, OFFSET_AMMO_PYTHON, OFFSET_AMMO_9MM, OFFSET_AMMO_ARGRENADE, OFFSET_AMMO_CROSSBOW, |
| 55 | OFFSET_AMMO_SHOTGUN, OFFSET_AMMO_RPG, OFFSET_AMMO_URANIUM, OFFSET_AMMO_URANIUM, OFFSET_AMMO_HORNET, |
| 56 | OFFSET_AMMO_HEGRENADE, OFFSET_AMMO_TRIPMINE, OFFSET_AMMO_SATCHEL, OFFSET_AMMO_SNARK |
| 57 | } |
| 58 | |
| 59 | /* Returns player deaths. |
| 60 | */ |
| 61 | stock hl_get_user_deaths(client) |
| 62 | { |
| 63 | return get_pdata_int(client, OFFSET_DEATHS, EXTRAOFFSET) |
| 64 | } |
| 65 | |
| 66 | /* Sets player deaths. |
| 67 | */ |
| 68 | stock hl_set_user_deaths(client, deaths) |
| 69 | { |
| 70 | set_pdata_int(client, OFFSET_DEATHS, deaths, EXTRAOFFSET) |
| 71 | |
| 72 | static ScoreInfo |
| 73 | if(ScoreInfo || (ScoreInfo = get_user_msgid("ScoreInfo"))) |
| 74 | { |
| 75 | message_begin(MSG_BROADCAST, ScoreInfo) |
| 76 | write_byte(client) |
| 77 | write_short(get_user_frags(client)) |
| 78 | write_short(deaths) |
| 79 | write_short(0) |
| 80 | write_short(hl_get_user_team(client)) |
| 81 | message_end() |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /* Get amount of ammo in backpack on a user for a specific weapon. |
| 86 | * Look in hlsdk_const.inc for weapon types: HLW_*. |
| 87 | * Weapons on the same line uses the same ammo type: |
| 88 | * shotgun |
| 89 | * mp5, glock |
| 90 | * argrenade |
| 91 | * python |
| 92 | * gauss, egon |
| 93 | * rpg |
| 94 | * crossbow |
| 95 | * tripmine |
| 96 | * satchel |
| 97 | * handgrenade |
| 98 | * snark |
| 99 | * hornet |
| 100 | */ |
| 101 | stock hl_get_user_bpammo(client, weapon) |
| 102 | { |
| 103 | return get_pdata_int(client, _HLW_to_offset[weapon], EXTRAOFFSET) |
| 104 | } |
| 105 | |
| 106 | /* Restock/remove ammo in a user's backpack. |
| 107 | */ |
| 108 | stock hl_set_user_bpammo(client, weapon, ammo) |
| 109 | { |
| 110 | if(weapon <= HLW_CROWBAR) |
| 111 | return |
| 112 | |
| 113 | set_pdata_int(client, _HLW_to_offset[weapon], ammo, EXTRAOFFSET) |
| 114 | } |
| 115 | |
| 116 | /* Get user model. |
| 117 | */ |
| 118 | stock hl_get_user_model(client, model[], len) |
| 119 | { |
| 120 | get_user_info(client, "model", model, len) |
| 121 | } |
| 122 | |
| 123 | /* Set user model. |
| 124 | */ |
| 125 | stock hl_set_user_model(client, const model[]) |
| 126 | { |
| 127 | set_user_info(client, "model", model) |
| 128 | } |
| 129 | |
| 130 | /* Returns health value. |
| 131 | */ |
| 132 | stock hl_get_user_health(client) |
| 133 | { |
| 134 | static Float:healthvalue |
| 135 | pev(client, pev_health, healthvalue) |
| 136 | return floatround(healthvalue) |
| 137 | } |
| 138 | |
| 139 | /* Sets player health. |
| 140 | */ |
| 141 | stock hl_set_user_health(client, health) |
| 142 | { |
| 143 | health > 0 ? set_pev(client, pev_health, float(health)) : dllfunc(DLLFunc_ClientKill, client) |
| 144 | |
| 145 | return 1 |
| 146 | } |
| 147 | |
| 148 | /* Returns armor value. |
| 149 | */ |
| 150 | stock hl_get_user_armor(client) |
| 151 | { |
| 152 | static Float:armorvalue |
| 153 | pev(client, pev_armorvalue, armorvalue) |
| 154 | return floatround(armorvalue) |
| 155 | } |
| 156 | |
| 157 | /* Sets player armor. |
| 158 | */ |
| 159 | stock hl_set_user_armor(client, armorvalue) |
| 160 | { |
| 161 | set_pev(client, pev_armorvalue, float(armorvalue)) |
| 162 | } |
| 163 | |
| 164 | /* Returns team id. When length is greater then 0 then a name of team is set. |
| 165 | */ |
| 166 | stock hl_get_user_team(client, team[] = "", len = 0) |
| 167 | { |
| 168 | if(hl_get_user_spectator(client)) |
| 169 | return 0 |
| 170 | |
| 171 | static Float: tdm; global_get(glb_teamplay, tdm) |
| 172 | if(tdm < 1.0) return 0 |
| 173 | |
| 174 | if(!len) len = 16 |
| 175 | get_user_info(client, "model", team, len) |
| 176 | |
| 177 | return __get_team_index(team) |
| 178 | } |
| 179 | |
| 180 | /* Set player team by teamname. |
| 181 | */ |
| 182 | stock hl_set_user_team(client, const team[]) |
| 183 | { |
| 184 | static Float: tdm; global_get(glb_teamplay, tdm) |
| 185 | if(tdm < 1.0) return 0 |
| 186 | |
| 187 | static teamid; teamid = __get_team_index(team) |
| 188 | if(teamid == -1) return 0 |
| 189 | |
| 190 | hl_set_user_spectator(client, false) |
| 191 | |
| 192 | engfunc(EngFunc_SetClientKeyValue, client, engfunc(EngFunc_GetInfoKeyBuffer, client), "model", team) |
| 193 | engfunc(EngFunc_SetClientKeyValue, client, engfunc(EngFunc_GetInfoKeyBuffer, client), "team", team) |
| 194 | |
| 195 | static TeamInfo |
| 196 | if(TeamInfo || (TeamInfo = get_user_msgid("TeamInfo"))) |
| 197 | { |
| 198 | message_begin(MSG_ALL, TeamInfo) |
| 199 | write_byte(client) |
| 200 | write_string(team) |
| 201 | message_end() |
| 202 | } |
| 203 | |
| 204 | static ScoreInfo |
| 205 | if(ScoreInfo || (ScoreInfo = get_user_msgid("ScoreInfo"))) |
| 206 | { |
| 207 | message_begin(MSG_ALL, ScoreInfo) |
| 208 | write_byte(client) |
| 209 | write_short(get_user_frags(client)) |
| 210 | write_short(hl_get_user_deaths(client)) |
| 211 | write_short(0) |
| 212 | write_short(teamid) |
| 213 | message_end() |
| 214 | } |
| 215 | |
| 216 | return 1 |
| 217 | } |
| 218 | |
| 219 | stock __get_team_index(const team[]) |
| 220 | { |
| 221 | static teamid; teamid = 0 |
| 222 | static valid; valid = 0 |
| 223 | static i; i = 0 |
| 224 | |
| 225 | __count_teams() |
| 226 | |
| 227 | for(i = 0 ; i < sizeof teams; i++) |
| 228 | { |
| 229 | teamid++ |
| 230 | if(equali(teams[i][0], team)) |
| 231 | { |
| 232 | valid = 1 |
| 233 | break |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if(valid) |
| 238 | return teamid |
| 239 | |
| 240 | return 0 |
| 241 | } |
| 242 | |
| 243 | stock __count_teams() |
| 244 | { |
| 245 | if(!teams[0][0]) |
| 246 | { |
| 247 | new teamlist[50] |
| 248 | get_pcvar_string(get_cvar_pointer("mp_teamlist"), teamlist, charsmax(teamlist)); trim(teamlist) |
| 249 | __explode_teamlist(teams, charsmax(teams[]), teamlist, ';') |
| 250 | } |
| 251 | |
| 252 | static teamcount |
| 253 | |
| 254 | if(!teamcount) |
| 255 | { |
| 256 | for(new i = 0; i < sizeof teams; i++) |
| 257 | { |
| 258 | if(teams[i][0]) |
| 259 | teamcount++ |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | return teamcount |
| 264 | } |
| 265 | |
| 266 | stock __explode_teamlist(output[][], size, input[], delimiter) |
| 267 | { |
| 268 | new nIdx = 0, l = strlen(input) |
| 269 | new nLen = (1 + copyc(output[nIdx], size, input, delimiter )) |
| 270 | |
| 271 | while( (nLen < l) && (++nIdx < HL_MAX_TEAMS) ) |
| 272 | nLen += (1 + copyc(output[nIdx], size, input[nLen], delimiter )) |
| 273 | } |
| 274 | |
| 275 | /* Returns entity index of active weapon. |
| 276 | */ |
| 277 | stock hl_get_user_weapon_ent(client) |
| 278 | { |
| 279 | return get_pdata_cbase(client, OFFSET_ACTIVEITEM, EXTRAOFFSET) |
| 280 | } |
| 281 | |
| 282 | /* Returns amount of ammo in weapon's clip. |
| 283 | */ |
| 284 | stock hl_get_weapon_ammo(entity) |
| 285 | { |
| 286 | return get_pdata_int(entity, OFFSET_WEAPONCLIP, EXTRAOFFSET_WEAPONS) |
| 287 | } |
| 288 | |
| 289 | /* Set amount of ammo in weapon's clip. |
| 290 | */ |
| 291 | stock hl_set_weapon_ammo(entity, clip) |
| 292 | { |
| 293 | set_pdata_int(entity, OFFSET_WEAPONCLIP, clip, EXTRAOFFSET_WEAPONS) |
| 294 | } |
| 295 | |
| 296 | /* Get weapon type. Corresponds to HLW_* in hlsdk_const.inc: 1 is HLW_CROWBAR, 2 is HLW_GLOCK and so on... |
| 297 | */ |
| 298 | stock hl_get_weapon_id(entity) |
| 299 | { |
| 300 | return get_pdata_int(entity, OFFSET_WEAPONID, EXTRAOFFSET_WEAPONS) |
| 301 | } |
| 302 | |
| 303 | /* Returns weapon entity index from weaponbox. |
| 304 | */ |
| 305 | stock hl_get_wbox_weapon_ent(entity) |
| 306 | { |
| 307 | static wpn_entity, i |
| 308 | static const m_rgpPlayerItems_weaponbox[] = {22, 23, 24, 25, 26} |
| 309 | |
| 310 | for(i = 0; i < sizeof(m_rgpPlayerItems_weaponbox); i++) |
| 311 | { |
| 312 | wpn_entity = get_pdata_cbase(entity, m_rgpPlayerItems_weaponbox[i], EXTRAOFFSET_WEAPONS) |
| 313 | if(wpn_entity > 0) |
| 314 | { |
| 315 | break |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | return wpn_entity |
| 320 | } |
| 321 | |
| 322 | /* Returns amount of ammo in weaponbox. |
| 323 | */ |
| 324 | stock hl_get_wbox_ammo(entity) |
| 325 | { |
| 326 | return get_pdata_int(entity, OFFSET_WEAPONBOX, EXTRAOFFSET_WEAPONBOX) |
| 327 | } |
| 328 | |
| 329 | /* Set amount of ammo in weaponbox. |
| 330 | */ |
| 331 | stock hl_set_wbox_ammo(entity, ammo) |
| 332 | { |
| 333 | set_pdata_int(entity, OFFSET_WEAPONBOX, ammo, EXTRAOFFSET_WEAPONBOX) |
| 334 | } |
| 335 | |
| 336 | /* Spawns a Half-Life player. |
| 337 | */ |
| 338 | stock hl_user_spawn(client) |
| 339 | { |
| 340 | if(!hl_strip_user_weapons(client)) |
| 341 | return |
| 342 | |
| 343 | set_pev(client, pev_deadflag, DEAD_RESPAWNABLE) |
| 344 | dllfunc(DLLFunc_Spawn, client) |
| 345 | } |
| 346 | |
| 347 | /* Strips all weapons from player. |
| 348 | */ |
| 349 | stock hl_strip_user_weapons(client) |
| 350 | { |
| 351 | new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "player_weaponstrip")) |
| 352 | if(!pev_valid(ent)) |
| 353 | return 0 |
| 354 | |
| 355 | dllfunc(DLLFunc_Spawn, ent); |
| 356 | dllfunc(DLLFunc_Use, ent, client) |
| 357 | engfunc(EngFunc_RemoveEntity, ent) |
| 358 | |
| 359 | return 1 |
| 360 | } |
| 361 | |
| 362 | /* Check if player in spectator mode. |
| 363 | */ |
| 364 | stock bool:hl_get_user_spectator(client) |
| 365 | { |
| 366 | if(pev(client, pev_iuser1) || pev(client, pev_iuser2)) |
| 367 | return true |
| 368 | |
| 369 | return false |
| 370 | } |
| 371 | |
| 372 | /* Switch player to spectator mode. |
| 373 | */ |
| 374 | stock hl_set_user_spectator(client, bool:spectator = true) |
| 375 | { |
| 376 | if(hl_get_user_spectator(client) == spectator) |
| 377 | return |
| 378 | |
| 379 | if(spectator) |
| 380 | { |
| 381 | static AllowSpectatorsCvar |
| 382 | if(AllowSpectatorsCvar || (AllowSpectatorsCvar = get_cvar_pointer("allow_spectators"))) |
| 383 | { |
| 384 | if(!get_pcvar_num(AllowSpectatorsCvar)) |
| 385 | set_pcvar_num(AllowSpectatorsCvar, 1) |
| 386 | |
| 387 | engclient_cmd(client, "spectate") |
| 388 | } |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | hl_user_spawn(client) |
| 393 | |
| 394 | set_pev(client, pev_iuser1, 0) |
| 395 | set_pev(client, pev_iuser2, 0) |
| 396 | |
| 397 | set_pdata_int(client, OFFSET_HUD, 0) |
| 398 | |
| 399 | static szTeam[16] |
| 400 | hl_get_user_team(client, szTeam, charsmax(szTeam)) |
| 401 | |
| 402 | static TeamInfo |
| 403 | if(TeamInfo || (TeamInfo = get_user_msgid("TeamInfo"))) |
| 404 | { |
| 405 | message_begin(MSG_ALL, TeamInfo) |
| 406 | write_byte(client) |
| 407 | write_string(szTeam) |
| 408 | message_end() |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /* Check if player have longjump module. |
| 414 | */ |
| 415 | stock bool:hl_get_user_longjump(client) |
| 416 | { |
| 417 | new value[2] |
| 418 | engfunc(EngFunc_GetPhysicsKeyValue, client, "slj", value, 1) |
| 419 | switch (value[0]) |
| 420 | { |
| 421 | case '1': return true |
| 422 | } |
| 423 | |
| 424 | return false |
| 425 | } |
| 426 | |
| 427 | /* Set longjump module to player. |
| 428 | */ |
| 429 | stock hl_set_user_longjump(client, bool:longjump = true, bool:tempicon = true) |
| 430 | { |
| 431 | if(longjump == hl_get_user_longjump(client)) |
| 432 | return |
| 433 | |
| 434 | if(longjump) |
| 435 | { |
| 436 | engfunc(EngFunc_SetPhysicsKeyValue, client, "slj", "1") |
| 437 | |
| 438 | if(tempicon) |
| 439 | { |
| 440 | static msgid_itempickup |
| 441 | if(!msgid_itempickup) |
| 442 | msgid_itempickup = get_user_msgid("ItemPickup") |
| 443 | |
| 444 | message_begin(MSG_ONE, msgid_itempickup, _, client) |
| 445 | write_string("item_longjump") |
| 446 | message_end() |
| 447 | } |
| 448 | } |
| 449 | else |
| 450 | engfunc(EngFunc_SetPhysicsKeyValue, client, "slj", "0") |
| 451 | |
| 452 | set_pdata_int(client, OFFSET_LONGJUMP, longjump, EXTRAOFFSET) |
| 453 | } |
| 454 | /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE |
| 455 | *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par } |
| 456 | */ |
| 457 | |