ID:523899
 
(See the best response by Albro1.)
Code:
mob
player
var/list/spamnumber // number of messages in last n seconds
var/list/spammax = list("40"=4, "20"=3) // "[time]"=max format

mob/verb
ooc(msg as text)
set src = usr
set name = "OOC" //Gave this shit a shorter name so you only have to time out "ooc" rather than "ooc message" to use it --NeoFite
set category = "Social"
if(length(msg) > 400) msg = copytext(msg, 1, 401)
if(!usr.spamnumber) usr.spamnumber = new
for(var/spamtime in usr.spammax)
if(++usr.spamnumber[spamtime] >= usr.spammax[spamtime])
world << "<I>[usr.name] was booted for spam.</I>"
del(usr)
return
spawn(text2num(spamtime))
--usr.spamnumber[spamtime]
if(!msg)
return
if (!src.client.listen_ooc)
return
// else if (src.muted)
// return
else if (findtext(msg, "byond://")/* && !src.client.holder*/)
src << "\red <B>Advertising other servers is not allowed.</B>"
// log_admin("[key_name(src)] has attempted to advertise in OOC.")
// message_admins("[key_name_admin(src)] has attempted to advertise in OOC.")
return
world << "\blue <b>[usr.name]</b> says in OOC, \"<b>[html_encode(msg)]</b>\""


Problem description:
DM tells me that my variables are undefined, when clearing they are defined in the players variable list. I'm just trying to make sure that I am safe from spammers making my game look worse than it currently does. Help?
Best response
It's because the verb is only under the /mob tree, while those vars are under the /mob/player tree. Inheritance works backwards, but never forwards.
Rewrote about a fourth of all the verb/usr codes in the game and it runs much more efficient. I don't know how but every time I find a minor bug, I end up making large changes.
Try not to swap between usr and src in your verbs, usr should be used here. You also should remove the return under if(++usr.spamnumber[spamtime] >= usr.spammax[spamtime]) as it doesn't doing anything.