ply:SetName() Why doesn't it work? HELP

Hey all, im just setting up a gamemode to set peoples names but its not working i put in for a test.



function GM:PlayerSpawn( ply )

ply:SetName("Bob the Tester")
end


I don’t Know why it doesn’t work doesn’t give me errors…

I never played with player names, but I think that this function is for non-player entities only.

Try:


Player.Name = ""

or


Player.Nick = ""

Might be wrong, but worth the try.

Well i see it in darkrp and hl2rp

Where are you putting it? Can you give me a bit more inner code? If you don’t want to share your code, just PM it to me.

Creators of hl2rp, drp could overwrite the function and create their own, one that works with players.

Also, as a person mentioned before: What realm are you running the function in? According to the wiki it’s a serverside only function.
Which isn’t the issue I assume, because then you would be getting errors about using unknown function.

its in the init.lua

[editline]8th April 2014[/editline]

it made some errors because of Player. so thats the way

You gotta replace Player with the actual Player.
So if you were doing ply:SetName(), you gotta run ply.Nick = “” etc.

And if it doesn’t work, then I am clueless.

It Didn’t Work. But this time no errors i don’t know why…

Yes, you can override the function in your gamemode so that you can return an appropriate name for them. Store their name in another variable, and do this

[lua]local meta = FindMetaTable(“Player”)
local exampleVar = “John Doe”

– Their name that can be referenced in your gamemode.
function meta:Name()
return exampleVar
end

– Get their actual Steam name.
function meta:SteamName()
return self:Nick()
end[/lua]
Then if you wanted to set their name, you’d set exampleVar = whatever

Obviously you don’t want a name for the player hardcoded into the gamemode. It’s just an example of how you can “change” a player’s name.

I put it in my init.lua file and in the



GM:PlayerSpawn()

local meta = FindMetaTable("Player")
local exampleVar = "John Doe"

-- Their name that can be referenced in your gamemode.
function meta:Name()
    return exampleVar
end

-- Get their actual Steam name.
function meta:SteamName()
    return self:Nick()
end

end


and my results are… my steam name…
So its something we are doing wrong or its just me being stupid

Okay, first of all try to see if the function is even running. So put:



function GM:PlayerSpawn( ply )
     print("Xrayhunter1's PlayerSpawn code has just been called!")
     ply:SetName("Bob the Tester")
end


I think he wants something like this:


local meta = FindMetaTable("Player")
meta.oldNick = meta.Nick

-- This replaces their name everywhere except by C calls (status command, for example)
function meta:Nick()
    return self.NickName or self:oldNick()
end

meta.Name = meta.Nick -- duplicate functions built into gmod for backwords compatability I assume
meta.GetName = meta.Nick

function meta:SetName(str)
   self.NickName = str
end

function meta:ResetName()
   self.NickName = nil
end

I Did that in the beginning…