ID:160817
 
I don't know if this question can be a simple, "How do I do this?", "This is how.", but any help would be appreciated. My MSN is [email protected] if you want to offer in-depth help.

I am attempting to code a usable object, that you can throw. When and if the object bumps another player, I run into trouble, because I cannot get the object to recognize the relevant vars of the thrower, and the mob hit. I want to take the values of the mob hits defense, and other relevant variables, subtract them from the value of the "damage" relevant variables from the thrower, to get a total damage value.

When I try to code them, I can't get it to recognize the variables of the target mob without putting the variables into the object itself, and even if I were to do that, I don't know how I would make the objects variables equal to the target and attackers values.

Thanks for your time.
That's easy. For the basic part you just have to do the same you'd do for any projectile system. You need to have a variable on the projectile (the thrown object) that keeps a reference to the mob who threw it, so it can know who that mob is later. The gist of it would be:
obj/item/throwable
var/mob/thrower //define a var so you can use it to keep the necessary reference info
verb/Throw()
walk(src,usr.dir) //make it move
src.thrower = usr //keep track of the player
Bump(mob/M)
if(istype(M)) //if it's a mob
viewers(src) << "[src.thrower] hits [M]!" //you have all the info you need here, so you can do whatever
//...

walk(src,0) //stop the movement of walk() (normally it continues attempting to move even after Bump()
src.thrower = null //unflag the thrower - the object \
has bumped and isn't moving/being thrown anymore.
In response to Kaioken
Hmm, that gets rid of the majority of the errors I was having, when I tried it that way. There's still a problem though, during the Bump(mob/M) I attempt to use M's variables, such as defense to influence the change in M's health. When I call any of M's variables it says they are undefined, and I can't think of a fix.

Thank you for that though, it really helped. Here is the code I have for my object as of now, with the errors.
obj
consumable
Shuriken
var/mob/owner
var/delay = 2
icon='ninjatools.dmi'
icon_state="shuriken"
verb/Throw()
src.amount--
walk(src,usr.dir)
src.owner=usr
Bump(mob/M)
if(istype(M))
var/damage=(owner.Dexterity+(owner.Strength/2))-M.Defense
if(damage<=0)
return
else
M.Health-=damage

The only error I get is the M.Defense, for some reason it recognizes M.Health, though I am not sure it will work out.
In response to Pikkon53
Pikkon53 wrote:
Hmm, that gets rid of the majority of the errors I was having, when I tried it that way. There's still a problem though, during the Bump(mob/M) I attempt to use M's variables, such as defense to influence the change in M's health. When I call any of M's variables it says they are undefined, and I can't think of a fix.

Thank you for that though, it really helped. Here is the code I have for my object as of now, with the errors.
obj
> consumable
> Shuriken
> var/mob/owner
> var/delay = 2
> icon='ninjatools.dmi'
> icon_state="shuriken"
> verb/Throw()
> src.amount--
> walk(src,usr.dir)
> src.owner=usr
> Bump(mob/M)
> if(istype(M))
> var/damage=(owner.Dexterity+(owner.Strength/2))-M.Defense
> if(damage<=0)
> return
> else
> M.Health-=damage

The only error I get is the M.Defense, for some reason it recognizes M.Health, though I am not sure it will work out.

That just means you haven't declared the variable Defense in the mob type. Or M is not of mob type. Or maybe the value of Defense is not what the compiler expects.

http://www.byond.com/members/ DreamMakers?command=view_post&post=37193

That page might help.
In response to Pikkon53
Maybe you misspelled "Defense" on your definition.
In response to Green Lime
When using a Bump proc, I find it best to redefine the contacted object.

Bump(M)
if(ismob(M))
var/mob/a = M //This will tell the bump proc that M is a mob, sometimes the bump won't detect the mob normally, so this clears it up, then use -a- as the var
a.Health-=damage


I found that many times, even though the (ismob) statement is in effect, the proc will "Forget" what's going on. This has happened to me many times but using the transfer from M to var/mob/a works best in defeating that issue. I've never had a problem with Bump() since I started using that.
In response to Bravo1
Thank you all for your help. I'm kind of embarrased, Jemai was right, in the Shuriken I told it to use "M.Defense", while my mob has the stat listed as "defense". I'll be sure to check my punctuation and capitalization before asking for help, thank you everyone.
In response to Bravo1
The procedure/compiler doesn't "forget" what's going on, it simply doesn't care. DM is a language that assumes you know what you're doing. This is why if you override Bump(M), then it'll go by the type /M even if you precede your code with if(ismob(M)). Likewise, this is also why if you override Bump(mob/M), M can still be any dense object.