ID:178925
 
I'm trying to write some code here to cover for if a player logs out while on a planet, it will remove them from the list. Anyone have an idea how I can do this with the current code I have??? players = var/list/players for your NFO.

LJR


usr << "You land on [name]."
players += usr
usr << "Players on this planet:"
for(var/mob/pc/M as mob in players)

if(M.client)
usr << M
Try adding another if statement under the current one like this:

if(M.Logout)
players -= (whatever goes here)


I aint sure if it is what you need nor whether it will work but who knows...It might work :-D

Lee
In response to Mellifluous
Yeah Idea Wise I'd like that to happen.
But I think I need another For statement above the one now, and to do an in world. But what I need is the next line of code that will check if(M != *In the game*) then do a -= on it.

LJR
In response to LordJR
Hmm, ok, I will try and play around on my own and try and create you one, that is if someone else doesnt do one before me or I can't do it :D

Lee
In response to Mellifluous
I dont know if the following will work but I hope it can help you ^_^

    usr << "You land on [name]."
players += usr
usr << "Players on this planet:"
for(var/mob/pc/M as mob in players)

if(M.client)
usr << M
for(var/mob/pc/M as mob in world)

if(M != inworld) //Checking to see whether mob is in the world
//Add natural settings here
else
players -= (whatever goes here) //Input the correct term in the "(whatever goes here)" section


mob
var
inworld


Lee
In response to Mellifluous
What is this inworld stuff??? Is that a typo?
I haven't seen this PROC anywhere does it even exsist?

LJR
In response to LordJR
LordJR wrote:
What is this inworld stuff??? Is that a typo?
I haven't seen this PROC anywhere does it even exsist?

LJR

Hey, sorry ok, I know I aint the best coder around and I cant compile it because if I do I will gain a tonne of errors. I am only trying to help...I still class myself as a Newbie programmer because I still have alot to learn about the DM language...

If you dont understand that what I put dont look at it just ignor it I am only doing this to try and see if you can think of a way to do it because I dont know how I would go about it anyway...

I will just leave this topic now as I aint of use to you so see you around

Lee
Well, I would add two new variables to mob/PC:

var/is_landed

and

var/obj/planet/Planet (or whatever the path to your planet obj is)

Then, when a player lands, set their is_landed var to 1 and their Planet var to the planet that they just landed on.

Then, in the mob Logout() proc, check to see if their is_landed var is set to 1, and if so, remove them from the list of players on that planet.

~X
I need help with this code to remove the name in the players list once the person leaves the planet. Also the same code will be helpful for checking for players who have logged out.

Only part of this code that is working is its adding M.name to the list over and over and over.

LJR



Landing Code:
if(M.client)
players += ("[M.name]
")
for(var/mob/pc/NAMES in players)
if(NAMES.name == null)
players -= ("NAMES.name")
usr << "Players on this planet:"
usr << players

Launch Code:
if(C == "Launch Ship")
M.loc = M.lastloc
M.icon_state = M.lasticon
usr << "You launch into space."
for(var/mob/pc/NAMES in players)
if(M.name == NAMES.name)
players -= NAMES.name
In response to LordJR
Firstly, do as Xooxer suggested and add a planet var. When the usr lands set that var equal to the planet they landed on. Then when they take off set it equal to null. Then when they logout do this:

mob
Logout()
if(Planet) //will be null if not on planet
Planet.players -= src //remove player from planet list
..()


Landing Code:
if(M.client)
players += <font color=red>("[M.name]")</font>

that's your main problem. Your adding their name to the list, not the actual player. Then down here:

for(var/mob/pc/NAMES in players)
if(NAMES.name == null)

your looking for players in the list, but only their names are stored in it.


for(var/mob/pc/NAMES in players)
if(M.name == NAMES.name)
players -= NAMES.name

This won't work for the same reason. There are no mobs in the players list, only names (text strings).
In response to English
This is not going to work due to how my planets are assigned dynamically at runtime :(
In response to LordJR
I don't see how that would have any affect on this. Try it.
In response to LordJR
LordJR wrote:
Yeah Idea Wise I'd like that to happen.
But I think I need another For statement above the one now, and to do an in world. But what I need is the next line of code that will check if(M != *In the game*) then do a -= on it.

If a mob exists but the user playing it has disconnected, M.client will be null. Therefore you can do this:
if(!M.client)
players-=M

Lummox JR
In response to Lummox JR
He just wants to remove a player from the list of players on the planet if the player logs out while on the planet. I don't see what's so complex about that...

~X
In response to Xooxer
What I need since I can add the Text. And I DON'T wanna add the actual mob thats whats giving me all my problems before to where my code stopped working.

I just need to be able to scan the list for the TEXT that == the usr.name. If so remove that text from the list, how would I do this??

LJR
In response to LordJR
Ok, you are adding M.name to the players list when they land. M.name is a text string. This is correct. Your problem is when you try to search the players list and compare the name to the list of names, you're not comparing text stings. This is incorrect.

for(var/mob/pc/NAMES in players)

This is telling DM to scan the players list for a mob/pcs in that list, of which there is none becuase the list contains only text strings. Change that line to:

for(var/NAMES in players)

And this is also wrong, becuase a text string cannot hold a variable:

if(NAMES.name == null)

it should be:

if(NAMES == null)

Which, although is proper use of if(), does nothing in your for loop becuase the for statement only goes through things that exsist. That if statement will never be true. As for your code in general...

Landing Code:
if(M.client)
players += ("[M.name]")
usr << "Players on this planet:"
usr << players

Launch Code:
if(C == "Launch Ship")
M.loc = M.lastloc
M.icon_state = M.lasticon
usr << "You launch into space."
players -= NAMES.name

There is no sane reason why you need those for loops in the first place. The above code will add the players name to the list when they land, and remove it when they luanch. If you want to remove their name from the list of players when they log out while on a planet, see my other post in this thread...

~X

In response to Xooxer
can someone answer my question? How do I search a list for a string of text, select that text for removeable, and remove it??

LJR
In response to LordJR
for(var/T in list)
if(T == "something")
list-=T

or...

for(var/T in list)
if(T == "something")
list.Remove(T)
In response to LordJR
var/list/players = list("Me","Myself",name)
players -= name

The resulting list would be == list("Me","Myself")

-= and Remove automatically find matches and remove them. Just like they do for a list of mobs.

mob
Logout()
if(planet)
planet.players -= name
..()

Land(var/mob/M)
players += M.name
M.planet = src
Takeoff(var/mob/M)
players -= M.name
M.planet = null

Is that what you want? If not, you need to better define your goals. I'm not quite sure why you don't want to have a list of players and just a list of their names...
In response to English
I think LJR needs to get more sleep. The burnout is showing...
Page: 1 2