ID:262157
 
For some reason, people tend to complain that they can't hit anything in my game. I looked into this more closely and found this out as a runtime error:
runtime error: Cannot read null.exphit proc name: Attack (/mob/verb/Attack) source file: Attack And Equip System.dm,110 usr: \[Owner... (/mob/players/Knight) src: \[Owner... (/mob/players/Knight) call stack: \[Owner... (/mob/players/Knight): Attack()

This runtime error prevents players to actually hit their target, but the icon still does the attack animation. Here's my Attack verb that covers line 110. (W/O the attack animation code)
mob
verb
Attack()
if(usr.attacking == 0)
var/obj/K = new/obj/Weapons
usr.attacking = 1
K.dir = usr.dir
K.loc = usr.loc
step(K, dir)
var/turf/X = K.loc
spawn(3)
del(K)
for(var/mob/M as mob in X)
if(M == src)
if(M.pvp == 0)
usr << "<font size=1>They are not PK!"
return
else
continue
var/damage = rand(1,usr.attack-10+usr.attackadd-M.defense+10+M.defadd)
if(damage <= 0)
damage = 1
M.killlist += usr.name
if(prob(70))
var/num = damage
s_damage(M, num, "red")
usr.exp += M.exphit
levelup()
M.health -= damage
if(M.health <= 0)
levelup()
Death(M)
if(prob(10))
var/num = damage*2
s_damage(M, num, "red")
usr.exp += M.exphit // <--- Right here is line 110
levelup()
M.health -= damage*2
if(M.health <= 0)
levelup()
Death(M)
else
sleep(7)
usr.attacking = 0


It's kinda hard to reproduce the problem kind of, as the production of the runtime error is pretty random. Anyone have any fixes/suggestions?
According to that runtime, Exphit is null, and it can't subtract a null value, so your going to have to set exphit to something. (Thats what it seems like.)
Mega fart cannon wrote:
For some reason, people tend to complain that they can't hit anything in my game. I looked into this more closely and found this out as a runtime error:
<code> > runtime error: Cannot read null.exphit > proc name: Attack (/mob/verb/Attack) > source file: Attack And Equip System.dm,110 > usr: \[Owner... (/mob/players/Knight) > src: \[Owner... (/mob/players/Knight) > call stack: > \[Owner... (/mob/players/Knight): Attack() > </CODE>

It's kinda hard to reproduce the problem kind of, as the production of the runtime error is pretty random. Anyone have any fixes/suggestions?

The mob they're attacking is probably already dead. if(prob(70)) succeeded, and the enemy mob was attacked. The enemy mob died. After that if(prob(10)) also succeded. Unfortunately, M is already dead and gone.
In response to Lenox
Lenox wrote:
According to that runtime, Exphit is null, and it can't subtract a null value, so your going to have to set exphit to something. (Thats what it seems like.)

<code> runtime error: Cannot read null.exphit </CODE>

The runtime is saying that it can't read null.exphit
The object that is being accessed is null. In this case, it's M, a mob.
In response to Jon88
Jon88 wrote:
The mob they're attacking is probably already dead. if(prob(70)) succeeded, and the enemy mob was attacked. The enemy mob died. After that if(prob(10)) also succeded. Unfortunately, M is already dead and gone.

To fix this, you're going to need to add an if expression check to make sure that M is still alive.
In response to Wizkidd0123
Do I have to make an if expression or can for() work also?
In response to Mega fart cannon
Mega fart cannon wrote:
Do I have to make an if expression or can for() work also?

You're going to need an if().
for(var/A in MyList) statement
, as you're using it, means that it will loop through everything in MyList, and everytime it finds an element which matches A in that list, it will execute statement. So,
for(mob/M in world) M << "You are a mob."

means that for evrey single mob in the world, it will tell each mob: "You are a mob.".
In response to Wizkidd0123
Ah. It's fixed now. Thanks for all your help!
You should take another look at your Death() proc and how it's called, because right now you're doing it backwards. Death() should always be the responsibility of the mob that dies, and it should be sent the killer as an argument. Right now you've got src as the killer and the argument (M) as the victim. A correct DeathCheck() proc looks like this:
mob/proc/DeathCheck(mob/killer)

Lummox JR