ID:143886
 
Code:
obj/blade
icon = 'basic.dmi'
icon_state = "blade"
density = 1
obj
blade
Bump(obj/blade/D)
D.hp -= src.Str - D.Def
usr<<"You damage [src] for [Str]"
..()
turf
clicker
Click()
if(usr.blading == 1)
walk_towards(usr.myblade,src)

Problem description:

im trying to make it so that when the blade bumps with the other blade it takes the health away from the other one as you can see. the code has no errors but it just wont bump or take away the health off the other blade. I dont know whats wrong with it.
First of all: you don't want to be using usr in Bump(). Technically, in this case, it will usually work.

And that's the crux: usually.

Instead, give the blade a variable, var/mob/owner. Use that instead of usr.

Now, second problem: when you define a proc like Bump(obj/blade/D) this doesn't restrict what it's bumping into. It simply says, "When I bump into something, pretend it's a blade." So, you'll need to ensure that it IS a blade. Fortunately, you can use istype(D), which will be true if D is the type you say it is, and false otherwise. For example: if the blade bumps into a turf, your code would generate errors.

Third problem: your damage calculation. hp -= Str - Def. I understand that you want to keep it simply, but that's going to result in cases where an attack will heal the target. Slap a max() on there, so that it never goes negative. Like so:

hp -= max((src.Str - D.Def), 1)


It will always do at least 1 damage, then.

Fourth problem: you're telling usr (remember: you're going to change that to a variable belonging to the blade) that you hit [src] for [Str], when you're really hitting [D] for [Str-Def] (which will become [max((src.Str - D.Def), 1)] once you make that change).

Fifth problem: I don't see you defining obj/blade/Str, Def, or hp anywhere. Either you neglected to post that code (understandable, considering that you have it organized sloppily), or... I don't know. It wouldn't compile if you didn't.

Speaking of which... sixth problem: sloppy code. Your code for each object seems to be all over the place. Each object's code should be all in one place, unless if your program gets VERY complicated, to the point where you need separate code files for each concept, rather than each object. By not having your code all over the place, it won't be so hard to find your problems.