2019-08-31 19:18:15 -07:00
|
|
|
/*
|
2020-04-07 05:46:23 -07:00
|
|
|
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
2019-08-31 19:18:15 -07:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2020-04-03 03:12:11 -07:00
|
|
|
/*QUAKED weapon_9mmhandgun (0 0 1) (-16 -16 0) (16 16 32)
|
|
|
|
"model" "models/w_9mmhandgun.mdl"
|
|
|
|
|
|
|
|
HALF-LIFE (1998) ENTITY
|
|
|
|
|
|
|
|
9mm Handgun/Glock Weapon
|
|
|
|
Same as weapon_glock
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*QUAKED weapon_glock (0 0 1) (-16 -16 0) (16 16 32)
|
|
|
|
"model" "models/w_9mmhandgun.mdl"
|
|
|
|
|
|
|
|
HALF-LIFE (1998) ENTITY
|
|
|
|
|
|
|
|
9mm Handgun/Glock Weapon
|
|
|
|
Same as weapon_9mmhandgun
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-01-28 18:40:14 -08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
GLOCK_IDLE1,
|
|
|
|
GLOCK_IDLE2,
|
|
|
|
GLOCK_IDLE3,
|
|
|
|
GLOCK_SHOOT,
|
|
|
|
GLOCK_SHOOT_EMPTY,
|
|
|
|
GLOCK_RELOAD_EMPTY,
|
|
|
|
GLOCK_RELOAD,
|
|
|
|
GLOCK_DRAW,
|
|
|
|
GLOCK_HOLSTER
|
|
|
|
};
|
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
void
|
|
|
|
w_glock_precache(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef SERVER
|
2020-04-02 14:39:27 -07:00
|
|
|
Sound_Precache("weapon_glock.fire");
|
2019-01-28 18:40:14 -08:00
|
|
|
precache_model("models/w_9mmhandgun.mdl");
|
2020-05-03 20:48:19 -07:00
|
|
|
#else
|
|
|
|
precache_model("models/v_9mmhandgun.mdl");
|
2019-01-28 18:40:14 -08:00
|
|
|
precache_model("models/p_9mmhandgun.mdl");
|
2020-05-03 20:48:19 -07:00
|
|
|
#endif
|
2019-01-28 18:40:14 -08:00
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
w_glock_updateammo(player pl)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef SERVER
|
2019-09-15 01:14:26 -07:00
|
|
|
Weapons_UpdateAmmo(pl, pl.glock_mag, pl.ammo_9mm, -1);
|
2019-08-20 23:02:35 -07:00
|
|
|
#endif
|
2019-01-28 18:40:14 -08:00
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
string
|
|
|
|
w_glock_wmodel(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
|
|
|
return "models/w_9mmhandgun.mdl";
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
string
|
|
|
|
w_glock_pmodel(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
|
|
|
return "models/p_9mmhandgun.mdl";
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
string
|
|
|
|
w_glock_deathmsg(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
int
|
2020-04-26 04:17:19 -07:00
|
|
|
w_glock_pickup(int new, int startammo)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef SERVER
|
2019-01-28 18:40:14 -08:00
|
|
|
player pl = (player)self;
|
2019-09-12 22:22:17 -07:00
|
|
|
|
|
|
|
if (new) {
|
|
|
|
pl.glock_mag = 18;
|
|
|
|
} else {
|
2019-09-15 14:55:18 -07:00
|
|
|
if (pl.ammo_9mm < MAX_A_9MM) {
|
|
|
|
pl.ammo_9mm = bound(0, pl.ammo_9mm + 18, MAX_A_9MM);
|
2019-09-12 22:22:17 -07:00
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 18:40:14 -08:00
|
|
|
#endif
|
2019-09-12 22:22:17 -07:00
|
|
|
return TRUE;
|
2019-01-28 18:40:14 -08:00
|
|
|
}
|
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
void
|
|
|
|
w_glock_draw(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-08-20 23:02:35 -07:00
|
|
|
Weapons_SetModel("models/v_9mmhandgun.mdl");
|
2019-01-28 18:40:14 -08:00
|
|
|
Weapons_ViewAnimation(GLOCK_DRAW);
|
|
|
|
#endif
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
w_glock_holster(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-01-28 18:40:14 -08:00
|
|
|
Weapons_ViewAnimation(GLOCK_HOLSTER);
|
2019-09-14 23:38:52 -07:00
|
|
|
#endif
|
2019-01-28 18:40:14 -08:00
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
w_glock_primary(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
|
|
|
player pl = (player)self;
|
|
|
|
|
|
|
|
if (pl.w_attack_next > 0.0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
/* ammo check */
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-01-28 18:40:14 -08:00
|
|
|
if (!pl.a_ammo1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!pl.glock_mag) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
#endif
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
/* actual firing */
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-09-14 23:38:52 -07:00
|
|
|
pl.a_ammo1--;
|
|
|
|
View_SetMuzzleflash(MUZZLE_SMALL);
|
|
|
|
Weapons_ViewPunchAngle([-2,0,0]);
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
if (pl.a_ammo1) {
|
|
|
|
Weapons_ViewAnimation(GLOCK_SHOOT);
|
|
|
|
} else {
|
|
|
|
Weapons_ViewAnimation(GLOCK_SHOOT_EMPTY);
|
|
|
|
}
|
|
|
|
#else
|
2019-01-28 18:40:14 -08:00
|
|
|
pl.glock_mag--;
|
2020-12-11 16:54:00 -08:00
|
|
|
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, Skill_GetValue("plr_9mm_bullet", 8), [0.01,0.01], WEAPON_GLOCK);
|
2020-04-02 14:39:27 -07:00
|
|
|
Sound_Play(pl, CHAN_WEAPON, "weapon_glock.fire");
|
2019-09-14 23:38:52 -07:00
|
|
|
|
2019-08-07 00:20:42 -07:00
|
|
|
if (self.flags & FL_CROUCHING)
|
|
|
|
Animation_PlayerTopTemp(ANIM_SHOOT1HAND, 0.45f);
|
|
|
|
else
|
|
|
|
Animation_PlayerTopTemp(ANIM_CR_SHOOT1HAND, 0.45f);
|
2019-01-28 18:40:14 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
pl.w_attack_next = 0.3f;
|
|
|
|
pl.w_idle_next = 5.0f;
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
w_glock_secondary(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
|
|
|
player pl = (player)self;
|
|
|
|
|
|
|
|
if (pl.w_attack_next > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
/* ammo check */
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-01-28 18:40:14 -08:00
|
|
|
if (!pl.a_ammo1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!pl.glock_mag) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
#endif
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-09-14 23:38:52 -07:00
|
|
|
pl.a_ammo1--;
|
|
|
|
View_SetMuzzleflash(MUZZLE_SMALL);
|
|
|
|
Weapons_ViewPunchAngle([-2,0,0]);
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
if (pl.a_ammo1) {
|
|
|
|
Weapons_ViewAnimation(GLOCK_SHOOT);
|
|
|
|
} else {
|
|
|
|
Weapons_ViewAnimation(GLOCK_SHOOT_EMPTY);
|
|
|
|
}
|
|
|
|
#else
|
2019-01-28 18:40:14 -08:00
|
|
|
pl.glock_mag--;
|
2020-12-11 16:54:00 -08:00
|
|
|
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, Skill_GetValue("plr_9mm_bullet", 8), [0.1,0.1], WEAPON_GLOCK);
|
2020-04-02 14:39:27 -07:00
|
|
|
Sound_Play(pl, CHAN_WEAPON, "weapon_glock.fire");
|
2019-08-07 00:20:42 -07:00
|
|
|
|
|
|
|
if (self.flags & FL_CROUCHING)
|
|
|
|
Animation_PlayerTopTemp(ANIM_SHOOT1HAND, 0.45f);
|
|
|
|
else
|
|
|
|
Animation_PlayerTopTemp(ANIM_CR_SHOOT1HAND, 0.45f);
|
2019-01-28 18:40:14 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
pl.w_attack_next = 0.2f;
|
|
|
|
pl.w_idle_next = 5.0f;
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
w_glock_reload(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
|
|
|
player pl = (player)self;
|
2019-09-15 01:14:26 -07:00
|
|
|
|
|
|
|
if (pl.w_attack_next > 0.0) {
|
2019-01-28 18:40:14 -08:00
|
|
|
return;
|
|
|
|
}
|
2019-09-15 01:14:26 -07:00
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-01-28 18:40:14 -08:00
|
|
|
if (pl.a_ammo1 >= 18) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-15 01:14:26 -07:00
|
|
|
if (pl.a_ammo2 <= 0) {
|
2019-08-08 01:42:05 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2019-09-15 01:14:26 -07:00
|
|
|
if (pl.a_ammo1) {
|
|
|
|
Weapons_ViewAnimation(GLOCK_RELOAD);
|
|
|
|
} else {
|
|
|
|
Weapons_ViewAnimation(GLOCK_RELOAD_EMPTY);
|
|
|
|
}
|
2019-01-28 18:40:14 -08:00
|
|
|
#else
|
|
|
|
if (pl.glock_mag >= 18) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-15 01:14:26 -07:00
|
|
|
if (pl.ammo_9mm <= 0) {
|
2019-01-28 18:40:14 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Weapons_ReloadWeapon(pl, player::glock_mag, player::ammo_9mm, 18);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pl.w_attack_next = 2.0f;
|
|
|
|
pl.w_idle_next = 10.0f;
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
w_glock_release(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
|
|
|
player pl = (player)self;
|
2019-09-14 23:38:52 -07:00
|
|
|
int r;
|
|
|
|
|
|
|
|
if (pl.w_idle_next > 0.0) {
|
2019-01-28 18:40:14 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-17 11:46:00 -07:00
|
|
|
r = (float)input_sequence % 3;
|
2019-01-28 18:40:14 -08:00
|
|
|
switch (r) {
|
|
|
|
case 1:
|
|
|
|
Weapons_ViewAnimation(GLOCK_IDLE2);
|
2019-09-14 23:38:52 -07:00
|
|
|
pl.w_idle_next = 2.5f;
|
2019-01-28 18:40:14 -08:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Weapons_ViewAnimation(GLOCK_IDLE3);
|
2019-09-14 23:38:52 -07:00
|
|
|
pl.w_idle_next = 3.5f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Weapons_ViewAnimation(GLOCK_IDLE1);
|
|
|
|
pl.w_idle_next = 3.75f;
|
2019-01-28 18:40:14 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 00:20:42 -07:00
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
float
|
|
|
|
w_glock_aimanim(void)
|
2019-08-07 00:20:42 -07:00
|
|
|
{
|
|
|
|
return self.flags & FL_CROUCHING ? ANIM_CR_AIM1HAND : ANIM_AIM1HAND;
|
|
|
|
}
|
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
void
|
|
|
|
w_glock_hud(void)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-09-14 23:38:52 -07:00
|
|
|
vector cross_pos;
|
|
|
|
vector aicon_pos;
|
|
|
|
|
2020-04-01 09:43:09 -07:00
|
|
|
cross_pos = g_hudmins + (g_hudres / 2) + [-12,-12];
|
|
|
|
aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42];
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
drawsubpic(
|
|
|
|
cross_pos,
|
|
|
|
[24,24],
|
2020-05-31 03:54:04 -07:00
|
|
|
g_cross_spr,
|
2019-09-14 23:38:52 -07:00
|
|
|
[0.1875,0],
|
|
|
|
[0.1875, 0.1875],
|
|
|
|
[1,1,1],
|
|
|
|
1.0f,
|
|
|
|
DRAWFLAG_NORMAL
|
|
|
|
);
|
|
|
|
|
2019-01-28 18:40:14 -08:00
|
|
|
HUD_DrawAmmo1();
|
|
|
|
HUD_DrawAmmo2();
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
drawsubpic(
|
|
|
|
aicon_pos,
|
|
|
|
[24,24],
|
2020-05-31 03:54:04 -07:00
|
|
|
g_hud7_spr,
|
2019-09-14 23:38:52 -07:00
|
|
|
[0,72/128],
|
|
|
|
[24/256, 24/128],
|
|
|
|
g_hud_color,
|
2020-04-12 06:50:42 -07:00
|
|
|
pSeat->m_flAmmo2Alpha,
|
2019-09-14 23:38:52 -07:00
|
|
|
DRAWFLAG_ADDITIVE
|
|
|
|
);
|
2019-01-28 18:40:14 -08:00
|
|
|
#endif
|
|
|
|
}
|
2019-09-14 23:38:52 -07:00
|
|
|
|
|
|
|
void
|
2020-03-24 08:20:58 -07:00
|
|
|
w_glock_hudpic(int selected, vector pos, float a)
|
2019-01-28 18:40:14 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef CLIENT
|
2019-09-14 23:38:52 -07:00
|
|
|
if (selected) {
|
|
|
|
drawsubpic(
|
|
|
|
pos,
|
|
|
|
[170,45],
|
2020-05-31 03:54:04 -07:00
|
|
|
g_hud4_spr,
|
2019-09-14 23:38:52 -07:00
|
|
|
[0,45/256],
|
|
|
|
[170/256,45/256],
|
|
|
|
g_hud_color,
|
2020-03-24 08:20:58 -07:00
|
|
|
a,
|
2019-09-14 23:38:52 -07:00
|
|
|
DRAWFLAG_ADDITIVE
|
|
|
|
);
|
2019-01-28 18:40:14 -08:00
|
|
|
} else {
|
2019-09-14 23:38:52 -07:00
|
|
|
drawsubpic(
|
|
|
|
pos,
|
|
|
|
[170,45],
|
2020-05-31 03:54:04 -07:00
|
|
|
g_hud1_spr,
|
2019-09-14 23:38:52 -07:00
|
|
|
[0,45/256],
|
|
|
|
[170/256,45/256],
|
|
|
|
g_hud_color,
|
2020-03-24 08:20:58 -07:00
|
|
|
a,
|
2019-09-14 23:38:52 -07:00
|
|
|
DRAWFLAG_ADDITIVE
|
|
|
|
);
|
2019-01-28 18:40:14 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
weapon_t w_glock =
|
|
|
|
{
|
2020-05-01 17:36:37 -07:00
|
|
|
.name = "9mmhandgun",
|
|
|
|
.id = ITEM_GLOCK,
|
2020-04-22 03:47:01 -07:00
|
|
|
.slot = 1,
|
|
|
|
.slot_pos = 0,
|
|
|
|
.draw = w_glock_draw,
|
|
|
|
.holster = w_glock_holster,
|
|
|
|
.primary = w_glock_primary,
|
|
|
|
.secondary = w_glock_secondary,
|
|
|
|
.reload = w_glock_reload,
|
|
|
|
.release = w_glock_release,
|
|
|
|
.crosshair = w_glock_hud,
|
|
|
|
.precache = w_glock_precache,
|
|
|
|
.pickup = w_glock_pickup,
|
|
|
|
.updateammo = w_glock_updateammo,
|
|
|
|
.wmodel = w_glock_wmodel,
|
|
|
|
.pmodel = w_glock_pmodel,
|
|
|
|
.deathmsg = w_glock_deathmsg,
|
|
|
|
.aimanim = w_glock_aimanim,
|
|
|
|
.hudpic = w_glock_hudpic
|
2019-01-28 18:40:14 -08:00
|
|
|
};
|
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
/* pickups */
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifdef SERVER
|
2019-09-14 23:38:52 -07:00
|
|
|
void
|
|
|
|
weapon_9mmhandgun(void)
|
|
|
|
{
|
2019-01-28 18:40:14 -08:00
|
|
|
Weapons_InitItem(WEAPON_GLOCK);
|
|
|
|
}
|
2019-09-15 01:14:26 -07:00
|
|
|
|
2019-09-14 23:38:52 -07:00
|
|
|
void
|
|
|
|
weapon_glock(void)
|
|
|
|
{
|
2019-01-28 18:40:14 -08:00
|
|
|
Weapons_InitItem(WEAPON_GLOCK);
|
|
|
|
}
|
|
|
|
#endif
|