ID:171422
 
Ive tried and ive tried and ive tried, hell ive even tried some more...

can someone just give me code for a grenade?

you can tell me off for asking for code when i have no proof that ive even had a go but believe me i have and i just cant seem to get my head around it.

about as far as ive gotten is to use the missile proc to make it so that if there is a mob in front of the character it will show the grenade going towards them but i want to be able to make it so that the grenade only travels a few squares and then blows up...

if you can help i will be forever in your debt.
Basically what you want to do is create a new object at the throwers location, then move that object a few steps in the direction the thrower is facing.

Well first need the trigger on the mob, for this demo I'm just going to make a 'throwGrenade' verb.

mob/verb/throwGrenade()
//Throw the grenade.


Now we need to create the prototype for our grenade object type.

obj
grenade
icon = 'grenade.dmi'


Now back to our trigger. We'll figure out a psuedo-code version before actually writing anything.

Start
Create new /obj/grenade
Place the new grenade on the map at the players location
Move the grenade across the map three tiles in the direction the thrower (aka, src) is facing
Make the grenade explode

Ok. We can combine the first two lines easily enough. We also need to store the object in a var so we can manipulate it later.

    var/obj/grenade/activeGrenade = new /obj/grenade (src.loc)


Now we need to move the 'activeGrenade' across the map three spaces and make sure that it moves in the direction is was thrown.
We'll do this a simple way, by using step() three times in a row. step() will take two arguments, the object to make step and the direction to make it step.
We'll use activeGrenade as the first argument and src.dir (aka the direction the thrower is facing).

    step(activeGrenade,src.dir)
step(activeGrenade,src.dir)
step(activeGrenade,src.dir)


Now that's good, but we'll need to be a little safer. You see if src changes direction (which it probably will) the direction the activeGrenade steps in will be wrong.
So we'll fix this by recording src.dir to a var at the start of the trigger. So now it should look something like this.

mob/verb/grenadeTrigger()
var/throwDirection = src.dir
var/obj/grenade/activeGrenade = new /obj/grenade (src.loc)
step(activeGrenade,throwDirection)
step(activeGrenade,throwDirection)
step(activeGrenade,throwDirection)



Ok. Now most of this is done, we just need to blow the grenade up.
You'll probably have your own way of doing this. If not just ask. You really just have to make it for() through everything in range(radius,activeGrenade), damaging everything, then delete activeGrenade.
I won't *give* you the code, instead I'll help you. You won't learn if I just give it to you.

First off, you start by making a grenade object. Then you want to give it variables. You said you want it to blow after a certain ammount of steps? Give the grenade a variable "StepsBlow". Then, override the grenade's movement proc, and make its "StepsBlow" decrease by one everytime it moves, THEN check if "StepsBlow" is 1 or lower, if so, run the blowing up procedure. Now, with the blowing up part, you can do it like this: You can give the turfs around you an overlay of "fire". Since that's what people like to do, not knowing what a grenade does. Then just delay it, and remove the grenade and overlays. OR, if you want to do it right, make an object called shrapnel. Then, in the blowing up procedure, make a bunch of new shrapnel objects, and make them fly in all different directions. Now, you'll want to override the shrapnel's Bump() procedure, and if it hits a living thing, it'll deal damage and what not. Now, to *throw* a grenade, you DON'T WANT TO USE MISSILE(). Instead, create a new grenade object, and make it walk().

Darkview helped you but I posted awhile back somthing similar,you might want to take a look at it.
In response to DarkView
thank you so very much, after reading the code it seems so easy but yeah, in hind sight...

anyway i have finnaly managed to get it to work thanks to both DarkView, Crashed and CodingSkillz. thank you all very much.