ID:280506
 
(See the best response by LordAndrew.)
Code:
mob
verb
exploding_kunai(mob/M in oview(6))
set name = "kunai"
set category = "Ninja"

new/obj/projectile
var/FallDir = get_dir(src,M)
src.dir = FallDir
walk(M,FallDir)
switch(FallDir)
if(NORTH)M.dir = SOUTH
if(NORTHWEST)M.dir = SOUTHEAST
if(WEST)M.dir = EAST
if(SOUTHWEST)M.dir = NORTHEAST
if(SOUTH)M.dir = NORTH
if(SOUTHEAST)M.dir = NORTHWEST
if(EAST)M.dir = WEST
if(NORTHEAST)M.dir = SOUTHWEST
sleep(50)
explosion()
mob
proc
explosion()
new/obj/pushwave
layer=MOB_LAYER+1

obj
pushwave
icon='explosion2.dmi'

obj
projectile
icon = 'Ki Attack.dmi'


Hello everyone, I wanna start out with saying, that this code is flawed, duhh, that's why I am here right?

The thing is, that it doesn't make an project, it does something, but not what it's supposed to.

I would like it to fire the kunai, and when it hits, it displays the pushwave and pushes the target back a few steps. But I am unable to make it work, and I've been trying for 3 days now :P

Any help would be greatly appreciated!


Best response
You're making a new instance of /obj/projectile, but then you're not really doing anything with it. src in this case is still the player who used the verb.

mob
verb
exploding_kunai()
// Create a new projectile, and provide the player as an argument.
new /obj/projectile(src)

obj
projectile
var/mob/owner

proc
move()
while(step(src, dir))
sleep(1)

// Conversely you can just do "del src" here as well.
loc = null

New(mob/m)
owner = m

loc = owner.loc
dir = owner.dir

// Spawn the move() proc off in a separate "thread".
spawn move()

Bump(mob/m)
if(istype(m))
world << "[owner]'s projectile hits [m]!"

// Tell an explosion to show up where is standing and supply it with the delay argument, in this case 2 seconds.
new /obj/explosion(m.loc, 20)

// Pushes m backwards while still retaining their current direction.
// turn(m.dir, 180) will turn the player around to the opposite direction they're currently facing, bypassing having to do that switch for FallDir you have going on.
m.Move(get_step(m, turn(m.dir, 180)), m.dir)

explosion
New(newloc, n)
// This is just an example but you can tell an explosion how long you want it to stick around before deleting itself.
spawn(n)
loc = null


(Untested but it gives a general idea of projectiles.)
Thanks for the effort, though, I get like 800 errors and thousands of warnings if I try that code, or even trying to adapt it :P

I dunno, but it states errors that are in other DM files, though they run perfectly fine, without that code :P

Can you elaborate further with me on this?
Posting some of the errors would be rather helpful.
Whoops, I left out a parenthesis. Modified my post with the right code now.
Thanks now it works without error, though a slight note, it doesn't hit like in my dbz source (for testing) it's not hitting the saibaman, it goes right through the little bugger.

It doesn't hit any mob for that matter, and I wonder why, can't figure it out, but we've got this far, maybe you guys can help me out a little tad further?

Also there's no errors on runtime (or compiling) :D
Oh right, the projectile needs to be dense in order for it to do its thing with Bump().
Aaah yeah, that's right, not excusing myself, but I was thinking in that direction, but never really think it would be just that, hehe.

I'm going to be doing that right now, and will let you know :D
Oke, now it hits, but it doesn't push the dude back. Thanks for everything, but I still need some help I guess.

Sorry to be such a bother, but I've done everything that was needed, though, it does not push the guy back, which is the main reason, why I need this kunai to work :P

The great guy that you are, could possible help me some more, cause i've learned a great bunch at the moment, but yet, I fail to let this succeed :P
Oh. I see what I did wrong (again for like the eighth time. I really need to learn to test these things before I hand them out!)

Change the m.Move(...) part to this:

m.Move(get_step(m, get_dir(loc, m.loc)), m.dir)
Thanks it does it now, but not for players :/

I am trying something out right now, changed the m's into uppercase M's, and made a second code file with the same code, but with an extra little code within the verb's (), so let's see.

If that does not work, how would I enable such?

And I just wanna say: Dude, I didn't mind that you didn't test them, after all doing this is not obligation, it's more of a luxury to me, that I can learn from it ;)

Fixed instead of:
Bump(mob/m) ->> Bump(mob/PC/M)



Thanks for everything, it works now, now that I got this up and working, I want to take it to a next step :P

There isn't any real difference between lowercase and uppercase variable names. mob/m and mob/M both do the exact same thing, albeit using a different variable name.

I'm not sure why it wouldn't work for players since it should fire on any /mob, unless you're doing something like making your players control /objs or something.

edit: oh. welp :P
Well I forgot that I class my player characters, under the path called mob/PC which stands for Player Character :P

So yeah, ofcourse it wouldn't work, though, oddly enough, other attacks work perfectly fine for PC mobs without PC :/

Got to look into that :P