Garry's Mod Wiki

NPC:DropWeapon

NPC:DropWeapon( Weapon weapon = nil, Vector target = nil, Vector velocity = nil )

Description

Forces the NPC to drop the specified weapon.

Arguments

1 Weapon weapon = nil
Weapon to be dropped. If unset, will default to the currently equipped weapon.
2 Vector target = nil
If set, launches the weapon at given position. There is a limit to how far it is willing to throw the weapon. Overrides velocity argument.
3 Vector velocity = nil
If set and previous argument is unset, launches the weapon with given velocity. If the velocity is higher than 400, it will be clamped to 400.

Example

A console command that makes all NPCs on the map throw their weapons at the player who executed the console command

concommand.Add( "dropall",function( ply ) for id, ent in ipairs( ents.GetAll() ) do if ( ent:IsNPC() ) then -- Some NPCs on some maps delete their weapons when the weapon is dropped, we don't want that. ent:SetKeyValue( "spawnflags", bit.band( ent:GetSpawnFlags(), bit.bnot( SF_NPC_NO_WEAPON_DROP ) ) ) ent:DropWeapon( nil, ply:GetPos() ) end end end )

Page Links


Special Pages


Wikis

?

Render Time: 68ms

DB GetPage 38
Generate Html 6
SaveChanges (1) 10
Render Body 0
Render Sidebar 11