How to create grenades for your player and npcs.
There are two types of grenades you might need; realistic objects that look like ball or stick grenades and have a physical presence in the world, and special effects grenades which are futuristic weapons suitable for sci-fi worlds.
Search for grenade in the gallery and you get Astro Marine Grenade, which is a roughly spherical grenade, and Stick Grenade, which is … well, a stick. There is also the TNT Bundle that can be thrown as an explosive device. Despite them doing very similar things, the 3 grenade objects have different brains. All allow the player to pick up the object and hold it as equipment.None of these brains however will allow your player to throw the object and therefore make the explosives work.
In your player brain add the following
WHEN [right bumper][pressed] DO [throw][equipment]
Now try it out with the 3 explosive objects. Note they act slightly differently when thrown. The round grenade, and the TNT bundle are thrown in an arc, and roll along the floor, after they hit the ground ,before exploding. The stick grenade rotates in the air.
Here is a brain for a grenade that explodes as soon as it hits the ground
- WHEN [not][equipped][and][not][is projectile]
- …WHEN [interacted] DO [it][equip][me]
- WHEN [is projectile]
- …WHEN [started to][bump terrain] DO [boolvar:explode][equals][true]
- WHEN [boolvar:explode]
- …WHEN DO [play sound][Explosions TNT Boom]
- …WHEN DO [play fx][Fire explosion][at position][center][volume]
- …WHEN [for each of][detect]
- …/…WHEN DO [damage][it]
- …/…WHEN DO [push][it][away from][me]
- …WHEN DO [destroy]
Grenade throwing skill
To make this a constantly available grenade for the player. Make it a template.
In player brain change your throw command to
WHEN [right bumper][pressed] DO [throw][IWP:grenade]
Your player can now thrown as many grenades as he likes.
To make the skill only available when a meter is full add this kode.
WHEN DO [display meter][max][numvar:throw meter][screen top center]
WHEN [once] DO [numvar:throw meter][equals]
WHEN DO [numvar:throw meter][equals][clamp][min][max][numvar:throw meter]
WHEN [countdown timer][loop] DO [numvar:throw meter][increment by]
WHEN [right bumper pressed]
…WHEN [numvar:throw meter][greater than or equal to]
…WHEN DO [throw][IWP:grenade}
…WHEN DO [numvar:throw meter][equals]
…WHEN [else] DO [play sound][UI negative]
You can change the amount of time it takes to get to 10 or make the number higher for a longer cooldown period.
Special effects grenades.
You can add this brain to a templated special effect too. It acts just like the objects you were throwing.
To get NPCs to throw grenades
try something like:
WHEN [distance to][objvar:my enemy][less than][and][distance to][objvar:my enemy][greater or equal to]
…WHEN [started to] DO [throw][IWP:grenade][in direction][objvar:my enemy]