Jump to content
Sign in to follow this  
RonnieJ

Broadcast MP messages

Recommended Posts

Im a bit confused how to broadcast messages in multiplayer... using the command hint does that hint to every player in-game? and how do I make a hint for only one player? Basicly what I need is a way to send a message to all players and to a single player... what I like about the hint box is that I can parseText to it...

Share this post


Link to post
Share on other sites

Ok, I put this together real fast so excuse typos or other errors. I also have not tested this code, but, I have used the same concepts successfully in the past. I have added a lot of comments so you can see what each section is for. The basic idea is that there is a public variable event handler that runs code that determines to whom a hint should go whenever. The PVEH will fire whenever the hint array (see below) is brodcast via the publicVariable command.

First, in the init.sqf...intialize the array (empty) and add the PVEH

//init.sqf

// Create a global array thay will later be populated with the intended recipients of the hint and the message for the hint.

MY_hint = [];

// Add a public variable event handler (PVEH)  that will pass the value of the array after it is broadcast.  _this select 0: variable name.  _this select 1: new variable value .

"MY_hint" addPublicVariableEventHandler {_nul = [_this select 1] execVM "sendHint.sqf";};

Then, later on, give the array a new value, PV it, and determine whether the client sending it should also receive the message (since PVEH's don't fire where the PV is sent from). How you determine what the text is and where doesn't matter as long as you follow the concept. The way I have set this up is that if you want all clients to receive the message, then the first element of the array should be a string with the value of "ALL". Otherwise, if only to a certain unit, then put the unit's editor name. If you are not using editor assigned names then we have to tweak this.

// someOtherScript.sqf

private ["_unit", "_msg"];

// Assign a recipent of the hint as designated in the mission editor and the actual message contents.  If you want to send the hint to all units then make the first element "ALL" instead of a unit name.

MY_hint = [loon1, "Here's a hint!"]; // Send this hint just to a unit named loon1

// Broacast the array to all machines.

publicVariable "MY_hint" ;

// Because a PVEH will not fire on a machine that broadcasts a PV, mimic the same effects of the PVEH on this machine.


_unit = MY_hint select 0;
_msg = MY_hint select 1;

if ( (player == _unit )or (_unit == "ALL") ) then {hint _msg;};

This is the script that is executed by the PVEH that determines whether the client receiving it should see the message.

// sendHint.sqf

// Set Scope

private ["_unit", "_msg"];

// Determine the intended recipient and message contents.

_unit = _this select 0;
_msg = _this select 1;

// if the player is the recipient OR the hint was intended for all units then display the hint message.
if ( (player == _unit )or (_unit == "ALL") ) then {hint _msg;};

The only issue (other than typos or syntax errors in my example) might be that sometimes MY_hint select 1 might be a string, and sometimes a object...I don't think it will cause errors (type mismatch) but if it does let me know and we can tweak.

Good luck!

Share this post


Link to post
Share on other sites

Im a bit confused :)

If I use hint... then it will be passed to every player in-game? If so... then we need to fire of a script on every player determing if the hint should be displayed - is that correct?

And if a script is executed on the player side with a hint... will it only be shown for that single player or is it broadcasted to everyone?

Edited by RonnieJ

Share this post


Link to post
Share on other sites

Sorry, I have may have given you a solution before explaining the reasoning for it.

Hint has local effects only...so, depending on how you execute the hint, some or all of the players will see it. Here are some examples:

Example 1:

Hint shows for all players.

You place a trigger in the editor (so by default that trigger is present (local) on everyone's computer) that triggers when opfor enters the detection area. The On activation code is:

hint "The enemy is here!";

Because the trigger is local to every player the code will run on every player's computer and everybody will see the hint.

Example 2:

Hint shows for only one player.

You assign an action to a flagpole object using the addAction command. When the action is selected by the player it executes a script that displays a hint. This hint will only show for the player that used the action because the effects of addAction are only local to the computer that runs it.

So, say for example 2 you wanted every player to see the hint, not just the one activating the action...you could then use the code examples I gave in my earlier post to send it to everyone if you used "ALL" in the array:

MY_hint = ['ALL", "Someone touched a flagpole (maybe even me)!!!"];

If you wanted someone OTHER than the player who activated the action to see the hint, you could use that player's editor unit name to do so:

MY_hint = [loon1, "Someone other than me touched the flagpole!!!"];

I hope that helps a little more.

Added in edit:

It should also be noted, placing triggers in the editor is another good way achieve the same results as the code I have given. It may be a better solution depending on how intricate your hints need to be. If you want every player to get a hint, just set the triggers condition and activation code to show a hint whenever the trigger is activated. As long as the trigger is placed in the editor, everyone should see the hint. You can also use the trigger to send the hint to only one player. For the example I gave above, if you use the following condition code, than only the player who is loon1 will see the hint when opfor enters the trigger:

this and (player == loon1)

Good luck!

Edited by Loyalguard
Alternative Method

Share this post


Link to post
Share on other sites

Cool thx m8 that cleared everything! :)

Share this post


Link to post
Share on other sites

You might also want to check out Multiplayer framework. Just add the functions module then a hint is called as so:

[nil,nil,rHINT,"Enjoy the game."] call RE;

Share this post


Link to post
Share on other sites

Hey Guys,

I am working on a mission and I want to create a special Trigger.

The Trigger I am looking for should only sent a hint to the unit which entered/activated the trigger.

The hint should not be sent to every one on the server!

How I do that?

I hope some1 could help me!

Share this post


Link to post
Share on other sites

Just use a regular trigger. Hint is a local command. It will only work where the hint is local. Triggers are created for the server and the client. Triggers are set off locally.

It will get executed on the client and the server. But the hint will do nothing on the server.

This is a good thread on this subject to help you under stand more:

http://forums.bistudio.com/showthread.php?t=96812

Share this post


Link to post
Share on other sites
Hey Guys,

I am working on a mission and I want to create a special Trigger.

The Trigger I am looking for should only sent a hint to the unit which entered/activated the trigger.

The hint should not be sent to every one on the server!

How I do that?

I hope some1 could help me!

Use condition: (vehicle player) in thislist

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×