Description
The "simple weapon system" consists of hand-held guns for non-NPC avatars, together with a server. The guns can be used to shoot both NPCs and non-NPCs, which are then animated in a "death position" for a period of time.
Construction
The weapon may be any handgun. Inside this is a projectile prim, the "simple gun" script, and an option gunshot sound file.
The projectile prim contains the "simple projectile" script, a "death cry" sound and a blood splatter texture.
The server object should contain the "simple gun server" script, an animation and a config file called "Simple gun server config". This may easily be combined with other assets in a single prim for convenience.
Operation
The gun can be fired at any NPC or non-NPC avatar. On impact, the avatar will fall to the ground (according to the animation in the server) and a blood splatter will appear (from the texture in the projectile). The avatar will remain locked in that animation for a period determined by the server configuration.
Configuration
The server config file is the usual INI-style file with "//" comments. The following elements are allowed:
PlayerDeathTime
NpcDeathTime
DeathAnimation
The time (in seconds) that a shot non-NPC avatar will be animated
The time (in seconds) that a shot NPC avatar will be animated
The name of the animation file in the server inventory
How it works
The server listens permanently on channel -93304424900.
When the owner enters mouselook and left-clicks, the gun rezzes the projectile with a velocity based on the camera rotation. While the avatar is in mouselook, the built-in animation "hold_r_handgun" is triggered; this aligns the avatar with the mouselook direction.
On impact with a target, the projectile:
checks that the target is an avatar (but not the owner), and if so:
creates the blood splatter
triggers the "death cry" sound
uses osMessageObject() to send a message to the weapon, consisting of "H" followed by the avatar's UUID
That message is picked up by the weapon, which broadcasts the avatar UUID on the server's listening chat channel.
On receiving the message from the weapon, the server animates the avatar and adds it to a list, periodically checking the list for avatars whose "death time" has expired and releasing them.