ID:270830
 
In my game, when you throw a kunai. it goes in a straight line. theres no problem with that. but when it hits a npc(or a client), in the deathcheck it turns out null.

    Kunai2
name="Kunai"
icon='Ex.dmi'
icon_state="kunai"
layer = 10000
density = 1
Bump(A)
if(istype(A,/mob))
var/mob/M = A
var/damage = round(src.Attack)
if(damage >= 1)
M.health -= damage
view(M) << "<font size=1><b><font color=silver>[M] was hit by a Kunai for [damage] damage!"
var/mob/N = src.Gowner
M.deathcheck(N)
del(src)
if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)

Ex:
Snake was killed by 0

I want it to be able to know who the owner is(person who threw it)
I tried giveing it a var such as owner = "usr"(just an example) but it still would turn out null
If you want to see the deathcheck, just tell me.
Show deathcheck and seems that it's missile so show code which creates it
In response to Ripiz
Code to create:
    Kunai
icon='Ex.dmi'
icon_state="kunai"
layer = 10000
verb
ThrowKunai()
set category = "Taijutsu"
set name = "Throw-Kunai"
if(usr.firing)
return
if(usr.locked)
return
if(usr.chakra < 10)
usr<<"You dont have enough chakra!"
return
else.
usr.locked=1
usr.chakra-=10
usr.fireing=1
var/obj/Kunai2/K = new /obj/Kunai2
sleep(10)
usr.<<"<font color=silver><font size=1><b>You throw a kunai!"
K.Village = "None"
K.loc = usr.loc
K.Attack=usr.Attack
K.dir = usr.dir
K.name="Kunai"
K.movespeed = 1
K.Gowner=usr
walk(K,usr.dir)
spawn(6)usr.fireing = 0
sleep(10)
usr.locked=0
del(K)
return
In response to Chibi-Gohan0
Deathcheck:
mob
proc
deathcheck()
if(src.health <= 0)
if(src.Village == "Akatsuki")
world << "<font color=red>Death: <font color=green>[src](Akatsuki-Nin) has been killed by [usr]([usr.Village]-Nin)!"
src.ChuuninPoints =0
usr.exp += src.max_exp
src.deaths+=1
src.resting = 0
src.doing = 0
src.Moveing = 0
src.firing = 0
src.doing = 0
usr.kills+=1
usr.Levelup()
src.health = src.maxhp
src.loc=locate(0,0,0)
src<<"<font color=red>Itachi: I'll let you rest up."
sleep(80)
src.loc=locate(170,68,1)
usr.CoppyWheel = 0
src<<"<font color=red>Itachi:<font color=blue> Idiot!"
src<<"<font color=red>Itachi:<font color=blue> You were lucky, Sasori found you."
if(src.Village == "Leaf")
world << "<font color=red>Death: <font color=green>[src](Leaf-Nin) has been killed by [usr]([usr.Village]-Nin)!"
src.ChuuninPoints =0
usr.exp += src.max_exp
src.deaths+=1
src.resting = 0
src.doing = 0
src.Moveing = 0
src.firing = 0
src.doing = 0
usr.kills+=1
usr.Levelup()
src.health = src.maxhp
src.loc=locate(0,0,0)
src<<"Hokage: We'll let you rest up for a bit!"
sleep(80)
src.loc=locate(192,321,2)
usr.CoppyWheel = 0
src<<"Hokage: Welcome back to the village hidden in the leaves!"
src<<"Hokage: You were out cold for a wile. your lucky one of our jounins found you."
if(src.Village == "None") //None, is refering to npcs
src.loc=locate(0,0,0)
sleep(20)
world<<"<font color=green>[src]<font color=red> has died at the hands of<font color=green> [usr]!"
del(src)
In response to Chibi-Gohan0
Replace with similar one
var/obj/Kunai2/K = new

usr.name better because just usr makes var to reference
K.Gowner=usr.name
In response to Ripiz
done.
In response to Chibi-Gohan0
You made it to 'send' extra information to proc but didn't made it to use


deathcheck(killer as text)

world << "<font color=red>Death: <font color=green>[src](Akatsuki-Nin) has been killed by [killer]([killer.Village]-Nin)!"
In response to Ripiz
Ripiz wrote:
You made it to 'send' extra information to proc but didn't made it to use


deathcheck(killer as text)

world << "<font color=red>Death: <font color=green>[src](Akatsuki-Nin) has been killed by [killer]([killer.Village]-Nin)!"
                    var/mob/killer = src.Gowner
M.deathcheck(killer as text)

Like so?
when i do that it says as is unused, and statement has no effect
In response to Chibi-Gohan0
Nope..

You call deathcheck proc as it should be
In deathcheck proc replace
deathcheck()
with
deathcheck(killer as text)

So it will be:
mob
proc
deathcheck(killer as text)
if(src.health <= 0)
if(src.Village == "Akatsuki")
world << "<font color=red>Death: <font color=green>[src](Akatsuki-Nin) has been killed by [usr]([usr.Village]-Nin)!"
src.ChuuninPoints =0
usr.exp += src.max_exp
//and other code ..

Then replace
world << "<font color=red>Death: <font color=green>[src](Akatsuki-Nin) has been killed by [usr]([usr.Village]-Nin)!"
with
world << "<font color=red>Death: <font color=green>[src](Akatsuki-Nin) has been killed by [killer]([killer.Village]-Nin)!"
In response to Ripiz
I was fast enough to read that message! xD

Didn't notice that it will need village var .. Going to post all code ..
In response to Ripiz
dont bother. i figured it out..
instead of killer.village
it needed killer:village
In response to Chibi-Gohan0
That fixed it, and it says the person. but i have a second question.
would killer work for vars, too?
In response to Chibi-Gohan0
Chibi-Gohan0 wrote:
when i do that it says as is unused, and statement has no effect

Don't listen to ripiz. It seems like he doesn't know what hes talking about.


                    var/mob/killer = src
M.deathcheck(killer)

mob
proc
deathcheck(mob/killer)
world << "[src] has died[killer&&ismob(killer)?(" by [killer][killer.village]"):""]"


Add whatever you need to it and it should work.
In response to Chibi-Gohan0
Don't use the colon operator.

There is few uses for it, and this is not one of them.
In response to Justin B
No actually, i got it right thanks to him, it displays the person.
In response to Chibi-Gohan0
Yeah, but you had to use the the : operator. You shoud be type-casting and accessing the vars directly, compile-time. The colon operator accesses them runtime which can lead to runtime errors.
In response to Justin B
He doesn't seem to know what he's talking about because he doesn't know what he's talking about.

Back on topic, you forgot to make sure killer is actually a mob.
In response to Chibi-Gohan0
Using the colon (:) operator is just a way to assume something is what you think it is. In that case, it probably was, but if you put in a mob with another type path, then you'll get runtime errors, which are not pretty. Type casting is more safe and robust.

~~> Unknown Person
In response to Audeuro
Whoops. Fixed. I think you can put multiple conditions in the ? operator. I've never tried it so I don't know :P
In response to Justin B
i changed it to mob/killer

You throw a kunai!
Haku (NPC) was hit by a Kunai for 1000 damage!
Haku (NPC) has died at the hands of Inuyasha!

As far as i can tell, it seams wright.
Thanks for the help, guys.
Page: 1 2