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?
<player>.set_name doesnt work
You should do
, not what you did
Syntax: Select all
<PlayerObject>.set_name(command.get_arg_string())
/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.
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.
Good catch! Another possibility would be this one:
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.
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.
It works fine for me:
*Edit: tested on CS:S / Windows
Tested by using the following in chat:
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!!
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:
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.
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.
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"
2nd Edit:
doesnt work , no errors
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
I believe you need to use PreEvent from events.hooks, not regular Event
What if you use SayText instead of SayText2?
In sourcemod \x03 seems to be the team color, but in SourcePython \x03 is purple
What if you use SayText instead of SayText2?
/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.
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.
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()
SayText2 and SayText work exactly the same in CS:GO except for \x0D:iPlayer wrote:What if you use SayText instead of SayText2?
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.
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:iPlayer wrote:I believe you need to use PreEvent from events.hooks, not regular Event
http://forums.sourcepython.com/showthread.php?980
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 14 guests