ID:1291933
 
(See the best response by Super Saiyan X.)
Code:
mob/Admin/RuleEnforcer1
verb
Warn(client/C in world)
set category = "Admin"
if(!C) return
switch(alert("Are you sure you want to warn [C.key]?","Warn [C]","Yes","No"))
if("No") return
if("Yes")
var/Warn=input("Include What In The Warning? (Admin Warning: \[Warning\])")
C << "<font color=red>Admin Warning: </font>[Warn] ~ [usr.key]"
AdminLog("Warn","[Warn]",C)
AdminMessage("[usr] Warned [C]: [Warn].")
return


Problem description: So what I am trying to do is pretty obvious: make a warning verb to well, warn them. However, when I test run this verb with multiple players, the verb only recognizes the first person to log in to the game, not all of the players in the world. I have it set up for client/C so that it won't loop through the rest of the NPCs, but I am not sure if that is the correct way to do so. I have also tried mob/PC/P in world, which have the same results. Any help will be much appreciated. Thanks!

Best response
For one, clients do not exist in the world. Either you'd do it that:
1. as an input() in the actual contents of the proc; or
2. you create your own list to store clients upon connection, and remove them when they leave, and use that list in place of world, in the verb definition.
3. create a procedure to generate a list, and call that procedure in place of world, in the verb definition.

Secondly, you don't need that switch statement, it could be simplified to:
if(alert("Are you sure you want to warn [C.key]?","Warn [C]","Yes","No")=="Yes")
var/Warn=//etc

You also do not need the return at the end of your proc.


Can you provide a screenshot of what the prompt for players you get looks like? "client/C in world" would actually generate a list of every object in the world, because it does not recognize client as a valid type (verb arguments must be atomic or have no type). Your exact code (minus the three last lines) gives me this:
I see, that makes sense, I have always had problems with simplification, as I am not completely comfortable with it yet. As for the picture, this is what comes up.

http://i44.tinypic.com/33c4swp.jpg

I'm just messing around coding see where my imagination takes me, so I don't really have anything but the verbs lol.



Sorry for the late reply, I had to go out on an urgent matter, but I'll let you know how the results work. Thanks!

It's fine. That's what a forum is for, it's not a live chat.

I'm assuming yours automatically chooses one, because there are no other objects in the world (not even another mob from a player, like you said...?), but that's not important.

Just be sure to have a list of clients (either generate one each time via a proc, or keep a list) which you can choose from.
I think when you put Client/C it finds the person with the name that starts with a C try Client in world maybe it might work?
In response to BoyDolphin
BoyDolphin wrote:
I think when you put Client/C it finds the person with the name that starts with a C try Client in world maybe it might work?

no.
go home.
you're drunk.
I ended up doing this

mob/Admin/RuleEnforcer1
verb
Warn()
set category = "Admin"
var/list/warnlist = list()
for(var/mob/m in world)
m.name=m.key
if(!m.client) continue
// if(m.key != usr.key)
warnlist.Add(m)
var/mob/M = input("Who will you warn?","Warn") as null | anything in warnlist
if(!M) return
if(alert("Are you sure you want to warn [M.key]?","Warn [M]","Yes","No")=="Yes")
var/Warn=input("Include What In The Warning? (Admin Warning: \[Warning\])")
M << "<font color=red>Admin Warning: </font>[Warn] ~ [usr.key]"
AdminLog("Warn","[Warn]",M)
AdminMessage("[usr] Warned [M]: [Warn].")


and it works perfectly fine. Any suggestions on improving the syntax are greatly appreciated lol.


@BoyDolphin, lol......
If you're doing it inside of the proc, you CAN loop through just clients (with some simplifications) like so:

//bleh
mob/Admin/RuleEnforcer1
verb
Warn()
set category = "Admin"
var/list/warnlist = list()
for(var/client/C) //notice, no world!
warnlist += C
var/client/M = input("Who will you warn?","Warn") as null | anything in warnlist
if(M && \
alert("Are you sure you want to warn [M]?","Warn [M]","Yes","No")=="Yes")
//etc


I don't think you really care if you use the mob or client for the warning display?
If you use the client, it'll always show the key.
I see, that makes sense. I am planning on eventually doing something with the source, depends on the ideas I get, so it would be nice to have the names of the players instead of the keys. So I guess looping through the mobs would be more beneficial on my part.

Thanks for all the help!
If you want to display mob names; all you do is M.mob, rather than just M. (M being the client, in this case)

clients and mobs have this circular referencing thing.
Oh awesome!

That's a great deal of help, thank you very much for all your help :)