ID:261448
Apr 1 2002, 11:30 pm
|
|
If a Client is in an area, how do you make it if another Client tryes to enter that area, it makes him do something.
|
In response to Shadowdarke
|
|
That's pretty good code, though you'd be better off with a list. With a list, you can also save the hassle of Login() and Logout() by simply rechecking mob.client for every mob in the area any time it would matter. I find player lists can become dreadful nightmares if you overstress them by doing too much at login or logout; places like that are where the worst bugs creep in.
area Lummox JR |
In response to Shadowdarke
|
|
Shadowdarke wrote:
SSJ4_Link wrote: |
You could loop through all the mobs in the area to see if one has a client, but that would be potentially slow. I'd give the special area a var to count how many clients are present inside.
area
var
clients = 0
Entered(O) // O entered this area
if(ismob(O)) // see if O is a mob
var/mob/M = O // make a mob alias
if(M.client)
clients++ // increase the area client count
..() // do any other Entered() procs that apply
Exited(O) // O exited this area
if(ismob(O)) // see if O is a mob
var/mob/M = O // make a mob alias
if(M.client)
clients-- // decrease the area client count
..() // do any other Exited() procs that apply
We should also change the clients count if someone logs in or out from a mob
mob
Login()
// get the area the mob is in
var/area/A = get_area()
if(A) A.clients++ // increase the client count
..() // do other Login() procs that apply
Logout()
// get the area the mob is in
var/area/A = get_area()
if(A) A.clients-- // decrease the client count
..() // do other Logout() procs that apply
proc
get_area()
// get the area the mob is in
var/atom/A = loc
while(A && !isarea(A))
A = A.loc
return A
Now, you just define the special area that makes the second client "do something"
area
special_area
Enter(O) // O tried to enter this area
if(ismob(O))
var/mob/M = O // get a mob alias to O
if(M.client && src.clients) // if the mob has a client, and the area already has clients
M.DoSomething() // call M's DoSomething() proc
return ..() // return whatever Enter() would return if it hadn't been overidden