Changing Players Nickname using Derma Textentry

So how do I change the players nickname in my gamemode using Derma Text Entry
This is my code for the text entries
this is on cl_init.lua I think the function may have to be called on the init.lua but IDK
if someone could explain that would be great!



local FirstName = vgui.Create( "DTextEntry", Frame )	-- create the form as a child of frame
FirstName:SetPos( 25, 75 )
FirstName:SetSize( 900, 25 )
FirstName:SetText( "First Name" )
FirstName.OnEnter = function( self )

end    

local LastName = vgui.Create( "DTextEntry", Frame )	-- create the form as a child of frame
LastName:SetPos( 25, 125 )
LastName:SetSize( 900, 25 )
LastName:SetText( "Last Name" )
LastName.OnEnter = function( self )
	
end


[editline]13th February 2016[/editline]

Also How can I have the player die when they initaly spawn into the server?

About the nick, I dont know if it works, but you could send it to the server, and set the players nick var, which gets retrieved by ply:Nick().

About the slay, just hook into PlayerInitialSpawn and do ply:Kill()

This is my GM:PlayerInitialSpawn code and it doesnt work



if(SERVER) then
local TEAM_CITIZEN = 1
 
function GM:PlayerInitialSpawn( ply )
		ply:SetTeam( TEAM_CITIZEN )
		ply:SetGravity( 1 )
		ply:SetWalkSpeed( 5 )
		ply:SetRunSpeed( 1 )
		ply:SetCrouchedWalkSpeed( 0.3 )
		ply:SetDuckSpeed( 0.5 )
		ply:SetNoCollideWithTeammates( false )
		ply:SendLua( [[chat.AddText( Color( 70, 70, 200 ), "[GMODLife] ", Color( 255, 255, 255 ), "Welcome to the server, ]] ..ply:Nick() .. [[!" )]] )
		ply:Kill()
	end
end
//Sets players default Loadout
function GM:PlayerLoadout( ply )
	ply:Give( "gml_hands" )
	ply:Give( "weapon_physgun" )
end


try this

[lua]
ply:SendLua( [[chat.AddText( Color( 70, 70, 200 ), "[GMODLife] ", Color( 255, 255, 255 ), “Welcome to the server, ]]” …ply:Nick() … “[[!” )]] )
[/lua]

use timer.simple to make the player be killed 1-3 seconds after initialization, the player didn’t ‘fully’ spawn there yet.

To set the name. Use net messages and send to the server in LastName.OnEnter

Hop on to server side and receive the net message.

Then use dis

Player:setRPName(string name, boolean firstrun)

#ICantExplainShit

He said before his gamemode was based off Sandbox, not darkRP

You can manually override the metafunctions that return a players name to return the one you want. Net message the content of the dtextentry to the server, setnwstring on the sender, override the player name metas to return the nwstring and default to old meta functions.

So what I said above actually will work? Interresting.

So if I did something like this



player:SetNWString( "Nickname", "FirstName" )


after net messaging first name
to the server
is that what you mean?

You also should overwride the players name variable, as he said, I don’t know the player table layout right now, but you have to use GetMetaTable on the player object, and then overwrite the Player.Name(I THINK!!) variable with the given name, and then do SetMetaTable, so ply:Nick() would return the overwritten var.

[lua]local ply = FindMetaTable(“Player”)

local oldnick = ply.Nick – store the old so we can fall back to that
function ply:Nick()
local name = self:GetNWString(“whatever”)
if name == “” then – or another condition if a name shouldn’t be valid
name = oldnick(self) – set to what the old :Nick() function would return
end
return name
end[/lua]
Repeat with ply:Name() and ply:GetName() if you want it to work with all addons. Something like this at least.

I mean technically do you even need to repeat it, can’t you just do ply.Name = ply.Nick and ply.GetName = ply.Nick

technically, yes.