Weapon
A gun held in first person, with no code: Fire shoots where the player looks. It hits the first thing in the way straight away (or launches a Projectile), hurting anything with Health. Several weapons on one player are picked with the number keys (their Slot) or the mouse wheel. Put it on the entity a FirstPersonView looks through.
Part of the First Person module: First-person games: the world seen through the player’s eyes from a flat map (FirstPersonView), walking and turning (FirstPersonMovement), weapons, billboards and solid blocks, and the Shooter template.
Ammo comes from the player’s Inventory: a weapon with Ammo “Shells” uses up a shell a shot, a Pickup with Item “Shells” gives more, and a Counter with Item “Shells” shows how many are left. A weapon with NeedsItem can’t be used until it’s picked up, and is taken out as soon as it is.
Works with: Inventory (holds its ammo); FirstPersonMovement (aims it)
Takes the player’s input only while the FirstPersonMovement it goes with has focus.
Properties
Section titled “Properties”Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.
name: text = “Pistol”. The weapon’s name, e.g. “Shotgun”. (Plain text: the weapon’s name as shown, its own words.) (Field: text.)slot: a whole number = 1. The number key that takes it out, 1 to 9. (Field: a number.)action: text = “Fire”. The input action that fires it, e.g. “Fire” (the left mouse button, J, or the gamepad’s right trigger). (Names an input action.) (Field: a name.)
Firing
Section titled “Firing”damage: a number = 1. Hit points each bullet (or pellet) takes away. (Field: a number.)fireRate: a number = 3. Shots a second, at most. (Field: a number.)automatic: true or false = false. Keep firing while the action is held, like a machine gun. Otherwise it’s one shot a press. (Field: on or off.)range: a number = 30. How far bullets reach, in world units. (A distance: the Scene view draws it as a circle around the entity, with a handle to drag.) (Field: a number.)pellets: a whole number = 1. Bullets in each shot: 1 for a pistol, 7 or so for a shotgun. (Field: a number.)spread: a number = 1. Degrees the bullets scatter across. (Field: a number.)knockback: a number = 2. How hard a hit pushes what it hits, in units per second. 0 doesn’t push. (Field: a number.)
Ammo and Items
Section titled “Ammo and Items”ammo: text = null. The Inventory item each shot uses up, e.g. “Bullets”. Empty never runs out. (Names an item.) (Field: a name.)needsItem: text = null. An item the player must have to use it, e.g. “Shotgun”, given by a Pickup. Empty is always ready. (Names an item.) (Field: a name.)
Projectile
Section titled “Projectile”projectile: text = null. A prefab to launch instead of hitting straight away, e.g. “Rocket” or “Plasma”. It needs a Body to fly. (Names a prefab.) (Field: a name.)projectileSpeed: a number = 12. How fast a Projectile flies, in world units per second. (Only used when projectile is set.) (Field: a number.)
Sounds and Effects
Section titled “Sounds and Effects”impactEffect: text = null. A prefab spawned where a bullet hits, e.g. “Puff”: sparks off a wall, a splash on an enemy. (Names a prefab.) (Field: a name.)sound: text = null. The sound of a shot, e.g. “Sounds/shoot.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)emptySound: text = null. A click when it’s out of ammo. (Only used when ammo is set.) (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
image: text = null. The picture of the weapon in hand, drawn at the bottom of the screen. Without one it’s drawn as a simple gun in Color. (A picture in Assets, e.g. “Sprites/back.png”.) (Field: an image.)fireImage: text = null. The picture shown for a moment as it fires, e.g. with a flash at the muzzle. Empty uses Image. (A picture in Assets, e.g. “Sprites/back.png”.) (Field: an image.)color: a color, “#RRGGBB” or “#RRGGBBAA” = “#9AA0AAFF”. The gun’s color when it has no Image (or a tint over the image). (Field: a color.)size: a number = 0.45. How big it’s held, as a fraction of the screen’s height. (Field: a number.)muzzleFlash: a color, “#RRGGBB” or “#RRGGBBAA” = “#FFD86BFF”. The color of the flash at the muzzle as it fires. Transparent for none. (Field: a color.)kick: a number = 0.15. How far it jumps back as it fires, as a fraction of its size. (Field: a number.)shake: a number = 0. Shakes the screen by this much with each shot. 0 for none. (Field: a number.)
shots: a whole number = 0. How many shots it has fired. The game counts them. (Field: a number.)
Actions
Section titled “Actions”What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).
Fire. Fires it once, as pressing its Action does, if it’s the weapon in its player’s hands and ready, using up its Ammo, whether or not the player has the input: a note hit on the beat, a card or a trigger fires it.
Outputs
Section titled “Outputs”What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.
Shots(a whole number). How many shots it has fired. The game counts them.CoolingDown(true or false). True while it can’t fire again yet.
While the game runs
Section titled “While the game runs”Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.
isCoolingDown: true or false. True while it can’t fire again yet.
Scripts use it as Weapon: its methods, events and values that aren’t saved with the scene.