ID:144967
 
Code:
mob/combat
verb
Attack(mob/m in get_step(usr,usr.dir))
set category = "Combat"
if(usr.attack == 0 && ko==0) //if 0 it attacks if 1 it doesnt
var/Dmg = src.Strength/5+usr.Speed/m.Defense
if(src.Speed>m.Speed)
var/Dodge = prob(50)
if(Dodge)
Dmg = 0
view() << "<font color=red><i>[m] has dodged [src]'s attack!"
if(usr.Clan=="Normal")
usr.exp+=m.level/5
src.Levelup(usr)
if(usr.Clan=="Fighter")
usr.exp+=m.level/3
src.Levelup(usr)
if(Dmg<=0)
Dmg = 0
m.Health -= Dmg
src.kocheck(m)
view() << sound('punch1.wav',0)
usr.attack = 1
if(usr.Clan=="Normal")
usr.exp+=m.level/3
src.Levelup(usr)
if(usr.Clan=="Fighter")
usr.exp+=m.level/2
src.Levelup(usr)
m << "[src] is attacking you for [num2text(round(Dmg,1),7)] damage!"
src << "You attack [m] for [num2text(round(Dmg,1),7)] damage!"
if(Gomu_Gatling_Gun==1)
usr.attack = 0
if(ragemeter==100)
sleep(3)
usr.attack = 0
else
sleep(7)
usr.attack = 0

mob/var
attack = 0


mob/proc/kocheck(mob/m)
if(m.Health <= 0 && m.ko == 0)
usr << "You have KOd [m]"
m << "You've been beaten and have fallen to the ground"
m.ko=1
sleep(200)
m.ko=0


mob
verb
Kill(var/mob/m in oview(1))
if(m.ko==1)
src.deathcheck(m)


Problem description:

Everything goes well for awhile and I don't know exactly what the problem is. But while I'm attacking later on I get an error stating this:

runtime error: Cannot modify null.ko.
proc name: kocheck (/mob/proc/kocheck)
source file: Combat.dm,67
usr: Roronoa Zoro (/mob/PC)
src: Roronoa Zoro (/mob/PC)
call stack:
Roronoa Zoro (/mob/PC): kocheck(null)
Roronoa Zoro (/mob/PC): Attack(null)
runtime error: Cannot read null.level
proc name: Attack (/mob/combat/verb/Attack)
source file: Combat.dm,42
usr: Roronoa Zoro (/mob/PC)
src: Roronoa Zoro (/mob/PC)
call stack:
Roronoa Zoro (/mob/PC): Attack(null)
runtime error: Cannot modify null.ko.
proc name: kocheck (/mob/proc/kocheck)
source file: Combat.dm,67
usr: Roronoa Zoro (/mob/PC)
src: Roronoa Zoro (/mob/PC)
call stack:
Roronoa Zoro (/mob/PC): kocheck(null)
Roronoa Zoro (/mob/PC): Attack(null)
runtime error: Cannot read null.level
proc name: Attack (/mob/combat/verb/Attack)
source file: Combat.dm,42
runtime error: Cannot modify null.ko.
proc name: kocheck (/mob/proc/kocheck)
source file: Combat.dm,67
runtime error: Cannot read null.level
proc name: Attack (/mob/combat/verb/Attack)
source file: Combat.dm,42
runtime error: Cannot modify null.ko.
proc name: kocheck (/mob/proc/kocheck)
source file: Combat.dm,67
runtime error: Cannot read null.level
proc name: Attack (/mob/combat/verb/Attack)
source file: Combat.dm,42
runtime error: Cannot modify null.ko.
proc name: kocheck (/mob/proc/kocheck)
source file: Combat.dm,67
runtime error: Cannot read null.level
proc name: Attack (/mob/combat/verb/Attack)
source file: Combat.dm,42

runtime error: Cannot modify null.ko.
proc name: kocheck (/mob/proc/kocheck)
source file: Combat.dm,67
runtime error: Cannot read null.level
proc name: Attack (/mob/combat/verb/Attack)
source file: Combat.dm,42
runtime error: Cannot modify null.ko.
proc name: kocheck (/mob/proc/kocheck)
source file: Combat.dm,67
runtime error: Cannot read null.level
proc name: Attack (/mob/combat/verb/Attack)
source file: Combat.dm,42



This wasn't happening until I added that small KO system so I am guessing it has something to do with that. Please help me if you can.
Make sure you add safety checks

What that error is saying is that 'm' is null, meaning no mob

so add this before anything else (well, except after set...but you know what I mean)
if(!m)return //stops the verb from happening if m is FALSE (eg: null)


- GhostAnime


PS: Learn about Boolean shortcuts

if, let's say you put KO=null somewhere,than KO==0 will NOT happen but !KO will [read it to see what I mean]
In response to GhostAnime
Thanks but now I am getting an error stating that if(!m)return is an invalid expression.
In response to Charlesg154
space the "return"? (Its 1:04 AM :D)
In response to Mechanios
lol thanks but even still.
In response to Charlesg154
Please show us where/how you entered it

BTW, found one error:
    if(Dmg<=0)
Dmg = 0
m.Health -= Dmg


You want to indent Dmg=0

- GhostAnime
One thing you need to fix is your Levelup() proc, which is obviously backwards. Such a proc should never ever take an argument, because there's no foreseeable case where it would need to know more than who is (potentially) leveling up. Also, that proc should always belong to the player leveling, not the person they killed, hence it's backwards. The way you should be calling it from that verb is:
usr.Levelup()

Since usr's experience is going up, they're the one who should be src within the Levelup() proc.

Your deathcheck() proc is backwards as well, for the same reason. From mob/Kill() you're calling src.deathcheck(m), where m is the target. Totally wrong. In deathcheck(), the victim must always be src inside that proc, and the argument must be the killer (if it needs that information). So that should be m.deathcheck(src) instead.

kocheck() has similar problems, and it also has usr abuse. Get usr out of there, and fix the proc. src must be the victim, m the person who knocked them out.

Lummox JR
In response to GhostAnime
mob/combat
verb
Attack(mob/m in get_step(usr,usr.dir))
set category = "Combat"
if(!m)return //stops the verb from happening if m is FALSE (eg: null)
if(usr.attack == 0 && m.ko==0)
var/Dmg = src.Strength/5+usr.Speed/m.Defense
if(src.Speed>m.Speed)
var/Dodge = prob(50)
if(Dodge)
Dmg = 0
view() << "<font color=red><i>[m] has dodged [src]'s attack!"
if(usr.Clan=="Normal")
usr.exp+=m.level/5
src.Levelup(usr)
if(usr.Clan=="Fighter")
usr.exp+=m.level/3
src.Levelup(usr)
if(Dmg<=0)
Dmg = 0
m.Health -= Dmg
src.kocheck(m)
view() << sound('punch1.wav',0)
usr.attack = 1
if(usr.Clan=="Normal")
usr.exp+=m.level/3
src.Levelup(usr)
if(usr.Clan=="Fighter")
usr.exp+=m.level/2
src.Levelup(usr)
m << "[src] is attacking you for [num2text(round(Dmg,1),7)] damage!"
src << "You attack [m] for [num2text(round(Dmg,1),7)] damage!"
if(Gomu_Gatling_Gun==1)
usr.attack = 0
if(ragemeter==100)
sleep(3)
usr.attack = 0
else
sleep(7)
usr.attack = 0

mob/var
attack = 0


That's the updated one, the error is actually coming from
                if(usr.attack == 0 && m.ko==0)
In response to Charlesg154
Try unindenting everything after "if(!m) return" by 1.
In response to Lummox JR
Thanks I kind of feel embarrased after all those errors you listed ^_^;;.
In response to Lummox JR
Ok I think all the other stuff is now fixed thanks to your help o.o. However I am now having problems with the kill verb. It simply won't work.
mob
verb
Kill(var/mob/m in oview(1))
set category="Combat"
if(src.ko==1)
m.deathcheck(src)





mob/proc/deathcheck(mob/m)
if(src.Health <= 0)
m << "You killed [src]"
src << "You die"
new /obj/corpse(src.loc,src,"corpse")
src.icon_state=""
src.Spwn()
src.Health = src.MaxHealth
src.Deaths++
m.kills++
m.exp+=src.level*5
m.Levelup()
m.Bounty+=src.Bounty/2
if(src.Baddy==1)
del(src)
In response to Charlesg154
Do you actually change the KO var?

If you don't, there's your problem.
In response to RedlineM203
yes in changes during the ko check proc.