Page MenuHomeFeedback Tracker

1.08.153164 - SendNotificationToPlayerExtended and SendNotificationToPlayer unable to send to all players
Closed, ResolvedPublic

Description

In the NotificationSystem class (in 3_Game\Client\Notifications\NotificationSystem.c), there are two static methods, SendNotificationToPlayerExtended and SendNotificationToPlayer whose descriptions claim they can be used to send notifications to all players, but their implementations do not actually support it.

	/**
	\brief Send custom notification to player from server
	@param player the target player to send notification to - if null, will send to all players
	@param show_time amount of time this notification is displayed
	@param title_text the title text that is displayed in the notification
	@param detail_text additional text that can be added to the notification under the title - will not display additional text if not set
	@param icon the icon that is displayed in the notification - will use default icon if not set
	*/
	static void SendNotificationToPlayerExtended( Man player, float show_time, string title_text, string detail_text = "", string icon = "" )
	{
		if( player )
		{
			SendNotificationToPlayerIdentityExtended( player.GetIdentity(), show_time, title_text, detail_text, icon );
		}
	}
	/**
	\brief Send notification from default types to player from server
	@param player the target player to send notification to - if null, will send to all players
	@param type the type of notification to send - these can be viewed in /Scripts/Data/Notifications.json
	@param show_time amount of time this notification is displayed
	@param detail_text additional text that can be added to the notification under the title - will not display additional text if not set
	*/
	static void SendNotificationToPlayer( Man player, NotificationType type, float show_time, string detail_text = "" )
	{
		if( player )
		{
			SendNotificationToPlayerIdentity( player.GetIdentity(), type, show_time, detail_text );
		}
	}

When null is passed as the player parameter to these methods, they do nothing.

The current work-around for sending notifications to all players is to use SendNotificationToPlayerIdentityExtended or SendNotificationToPlayerIdentity, instead.

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
Scripting
Steps To Reproduce

The following script code will not deliver notifications to all players.

NotificationSystem.SendNotificationToPlayerExtended(null, 5.0, "some message");
NotificationSystem.SendNotificationToPlayer(null, FRIEND_CONNECTED, 5.0, "another message");
Additional Information

I recommend the following fixes to make the documentation about the player parameter correct:

	/**
	\brief Send custom notification to player from server
	@param player the target player to send notification to - if null, will send to all players
	@param show_time amount of time this notification is displayed
	@param title_text the title text that is displayed in the notification
	@param detail_text additional text that can be added to the notification under the title - will not display additional text if not set
	@param icon the icon that is displayed in the notification - will use default icon if not set
	*/
	static void SendNotificationToPlayerExtended( Man player, float show_time, string title_text, string detail_text = "", string icon = "" )
	{
		if( player )
		{
			SendNotificationToPlayerIdentityExtended( player.GetIdentity(), show_time, title_text, detail_text, icon );
		}
		else
		{
			SendNotificationToPlayerIdentityExtended( null, show_time, title_text, detail_text, icon );
		}
	}
	/**
	\brief Send notification from default types to player from server
	@param player the target player to send notification to - if null, will send to all players
	@param type the type of notification to send - these can be viewed in /Scripts/Data/Notifications.json
	@param show_time amount of time this notification is displayed
	@param detail_text additional text that can be added to the notification under the title - will not display additional text if not set
	*/
	static void SendNotificationToPlayer( Man player, NotificationType type, float show_time, string detail_text = "" )
	{
		if( player )
		{
			SendNotificationToPlayerIdentity( player.GetIdentity(), type, show_time, detail_text );
		}
		else
		{
			SendNotificationToPlayerIdentity( null, type, show_time, detail_text );
		}
	}

Event Timeline

tjensen created this task.Jun 13 2020, 3:16 PM
tjensen changed Category from General to Scripting.Jun 13 2020, 3:20 PM

From the naming scheme of SendNotificationToPlayer and SendNotificationToPlayerExtended, you can tell that those functions are specifically aimed at sending to the player specified and not all players.

I understand your confusion completely. In order to send the notification to all clients, you will need to simply use SendNotificationToPlayerIdentityExtended with a null identity as this function specifically allows you to pass a null identity to the RPC which will send it to all players.

But I do agree, we should remove the "if null, will send to all players" from SendNotificationToPlayerExtended and SendNotificationToPlayer. It just seems like it was a copy-paste from the author and is causing some confusion for new scripters.

@ukulelekid713 Removing the "if null, will send to all players" comment sounds fair if there is no intention to support null for the player argument. However, I think a notnull modifier should also be added so that the function doesn't silently ignore incorrect usage.

Geez changed the task status from New to Assigned.Jun 15 2020, 1:15 PM

Why the heck is none of this in the Wiki??

Geez closed this task as Resolved.Sep 21 2021, 10:33 AM
Geez claimed this task.
Geez added a subscriber: Geez.

Hello everyone.
There have been changes done to this for the next update.

Comment over SendNotificationToPlayer and SendNotificationToPlayerExtended has been updated to no longer include "null to send to all players" as this is misleading.

If user desires to send to all players they should prefer

SendNotificationToPlayerIdentityExtended with null playerIdentity parameter.

Regards,
Geez