ID:268657
 
mob
proc
Ban(mob/M as mob in world)
switch(alert("Do you really want to ban [M]?","Ban","Ban","Quit"))
if("Ban")
if((Admins.Find(M.key)))
src<<"Cant ban admins!"
text2file("<br>[time2text(world.realtime, "Day, Month DD, YYYY \[hh:mm:ss\]")]:<font color = red><B>[src] tried to ban the admin [M]","Log.html")
world << "<font color =red><b>[src] has just banned [M]."
text2file("<br>[time2text(world.realtime, "Day, Month DD, YYYY \[hh:mm:ss\]")]:<font color = red><B>[src] bans Name [M]/ Key [M.key]/ IP [src.client.address]","Log.html")
crban_fullban(M)
del(M)


K, i used spell check to make my spelling better because smoko complained! I need it to work heres the error i get

runtime error: Cannot read null.key
proc name: Ban (/mob/proc/Ban)
source file: Game Administer.dm,65
usr: VV (/mob/Player)
src: VV (/mob/Player)
call stack:
VV (/mob/Player): Ban(null)


line 55 is if((Admins.Find(M.key))) please help me

Well, first I see a few issues that aren't pressing but should be addressed.

You don't need mob/M as mob in world, just use mob/M in world. Secondly, don't use HTML documents for logs. I learned my lesson with that a while ago when I downloaded a 1MB logfile with only a handful of lines in it.

Now, on to your problem. It's easy to see that the mob/M you selected doesn't exist or wasn't defined, as dictated by this line in your runtime error:

Ban(null)

This is also something I learned about many runtimes later; perform sanity checks after any and every operation that sleeps the proc, to make sure the target is still there.

mob
proc
Ban(mob/M in world)
switch(alert("Do you really want to ban [M]?","Ban","Ban","Quit"))
if(!M) return //Make sure M is still there!
if("Ban")
if((Admins.Find(M.key)))
src<<"Cant ban admins!"
//etc...

Since the switch statement sleps the proc, the target M may log out, be booted, deleted etc. in the time it takes the person using the verb to select "Ban".

Which brings up another issue... Are you trying to use this as a verb? Procs do not prompt you for an argument as verbs do, they assume that you will give them a value to work with, in this case a mob. If you meant to use this as a proc, you're going about it wrong... you need a variable supplied by the user to go through this proc.

mob
verb
Ban_Player(mob/M in world)
src.Ban(M)
proc
Ban(mob/M)
switch(alert("Do you really want to ban [M]?","Ban","Ban","Quit"))
if(!M) return //Make sure M is still there!
if("Ban")
if((Admins.Find(M.key)))
src<<"Cant ban admins!"
//etc...

If you don't want to do that, just change proc to verb:

mob
verb
Ban(mob/M in world)
switch(alert("Do you really want to ban [M]?","Ban","Ban","Quit"))
if(!M) return //Make sure M is still there!
if("Ban")
if((Admins.Find(M.key)))
src<<"Cant ban admins!"
//etc...
In response to Mobius Evalon
Same problem.
In response to Vash_616
Well what are you trying to ban? an actual person with a client or a NPC?
In response to Wanabe
a client/person the reason its a proc because im doing something similar to [link]
Clearly M is null when this runtime error occurs, since it's the only place something.key is used in that proc.

A source of grief for you here is that you're taking M from an argument, by which I take it you intend to use this proc as a verb by adding it to src.verbs. Choosing M from any mob in the world isn't nearly as good as choosing it from a proc, though.
proc/Kick(mob/M as mob in players)
if(!M) return

If you have a global players list, this makes a lot of sense; it ignores any NPCs completely.

Notice I changed this to Kick(). That's because there's another hidden pitfall here. With Kick(), you'd always be acting on a live user. However with Ban(), you should give your admins the ability to ban after the fact, to deal with trolls that are logging in and out and in and out. That requires text.
/*
Create a global list:
var/list/keys_this_session = new

Use association when a client logs in to record their IP address in this list.

keys_this_session[client.key] = client.address
*/

proc/Ban(k in keys_this_session)
if(!k) return
if(k in Admins) return
// always always always close your HTML tags
world << "<b style="color:red">[name] has just banned [k].</b>"
LogAdminAction("[name] bans Key [k]/ IP [keys_this_session[k]]")
banned_keys += k
SaveAdmin() // save changes to the ban list
// IP address lists should not be saved; make them session-only
banned_ips += keys_this_session[k]

Note I added a new proc in there, LogAdminAction(), that keeps you from having to use that text2file() line constantly. Here's what it would look like:
proc/LogAdminAction(msg)
text2file("<br />[time2text(world.realtime, "Day, Month DD, YYYY")] \
[time2text(world.timeofday, "\[hh:mm:ss\]")]: \
[msg]",\
"Log.html")

Also I should point out your earlier Ban() proc had a minor bug: You were reporting the admin's IP address in the log, not the bannee's.

Lummox JR
In response to Vash_616
Ok one last thing, how would i do this for mute as well?
In response to Vash_616
Ok i have this so far and i turned it into verb

mob
verb
Ban_Player(mob/M as mob in world)
set hidden=1
if (alert(src,"Do you really want to ban [M]?","Really ban?","Ban","Cancel")=="Ban")
if("Ban")
if((Admins.Find(M.key)))
src<<"Cant ban admins!"
crban_fullban(M)
world << "<font color =red><b>[src] has just banned [M]."
del(M)


Still getting same error
In response to Vash_616
Your main mistake was putting parenthesis in the wrong place. the correct line is
if(Admins.Find(M.key))

There were also other mistakes that would have have compiled but wouldn't have worked the way you wanted them to(ie: In your version, you could ban admins). Also, the if(Ban) after your alert was redunatant and unnecessary since you had a =="Ban" in the line above.
mob
verb
Ban_Player(mob/M in world)//This line works just as well and better.
if(alert(src,"Do you really want to ban [M]?","Ban","Ban","Cancel")=="Ban")
if(Admins.Find(M.key))// Removed a right paren. -- That was cauing the error.
src<<"Cant ban admins!"
return 0//Added this line. You could have banned Admins w/o it.
crban_fullban(M)
world << "<font color=red><b>[src] has just banned [M].</b></font color=red>"//ALWAYS close HTML tags.
del(M)//This line only delete's M's mob.
del(M.client)//This deletes M's actual self.
In response to Wizkidd0123
Wizkidd0123 wrote:
del(M)//This line only delete's M's mob.
del(M.client)//This deletes M's actual self.

This second line is redundant, as deleting a mob with a connected client will also disconnect that client. In fact, you'll get a runtime error on that line because by then, M is null, and the client itself would be null too.

You should also start putting some tabs and/or spaces before // comments to separate them from the code. Don't butt them up against each other like that, because it just makes them hard to read for no reason.

Lummox JR