ID:145647
 
Code: Zombie Attack Code
mob
TEST
zombie
name = "Zombie"
icon = 'mobs.dmi'
icon_state = "Zombie"
hp = 10
proc
Grab()
usr in oview(1)
sleep(20)
usr.hp -= 10
if(usr.defitem) // I'm checking here to see if they have a defense item equipped
src.hp -= usr.defitemd //The D at the end of this defitem is for "Damage Dealt"
usr << "The Zombie lunges for you! Lightning quick, you bury your [usr.defitem] into it's skull!"
usr.defitem = null
DeathTest()
else
usr << "The Zombie lunges for you! Grabbing hold, it sinks it's teeth into your arm!"
usr.hp -= 30


Problem description: The problem with this is, that it just doesn't execute. I get into the square next to it and I don't get any messages, or take any damage. Can someone tell me why this doesn't work?

mob/zombie/proc/Grab()
for(var/mob/user in oview(1))
sleep(20)
if(user)
user.hp -= 10
if(user.defitemd)
hp -= user.defitemd
user << "[src] lunges for you! You quickly bury your [user.defitemd] into its skull."
user.defitemd = null
user.DeathTest(src)
else
user << "The zombie lunges for you! Grabbing hold of you, it sinks its teeth into your arm!"
user.hp -= 30
break
In response to Artemio
You mis indendet the second if(), Art.
Also, if the damage is null, you don't need the deathcheck o.O
In response to Mysame
I didn't misindent, it's indented perfectly but the table or somesuch messed it up. The damage is not null, however defitem is after the damage is done.
In response to Artemio
Thanks! Though, I'm getting an error with:

if(user.defitem)

npc.dm:14:error::invalid expression
In response to Pakbaum
Oh, woops.
Remove the d at the end from hp -= user.defitemd.
If you copy and pasted it you might want to reindent it.
In response to Artemio
Well, the D is supposed to be there. It's there for Defense Item Damage. :P
In response to Pakbaum
So can anyone help? Please review the previous posts before answering.
In response to Pakbaum
Does the Grab()'d mob have a defitemd var?

If so, and if you still have the problem, post your newest code.

Hiead
In response to Hiead
I still have the problem, and my code is under my first edited post. And yes, the mob does have that var.
In response to Pakbaum
you need to call the proc first for what i see of it
First of all, read the usr lecture.

In any case, even without usr abuse, this still wouldn't do as you seem to want it to do.

When you ask for help, you should really tell us, in detail and in English (as opposed to DM), what you're trying to do. Though I can't really be sure since you didn't say, it seems like you want the zombie.Grab() proc to be executed whenever the zombie mob is adjacent with a player mob.

There are a few ways of accomplishing this. One is to leave the zombie object fully in charge of player detection. This wouldn't be an effective choice because it would require a loop lasting as long as the zombie object, which simply doesn't make sense.

Another way to accomplish this is to have players detect zombies on player.Move(), and if zombies move, have zombies detect players on zombie.Move(). This is an effective choice; one that I would recommend.
In response to Wizkidd0123
I've read that before, just forgot :P

What the code is supposed to do when executed, is whenever a player comes w/in one square of the zombie, the usr takes 10 damage first-hand. If the usr has a Defense item, it is used on the zombie, dealing damage equal to usr.defitemd (If you can show me how to link the item's damage DIRECTLY to the item instead of through the player's vars I would appreciate it. I'm fairly certain that's what I SHOULD be doing.) After dealing the damage, it deletes the defitem (Defense Item) and clears the defitem's damage (oops! Forgot to add that part :P). BUT! If the usr does not have a defitem, then the proc continues, dealing another 30 damage to the player, and waiting 3 seconds before executing the proc again.

mob
TEST
zombie
name = "Zombie"
icon = 'mobs.dmi'
icon_state = "Zombie"
hp = 10
proc
Grab()
for(var/mob/user in oview(1)) // Looks for nearby mob
if(user) // If it's a player...
user.hp -= 10 // Deal damage
if(user.defitem) // If the player has a defitem
hp -= user.defitemd //Stab that zombeh!
user << "A [src] lunges for you! You quickly bury your [usr.defitem] into its skull."
user.defitem = null //Delete Defitem
user.defitemd = 0 //No defitem? No more damage.
user.DeathTest(src) //Zombie dead?
sleep(30) //Zombie takes a break anyways
else //Didn't have a defitem!
user << "The zombie lunges for you! Grabbing hold of you, it sinks its teeth into your arm!"
user.hp -= 30 //More damage!
sleep(30) //Zombie takes a break.


Oh! Even though I read the lecture, what should I replace these usr with?
In response to Pakbaum
Personally I would make it realistic and have it to where the zombie would follow the person it's attached to and continually do damage to the person, slowing down movement and such, but that's just me.
I'm not quite sure if this is the best way to do it or even if it works, but-
mob/TEST/zombie
name = "Zombie"
icon = 'mobs.dmi'
icon_state = "Zombie"
hp = 10
proc/Grab()
var/mob/user=locate(oview(1))
user.hp-=10
if(user.DeathTest(src)) // make it return 1 if the person is dead
return
if(user.defitem)
if(!user.defitem.damage) return
hp -= user.defitem.damage
user << "A [src] lunges for you! You quickly bury your [usr.defitem] into its skull."
user.defitem = null
src.DeathTest(user)
else
user << "The zombie lunges for you! Grabbing hold of you, it sinks its teeth into your arm!"
user.hp -= 30
user.DeathTest(src)
sleep(30)
Grab()
mob/var/defitem=/obj/ZombieHurter
obj/ZombieHurter/var/damage=10
In response to Artemio
I originally planned that, though I couldn't think of a good point to break the zombie off the player, so it's not always an instant death. I've decided to make it more like Resident Evil, where they break off after one, painful attack.
In response to Artemio
mob/TEST/zombie
name = "Zombie"
icon = 'mobs.dmi'
icon_state = "Zombie"
hp = 10
New()
src.Grab()
proc/Grab()
var/mob/user=locate(oview(1))
user.hp-=10
if(user.DeathTest(src)) // make it return 1 if the person is dead
return
if(user.defitem)
if(!user.defitem.damage) return
hp -= user.defitem.damage
user << "A [src] lunges for you! You quickly bury your [usr.defitem] into its skull."
user.defitem = null
src.DeathTest(user)
else
user << "The zombie lunges for you! Grabbing hold of you, it sinks its teeth into your arm!"
user.hp -= 30
user.DeathTest(src)
sleep(30)
Grab()
mob/var/defitem=/obj/ZombieHurter
obj/ZombieHurter/var/damage=10


You defined the proc but never told it to start on spawn =\, try this instead.
In response to Spire8989
IT WORKS! But....:

runtime error: Cannot read null.hp
proc name: Grab (/mob/TEST/zombie/proc/Grab)
usr: Zombie (/mob/TEST/zombie)
src: Zombie (/mob/TEST/zombie)
call stack:
Zombie (/mob/TEST/zombie): Grab()
Zombie (/mob/TEST/zombie): New(the grass (4,24,1) (/turf/natural/grass))


:(
In response to Budboinker
I'm very much aware that this is an old post, but I'd like to clear one more thing up.

Using Art's edited code from above, shouldn't the proc automatically call when a user is within 1 square? If not, should I call it when the player moves, or when the zombie moves? Or what?
In response to Pakbaum
The process repeats itself every three seconds. I'd suggsest using it in Move(), with a check which will only perform the loop if someone is still near it.
e.g.
Grab(mob/Grabee)
...
sleep(Delay_Between_Each_Performance)
for(var/mob/m in oview(1))
Grab(m)
return
MOve()
...
for(var/mob/m in oview(1))
Grab(m)

In response to DivineO'peanut
:D Thanks! I'll try it now.