• Print

Author Topic: Inform Users On Name Change (Like TF2)  (Read 11109 times)

0 Members and 1 Guest are viewing this topic.

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Inform Users On Name Change (Like TF2)
« on: June 15, 2014, 10:42:26 pm »
Ok, I was wondereing if like the server would display a message if a user playing on the server changes the name,

for example, lets say a guy named "Razor" is playing on my server and he changes his name to "Mr.Goodguy"
the server would display this message in the chat: "Player Razor has changed his name to Mr.Goodguy"


Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Inform Users On Name Change (Like TF2)
« Reply #1 on: June 16, 2014, 12:54:25 am »
You can achieve this using the ULibPlayerNameChanged. You could do something like this:
Code: Lua
  1. function NotifyNames( ply, old, new )
  2.  
  3.         for _, v in ipairs( player.GetAll() ) do
  4.                
  5.                 v:ChatPrint( old .. " changed name to: " .. new )
  6.                
  7.         end
  8.  
  9. end
  10. hook.Add( "ULibPlayerNameChanged", "NotifyNames", NotifyNames )

This does, of course, require ULib.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Inform Users On Name Change (Like TF2)
« Reply #2 on: June 16, 2014, 02:20:40 pm »
Would that go in garrysmod/lua/autorun ?
Tried it in that location, didn't work

So where would that go?


Never mind. I was being dumb.
I got it now :)
« Last Edit: June 16, 2014, 02:43:40 pm by Zmaster »

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: Inform Users On Name Change (Like TF2)
« Reply #3 on: June 22, 2014, 01:54:46 pm »
Where does it go xD

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Inform Users On Name Change (Like TF2)
« Reply #4 on: June 22, 2014, 02:44:10 pm »
Where does it go xD
Like most scripts would go: autorun, or as an addon.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: Inform Users On Name Change (Like TF2)
« Reply #5 on: July 05, 2014, 05:08:11 pm »
It works but it does it twice like:

Valgoid changed name to: Valgoid+
Valgoid changed name to: Valgoid+

Valgoid+ changed name to: Valgoid
Valgoid+ changed name to: Valgoid

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Inform Users On Name Change (Like TF2)
« Reply #6 on: July 05, 2014, 05:17:10 pm »
It works but it does it twice like:

Valgoid changed name to: Valgoid+
Valgoid changed name to: Valgoid+

Valgoid+ changed name to: Valgoid
Valgoid+ changed name to: Valgoid

Hmmm... there's nothing in my code that should make it print twice. Temporarily remove the script and change your name to see if it prints?
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: Inform Users On Name Change (Like TF2)
« Reply #7 on: July 05, 2014, 05:29:35 pm »
I did, its still priniting twice, do you think its beacuse im running it in single player?

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Inform Users On Name Change (Like TF2)
« Reply #8 on: July 05, 2014, 05:35:01 pm »
Sometimes it would print it more than twice on my server
Usually two, but sometimes three or four

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: Inform Users On Name Change (Like TF2)
« Reply #9 on: July 05, 2014, 05:38:11 pm »
Yea the script is wrong.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Inform Users On Name Change (Like TF2)
« Reply #10 on: July 06, 2014, 02:03:52 am »
I did, its still priniting twice, do you think its beacuse im running it in single player?

Wait, you removed it and it was still printing? It wouldn't be my script if that's the case.

Sometimes it would print it more than twice on my server
Usually two, but sometimes three or four
Yea the script is wrong.

I'm going to test this on my own server when I get home.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Inform Users On Name Change (Like TF2)
« Reply #11 on: July 06, 2014, 06:45:24 am »
I tested it a few times, in both sandbox and TTT. It only printed once per namechange. I put screenshots below, where I changed my name twice per screenshot. So it could be a different script causing it, or something like that.

Sandbox:

TTT:
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Inform Users On Name Change (Like TF2)
« Reply #12 on: July 06, 2014, 06:26:28 pm »
http://puu.sh/9ZXgI/6387472fed.lua
I had that lying around, there is a function at the bottom that will fix the hook calling repeatedly.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Inform Users On Name Change (Like TF2)
« Reply #13 on: July 07, 2014, 12:53:26 am »
You can also use a timer.Create to stop the hook from spamming. http://wiki.garrysmod.com/page/timer/Create
I cry every time I see that I am not a respected member of this community.

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: Inform Users On Name Change (Like TF2)
« Reply #14 on: July 11, 2014, 10:17:44 pm »
Still spams, and also when people join it says unconnected changed their name to : "then their name"

  • Print