ID:171631
 
Hellow all i need a little help with something. I need someone to please tell me how to make it so that when a mob uses a certain verb (such as "bomb"), a bomb appears and moves in the usrs dir, goes about 3 spaces moving, then STOPS at the turf its on, waits 3 seconds, and explodes. can someone tell me how to do that?
Reinhartstar wrote:
Hellow all i need a little help with something. I need someone to please tell me how to make it so that when a mob uses a certain verb (such as "bomb"), a bomb appears and moves in the usrs dir, goes about 3 spaces moving, then STOPS at the turf its on, waits 3 seconds, and explodes. can someone tell me how to do that?

[Insert standard rant about the usr not being the user, etc]

Now that that's out of the way, first you'll need your bomb object. You want your bomb to be able to move 3 spaces in a certain direction, and you want it to explode. You'll need a proc for each of those.
obj
bomb
proc
MoveInDir(direction)
// Do movement in here
// When done, call Explode()
Explode()
// Do exploding in here


For doing the actual moving, I'd suggest using the step() proc three times. With step(), it's easier to be sure when you've finished moving than with walk_to().

Between the calls to step() you might also want to sleep() for a bit so that the bomb doesn't move too fast. Now all that's left is for the bomb to wait for 3 seconds (sleep(30)), and explode.

Theodis has a couple of explosion-related libraries on his hub page. Check them out to see if you want to use them for when your bomb Explode()s.

So in the verb would just have to create the bomb object, and call its MoveInDir() procedure with the proper direction.


Also, in the future, what if you want a bomb that moves slower? Or a bomb that waits a different amount of time before exploding? Or a bomb that explodes in a different way? You have two ways to do that. You can either have subtypes of /obj/bomb:
obj/bomb
icebomb
MoveInDir(direction)
// Do movement in here, but with shorter sleeps
Explode()
// Do exploding in here, but with ice graphics


Or you can give/pass /obj/bomb variables/arguments to determine what to do:
obj
bomb
var
explosionType
MoveInDir(direction, moveDelay, explodeDelay)
// Use variables instead of hard-coded numbers
Explode()
// Check explosionType to determine what type of explosion