<player>.set_name doesnt work

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

<player>.set_name doesnt work

Postby decompile » Mon Feb 08, 2016 4:20 pm

Hey,

I tried to change my name ingame with a command by using <PlayerObject>.set_name = command.get_arg_string()
Just nothing happens

Maybe cause of an offset?
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Mon Feb 08, 2016 6:21 pm

Which game and which OS?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Mon Feb 08, 2016 7:47 pm

You should do

Syntax: Select all

<PlayerObject>.set_name(command.get_arg_string())
, not what you did
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Mon Feb 08, 2016 7:50 pm

Good catch! Another possibility would be this one:

Syntax: Select all

<Player object>.name = command.get_arg_string()


Edit:
You can easily remember if something is a function/method or variable/attribute. If the name starts with a verb (set, get, is, etc.) it's a function/method. Otherwise it's a variable/attribute.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Mon Feb 08, 2016 9:42 pm

CSS - Windows

EDIT:

both ways doesnt work
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Feb 09, 2016 4:28 am

It works fine for me:

Syntax: Select all

from commands.say import SayCommand
from players.entity import Player

@SayCommand('name')
def change_name(command, index, team_only):
new_name = command.get_arg_string()
if new_name:
Player(index).name = new_name
else:
print('no name given...')


*Edit: tested on CS:S / Windows

Tested by using the following in chat:

Code: Select all

name look at my new name!!
Image
User avatar
Kami
Global Moderator
Posts: 264
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Tue Feb 09, 2016 11:41 am

Just a thought, but the name in CS:S and CS:GO is directly taken from the Steam settings for friends.

When testing this in CS:GO I noticed, that the scoreboard name changes, the ingame chat name on the other hand does not. Maybe this is the reason you didn't notice a change?


Edit:

If that in case is your problem, you could try something like this to make it look like the name changed in the chat too:

Syntax: Select all

from messages import SayText2
from commands.say import SayCommand
from commands.say import SayFilter
from players.entity import Player
from events import Event
from filters.players import PlayerIter

player_names = {}

@Event('player_activate')
def _player_activate(event):
userid = event.get_int('userid')
player_names[userid] = 0


@SayCommand('name')
def change_name(command, index, team_only):
new_name = command.get_arg_string()
if new_name:
player = Player(index)
player.name = new_name
player_names[player.userid] = new_name
else:
SayText2('\x05You need to add a name after the \x04name saycommand').send(index)

@SayFilter
def _say_command_hook(command, index, team=None):
player = Player(index)
if not player.userid in player_names:
player_names[player.userid] = 0
if player_names[player.userid] != 0:
message = command.get_command_string()
for player_ent in PlayerIter():
SayText2('%s: %s' % (player_names[player.userid], message)).send(player_ent.index)
return False


This works in CS:GO, but you will need to add color codes to the message, as I couldn't find the corresponding team color codes (In sourcemod \x03 seems to be the team color, but in SourcePython \x03 is purple)

Also this does not account for team say yet.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Tue Feb 09, 2016 12:06 pm

So it seems to work now by using <Player>.name = <insert name> after I updated to the latest build.. Weird, anyway thank you.

And to @Kami,

Thank you! I already added that since im using "chatranks" for players. I just had the problem that the scoreboard name didnt changed.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Tue Feb 09, 2016 12:08 pm

So one last thing,

How can I block the message "XX changed his name to YY" with SP?

EDIT:

Found it out, you can do it with: "return EventAction.STOP_BROADCAST"

Syntax: Select all

@Event('player_changename')
def player_changename(GameEvent):
return EventAction.STOP_BROADCAST


2nd Edit:

doesnt work :( , no errors
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Tue Feb 09, 2016 1:05 pm

I believe you need to use PreEvent from events.hooks, not regular Event


In sourcemod \x03 seems to be the team color, but in SourcePython \x03 is purple

What if you use SayText instead of SayText2?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Feb 09, 2016 1:15 pm

Kami wrote:This works in CS:GO, but you will need to add color codes to the message, as I couldn't find the corresponding team color codes (In sourcemod \x03 seems to be the team color, but in SourcePython \x03 is purple)

That is because you are not passing in the player's index for the \x03 color to be the team's color. And, instead of looping through all players to send the message, just don't pass in anything or pass in PlayerIter() to the send method:

Syntax: Select all

SayText2('\x03{0}\x01: {1}'.format(player_names[player.userid], message), index).send()



iPlayer wrote:What if you use SayText instead of SayText2?
SayText2 and SayText work exactly the same in CS:GO except for \x0D:
http://forums.sourcepython.com/showthread.php?586&p=3062&viewfull=1#post3062

For CS:S, if I remember correctly, the work the same except for \x03 doesn't display team colors in SayText.



iPlayer wrote:I believe you need to use PreEvent from events.hooks, not regular Event
This is definitely true. You cannot use EventAction inside Event, only PreEvent. However, I did test myself, and it still didn't stop the message from displaying. I tested EventAction.BLOCK, as well, with no effect. You will probably need to use a user message hook to block the specific user message from being sent. We haven't added that functionality directly to SP itself, yet, but you can still accomplish it using the memory package:
http://forums.sourcepython.com/showthread.php?980
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 14 guests