I've been working on a gamemode for a while, and had to stop due to computer issues, and school. but I picked the project back up, because I'm determined to make this a great gamemode. The question is how could I implement a In-Game Name System. Because when playing I want the players to have their Identities concealed. Any recommendations on how to go and set it up?
thanks
budm
So you want players to have an alternate identification to their SteamID or nickname?
yes within the gamemode only
like PERP, or darkRP
You could add some code into the [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerInitialSpawn]Gamemode.PlayerInitialSpawn [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] hook that adds a [B]NWVar[/B] or [B]PData[/B] to each player. Do you want it so the player can choose their name? Or is it going to be a server-assigned number that the player doesn't need to know?
Thanks I'll look at that hook, yeah i would like it for the player to be able to choose their name.
If you want the data to be saved, and available after a player leaves and reconnects, use [B]PData[/B]. It gets saved to the the server's SQLite database (sv.db in the GMod base folder). Also, to allow a player to enter their name when they join a server, you'd have to have a clientside derma script that is downloaded by the player, which then sends what the player entered back to the server.
[editline]17th July 2011[/editline]
I coded a name entry menu for DarkRP recently that could easily be modified for your needs, PM me if you want the code.
Override the PLAYER:Nick() and PLAYER:Name() function's.
[QUOTE=Derek_SM;31177992]Override the PLAYER:Nick() and PLAYER:Name() function's.[/QUOTE]
Trust me, dont. Use another function and in your hud just call it from there.
Also use usermessages, don't use networkedvariables.
PLAYER:RPNick().
Also Name = Nick, they're the same function.
[QUOTE=Gfoose;31178160]Trust me, dont. Use another function and in your hud just call it from there.
Also use usermessages, don't use networkedvariables.
PLAYER:RPNick().
Also Name = Nick, they're the same function.[/QUOTE]
What is wrong with overriding functions to make it backwards compatible with other things?
[QUOTE=Gfoose;31178160]Trust me, dont. Use another function and in your hud just call it from there.
Also use usermessages, don't use networkedvariables.
PLAYER:RPNick().
Also Name = Nick, they're the same function.[/QUOTE]
Why wouldn't you, infact it's better to.
Ok will this In theory work:
[code]
local Namechange = vgui.Create( "DButton" )
Namechange:SetTall( 20 )
Namechange:SetText( "Change Your Name" )
Namechange.DoClick = function()
Derma_StringRequest( "Change Your Name", "Pick yourself a New Name:", "John Doe", function( text ) RunConsoleCommand(LocalPlayer:Name = ( text )) end )
PlayerPanel:Close()
end
PlayerCommandList:AddItem( Namechange )
[/code]
[QUOTE=budm;31182767]Ok will this In theory work:
[code]
local Namechange = vgui.Create( "DButton" )
Namechange:SetTall( 20 )
Namechange:SetText( "Change Your Name" )
Namechange.DoClick = function()
Derma_StringRequest( "Change Your Name", "Pick yourself a New Name:", "John Doe", function( text ) RunConsoleCommand(LocalPlayer:Name = ( text )) end )
PlayerPanel:Close()
end
PlayerCommandList:AddItem( Namechange )
[/code][/QUOTE]
Did you try it yet?
tried to haha I think i broke my file.
trying to find a lone parentheses
EDIT:
No lone parentheses, so I guess its the code itself that broke the menu.
[lua]
function( text ) RunConsoleCommand(LocalPlayer:Name = ( text )) end )
[/lua]
What?
Firstly, you don't run lua like that. Secondly, it's LocalPlayer(). Thirdly, you can't set a name like that.
You're going to need to do a lot more than that. You need to override player:Nick() for example to return that user's stored RP nick, (PData), (you'll probably want to store the old name somewhere too) and then, you'll need to create a concommand that allows the user to change their nick, and then force them run it from the derma menu.
[QUOTE=LauScript;31179770]Why wouldn't you, infact it's better to.[/QUOTE]
Because what logs your Name is your admin mods, ban loggers etc all these addons will have to work with a new nickname which isn't linked with your steam profile. Even perp doesn't overwrite the Nick() function, neither does DarkRP. It's just stupid to.
Hey, lurked on this thread, and decided to spend 2 minutes cause i was bored.
untested but should work.
[lua]
-----------------------------------
-- Server
-----------------------------------
function _R.Player:SetNewName( a1 )
if a1 then
self:SetNWString( "NewName" , a1 );
self:SetPData( "NewName" , a1 );
end
end
function _R.Player:GetNewName()
return ( self:GetNWString( "NewName" ) or self:Nick() )
end
hook.Add( "PlayerInitialSpawn" , "NameChanger/loader" , function ( pl )
if ( pl:GetPData( "NewName" ) == nil or "" ) then
pl:SetPData( "NewName" , pl:Nick() );
end
pl:SetNWString( "NewName" , pl:GetPData( "NewName") );
end);
--------------------------------------
-- Client
--------------------------------------
function _R.Player:GetNewName()
return ( self:GetNWString( "NewName" ) or self:Nick() )
end
[/lua]
:)
thanks a ton, I dont have time to test this morning, but this evening I will test it, I also gotta fix some bugs thats causing issues.
[QUOTE=dingusnin;31189061]Hey, lurked on this thread, and decided to spend 2 minutes cause i was bored.
untested but should work.
[lua]
-----------------------------------
-- Server
-----------------------------------
function _R.Player:SetNewName( a1 )
if a1 then
self:SetNWString( "NewName" , a1 );
self:SetPData( "NewName" , a1 );
end
end
function _R.Player:GetNewName()
return ( self:GetNWString( "NewName" ) or self:Nick() )
end
hook.Add( "PlayerInitialSpawn" , "NameChanger/loader" , function ( pl )
if ( pl:GetPData( "NewName" ) == nil or "" ) then
pl:SetPData( "NewName" , pl:Nick() );
end
pl:SetNWString( "NewName" , pl:GetPData( "NewName") );
end);
--------------------------------------
-- Client
--------------------------------------
function _R.Player:GetNewName()
return ( self:GetNWString( "NewName" ) or self:Nick() )
end
[/lua]
:)[/QUOTE]
Don't use networked variables. sigh, it's not that hard to send a usermessage, is it?
[QUOTE=Gfoose;31192274]Don't use networked variables. sigh, it's not that hard to send a usermessage, is it?[/QUOTE]
You're not even smart enough to realize overriding the Nick() and Name() functions is the best way to go, and you're trying to tell people what to do? Get out.
Usermessages and override Nick/Name/GetName and done.
[QUOTE=Gfoose;31192274]Don't use networked variables. sigh, it's not that hard to send a usermessage, is it?[/QUOTE]
It's only an example, and only how i would do it. And in any case, it's the same thing. I wrote it in 2 minutes, i wasnt going to make a masterpiece out of it -_-'
I would've thought this is one of the situations where networked variables are a good idea... Why shouldn't they be used here?
[QUOTE=immibis;31223938]I would've thought this is one of the situations where networked variables are a good idea... Why shouldn't they be used here?[/QUOTE]
this :)
[QUOTE=immibis;31223938]I would've thought this is one of the situations where networked variables are a good idea... Why shouldn't they be used here?[/QUOTE]
Usermessages are always better because you can delay sending them to connecting people to stop them getting buffer overflow
[QUOTE=King Penisless;31225308]Usermessages are always better because you [b]cant[/b] delay sending them to connecting people to stop them getting buffer overflow[/QUOTE]
I'll assume that was meant to be "can" ... because otherwise wouldn't they cause buffer overflows?
Sure but... this seems like what NWVars were [b]designed for[/b]. Surely a string per player isn't enough to cause a buffer overflow? Of course, without actually testing it, it's probably better to use usermessages since at least you know they work properly.
[QUOTE=immibis;31227109]I'll assume that was meant to be "can" ... because otherwise wouldn't they cause buffer overflows?
Sure but... this seems like what NWVars were [b]designed for[/b]. Surely a string per player isn't enough to cause a buffer overflow? Of course, without actually testing it, it's probably better to use usermessages since at least you know they work properly.[/QUOTE]
When a new player spawns, the string of every other player isn't just sent to the player who just spawned. It's sent to everybody (If I remember right)
That's why usermessages should be used.
Sorry, you need to Log In to post a reply to this thread.