ID:142321
 
Code:
mob
verb
Attack()
set category = "Battle"
if(attack == 1)
for(var/mob/M in get_step(src,src.dir))
if(M.key == usr.key) continue
if(M.defensive == 0)
view() << "[usr] attacks [M]!"
M.Health -= Strength
Attack_Delay()
AttackGain()
M.attacked = 1
M.Attacked_Gain()
else
return
proc
AttackGain()
if(Strength <= 150*(StrMod))
StrEXP += (StrMod*rand(1,5))/StrLvl
if(StrEXP >= 100)
StrEXP -= 100
Strength += rand(1,5)*StrMod
StrLvl += 1
usr << "<font size = 4><font color = green>Your strength has gone up!</font>"
else if(Strength <= 300*(StrMod))
StrEXP += (StrMod*rand(1,5))/(StrLvl/2)
if(StrEXP >= 100)
StrEXP -= 100
Strength += rand(1,4)*StrMod
StrLvl += 1
usr << "<font size = 4><font color = green>Your strength has gone up!</font>"
else if(usr.Strength <= 600*(usr.StrMod))
StrEXP += (StrMod*rand(1,5))/(StrLvl/3)
if(StrEXP >= 100)
StrEXP -= 100
Strength += rand(1,3)*StrMod
else if(usr.Strength <= 1200*(StrMod))
usr.StrEXP += (usr.StrMod*rand(1,5))/(usr.StrLvl/4)
if(usr.StrEXP >= 100)
usr.StrEXP -= 100
usr.Strength += rand(1,2)*StrMod
else
return

Attacked_Gain()
if(Endurance <= 150*(EndMod) && attacked == 1)
EndEXP += (EndMod*rand(1,5))/EndLvl
if(EndEXP >= 100)
EndEXP -= 100
Endurance += rand(1,5)*EndMod
EndLvl += 1
usr << "<font size = 4><font color = green>Your endurance has gone up!</font>"
else if(Endurance >= 300*(EndMod) && attacked == 1)
EndEXP += (EndMod*rand(1,5))/(EndLvl/2)
if(EndEXP >= 100)
EndEXP -= 100
Endurance += rand(1,4)*EndMod
EndLvl += 1
usr << "<font size = 4><font color = green>Your endurance has gone up!</font>"
else if(Endurance >= 600*(EndMod) && attacked == 1)
EndEXP += (EndMod*rand(1,5))/(EndLvl/3)
if(EndEXP >= 100)
EndEXP -= 100
Endurance += rand(1,3)*src.EndMod
EndLvl += 1
usr << "<font size = 4><font color = green>Your endurance has gone up!</font>"
else if(Endurance >= 1200*(EndMod) && attacked == 1)
EndEXP += (EndMod*rand(1,5))/(EndLvl/4)
if(EndEXP >= 100)
EndEXP -= 100
Endurance += rand(1,2)*EndMod
EndLvl += 1
usr << "<font size = 4><font color = green>Your endurance has gone up!</font>"
else
return
if(Health <= 150*(src.HealthMod) && attacked == 1)
HealthEXP +=(HealthMod*rand(1,5))/HealthLvl
attacked = 0
if(HealthEXP >= 100)
HealthEXP -= 100
Health += rand(10,50)*HealthMod
HealthLvl += 1
else if(Health >= 300*(HealthMod) && attacked == 1)
HealthEXP +=(HealthMod*rand(1,5))/(HealthLvl/2)
attacked = 0
if(HealthEXP >= 100)
HealthEXP -= 100
Health += rand(10,40)*HealthMod
HealthLvl += 1
else if(Health >= 600*(HealthMod) && attacked == 1)
HealthEXP +=(HealthMod*rand(1,5))/(HealthLvl/3)
attacked = 0
if(HealthEXP >= 100)
HealthEXP -= 100
Health += rand(10,30)*HealthMod
HealthLvl += 1
else if(Health >= 1200*(HealthMod) && attacked == 1)
HealthEXP +=(HealthMod*rand(1,5))/(HealthLvl/4)
attacked = 0
if(HealthEXP >= 100)
HealthEXP -= 100
Health += rand(10,20)*HealthMod
HealthLvl += 1

else
return


Problem description: The code is supposed to attack whatever is in front of it, and then add some stats to the attacker and the attacked person. However, when I try to run it, I get a runtime error. The run-time error is below.

runtime error: Undefined operation: null / null
proc name: Attacked Gain (/mob/proc/Attacked_Gain)
usr: XeroXen (/mob)
src: the mob (/mob)
call stack:
the mob (/mob): Attacked Gain()
XeroXen (/mob): Attack()
XeroXen attacks the mob!

Apparantly, the mob I'm attacking still loses HP, and I'm unsure if the other mob's stats go up either. But I know my Strength stat still goes up as normal.

Also, a second run-time error began appearing, after a while.

runtime error: Undefined operation: null / null
proc name: Attacked Gain (/mob/proc/Attacked_Gain)


Adding if(M) before doing the operations should fix it.
In response to Andre-g1
Nope, I still have the same problem.
...You have everything backwards. You should be using usr in the verbs, and you also shouldn't use usr in procs.
In response to Jeff8500
Jeff8500 wrote:
...You have everything backwards.

Seems to me that rather, he has everything mixed, I only skimmed it, though.

You should be using usr in the verbs, and you also shouldn't use usr in procs.

But using 'src' instead of 'usr' in mob/verbs is perfectly valid. In those kind of verbs, by default, usr == src, and it is actually better to use the latter.
I'm guessing either one or all of your Mod/Lvl variables are null.
(EndMod*rand(1,5))/EndLvl
(null  *rand(1,5))/null            null*rand(1,5)=null
(      null      )/null
              null/null

Undefined operation: null / null


Give them a value, and keep in mind that you can't divide by zero either.