ID:164936
 
I'm the host to my game, and whenever a mob is killed by someone macro'ing, I get spammed by runtime errors. I've been wondering, is there a way to disable people from macro'ing certain verbs?
There are ways... but really, you (or whoever is programming) should be fixing up those runtime errors as they will eventually cause the server to crash.

We are here to help you (note: help, not spoonfeed) if you do not understand why a particular error is happening :)

- GhostAnime
In response to GhostAnime
Ah. Well, I'm not really sure how to get around the runtime error problem, here's a paste of it:

runtime error: Cannot read null.defense
proc name: Attack (/mob/verb/Attack)
source file: KingdomBuild.dm,1536
(I get this when I macro kill them)

And:
runtime error: Cannot read null.defense
proc name: New (/Frogs/Normal/New)
source file: ENEMIES.dm,142
usr: Frog (/Frogs/Normal)
src: Frog (/Frogs/Normal)
call stack:
Frog (/Frogs/Normal): New(DGrass (422,72,1) (/turf/DGrass))
(I get this when other people macro kill them)

I'll paste my attack code if necessary. Don't think I'm asking you to give me code, I just really need to know HOW to do it, and I'll fix it. ^_^

I know the first part of the error has to do with them being dead and you trying to attack a non-existant frog, I'm just not sure how to keep this from happening.
In response to Michael3131
You're trying to modify or access the the defense variable of something that isn't created. You must be defining a variable but never actually creating it.
proc/x()
var/mob/m
world << m.loc

That code would cause an error because x is never actually created.

proc/x()
var/mob/m = new
world << m.loc

This code would work because there's actually something to reference, so you can see where it's location is.
In response to Michael3131
How macros work, is that they rapidly send the same command when the button is <s>pressed</s> (well, held down). Now, of course, the client is limited in how many commands it can send, so if it passes the limit, the commands are queued up and sent later. The mob used may not exist anymore however, therefore you will get a runtime error. You solve this by simply checking if the mob still exists in the beginning:
mob/verb/attack(mob/M as mob in oview())
if(!M) return
In response to Michael3131
At least you understand the problem, it is because what they are trying to attack does not exist (via del most likely).

The best way to stop this type of error from happening is to safety check... by that, make it check if the attacked mob exists and if it doesn't, stop the rest of the code from happening:
mob/verb/attack(mob/M in view())
if(!M) return //If M does not exist, it stops the rest from happening
M.die()


- GhostAnime
In response to Popisfizzy
Ah! I see what your saying. The problem is though, it happens after you kill a frog. After you do, they are deleted, which causes the reading of a non-existant variable. I'll try to make a check to see if a frog is within 1 tile of you, and if so, execute the attack code. Thanks for the help, I'll repost if I have any problems,

Mike
In response to Michael3131
Gah, I can't get it to work. I'm getting this bug:
runtime error: Cannot read null.defense
proc name: New (/Frogs/Normal/New)
source file: ENEMIES.dm,142
usr: Frog (/Frogs/Normal)
src: Frog (/Frogs/Normal)
call stack:
Frog (/Frogs/Normal): New(DGrass (435,3,1) (/turf/DGrass))

Here's my attack code:

verb/Attack(mob/M in oview(1))
if(!M) return
var/damage = src.strength - M.defense
if(M.AFK==1)
usr<<"You can't attack AFK people!"
if(usr.canattack==1)
if(M.client)
M.hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked for [damage] by [src]!"
src.level_up()
M.death_check(src)
canattack = 0
sleep(10)
canattack = 1
else
M.hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked for [damage] by [src]!"
var/random = rand(1,3)
if(random == 1)
src.exp += 4
if(random == 2)
src.exp += 3
if(random == 3)
src.exp ++
src.level_up()
M.death_check(src)
canattack = 0
sleep(10)
canattack = 1


Sorry for all the trouble. I feel like an idiot not being able to fix this.
In response to Michael3131
The error doesn't have to do with your Attack() verb, but with the frog's New(), as shown by the error. I assume it is called by deathcheck() or levelcheck().
Post the relevant code.
In response to Kaioken
Found the problem! I believe the frog's 'macro' attack, or stack them. When they die, they have left over verbs they try to run, and it causes bugs!

I was right. That was the problem. I fixed it by adding the:

if(!M) return

Ya'll said to add to Attack. ^_^

Thanks for all the help everyone!