Weapons and Ammo Tutorial by LadyLexUK

Have something important that other people might find usefull? Well, drop it here and help others!
User avatar
Level 3
Level 3
Posts: 184

Weapons and Ammo Tutorial by LadyLexUK

Post#1 » Mon Aug 15, 2016 7:54 am

moved over from projectspark.com forums

What is a weapon?
Weapons are specialist objects which change the animation for attack and shoot depending on their type when equipped. There are 4 types of attack animations, and 4 shoot animations.

When you press X (default brain set up)
Hit/Punch (Alternative arms punch) - no items equipped, some non weapons, bow, blaster
Bladed swing (Right arm only) - swords, axes, torch, some non weapons (acorn for example)
Sweeping club (Right arm only)- club weapons
Flourishing blade (Right arm only) - Daggers, goblin spike

When you press Y (default brain set up)
Traditional Archery (Fires arrows) - Upright bows
Crossbow (Fires Arrows) - Horizontally held crossbows
Laser Gun (Fires small lit projectiles) - Guns
Fireball (Fires a ball of fire)- When no ranged weapon is equipped

How to change the projectile for ranged weapons

In the default brain is this line

WHEN [Y] DO [shoot]

Place an object from the gallery or an IWP templated object as a projectile.

WHEN [Y] DO [shoot][gallery:apple]

So instead of the default object such as an arrow or a fireball they will shoot your chosen object. Please note that objects with interact Kode built in (such as the apple) will fire with a B above them. To remove this either:
place the object into your world, remove the Kode, and save as a template. Use IWP.
place the object in your world, remove the Kode, save it as an assembly. Delete it from world. Use assembly gallery to choose it in your Kode line.

How to only shoot when you have a ranged weapon, and not attack when you have a ranged weapon

The standard Kode shoots fireballs on Y when you do not have a ranged weapon equipped and punches people with the ranged weapon when you press X. To stop this and only have the attack option of the weapon type you are using (either X or Y) use this:

WHEN [equipment] DO
...WHEN[else] DO
.../...WHEN [X][pressed] DO [attack]
...WHEN [not][it][is ranged weapon] DO
.../...WHEN[X][pressed] DO [attack]
.../...WHEN [else] DO
.../.../...WHEN [it][is ranged weapon] DO
.../.../.../...[Y] DO [shoot]

How to create your own weapons

Choose a weapon as your base with the attack or shoot style you want. You can attach objects to adapt a standard weapon to look different, and/or change the colour attributes. Or if you are making a weapon from scratch, attach the finished article to your base weapon so that it matches the handling point on both, and make the base weapon invisible using properties.
There is an issue with attached objects with collide on. It can cause characters to fly in the air when they touch them, or if they are created with the weapon equipped. If possible try to keep the scale of your new weapon and the old one the same, keep your invisible weapon collidable but invisible, but make your new weapon non-collidable. They will appear to be hitting things with your new weapon, but it will be the base weapon that is colliding. Bear this in mind for any koding - it will need to go in the base weapon not your attached “skin” weapon.

Limited ammo

Create a variable for your ammo

In the object that gives your character ammunition put this:

WHEN [interacted] DO [objvar: player][=][it]
...WHEN DO [objvar:player][numvar:ammo][incremented by][100]

In your player brain

WHEN [ammo][>][0] DO
...WHEN [bow (or whatever weapon)][is equipped] DO
.../...WHEN [Y][pressed] DO [shoot]
.../.../...WHEN DO [numvar:ammo][decremented by][1]

When the player has no more ammo he will not be able to fire, until he has picked up some more.

If you want the player to be able to hold down Y and fire continuously

WHEN [ammo][>][0] DO
...WHEN [bow (or whatever weapon)][is equipped] DO
.../...WHEN [Y] DO [shoot]
.../.../...WHEN DO [numvar:firing][incremented by][1]
.../.../...WHEN [started to][numvar:firing][increased][DO [numvar:ammo][decremented by][1]

Multiple ammo types/ranged weapons

If you have multiple weapons with different projectiles then use this:

In weapon brain

WHEN [not][equipped][and][not][attached] DO
...WHEN [interacted] DO [objvar:my owner][=][it]
.../...WHEN DO [objvar:my owner][equip][me]
.../...WHEN [once] DO[objvar:my owner][numvar:ammo][=][2] (quantity of ammo when you first pick up weapon)
WHEN [equipped] DO [objvar:my owner][numvar:ammotype][=][1] (the projectile)

In player brain

WHEN [Y][pressed]
...WHEN [numvar:ammo][>][0] Do [numvar:ammo][decrement by][1]
.../...WHEN DO [call page][2]

In page 2 of player brain

WHEN [numvar:ammotype][=[1] DO [shoot][arrow]
WHEN [numvar:ammotype][=[2] DO [shoot][IWP:flaming arrow]
WHEN [numvar:ammotype][=[3] DO [shoot][acorn]

At the moment "ammo" can be collected and it works in all weapons for whatever type they are. If you want to store different ammo for different weapons then you will need to change this to.

In the weapon

WHEN [once] DO [objvar:myowner][ammo1][=][2]

In the player brain

WHEN [Y][pressed]
...WHEN DO [call page][2]

page 2
WHEN [numvar:ammotype][=[1]
...WHEN [ammo1][>][0]
.../...WHEN DO [shoot][arrow]
.../.../...WHEN[page entered] DO [ammo1][decremented by][1]

do this for each ammo type
End of line.

Return to “Tutorials and guides”

Who is online

Users browsing this forum: No registered users and 1 guest