Page 1 of 1

<player>.set_name doesnt work

Posted: Mon Feb 08, 2016 4:20 pm
by decompile
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?

Posted: Mon Feb 08, 2016 6:21 pm
by Ayuto
Which game and which OS?

Posted: Mon Feb 08, 2016 7:47 pm
by iPlayer
You should do

Syntax: Select all

<PlayerObject>.set_name(command.get_arg_string())
, not what you did

Posted: Mon Feb 08, 2016 7:50 pm
by Ayuto
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.

Posted: Mon Feb 08, 2016 9:42 pm
by decompile
CSS - Windows

EDIT:

both ways doesnt work

Posted: Tue Feb 09, 2016 4:28 am
by satoon101
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!!

Posted: Tue Feb 09, 2016 11:41 am
by Kami
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.

Posted: Tue Feb 09, 2016 12:06 pm
by decompile
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.

Posted: Tue Feb 09, 2016 12:08 pm
by decompile
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

Posted: Tue Feb 09, 2016 1:05 pm
by iPlayer
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?

Posted: Tue Feb 09, 2016 1:15 pm
by satoon101
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