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 (gameover) 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);
82 if (IS_DEAD(this.owner))
84 // owner died; disappear
86 if (this.weaponchild) this.weaponchild.model = "";
89 if (this.w_weaponname != this.weaponname
90 || this.w_dmg != this.modelindex
91 || this.w_deadflag != this.deadflag)
93 // owner changed weapons; update appearance
94 this.w_weaponname = this.weaponname;
95 this.w_dmg = this.modelindex;
96 this.w_deadflag = this.deadflag;
98 CL_WeaponEntity_SetModel(this, this.weaponname, true);
101 this.alpha = -1; // TODO: don't render this entity at all
103 if (this.owner.alpha == default_player_alpha) this.m_alpha = default_weapon_alpha;
104 else if (this.owner.alpha != 0) this.m_alpha = this.owner.alpha;
105 else this.m_alpha = 1;
107 if (this.weaponchild)
109 this.weaponchild.alpha = this.alpha;
110 this.weaponchild.effects = this.effects;
114 void CL_ExteriorWeaponentity_Think(entity this)
116 this.nextthink = time;
117 .entity weaponentity = this.weaponentity_fld;
118 entity w_ent = this.owner.(weaponentity);
119 if (this.owner.exteriorweaponentity != this)
124 if (IS_DEAD(this.owner))
129 if (this.weaponname != w_ent.weaponname || this.dmg != w_ent.modelindex
130 || this.deadflag != w_ent.deadflag)
132 this.weaponname = w_ent.weaponname;
133 this.dmg = w_ent.modelindex;
134 this.deadflag = w_ent.deadflag;
135 if (w_ent.weaponname != "")
137 _setmodel(this, W_Model(strcat("v_", w_ent.weaponname, ".md3")));
138 setsize(this, '0 0 0', '0 0 0');
140 else this.model = "";
143 if ((tag_found = gettagindex(this.owner, "tag_weapon")))
145 this.tag_index = tag_found;
146 this.tag_entity = this.owner;
150 setattachment(this, this.owner, "bip01 r hand");
153 this.effects = this.owner.effects;
154 this.effects |= EF_LOWPRECISION;
155 this.effects = this.effects & EFMASK_CHEAP; // eat performance
156 if (this.owner.alpha == default_player_alpha) this.alpha = default_weapon_alpha;
157 else if (this.owner.alpha != 0) this.alpha = this.owner.alpha;
160 Weapon wep = this.owner.(weaponentity).m_weapon;
161 if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors, this.owner.(weaponentity));
162 this.colormap = this.owner.colormap;
164 CSQCMODEL_AUTOUPDATE(this);
167 // spawning weaponentity for client
168 void CL_SpawnWeaponentity(entity actor, .entity weaponentity)
170 entity view = actor.(weaponentity) = new(weaponentity);
171 view.solid = SOLID_NOT;
173 setmodel(view, MDL_Null); // precision set when changed
174 setorigin(view, '0 0 0');
175 view.weaponentity_fld = weaponentity;
176 setthink(view, CL_Weaponentity_Think);
177 view.nextthink = time;
178 view.viewmodelforclient = actor;
179 setcefc(view, CL_Weaponentity_CustomizeEntityForClient);
183 if (weaponentity == weaponentities[0]) // only one exterior model, thank you very much
185 entity exterior = actor.exteriorweaponentity = new(exteriorweaponentity);
186 exterior.solid = SOLID_NOT;
187 exterior.owner = actor;
188 exterior.weaponentity_fld = weaponentity;
189 setorigin(exterior, '0 0 0');
190 setthink(exterior, CL_ExteriorWeaponentity_Think);
191 exterior.nextthink = time;
193 CSQCMODEL_AUTOINIT(exterior);
198 void w_clear(Weapon thiswep, entity actor, .entity weaponentity, int fire)
200 actor.(weaponentity).m_weapon = WEP_Null;
201 actor.(weaponentity).m_switchingweapon = WEP_Null;
202 entity this = actor.(weaponentity);
205 this.state = WS_CLEAR;
210 void w_ready(Weapon thiswep, entity actor, .entity weaponentity, int fire)
212 entity this = actor.(weaponentity);
213 if (this) this.state = WS_READY;
214 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, 1000000, w_ready);
219 bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary, .entity weaponentity)
221 if ((actor.items & IT_UNLIMITED_WEAPON_AMMO)) return true;
223 if (secondary) ammo = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
224 else ammo = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
225 if (ammo) return true;
226 // always keep the Mine Layer if we placed mines, so that we can detonate them
227 if (thiswep == WEP_MINE_LAYER)
229 IL_EACH(g_mines, it.owner == actor && it.weaponentity_fld == weaponentity,
235 if (thiswep == WEP_SHOTGUN)
236 if (!secondary && WEP_CVAR(shotgun, secondary) == 1) return false; // no clicking, just allow
238 if (thiswep == actor.(weaponentity).m_switchweapon && time - actor.prevdryfire > 1) // only play once BEFORE starting to switch weapons
240 sound(actor, CH_WEAPON_A, SND_DRYFIRE, VOL_BASE, ATTEN_NORM);
241 actor.prevdryfire = time;
244 // check if the other firing mode has enough ammo
245 bool ammo_other = false;
246 if (secondary) ammo_other = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
247 else ammo_other = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
250 if (time - actor.prevwarntime > 1)
256 ITEM_WEAPON_PRIMORSEC,
262 actor.prevwarntime = time;
264 else // this weapon is totally unable to fire, switch to another one
266 W_SwitchToOtherWeapon(actor, weaponentity);
273 bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponentity, bool secondary, float attacktime)
275 if (actor.weaponentity == NULL) return true;
276 if (!weapon_prepareattack_checkammo(thiswep, actor, secondary, weaponentity)) return false;
278 // if sv_ready_restart_after_countdown is set, don't allow the player to shoot
279 // if all players readied up and the countdown is running
280 if (time < game_starttime || time < actor.race_penalty) return false;
282 if (timeout_status == TIMEOUT_ACTIVE) // don't allow the player to shoot while game is paused
285 // do not even think about shooting if switching
286 if (actor.(weaponentity).m_switchweapon != actor.(weaponentity).m_weapon) return false;
290 int slot = weaponslot(weaponentity);
291 // don't fire if previous attack is not finished
292 if (ATTACK_FINISHED(actor, slot) > time + actor.(weaponentity).weapon_frametime * 0.5) return false;
293 entity this = actor.(weaponentity);
294 // don't fire while changing weapon
295 if (this.state != WS_READY) return false;
300 void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary, float attacktime)
302 entity this = actor.(weaponentity);
303 if (this == NULL) return;
304 this.state = WS_INUSE;
306 actor.spawnshieldtime = min(actor.spawnshieldtime, time); // kill spawn shield when you fire
308 // if the weapon hasn't been firing continuously, reset the timer
311 int slot = weaponslot(weaponentity);
312 if (ATTACK_FINISHED(actor, slot) < time - this.weapon_frametime * 1.5)
314 ATTACK_FINISHED(actor, slot) = time;
315 // dprint("resetting attack finished to ", ftos(time), "\n");
317 ATTACK_FINISHED(actor, slot) = ATTACK_FINISHED(actor, slot) + attacktime * W_WeaponRateFactor(actor);
319 this.bulletcounter += 1;
320 // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, slot)), "\n");
323 bool weapon_prepareattack(Weapon thiswep, entity actor, .entity weaponentity, bool secondary, float attacktime)
325 if (weapon_prepareattack_check(thiswep, actor, weaponentity, secondary, attacktime))
327 weapon_prepareattack_do(actor, weaponentity, secondary, attacktime);
333 void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim);
336 * @param t defer thinking until time + t
337 * @param func next think function
339 void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,
340 .entity weaponentity, int fire) func)
342 entity this = actor.(weaponentity);
343 if (this == NULL) return;
345 if (fr == WFRAME_DONTCHANGE)
352 restartanim = fr != WFRAME_IDLE;
355 vector of = v_forward;
361 if (fr == WFRAME_IDLE) a = this.anim_idle;
362 else if (fr == WFRAME_FIRE1) a = this.anim_fire1;
363 else if (fr == WFRAME_FIRE2) a = this.anim_fire2;
364 else // if (fr == WFRAME_RELOAD)
365 a = this.anim_reload;
366 a.z *= g_weaponratefactor;
372 if (this.weapon_think == w_ready && func != w_ready && this.state == WS_RAISE) backtrace(
373 "Tried to override initial weapon think function - should this really happen?");
375 t *= W_WeaponRateFactor(actor);
377 // VorteX: haste can be added here
378 if (this.weapon_think == w_ready)
380 this.weapon_nextthink = time;
381 // dprint("started firing at ", ftos(time), "\n");
383 if (this.weapon_nextthink < time - this.weapon_frametime * 1.5
384 || this.weapon_nextthink > time + this.weapon_frametime * 1.5)
386 this.weapon_nextthink = time;
387 // dprint("reset weapon animation timer at ", ftos(time), "\n");
389 this.weapon_nextthink += t;
390 this.weapon_think = func;
391 // dprint("next ", ftos(this.weapon_nextthink), "\n");
395 FOREACH_CLIENT(true, LAMBDA(
396 if(it == actor || (IS_SPEC(it) && it.enemy == actor))
397 wframe_send(it, this, a, restartanim);
401 if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
403 bool primary_melee = boolean(fr == WFRAME_FIRE1 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_PRI));
404 bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_SEC));
405 int act = (primary_melee || secondary_melee)
409 animdecide_setaction(actor, act, restartanim);
411 else if (actor.anim_upper_action == ANIMACTION_SHOOT || actor.anim_upper_action == ANIMACTION_MELEE)
413 actor.anim_upper_action = 0;
417 bool forbidWeaponUse(entity player)
419 if (time < game_starttime && !autocvar_sv_ready_restart_after_countdown) return true;
420 if (round_handler_IsActive() && !round_handler_IsRoundStarted()) return true;
421 if (player.player_blocked) return true;
422 if (gameover) 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
441 if (forbidWeaponUse(actor))
443 if (this.state != WS_CLEAR)
445 Weapon wpn = this.m_weapon;
446 w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
451 if (this.m_switchweapon == WEP_Null)
453 this.m_weapon = WEP_Null;
454 this.m_switchingweapon = WEP_Null;
455 this.state = WS_CLEAR;
456 this.weaponname = "";
457 // actor.items &= ~IT_AMMO;
461 makevectors(actor.v_angle);
462 vector fo = v_forward; // save them in case the weapon think functions change it
467 if (this.m_weapon != this.m_switchweapon)
472 LOG_WARNF("unhandled weaponentity (%i) state for player (%i): %d", this, actor, this.state);
480 Weapon newwep = this.m_switchweapon;
481 this.m_switchingweapon = newwep;
483 // the two weapon entities will notice this has changed and update their models
484 this.m_weapon = newwep;
485 this.weaponname = newwep.mdl;
486 this.bulletcounter = 0;
487 newwep.wr_setup(newwep, actor, weaponentity);
488 this.state = WS_RAISE;
490 // set our clip load to the load of the weapon we switched to, if it's reloadable
491 if ((newwep.spawnflags & WEP_FLAG_RELOADABLE) && newwep.reloading_ammo) // prevent accessing undefined cvars
493 this.clip_load = this.(weapon_load[this.m_switchweapon.m_id]);
494 this.clip_size = newwep.reloading_ammo;
498 this.clip_load = this.clip_size = 0;
501 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
506 // in dropping phase we can switch at any time
507 this.m_switchingweapon = this.m_switchweapon;
513 this.m_switchingweapon = this.m_switchweapon;
514 entity oldwep = this.m_weapon;
516 // set up weapon switch think in the future, and start drop anim
517 if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + this.weapon_frametime * 0.5)
519 sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
520 this.state = WS_DROP;
521 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
528 // LordHavoc: network timing test code
529 // if (actor.button0)
530 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, slot)), " >= ", ftos(this.weapon_nextthink), "\n");
532 Weapon w = this.m_weapon;
534 // call the think code which may fire the weapon
535 // and do so multiple times to resolve framerate dependency issues if the
536 // server framerate is very low and the weapon fire rate very high
537 for (int c = 0; c < W_TICSPERFRAME; ++c)
539 if (w != WEP_Null && !(actor.weapons & WepSet_FromWeapon(w)))
541 if (this.m_weapon == this.m_switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
549 bool block_weapon = false;
551 bool key_pressed = PHYS_INPUT_BUTTON_HOOK(actor) && !actor.vehicle;
552 Weapon off = actor.offhand;
553 if (off && !(actor.weapons & WEPSET(HOOK)))
555 if (off.offhand_think) off.offhand_think(off, actor, key_pressed);
559 if (key_pressed && this.m_switchweapon != WEP_HOOK && !actor.hook_switchweapon)
560 W_SwitchWeapon(actor, WEP_HOOK, weaponentity);
561 actor.hook_switchweapon = key_pressed;
563 block_weapon = (this.m_weapon == h && (PHYS_INPUT_BUTTON_ATCK(actor) || key_pressed));
564 h.wr_think(h, actor, weaponentity, block_weapon ? 1 : 0);
574 Weapon e = this.m_weapon;
578 e.wr_think(e, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
582 e.wr_gonethink(e, actor, weaponentity);
586 if (time + this.weapon_frametime * 0.5 >= this.weapon_nextthink)
588 if (this.weapon_think)
593 Weapon wpn = this.m_weapon;
594 this.weapon_think(wpn, actor, weaponentity,
595 PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
599 bprint("\{1}^1ERROR: undefined weapon think function for ", actor.netname, "\n");
605 void W_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector offset)
608 flash.angles_z = random() * 360;
610 entity view = actor.(weaponentity);
611 entity exterior = actor.exteriorweaponentity;
613 if (gettagindex(view, "shot")) setattachment(flash, view, "shot");
614 else setattachment(flash, view, "tag_shot");
615 setorigin(flash, offset);
617 entity xflash = spawn();
618 copyentity(flash, xflash);
620 flash.viewmodelforclient = actor;
622 if (view.oldorigin.x > 0)
624 setattachment(xflash, exterior, "");
625 setorigin(xflash, view.oldorigin + offset);
629 if (gettagindex(exterior, "shot")) setattachment(xflash, exterior, "shot");
630 else setattachment(xflash, exterior, "tag_shot");
631 setorigin(xflash, offset);
635 void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponentity)
637 if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity))) return;
638 if ((actor.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo) return;
640 entity w_ent = actor.(weaponentity);
642 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
643 if (wep.reloading_ammo)
645 w_ent.clip_load -= ammo_use;
646 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
648 else if (wep.ammo_field != ammo_none)
650 actor.(wep.ammo_field) -= ammo_use;
651 if (actor.(wep.ammo_field) < 0)
654 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
655 "Please notify Samual immediately with a copy of this backtrace!\n",
658 GetAmmoPicture(wep.ammo_field),
660 actor.(wep.ammo_field)
666 // weapon reloading code
668 .float reload_ammo_amount, reload_ammo_min, reload_time;
669 .float reload_complain;
670 .string reload_sound;
672 void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int fire)
674 // finish the reloading process, and do the ammo transfer
676 entity w_ent = actor.(weaponentity);
677 Weapon wpn = w_ent.m_weapon;
679 w_ent.clip_load = w_ent.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
681 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
682 if (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_field == ammo_none)
684 w_ent.clip_load = w_ent.reload_ammo_amount;
688 // make sure we don't add more ammo than we have
689 float load = min(w_ent.reload_ammo_amount - w_ent.clip_load, actor.(wpn.ammo_field));
690 w_ent.clip_load += load;
691 actor.(wpn.ammo_field) -= load;
693 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
695 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
696 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
697 // so your weapon is disabled for a few seconds without reason
699 // ATTACK_FINISHED(actor, slot) -= w_ent.reload_time - 1;
701 w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
704 void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sent_sound)
706 TC(Sound, sent_sound);
707 // set global values to work with
708 entity this = actor.(weaponentity);
709 Weapon e = this.m_weapon;
711 if (MUTATOR_CALLHOOK(W_Reload, actor)) return;
713 this.reload_ammo_min = sent_ammo_min;
714 this.reload_ammo_amount = e.reloading_ammo;
715 this.reload_time = e.reloading_time;
716 if (actor.reload_sound) strunzone(actor.reload_sound);
717 actor.reload_sound = strzone(Sound_fixpath(sent_sound));
719 // don't reload weapons that don't have the RELOADABLE flag
720 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
723 "Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
727 // return if reloading is disabled for this weapon
728 if (!this.reload_ammo_amount) return;
730 // our weapon is fully loaded, no need to reload
731 if (this.clip_load >= this.reload_ammo_amount) return;
733 // no ammo, so nothing to load
734 if (e.ammo_field != ammo_none)
736 if (!actor.(e.ammo_field) && this.reload_ammo_min)
738 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
740 if (IS_REAL_CLIENT(actor) && actor.reload_complain < time)
742 play2(actor, SND(UNAVAILABLE));
743 sprint(actor, strcat("You don't have enough ammo to reload the ^2", this.m_weapon.m_name, "\n"));
744 actor.reload_complain = time + 1;
746 // switch away if the amount of ammo is not enough to keep using this weapon
747 if (!(e.wr_checkammo1(e, actor, weaponentity) + e.wr_checkammo2(e, actor, weaponentity)))
749 this.clip_load = -1; // reload later
750 W_SwitchToOtherWeapon(actor, weaponentity);
759 if (this.wframe == WFRAME_RELOAD) return;
761 // allow switching away while reloading, but this will cause a new reload!
762 this.state = WS_READY;
765 // now begin the reloading process
767 _sound(actor, CH_WEAPON_SINGLE, actor.reload_sound, VOL_BASE, ATTEN_NORM);
769 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
770 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
771 // so your weapon is disabled for a few seconds without reason
773 // ATTACK_FINISHED(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + this.reload_time + 1;
775 weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady);
777 if (this.clip_load < 0) this.clip_load = 0;
778 this.old_clip_load = this.clip_load;
779 this.clip_load = this.(weapon_load[this.m_weapon.m_id]) = -1;
782 void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity)
784 Weapon w = Weapons_from(weapon_type);
785 weapon_dropevent_item = weapon_item;
786 w.event(w, player, weaponentity);