1 #include "weaponsystem.qh"
3 #include "selection.qh"
5 #include "../command/common.qh"
6 #include "../mutators/_mod.qh"
7 #include "../round_handler.qh"
8 #include <common/t_items.qh>
9 #include <common/animdecide.qh>
10 #include <common/constants.qh>
11 #include <common/net_linked.qh>
12 #include <common/monsters/_mod.qh>
13 #include <common/notifications/all.qh>
14 #include <common/util.qh>
15 #include <common/weapons/_all.qh>
16 #include <common/state.qh>
17 #include <lib/csqcmodel/sv_model.qh>
18 #include <common/wepent.qh>
22 .float weapon_frametime;
24 float W_WeaponRateFactor(entity this)
27 if(g_weaponratefactor > 0)
28 t = 1.0 / g_weaponratefactor;
30 MUTATOR_CALLHOOK(WeaponRateFactor, t, this);
36 float W_WeaponSpeedFactor(entity this)
38 float t = 1.0 * g_weaponspeedfactor;
40 MUTATOR_CALLHOOK(WeaponSpeedFactor, t, this);
47 bool CL_Weaponentity_CustomizeEntityForClient(entity this, entity client)
49 this.viewmodelforclient = this.owner;
50 if (IS_SPEC(client) && client.enemy == this.owner) this.viewmodelforclient = client;
54 vector CL_Weapon_GetShotOrg(int wpn)
56 entity wi = Weapons_from(wpn);
58 CL_WeaponEntity_SetModel(e, wi.mdl, false);
59 vector ret = e.movedir;
60 CL_WeaponEntity_SetModel(e, "", false);
70 void CL_Weaponentity_Think(entity this)
72 this.nextthink = time;
73 if (game_stopped) this.frame = this.anim_idle.x;
74 .entity weaponentity = this.weaponentity_fld;
75 if (this.owner.(weaponentity) != this)
77 // owner has new gun; remove old one
78 if (this.weaponchild) delete(this.weaponchild);
79 if (this.hook) delete(this.hook);
83 if (IS_DEAD(this.owner))
85 // owner died; disappear
87 if (this.weaponchild) this.weaponchild.model = "";
90 if (this.w_weaponname != this.weaponname
91 || this.w_dmg != this.modelindex
92 || this.w_deadflag != this.deadflag)
94 // owner changed weapons; update appearance
95 this.w_weaponname = this.weaponname;
96 this.w_dmg = this.modelindex;
97 this.w_deadflag = this.deadflag;
99 CL_WeaponEntity_SetModel(this, this.weaponname, true);
102 this.alpha = -1; // TODO: don't render this entity at all
104 if (this.owner.alpha == default_player_alpha) this.m_alpha = default_weapon_alpha;
105 else if (this.owner.alpha != 0) this.m_alpha = this.owner.alpha;
106 else this.m_alpha = 1;
108 if (this.weaponchild)
110 this.weaponchild.alpha = this.alpha;
111 this.weaponchild.effects = this.effects;
115 void CL_ExteriorWeaponentity_Think(entity this)
117 this.nextthink = time;
118 .entity weaponentity = this.weaponentity_fld;
119 entity w_ent = this.owner.(weaponentity);
120 if (this.owner.exteriorweaponentity != this)
125 if (IS_DEAD(this.owner))
130 if (this.weaponname != w_ent.weaponname || this.dmg != w_ent.modelindex
131 || this.deadflag != w_ent.deadflag)
133 this.weaponname = w_ent.weaponname;
134 this.dmg = w_ent.modelindex;
135 this.deadflag = w_ent.deadflag;
136 if (w_ent.weaponname != "")
138 _setmodel(this, W_Model(strcat("v_", w_ent.weaponname, ".md3")));
139 setsize(this, '0 0 0', '0 0 0');
141 else this.model = "";
144 if ((tag_found = gettagindex(this.owner, "tag_weapon")))
146 this.tag_index = tag_found;
147 this.tag_entity = this.owner;
151 setattachment(this, this.owner, "bip01 r hand");
154 this.effects = this.owner.effects;
155 this.effects |= EF_LOWPRECISION;
156 this.effects = this.effects & EFMASK_CHEAP; // eat performance
157 if (this.owner.alpha == default_player_alpha) this.alpha = default_weapon_alpha;
158 else if (this.owner.alpha != 0) this.alpha = this.owner.alpha;
161 Weapon wep = this.owner.(weaponentity).m_weapon;
162 if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors, this.owner.(weaponentity));
163 this.colormap = this.owner.colormap;
165 CSQCMODEL_AUTOUPDATE(this);
168 // spawning weaponentity for client
169 void CL_SpawnWeaponentity(entity actor, .entity weaponentity)
171 entity view = actor.(weaponentity) = new(weaponentity);
172 view.solid = SOLID_NOT;
174 setmodel(view, MDL_Null); // precision set when changed
175 setorigin(view, '0 0 0');
176 view.weaponentity_fld = weaponentity;
177 setthink(view, CL_Weaponentity_Think);
178 view.nextthink = time;
179 view.viewmodelforclient = actor;
180 setcefc(view, CL_Weaponentity_CustomizeEntityForClient);
184 if (weaponentity == weaponentities[0]) // only one exterior model, thank you very much
186 entity exterior = actor.exteriorweaponentity = new(exteriorweaponentity);
187 exterior.solid = SOLID_NOT;
188 exterior.owner = actor;
189 exterior.weaponentity_fld = weaponentity;
190 setorigin(exterior, '0 0 0');
191 setthink(exterior, CL_ExteriorWeaponentity_Think);
192 exterior.nextthink = time;
194 CSQCMODEL_AUTOINIT(exterior);
199 void w_clear(Weapon thiswep, entity actor, .entity weaponentity, int fire)
201 actor.(weaponentity).m_weapon = WEP_Null;
202 actor.(weaponentity).m_switchingweapon = WEP_Null;
203 entity this = actor.(weaponentity);
206 this.state = WS_CLEAR;
211 void w_ready(Weapon thiswep, entity actor, .entity weaponentity, int fire)
213 entity this = actor.(weaponentity);
214 if (this) this.state = WS_READY;
215 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, 1000000, w_ready);
220 bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary, .entity weaponentity)
222 if ((actor.items & IT_UNLIMITED_WEAPON_AMMO)) return true;
224 if (secondary) ammo = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
225 else ammo = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
226 if (ammo) return true;
227 // always keep the Mine Layer if we placed mines, so that we can detonate them
228 if (thiswep == WEP_MINE_LAYER)
230 IL_EACH(g_mines, it.owner == actor && it.weaponentity_fld == weaponentity,
236 if (thiswep == WEP_SHOTGUN)
237 if (!secondary && WEP_CVAR(shotgun, secondary) == 1) return false; // no clicking, just allow
239 if (thiswep == actor.(weaponentity).m_switchweapon && time - actor.prevdryfire > 1) // only play once BEFORE starting to switch weapons
241 sound(actor, CH_WEAPON_A, SND_DRYFIRE, VOL_BASE, ATTEN_NORM);
242 actor.prevdryfire = time;
245 // check if the other firing mode has enough ammo
246 bool ammo_other = false;
247 if (secondary) ammo_other = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
248 else ammo_other = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
251 if (time - actor.prevwarntime > 1)
257 ITEM_WEAPON_PRIMORSEC,
263 actor.prevwarntime = time;
265 else // this weapon is totally unable to fire, switch to another one
267 W_SwitchToOtherWeapon(actor, weaponentity);
274 bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponentity, bool secondary, float attacktime)
276 if (actor.weaponentity == NULL) return true;
277 if (!weapon_prepareattack_checkammo(thiswep, actor, secondary, weaponentity)) return false;
279 // if sv_ready_restart_after_countdown is set, don't allow the player to shoot
280 // if all players readied up and the countdown is running
281 if (time < game_starttime || time < actor.race_penalty) return false;
283 if (timeout_status == TIMEOUT_ACTIVE) // don't allow the player to shoot while game is paused
286 // do not even think about shooting if switching
287 if (actor.(weaponentity).m_switchweapon != actor.(weaponentity).m_weapon) return false;
291 int slot = weaponslot(weaponentity);
292 // don't fire if previous attack is not finished
293 if (ATTACK_FINISHED(actor, slot) > time + actor.(weaponentity).weapon_frametime * 0.5) return false;
294 entity this = actor.(weaponentity);
295 // don't fire while changing weapon
296 if (this.state != WS_READY) return false;
301 void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary, float attacktime)
303 entity this = actor.(weaponentity);
304 if (this == NULL) return;
305 this.state = WS_INUSE;
307 actor.spawnshieldtime = min(actor.spawnshieldtime, time); // kill spawn shield when you fire
309 // if the weapon hasn't been firing continuously, reset the timer
312 int slot = weaponslot(weaponentity);
313 if (ATTACK_FINISHED(actor, slot) < time - this.weapon_frametime * 1.5)
315 ATTACK_FINISHED(actor, slot) = time;
316 // dprint("resetting attack finished to ", ftos(time), "\n");
318 ATTACK_FINISHED(actor, slot) = ATTACK_FINISHED(actor, slot) + attacktime * W_WeaponRateFactor(actor);
320 this.bulletcounter += 1;
321 // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, slot)), "\n");
324 bool weapon_prepareattack(Weapon thiswep, entity actor, .entity weaponentity, bool secondary, float attacktime)
326 if (weapon_prepareattack_check(thiswep, actor, weaponentity, secondary, attacktime))
328 weapon_prepareattack_do(actor, weaponentity, secondary, attacktime);
334 void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim);
337 * @param t defer thinking until time + t
338 * @param func next think function
340 void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,
341 .entity weaponentity, int fire) func)
343 entity this = actor.(weaponentity);
344 if (this == NULL) return;
346 if (fr == WFRAME_DONTCHANGE)
353 restartanim = fr != WFRAME_IDLE;
356 vector of = v_forward;
362 if (fr == WFRAME_IDLE) a = this.anim_idle;
363 else if (fr == WFRAME_FIRE1) a = this.anim_fire1;
364 else if (fr == WFRAME_FIRE2) a = this.anim_fire2;
365 else // if (fr == WFRAME_RELOAD)
366 a = this.anim_reload;
367 a.z *= g_weaponratefactor;
373 if (this.weapon_think == w_ready && func != w_ready && this.state == WS_RAISE) backtrace(
374 "Tried to override initial weapon think function - should this really happen?");
376 t *= W_WeaponRateFactor(actor);
378 // VorteX: haste can be added here
379 if (this.weapon_think == w_ready)
381 this.weapon_nextthink = time;
382 // dprint("started firing at ", ftos(time), "\n");
384 if (this.weapon_nextthink < time - this.weapon_frametime * 1.5
385 || this.weapon_nextthink > time + this.weapon_frametime * 1.5)
387 this.weapon_nextthink = time;
388 // dprint("reset weapon animation timer at ", ftos(time), "\n");
390 this.weapon_nextthink += t;
391 this.weapon_think = func;
392 // dprint("next ", ftos(this.weapon_nextthink), "\n");
396 FOREACH_CLIENT(true, LAMBDA(
397 if(it == actor || (IS_SPEC(it) && it.enemy == actor))
398 wframe_send(it, this, a, restartanim);
402 if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
404 bool primary_melee = boolean(fr == WFRAME_FIRE1 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_PRI));
405 bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_SEC));
406 int act = (primary_melee || secondary_melee)
410 animdecide_setaction(actor, act, restartanim);
412 else if (actor.anim_upper_action == ANIMACTION_SHOOT || actor.anim_upper_action == ANIMACTION_MELEE)
414 actor.anim_upper_action = 0;
418 bool forbidWeaponUse(entity player)
420 if (time < game_starttime && !autocvar_sv_ready_restart_after_countdown) return true;
421 if (player.player_blocked) return true;
422 if (game_stopped) return true;
423 if (STAT(FROZEN, player)) return true;
424 if (player.weapon_blocked) return true;
425 if (MUTATOR_CALLHOOK(ForbidWeaponUse, player)) return true;
429 .bool hook_switchweapon;
431 void W_WeaponFrame(Player actor, .entity weaponentity)
434 TC(PlayerState, PS(actor));
435 entity this = actor.(weaponentity);
436 if (frametime) this.weapon_frametime = frametime;
438 if (!this || actor.health < 1) return; // Dead player can't use weapons and injure impulse commands
440 int button_atck = PHYS_INPUT_BUTTON_ATCK(actor);
441 int button_atck2 = PHYS_INPUT_BUTTON_ATCK2(actor);
443 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
444 button_atck = button_atck2 = 0; // forbid primary and secondary fire, switching is allowed
446 if (forbidWeaponUse(actor))
448 if (this.state != WS_CLEAR)
450 Weapon wpn = this.m_weapon;
451 w_ready(wpn, actor, weaponentity, button_atck | (button_atck2 << 1));
456 if (this.m_switchweapon == WEP_Null)
458 this.m_weapon = WEP_Null;
459 this.m_switchingweapon = WEP_Null;
460 this.state = WS_CLEAR;
461 this.weaponname = "";
465 makevectors(actor.v_angle);
466 vector fo = v_forward; // save them in case the weapon think functions change it
471 if (this.m_weapon != this.m_switchweapon)
476 LOG_WARNF("unhandled weaponentity (%i) state for player (%i): %d", this, actor, this.state);
484 Weapon newwep = this.m_switchweapon;
485 this.m_switchingweapon = newwep;
487 // the two weapon entities will notice this has changed and update their models
488 this.m_weapon = newwep;
489 this.weaponname = newwep.mdl;
490 this.bulletcounter = 0;
491 newwep.wr_setup(newwep, actor, weaponentity);
492 this.state = WS_RAISE;
494 // set our clip load to the load of the weapon we switched to, if it's reloadable
495 if ((newwep.spawnflags & WEP_FLAG_RELOADABLE) && newwep.reloading_ammo) // prevent accessing undefined cvars
497 this.clip_load = this.(weapon_load[this.m_switchweapon.m_id]);
498 this.clip_size = newwep.reloading_ammo;
502 this.clip_load = this.clip_size = 0;
505 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
510 // in dropping phase we can switch at any time
511 this.m_switchingweapon = this.m_switchweapon;
517 this.m_switchingweapon = this.m_switchweapon;
518 entity oldwep = this.m_weapon;
520 // set up weapon switch think in the future, and start drop anim
521 if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + this.weapon_frametime * 0.5)
523 sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
524 this.state = WS_DROP;
525 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
532 // LordHavoc: network timing test code
533 // if (actor.button0)
534 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, slot)), " >= ", ftos(this.weapon_nextthink), "\n");
536 Weapon w = this.m_weapon;
538 // call the think code which may fire the weapon
539 // and do so multiple times to resolve framerate dependency issues if the
540 // server framerate is very low and the weapon fire rate very high
541 for (int c = 0; c < W_TICSPERFRAME; ++c)
543 if (w != WEP_Null && !(actor.weapons & WepSet_FromWeapon(w)))
545 if (this.m_weapon == this.m_switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
553 bool block_weapon = false;
555 bool key_pressed = PHYS_INPUT_BUTTON_HOOK(actor) && !actor.vehicle;
556 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
559 Weapon off = actor.offhand;
560 if (off && !(actor.weapons & WEPSET(HOOK)))
562 if (off.offhand_think) off.offhand_think(off, actor, key_pressed);
566 if (key_pressed && this.m_switchweapon != WEP_HOOK && !actor.hook_switchweapon)
567 W_SwitchWeapon(actor, WEP_HOOK, weaponentity);
568 actor.hook_switchweapon = key_pressed;
570 block_weapon = (this.m_weapon == h && (button_atck || key_pressed));
571 h.wr_think(h, actor, weaponentity, block_weapon ? 1 : 0);
581 Weapon e = this.m_weapon;
585 e.wr_think(e, actor, weaponentity, button_atck | (button_atck2 << 1));
589 e.wr_gonethink(e, actor, weaponentity);
593 if (time + this.weapon_frametime * 0.5 >= this.weapon_nextthink)
595 if (this.weapon_think)
600 Weapon wpn = this.m_weapon;
601 this.weapon_think(wpn, actor, weaponentity,
602 button_atck | (button_atck2 << 1));
606 bprint("\{1}^1ERROR: undefined weapon think function for ", actor.netname, "\n");
612 void W_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector offset)
615 flash.angles_z = random() * 360;
617 entity view = actor.(weaponentity);
618 entity exterior = actor.exteriorweaponentity;
620 if (gettagindex(view, "shot")) setattachment(flash, view, "shot");
621 else setattachment(flash, view, "tag_shot");
622 setorigin(flash, offset);
624 entity xflash = spawn();
625 copyentity(flash, xflash);
627 flash.viewmodelforclient = actor;
629 if (view.oldorigin.x > 0)
631 setattachment(xflash, exterior, "");
632 setorigin(xflash, view.oldorigin + offset);
636 if (gettagindex(exterior, "shot")) setattachment(xflash, exterior, "shot");
637 else setattachment(xflash, exterior, "tag_shot");
638 setorigin(xflash, offset);
642 void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponentity)
644 if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity))) return;
645 if ((actor.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo) return;
647 entity w_ent = actor.(weaponentity);
649 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
650 if (wep.reloading_ammo)
652 w_ent.clip_load -= ammo_use;
653 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
655 else if (wep.ammo_field != ammo_none)
657 actor.(wep.ammo_field) -= ammo_use;
658 if (actor.(wep.ammo_field) < 0)
661 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
662 "Please notify Samual immediately with a copy of this backtrace!\n",
665 GetAmmoPicture(wep.ammo_field),
667 actor.(wep.ammo_field)
673 // weapon reloading code
675 .float reload_ammo_amount, reload_ammo_min, reload_time;
676 .float reload_complain;
677 .string reload_sound;
679 void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int fire)
681 // finish the reloading process, and do the ammo transfer
683 entity w_ent = actor.(weaponentity);
684 Weapon wpn = w_ent.m_weapon;
686 w_ent.clip_load = w_ent.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
688 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
689 if (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_field == ammo_none)
691 w_ent.clip_load = w_ent.reload_ammo_amount;
695 // make sure we don't add more ammo than we have
696 float load = min(w_ent.reload_ammo_amount - w_ent.clip_load, actor.(wpn.ammo_field));
697 w_ent.clip_load += load;
698 actor.(wpn.ammo_field) -= load;
700 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
702 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
703 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
704 // so your weapon is disabled for a few seconds without reason
706 // ATTACK_FINISHED(actor, slot) -= w_ent.reload_time - 1;
708 w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
711 void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sent_sound)
713 TC(Sound, sent_sound);
714 // set global values to work with
715 entity this = actor.(weaponentity);
716 Weapon e = this.m_weapon;
718 if (MUTATOR_CALLHOOK(W_Reload, actor)) return;
720 this.reload_ammo_min = sent_ammo_min;
721 this.reload_ammo_amount = e.reloading_ammo;
722 this.reload_time = e.reloading_time;
723 if (actor.reload_sound) strunzone(actor.reload_sound);
724 actor.reload_sound = strzone(Sound_fixpath(sent_sound));
726 // don't reload weapons that don't have the RELOADABLE flag
727 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
730 "Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
734 // return if reloading is disabled for this weapon
735 if (!this.reload_ammo_amount) return;
737 // our weapon is fully loaded, no need to reload
738 if (this.clip_load >= this.reload_ammo_amount) return;
740 // no ammo, so nothing to load
741 if (e.ammo_field != ammo_none)
743 if (!actor.(e.ammo_field) && this.reload_ammo_min)
745 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
747 if (IS_REAL_CLIENT(actor) && actor.reload_complain < time)
749 play2(actor, SND(UNAVAILABLE));
750 sprint(actor, strcat("You don't have enough ammo to reload the ^2", this.m_weapon.m_name, "\n"));
751 actor.reload_complain = time + 1;
753 // switch away if the amount of ammo is not enough to keep using this weapon
754 if (!(e.wr_checkammo1(e, actor, weaponentity) + e.wr_checkammo2(e, actor, weaponentity)))
756 this.clip_load = -1; // reload later
757 W_SwitchToOtherWeapon(actor, weaponentity);
766 if (this.wframe == WFRAME_RELOAD) return;
768 // allow switching away while reloading, but this will cause a new reload!
769 this.state = WS_READY;
772 // now begin the reloading process
774 _sound(actor, CH_WEAPON_SINGLE, actor.reload_sound, VOL_BASE, ATTEN_NORM);
776 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
777 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
778 // so your weapon is disabled for a few seconds without reason
780 // ATTACK_FINISHED(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + this.reload_time + 1;
782 weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady);
784 if (this.clip_load < 0) this.clip_load = 0;
785 this.old_clip_load = this.clip_load;
786 this.clip_load = this.(weapon_load[this.m_weapon.m_id]) = -1;
789 void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity)
791 Weapon w = Weapons_from(weapon_type);
792 weapon_dropevent_item = weapon_item;
793 w.event(w, player, weaponentity);