Author Topic: How to change playernames  (Read 14165 times)

0 Members and 1 Guest are viewing this topic.

Offline Th3_§mp3r0r

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
How to change playernames
« on: January 16, 2014, 02:52:56 AM »
Hi Guys,
Does anybody know how to add a command wich can change the playernames (like ulx setname)?
DarkRP have that function wit "set rpname" and I tried to figure out how to add a similar command to ulx, but I couldn't find out the way it can be done. Is it even possible?
I wrote some addons myself, like a restart function for the server (running game.consolecommand) and a little more stuff. So I'm barely familar with lua and ulx.
But as I said I'm missing a basic command for console or a method/function to even change the names manually, so is there one?

I'm running newest version of ULX,ULib,UClip and have installed a few more like ULXMysqloo, ULX Globalbans, UTime mysql (cause I'm running two servers who shall be synced).

Thanks for your attention,

Th3_3mp3r0r

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: How to change playernames
« Reply #1 on: January 16, 2014, 08:57:46 AM »
If you know Lua, just go digging into darkrp's code.
Out of the Garry's Mod business.

Offline Th3_§mp3r0r

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
Re: How to change playernames
« Reply #2 on: January 16, 2014, 09:30:48 AM »
DarkRP have that function wit "set rpname" and I tried to figure out how to add a similar command to ulx, but I couldn't find out the way it can be done.

Guess what I've tried first

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: How to change playernames
« Reply #3 on: January 16, 2014, 11:06:28 AM »
You're gonna need to edit things. Can't just copy and paste things over and expect them to work.
Out of the Garry's Mod business.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: How to change playernames
« Reply #4 on: January 16, 2014, 05:31:12 PM »
It's not possible to change a players name in garrymod anymore. The only reason it can be done in DarkRP (presumably) is because that gamemode has special ways of displaying a player's name inside of the gamemode locally.

Without the gamemode supporting this, it cannot be done.

Offline Th3_§mp3r0r

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
Re: How to change playernames
« Reply #5 on: January 17, 2014, 03:19:03 AM »
You're gonna need to edit things. Can't just copy and paste things over and expect them to work.

You don't say.

I wanted to understand the way darkrp does and then adapt it.

@Mr.President

I thought something like this by myself. But there must be a way to get those functions into another gamemode. The problem is, i can't figure out how it was done in the first place to modify the gamemode.
« Last Edit: January 17, 2014, 03:21:31 AM by Th3_§mp3r0r »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: How to change playernames
« Reply #6 on: January 17, 2014, 04:37:52 AM »
It's not about getting the functions into another gamemode. It's about how the gamemode handles names.

an RP gamemode would handle names of players separately from the actual player's name. Thus, allowing you to change them.

Most gamemodes just utilize player:Nick() which grabs the player's steam name.



In order to utilize custom names, you would need to edit the gamemode you are using (including the scoreboard) to not use player:Nick() and instead use a naming system that you implement yourself.

Offline Th3_§mp3r0r

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
Re: How to change playernames
« Reply #7 on: January 17, 2014, 07:30:22 AM »
It's not about getting the functions into another gamemode. It's about how the gamemode handles names.

an RP gamemode would handle names of players separately from the actual player's name. Thus, allowing you to change them.

Most gamemodes just utilize player:Nick() which grabs the player's steam name.



In order to utilize custom names, you would need to edit the gamemode you are using (including the scoreboard) to not use player:Nick() and instead use a naming system that you implement yourself.

Well correct me if I'm wrong, but if it would be like that no other addon or command would work in DarkRP.
For example:
Player x changes name to y (in DarkRP).
That would mean, that rpname == y , and ply:Nick() == x .
Every other addon like ulx uses ply:Nick() to call playernames. So if I would try to "ulx kick y" it wouldn't be working because ply:Nick() is x and y doesn't exist. But the reality is different. Somehow it works for ulx to handle changed playernames. So there MUST be a way to just set rpname = ply:Nick(). If that is possible, it would be possible to do that outside that gamemode too.

Well I'm not a lua expert, but I studied computer science and I don't see any other way to get other plugins working except changing the default variables (in this case ply:Nick() ).
« Last Edit: January 17, 2014, 07:34:29 AM by Th3_§mp3r0r »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: How to change playernames
« Reply #8 on: January 17, 2014, 07:53:06 AM »
Perhaps RP overwrites the ply:Nick() function?
So that way, instead of returning the actual name of the player, it returns a set name.
« Last Edit: January 17, 2014, 07:54:52 AM by Neku »
Out of the Garry's Mod business.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: How to change playernames
« Reply #9 on: January 17, 2014, 05:27:13 PM »
Yeah, I don't know much about RP, but overwriting the ply:Nick() function would be a way to get it to work. Then you could change a players name pretty easily.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: How to change playernames
« Reply #10 on: January 17, 2014, 05:30:49 PM »
Where would that function be located though?
Out of the Garry's Mod business.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: How to change playernames
« Reply #11 on: January 17, 2014, 05:33:40 PM »
Inside of the Player MetaTable. :P

Now we're getting into more advanced GLua stuff.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: How to change playernames
« Reply #12 on: January 17, 2014, 05:39:47 PM »
you can override it, but there is no way to just see what it is already in lua. It's built into the game at the engine level.

to override it is just something like this:

in this example you could change a players name by setting the 'customname' object on their player entity to whatever string you want. If they don't have one it'll return their default steam name.

Code: [Select]
meta = FindMetaTable( "Player" )
function meta:Nick()
    if self.customname then return self.customname end
    return self:GetName()
end

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: How to change playernames
« Reply #13 on: January 17, 2014, 07:04:08 PM »
OP, can you paste DarkRP's set rpname function here?

The command works and all, but the scoreboard and chat still displays the original name.
Out of the Garry's Mod business.

Offline Th3_§mp3r0r

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
Re: How to change playernames
« Reply #14 on: January 18, 2014, 04:50:19 AM »
Code: [Select]
meta = FindMetaTable( "Player" )
function meta:Nick()
    if self.customname then return self.customname end
    return self:GetName()
end

OMG I found a similar code in DarkRP days ago, but I interpreted it wrong. I thought it creates his own table as a database to store variables, not that this is the actual game table.

Thank you! Now I have a point where I can begin to write a code.