• How to set AvatarImage's player?
    2 replies, posted
I am trying to display a player's image. I currently have playername defined to the player name. But when I use avatarimg:SetPlayer(playername, 64), the icon is a question mark. If I use LocalPlayer(), it shows my image, but this is going to be on multiplayer, so I don't think LocalPlayer() will show the user's image.
LocalPlayer(), when used in a client side script, like cl_init.lua, which I assume you are doing it in a file named something of that sort, will always return the clients entity. You are able to use other connected players entities in client side scripts by many means, one way to get a specific players entity, that isn't LocalPlayer() is to do something like this: [code] local SearchNick = "JoeBlow" local FoundEnt = nil for _,v in pairs(player.GetAll()) do if ( v:Nick() == SearchNick ) then FoundEnt = v break end end[/code]
Thank you so much. For future reference, what I did was this: [code] for k,v in pairs (player.GetAll()) do local playername = v:Nick() local SearchNick = playername local FoundEnt = nil for _,v in pairs(player.GetAll()) do if ( v:Nick() == SearchNick ) then FoundEnt = v avatarimg:SetPos(ScrW()/14, ScrH()/10) avatarimg:SetSize(64, 64) avatarimg:SetPlayer(v, 64) break end end end [/code] [editline]20th August 2013[/editline] Now when i'm in game with other players or bots, it displays the last player, and their profile image :/ [editline]20th August 2013[/editline] I realized that for k,v in pairs (player.GetAll()) do is wrong. But I still can't figure out why i'm getting [code] [ERROR] gamemodes/squadrush/gamemode/menus/cl_f2.lua:5: attempt to call method 'Nick' (a nil value) 1. Function - gamemodes/squadrush/gamemode/menus/cl_f2.lua:5 2. unknown - lua/includes/modules/usermessage.lua:87 [/code] with local playername = ply:Nick()
Sorry, you need to Log In to post a reply to this thread.