• Changing Players Nickname using Derma Textentry
    13 replies, posted
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! [CODE] 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 [/CODE] [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()
[QUOTE=whitestar;49734976]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()[/QUOTE] This is my GM:PlayerInitialSpawn code and it doesnt work [CODE] 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 [/CODE]
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
[QUOTE=Tupac;49735473]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[/QUOTE] 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.
[QUOTE=James xX;49735631]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.[/QUOTE] So what I said above actually will work? Interresting.
[QUOTE=James xX;49735631]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.[/QUOTE] So if I did something like this [CODE] player:SetNWString( "Nickname", "FirstName" ) [/CODE] 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.
[QUOTE=Zet0r;49743418] Repeat with ply:Name() and ply:GetName()[/QUOTE] I mean technically do you even need to repeat it, can't you just do ply.Name = ply.Nick and ply.GetName = ply.Nick
[QUOTE=monkeymacman;49744075]I mean technically do you even need to repeat it, can't you just do ply.Name = ply.Nick and ply.GetName = ply.Nick[/QUOTE] technically, yes.
Sorry, you need to Log In to post a reply to this thread.