Sending messages to all players

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Sending messages to all players

Postby arawra » Fri Aug 30, 2013 4:20 am

There is no error on the code, but on round_start no message appears.

Syntax: Select all

import messages

from events import Event

from player_c import CPlayerGenerator
from players.helpers import index_from_playerinfo

@Event
def round_start(game_event):
welcome = '[DND] Welcome to DND!'
for players in CPlayerGenerator():
i = index_from_playerinfo(players)
m = messages.SayText(index=i, chat=1, message=welcome)
m.send(i)
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Fri Aug 30, 2013 4:22 am

Oops, had to change messages.SayText to messages.SayText2
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Fri May 09, 2014 3:46 pm

Going to bump this thread instead of creating a new, How would i use saytext2 with the current release?

Edit: Would be great with an example for hinttext (hud hint) also

Thanks in advance
-Tuck
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Fri May 09, 2014 5:36 pm

You can supply your own tag to use on the second line.

Syntax: Select all

msg('This will be sent to all players.')

def msg(the_message):
formatted_message = '%s'%the_message
for players in PlayerGenerator():
i = index_from_playerinfo(players)
m = messages.SayText2(index=i, chat=1, message=formatted_message)
m.send(i)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri May 09, 2014 6:10 pm

No need to loop through all players yourself. If you do not pass a value for users, all users are sent the message. Also, the message package classes automatically loop through and send the appropriate translation for each user. This is how I would use both SayText2 and HintText:

Syntax: Select all

from messages import HintText
from messages import SayText2

my_hint = HintText(message='This is a test hinttext message')
my_saytext2 = SayText2(message='\x01One\x02 Two\x03 Three\x04 Four\x05 Five\x06 Six\x07 Seven')

def something():
my_hint.send()
my_saytext2.index = 1
my_saytext2.send()

Also, as I stated, you can pass in LangStrings values for the message, and each of the users will be sent their specific translation:

Syntax: Select all

# ../resource/source-python/translations/myaddon.ini
[HintText]
en = "This is a test hinttext message"

[SayText2]
en = "\x01One\x02 Two\x03 Three\x04 Four\x05 Five\x06 Six\x07 Seven"

Syntax: Select all

from messages import HintText
from messages import SayText2
from translations.strings import LangStrings

my_strings = LangStrings('myaddon')

my_hint = HintText(message=my_strings['HintText'])
my_saytext2 = SayText2(message=my_strings['SayText2'])

def something():
my_hint.send()
my_saytext2.index = 0
my_saytext2.send()

Obviously, if you want to use the "index" (used for the "team" color, /x03) of each user for their own message, then you will have to loop through each one. Or, at the very least, you can loop through each team and choose one index from the team and set the users on send().
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Fri May 09, 2014 8:42 pm

Is there a way to loop trough all PlayerEntities ? (for something else, where i need each steam id)

or is the PlayerGenerator returning IPlayerInfo for each player ?

from players.helpers import uniqueid_from_playerinfo

could get steamid from this i guess, however is this the fastest way to do this?
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri May 09, 2014 9:10 pm

First off, I do apologize for the lack of a wiki, currently. We hope to have that back up asap, but it will take some time.

This question was asked about recently:
http://www.sourcepython.com/showthread.php?146-Stripping-weapons&p=2525&viewfull=1#post2525

The link in that link shows functionality that has mostly not changed. The WeaponTagIter was moved to filters.weapons.WeaponClassIter and WeaponIter was moved to filters.weapons.WeaponEdictIter. We have also recently added filters.entities.EntityIter to loop through entities by classname. filters.players.PlayerIter has been untouched for some time.

To iterate over player steamids:

Syntax: Select all

from filters.players import PlayerIter

for steamid in PlayerIter(return_types='steamid'):
print(steamid)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 16 guests