ID:1535656
 
(See the best response by Koshigia.)
Code:
mob
verb
Arena(mob/M in world)


Problem description: I'm trying to find a replacement for mob/M in world so that I can have it only show the clients currently on the server. I can't use client because it won't recognize the mob vars. Any ideas?

Best response
Well, here's one option

mob
verb
Arena()
var/list/players = new
for(var/mob/M in world)
if(M.client) players.Add(M)
...


or, if you are already keeping track of a list of clients elsewhere...


var/list/players = new

client/New()
..()
players.Add(src)


client/Del()
players.Remove(src)
..()

mob/verb/Arena(client/C in players)
var/mob/M = C.mob
of course, you don't even need var/mob/M as long as you're ok with using C.mob. For instance, if your mobs have a variable called hp....

C.mob.hp = C.mob.max_hp
Koshigia is right, you can do something like this:

mob
verb
Arena(client/C in world)
if(!C)return
var/mob/M=C.mob
//you can now do M.VARIABLE = "" or such.

//or you can just do C.mob.VARIABLE = "" or such.
Your first method automatically invited every mob in the server to the arena, I don't know if I improperly wrote it, or what.
In response to Ssj4justdale
Ssj4justdale wrote:
Koshigia is right, you can do something like this:

> mob
> verb
> Arena(client/C in world)
> if(!C)return
> var/mob/M=C.mob
> //you can now do M.VARIABLE = "" or such.
>
> //or you can just do C.mob.VARIABLE = "" or such.
>


Just tried this. Literally everything was on the list, including turfs and objects.
In response to Micdogmic
Micdogmic wrote:
Ssj4justdale wrote:
Koshigia is right, you can do something like this:

> > mob
> > verb
> > Arena(client/C in world)
> > if(!C)return
> > var/mob/M=C.mob
> > //you can now do M.VARIABLE = "" or such.
> >
> > //or you can just do C.mob.VARIABLE = "" or such.
> >

Just tried this. Literally everything was on the list, including turfs and objects.


Hmm? well then just use Koshigia's "player list" method, it definitely will get the job done.
Thanks guys, the 2nd one of Koshigia's methods worked.
In response to Micdogmic
Hold on, I'm gonna test that first method out myself. You mind copying and pasting your implementation?
In response to Koshigia
Koshigia wrote:
Hold on, I'm gonna test that first method out myself. You mind copying and pasting your implementation?

var/list/players = new

client/New()
..()
players.Add(src)

client/Del()
players.Remove(src)
..()

mob
verb
Arena(client/C in players)
set category = "Commands"
var/mob/M=C.mob
usr.arenamenuopen = 1


This is what I'm currently using, I don't have your first method anymore. Sorry.
In response to Micdogmic
So, finding a client in world is not as straightforward as finding lets say a mob.

This will not work,
verb/test(client/c in world)


Provided you have a players list populated with clients, this will
verb/test(client/c in players)


I guess it's just that clients are not automatically added to world so you gotta find another way of addressing them.
In response to Micdogmic
Well, at any rate... in my opinion the second method would have been the preferred method, anyhow. I should've made that clear from the get go xD
client can't be used by the standard "in world" as clients aren't in world.

To use a list of clients (that isn't predefined) you would want to generate it on the fly instead by using for(var/client/c), which cycles though connected clients.

You may then use this custom proc as the list that you're offering for the verb to select from.

To go further, you can add them mobs instead, providing the op with the functionality that he wants.

world
proc
clients()
. = list()
for(var/client/c)
. += c
. += "null for testing"
clientmobs()
. = list()
for(var/client/c)

if(c.mob) . += c.mob
. += "null for testing"

mob/verb/client_input_test(c in world.clients())
world << "Selected: [c]"
mob/verb/clientmob_input_test(c in world.clientmobs())
world << "Selected: [c]"