ID:1177114
 
(See the best response by Super Saiyan X.)
Code:
proc
Scan()
while(1)
afkscanon = 1
sleep(600)//pick(18000,27000,36000))
if(afkoff == 0)
worldmute = 1
for(var/mob/M in world)
if(M.key)
if(M.afkchecksaver == 0)
M.AFK = 1
M.On_Afk()
afkverboff = 1
sleep(600)
for(var/mob/T in world)
if(T.key)
T.Off_Afk()
afkscanon = 0
afkverboff = 0
for(var/mob/N in world)
Jailer(N)

mob
proc
On_Afk(mob/M as mob)
if(M.afkchecksaver == 1)
winshow(M,"AFKON",1)
winset(M, "AFKON", "pos=24,46")
else
winshow(M,"AFKON",1)
winset(M, "AFKON", "pos=24,46")
winshow(M,"AFK",1)
winset(M, "AFK", "pos=256,256")
Off_Afk(mob/M as mob)
if(M.afkchecksaver == 1)
winshow(M,"AFKON",0)
winset(M, "AFKON", "pos=24,46")
else
winshow(M,"AFKON",0)
winset(M, "AFKON", "pos=24,46")
winshow(M,"AFK",0)
winset(M, "AFK", "pos=256,256")
worldmute = 0
world<< "<center><font size = 3><font color = red>OOC Has Been Unmuted"


im trying to make a afk scan for my game but at runtime i get the error: runtime error: Cannot read null.afkchecksaver
proc name: Off Afk (/mob/proc/Off_Afk)
source file: AFK System.dm,44
usr: null
src: Madhead88 (/mob/male1)
call stack:
Madhead88 (/mob/male1): Off Afk(null)
Scan()
: New()
any idea why it wont work?


Best response
It's because when you're calling Off_afk, and On_afk, you aren't providing an argument, so 'M' is null.

Rather, remove the argument in the definitions of those two procedures, and use 'src' instead of M. The procedure already has a reference to the thing you want to target, since it's called on that object.
So something like:
        On_Afk()
if(src.afkchecksaver == 1)
winshow(src,"AFKON",1)
winset(src, "AFKON", "pos=24,46")
//etc


Also, your Scan proc could be improved a bit, by looping through only things that are actually players.
proc
Scan()
while(1)
afkscanon = 1
sleep(600)//pick(18000,27000,36000))
if(!afkoff)
worldmute = 1
for(var/client/M)
if(M.mob.key)
if(!M.mob.afkchecksaver)
M.mob.AFK = 1
M.mob.On_Afk()
afkverboff = 1
sleep(600)
for(var/client/T)
if(T.mob.key)
T.mob.Off_Afk()
afkscanon = 0
afkverboff = 0
for(var/client/N)
Jailer(N.mob)


By looping through clients, instead of mobs, you only get results who are actually players. Then, to reference the client's mob, you just do client.mob, replacing client with whatever the loop variable is designated as.

It could probably improved a lot more...but that's still probably a big step up.
In response to Super Saiyan X
it worked :D , i will update the scan aswell, thanks alot