this wont work.....
it doesnt recognize the "M" in front of "health" and "deathcheck"
obj/image/bullet
density = 1
icon = 'weaponimages.dmi'
icon_state = "bullet"
Bump(atom/M)
M.health -= usr.damage
M.deathcheck()
ID:148033
Jul 31 2003, 5:06 am
|
|
In response to Airjoe
|
|
Airjoe wrote:
Xallius wrote: You also need to change the bump line to: Bump(mob/M) unless you have a health variable and a deathcheck proc defined for every atom! |
In response to Skysaw
|
|
I thought putting the ismob(M) and then indenting the health and deathcheck under the ismob(M), then you could leave atom/M. Because then you could use:
Bump(atom/M) if(ismob(M)) //blah else del src that way if it hits objs it would be deleted |
In response to Airjoe
|
|
Airjoe wrote:
I thought putting the ismob(M) and then indenting the health and deathcheck under the ismob(M), then you could leave atom/M. Because then you could use: No, because he references both M.health and M.deathcheck(). The compiler will complain because health and deathcheck() are not defined for all atoms. |
In response to Airjoe
|
|
Thanks I'll do both!
|
In response to Skysaw
|
|
obj/image/bullet
density = 1 icon = 'weaponimages.dmi' icon_state = "bullet" Bump(mob/M) if(ismob(M)) M.health -= usr.damage M.deathcheck() world << "[usr] hit [M] for[usr.damage] health!" del(src) i have that (the text to world is wordwrapped...) and it works in the compiler but now i get a runtime error where it cant read damage, health, etc... anger.... |
In response to Xallius
|
|
Xallius wrote:
obj/image/bullet The problem is that you're using usr in a proc where it does not necessarily mean what you want it to. usr in this context is not guaranteed to be the person who shot the bullet. What you need is a variable in the bullet that keeps track of who shot it. obj/image/bullet Then in your proc that creates the bullet, make sure you set the shooter variable to the person shooting the gun. Notice that this version also deletes the bullet no matter what it hits. You may want to adjust behavior if it hits a wall, or some other object. |
In response to Skysaw
|
|
how do i make the person the shooter?
shooter = usr? |
In response to Xallius
|
|
Xallius wrote:
how do i make the person the shooter? You'll have to show me the shooting proc. |
In response to Skysaw
|
|
mob/player/verb/fire()
var/obj/image/bullet/B = new /obj/image/bullet(src.loc) walk(B,src.dir) B.dir = src.dir sleep(10) del(B) |
In response to Xallius
|
|
mob/player/verb/fire()
var/obj/image/bullet/B = new /obj/image/bullet(src.loc) B.shooter = src<font color = red> <-- Add</font> walk(B,src.dir) B.dir = src.dir sleep(10) del(B) |
In response to Skysaw
|
|
now im getting this error...
terrorist is my test target mob runtime error: Cannot read null.health proc name: deathcheck (/mob/proc/deathcheck) usr: 0 src: the terrorist (/mob/terrorist) call stack: the terrorist (/mob/terrorist): deathcheck(null) the bullet (/obj/image/bullet): Bump(the terrorist (/mob/terrorist)) |
In response to Xallius
|
|
The error is in your deathcheck proc, according to that message. I haven't seen that proc, so I don't know what's wrong.
|
In response to Skysaw
|
|
mob/proc/deathcheck(mob/M as mob)
if(M.health <= 0) world << "[M] has died." del(M) |
In response to Xallius
|
|
Xallius wrote:
mob/proc/deathcheck(mob/M as mob) There is no reason to pass a mob into this proc, since it's already attached to the mob you want to check for. This should fix it: mob/proc/deathcheck() if(health <= 0) world << "[src] has died." del(src) |
Xallius wrote:
this wont work..... If health isn't an /atom variable, and deathcheck() isn't an /atom proc, it won't work because you have M defined as an /atom. You need to define M as a /mob if you want it to work. So you can either change the initial defenition: <code>Bump(mob/M) M.health -= damage M.deathcheck()</code> (But only if the object will only ever bump mobs! You'll get an error if it bumps anything that isn't a /mob.) Or you can check if M is a mob and declare a new mob variable for it. <code>Bump(atom/A) if(ismob(A)) var/mob/M = A M.health -= damage M.deathcheck()</code> |
if(ismob(M))
put that in there. =)
Should work.