ID:261424
 
When I click the attack turf I get a huge runtime error. I can't figure out whats wrong. Please Help

turf
Battleverbs
icon = 'Attack.dmi'
name = ""
Attack
icon_state = "Attack"
name = "Click To Attack Monster"
Click(mob/NPC/Monster/Rat/M)
sleep(1)
usr.loc = locate(8,145,1)
sleep(1)
usr.loc = locate(7,145,1)
sleep(8)
usr.loc = locate(8,145,1)
sleep(1)
usr.loc = locate(9,145,1)
M.HPnpc -= rand(1,3)


Thanks,
Little Sally
What runtime error do you get?
In response to Nadrew
runtime error: undefined variable /turf/Battleverbs/Attack/var/HPnpc
proc name: Click (/turf/Battleverbs/Attack/Click)
source file: Attack.dm,31
usr: GM Little Sally (/mob/PC)
src: Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack)
call stack:
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): Click(Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack))
In response to Little Sally
Ah I see. I think you need to handle attacking through the Click() of the certain mob you want to attack.

mob
NPC//or whatever you call it
icon = 'blah.dmi'
Click()
//rest of attack stuff here


Passing the type into the Click() proc of the turf doesn't tell the system you're clicking on that mob, it just points it to that type when you click the turf.
In response to Nadrew
Mmm, you're Click() proc is telling the turf that it is being clicked on by a mob/NPC/Monster/Whatever, and to move the user, then remove health from the thing that clicked on it. (However, since the user most likely is not a /mob/NPC/Monster/Whatever, it doesn't have the expected variable, so it's returning an error)

If that makes sense.
In response to Nadrew
Thank you I now know what to do. I was also woundering if there was a way to have it affect any mob stadning in a certain location. Like it I was to click an attack button it would move my mob and then no mater what mob was standing in the defined location it would subtract hitpoints from it.
In response to Foomer
Yes it does make sense.
In response to Little Sally
I tryed applying the Click() to the npc and it did that same thing... :(
In response to Little Sally
Just use something like this:

for(var/mob/M in locate(16,2,4)) // that being the coords you want.
// Make stuff happen to M
In response to Little Sally
I think Im getting farther but im geeting another runtime error.If there is another way to have a turf perform this action please let me know ;P Thank You :)

-------Code----------

turf
Battleverbs
icon = 'Attack.dmi'
name = ""
Attack
icon_state = "Attack"
name = "Click To Attack Monster"
Click()
sleep(1)
usr.loc = locate(8,145,1)
sleep(1)
usr.loc = locate(7,145,1)
sleep(8)
usr.loc = locate(8,145,1)
sleep(1)
usr.loc = locate(9,145,1)
for(var/mob/NPC/Monster/Rat/M in locate(5,145,1))
M.HPnpc -= rand(1,3)
usr <<"You attacked!"
M:npcdeathcheck()



------------------Runtime Error----------------

runtime error: Cannot read null.HPnpc
proc name: npcdeathcheck (/mob/NPC/Monster/Rat/proc/npcdeathcheck)
source file: NPC.dm,168
usr: GM Little Sally (/mob/PC)
src: Rat (/mob/NPC/Monster/Rat)
call stack:
Rat (/mob/NPC/Monster/Rat): npcdeathcheck(null)
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): Click(Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack))
In response to Little Sally
I believe it's saying that the error is in your npcdeathcheck() proc, not in the code you showed here.
In response to Foomer
This is the npcdeathcheck code...

mob
NPC
proc
deathchecknpc()
if(src.HP <= 0)
view() << "[src] dies!"
del(src)