ID:2211909
 
(See the best response by Lummox JR.)
I'm trying to make an image that appears only for players on your team. All I got right now is:

mob
Player
proc
teamindicator()
var/mob/Player/P
var/image/t = image('team.dmi')
for (P in world)
if (P.team == src.team)
src << t
t.loc = P.loc


the image does appear, but its static, it doesnt move around with the player... how do i get it to follow the player? =S

Best response
You only need to set the image's loc once, not in the loop. And you should be setting t.loc to a mob, not the mob's loc; that's why it's staying in one place, because you attached it to a turf.
Thanks, I think it worked but I still need to test with other players to know for sure (=
Mind you the loop is still incorrect; if you want a different image to appear on each mob, you need multiple images.

What makes more sense is for every mob with a team to have its own team image, and then to add that image to each player who joins the team.

mob
var/image/teamimage
...

proc/JoinTeam(t)
team = t
if(!teamimage) teamimage = new(loc=src, icon='team.dmi')
for(var/client/C)
if(C.mob && C.mob.team == t) C << teamimage

proc/LeaveTeam()
for(var/client/C)
if(C.mob) C.images -= teamimage
team = null
since the rest of my code had 'team' as a mob/Player var, not a client var, I did it like this

            teamindicator()
if(!teamimage) teamimage = new(loc=src, icon='team.dmi')
for(var/mob/Player/P)
if(P.team == src.team) P << teamimage

cancelteamindicator()
for(var/mob/Player/P)
if(P.client) P.images -= teamimage


but it says P.images is an undefined var
images is a client variable, not mob.
P.images doesn't exist because P is a mob, not a client. What you want there is P.client.images.

But I looped through clients, not mobs, for a reason. When you loop through mobs, even with a specific type path, the engine is going to loop through all mobs and simply skip over the ones that aren't a type match. When you want to loop through all players, looping through clients is always going to be faster than looping through all mobs and restricting it to a specific type. The only thing faster is if you keep a global list of all online player mobs (which you would update as players connect or disconnect), and loop through that instead.

Now that said, I did forget something in that original code: Nothing shows you existing team images of other players when you join a team.

mob
var/image/teamimage
...

proc/JoinTeam(t)
team = t
if(!teamimage) teamimage = new(loc=src, icon='team.dmi')
for(var/client/C)
if(C.mob && C.mob.team == t)
C << teamimage
src << C.mob.teamimage

proc/LeaveTeam()
for(var/client/C)
if(C.mob)
C.images -= teamimage
if(client) client.images -= C.mob.teamimage
team = null
In response to Lummox JR
Well it will take me a long time to readapt my code but I'll do it hahaha

About this:

Lummox JR wrote:
Now that said, I did forget something in that original code: Nothing shows you existing team images of other players when you join a team.

There is no problem because you can't join a team after a match has started.

Thanks (=