Jump to content
Sign in to follow this  
Doodle

Multiplayer Dedicate Message

Recommended Posts

Can anyone help me out with this one please

I ma trying to get a message displayed to all human players on a dedicated when a script is called from ADDACTION

//nul = execVM "spawn_mortor1.sqf";
//Spawn Mortor
playsound "drill";


_startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>";
_startuf  = _startuf ;
_titletuf  = "<t color='#FFFFFF' size='1.2' shadow='1' shadowColor='#000000' align='left'><br/>Mortor Support</t><br/>";
_texttuf   = "<t color='#58FA58' size='1.0' shadow='1' shadowColor='#000000' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight. <br/><br/>";
hint parseText (_startuf + _titletuf + _texttuf);
sleep 3.0;
hint "";
if (!isServer) exitWith {}; 


_mortor2tuf = "Chemlight_green" createVehicle (position s5);
_mortor2tuf setDir 0;
sleep 1.0;

_mortor2tufe = createVehicle ["SmokeShellGreen", getPos s5, [],1,"NONE"];
_mortor2tufe setDir 0;
sleep 1.0;

_mortor2tuff = "B_Mortar_01_F" createVehicle (position s5);
_mortor2tuff setDir 180;
sleep 1.0;



if (true) exitWith {}; 

the script works fine with the exception that no one other than the person activating the addaction sees the message. I have tried putting it after the if (!isServer) exitWith {};

But still nothing

Thanks in advance

Share this post


Link to post
Share on other sites

Checking if it is a client is to limit the execution, not expand it :P

As stated, everything related to addAction is local. However, if you have a separate script doing a waitUntil a certain global variable is true, I believe you can define that global variable in the script and it will be read. You would include your message in the script with the waitUntil.

For what its worth, you don't need to setDir the chemlight and smoke grenade.

Share this post


Link to post
Share on other sites

Hey Doodle - I think you bring up a really interesting issue that a lot of scripters in Arma run into - the issue of locality. I've drawn something up using publicVariableServer and publicVariableEventHandlers - essentially the client asks the server to do the work for it.

I would highly recommend reading KillzoneKid's article on Multiplayer Locality and how it affects things (not to mention reading the wiki article on locality wouldn't hurt either) - I've run into this issue A LOT with a medical system I am working on for ArmA III and its been frustrating but once you get used to the idiosyncratic nature of Arma Scripting you can work around its pitfalls.

Keep in mind I haven't had the time to test this code yet - so if there is any issues let me know and I will edit this post - I want to make sure people can manage this kind of issue in the future.

// All of this Server code you want to be in the intialization process - so 
that it is available when it needs to be called later on.

if (isServer) then {	
// Create a Public 
publicVariableServer "BroadcastMessage";
"BroadcastMessage" addPublicVariableEventHandler {
	[_this] call pre_fnc_broadcastMsg;
};

pre_fnc_broadcastMsg = {
	private ["_broadcastString"];
	// Ensure a string is being passed
	_broadcastString = [_this, 0, "EMPTY STRING OR WRONG TYPE", [""]] call BIS_fnc_params;
	hint format["%1", _broadcastString];
};
}

/* This code can reside anywhere - it needs to be accesible by all of the players so they 
all can request the message. You can literally transmit any string over the network - 

Keep in mind that there is the issue of multiple requests at once - you may want to 
implement a messaging queue so that each message gets displayed one after another
after a few seconds delay (this can be done by adding each message to an array and 
then broadcasting one every five seconds while there is still messages in the array) */ 

if (isPlayer) then {
// Message Content Here
_startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>"; 	
_titletuf  = "<t color='#FFFFFF' size='1.2' shadow='1' shadowColor='#000000' align='left'><br/>Mortor Support</t><br/>"; 
_texttuf   = "<t color='#58FA58' size='1.0' shadow='1' shadowColor='#000000' align='left'>A member of your sqaud is deploying a Mortor.<br/> <br/>It is marked with green smoke and chemlight. <br/><br/>";
// set our variable to send to the public variable.
_transmit = parseText (_startuf + _titletuf + _texttuf);

// Change the Public Variable - This triggers the publicVariablEvent Handler
BroadcastMessage = _transmitString;	
}

Edited by [LTac] Imperator
fixed a few typos in the code

Share this post


Link to post
Share on other sites

Firstly thanks guys for the info - I had a horrible feeling it was to do with "locality" and that is an area I just cant get my head round. No matter how much I read up on it.

What was even more fustrating was the scripts work fine on our dedi when called from a RADIO TRIGGER. All players see the message and the Mortor, Chemlight and Smoke get spawned - perfect -

I wanted to get the actions off the radio triggers and on to a vehicle addaction and that is where I ran into the problems - everything gets spawned ok on our dedi it was just the messages werent getting broadcast to everyone.

@[LTac] Imperator

WOW thanks for this - I am assuming I just paste what you posted above into my script - replacing my message section?

// All of this Server code you want to be in the intialization process - so 
that it is available when it needs to be called later on.

if (isServer) then {	
// Create a Public 
publicVariableServer "BroadcastMessage";
"BroadcastMessage" addPublicVariableEventHandler {
	[_this] call pre_fnc_broadcastMsg;
};

pre_fnc_broadcastMsg = {
	private ["_broadcastString"];
	// Ensure a string is being passed
	_broadcastString = [_this, 0, "EMPTY STRING OR WRONG TYPE", [""]] call BIS_fnc_params;
	hint format["%1", _broadcastString];
};
}

/* This code can reside anywhere - it needs to be accesible by all of the players so they 
all can request the message. You can literally transmit any string over the network - 

Keep in mind that there is the issue of multiple requests at once - you may want to 
implement a messaging queue so that each message gets displayed one after another
after a few seconds delay (this can be done by adding each message to an array and 
then broadcasting one every five seconds while there is still messages in the array) */ 

if (isPlayer) then {
// Message Content Here
_startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>"; 	
_titletuf  = "<t color='#FFFFFF' size='1.2' shadow='1' shadowColor='#000000' align='left'><br/>Mortor Support</t><br/>"; 
_texttuf   = "<t color='#58FA58' size='1.0' shadow='1' shadowColor='#000000' align='left'>A member of your sqaud is deploying a Mortor.<br/> <br/>It is marked with green smoke and chemlight. <br/><br/>";
// set our variable to send to the public variable.
_transmit = parseText (_startuf + _titletuf + _texttuf);

// Change the Public Variable - This triggers the publicVariablEvent Handler
BroadcastMessage = _transmitString;	
}


_mortor2tuf = "Chemlight_green" createVehicle (position s5); 
_mortor2tuf setDir 0; 
sleep 1.0; 

_mortor2tufe = createVehicle ["SmokeShellGreen", getPos s5, [],1,"NONE"]; 
_mortor2tufe setDir 0; 
sleep 1.0; 

_mortor2tuff = "B_Mortar_01_F" createVehicle (position s5); 
_mortor2tuff setDir 180; 
sleep 1.0; 

If the above is correct if I was to have another script that was exactly the same except spawned a static MG say would I need to edit anything in your code to make it work or would your code be ok to just copy paste into my other "spawn something and display a message" scripts?

@Grimes

Thanks for heads up re setDir. I was aware that I didnt need to setDir for Chem and smoke its just I am using this as a template for 8 other scripts and some need set Dir. But you may be a ble to help me with another queery,

At the moment three objects are sapwned in two different ways not sure how this happened and they both work perfectly I was just wondering what was the difference between the two and is one a better way that the other for use on dedi?

_mortor2tuf = "Chemlight_green" createVehicle (position s5);

_mortor2tufe = createVehicle ["SmokeShellGreen", getPos s5, [],1,"NONE"];

Once again guys thanks for your help.

Oh and a heads up - next questions will be about how to limit the amount of times a script can be called...I have a feeling this is another minefield...

Share this post


Link to post
Share on other sites

For your first question:

One uses createVehicle for only a position, while the other takes an array containing more details. See createVehicle vs. createVehicle array.

Second question:

Personally what I do is in init.sqf define a global variable as 0 and then in the script redefine that variable as itself + 1. Then either as a condition of executing it (depending on how/where you do that) or in the script itself, do a check.

For instance, mission starts, init.sqf has execcount = 0, so execcount == 0.

Execute script the first time. execcount = execcount + 1; is in the first line. Now, execcount == 1.

Right under that is the following:

if (execcount > 3) exitWith {hint "No longer available!"};

But because execcount is not greater than 3, the script continues.

Repeat steps until execcount == 4. Script will close due to the condition.

Share this post


Link to post
Share on other sites

@Grimes

Once again thanks for your help

I think i understand about the execount

What I am trying to acheive is each of the 10 players in the mission has a unique ability - eg; player one can spawn a mortor , player two can spawn a ATV etc

Currently I have 10 scripts - one per player - they are all the same with the exception of the message and the item spawned

Would I have to define a global variable for each of the 10 scripts?

ie: In init.sqf

execcount = 0

execcount1 = 0

execcount2 = 0

execcount3 = 0

execcount4 = 0

etc

.

.

execcount10 = 0

Thanks again in advance

Share this post


Link to post
Share on other sites

The term "global variable" isn't as global as it sounds. Global variables are universal variables on the machine (client or server) in which they are executed. If player 1 executes scripts defining global variables, player 2 DOES NOT have those variables. As well, if multiple clients launch the same file and define the same variables, they are still separate since they are technically on different machines. So in your case, no, you don't need multiple variables as long as the files are executed correctly, 1 per client.

Share this post


Link to post
Share on other sites
Currently I have 10 scripts - one per player - they are all the same with the exception of the message and the item spawned

Would I have to define a global variable for each of the 10 scripts?

This all depends on how you want the script to handle - you don't really have 10 seperate scripts - you have 10 instances of scripts that could be run by individual players - consider how often each player will use this addAction event. Second of all - you can simply setup an array

["StaticMortar", "B_G_Quadbike_01_F", "B_Heli_Light_01_F", "etc...."]

and then set on each unit a "specialPower" variable using the setVariable command according to the index of the array (0 for Mortar, 1 for Quadbike, etc - and perhaps a true or false value to determine if it was called so it would look like this:

 _unit setVariable ["specialPower", [0, false], true]; 

. Then whenever a unit calls the script check their specialVariable using getVariable and if the execution value (the true or false) returns false spawn the unit. This way you can create a reusable function to spawn all different 10 items rather than 10 different functions.

Grimes is right about global variables - you can get around this if you use the publicVariable command - be advised you cant transmit code blocks ( {} ), displays or local objects (objects that were created on a clients machine).

Its not a simply copy and paste job - the dedicated server stuff needs to go fairly early in your init.sqf or at least be included in it earlier there - then the messaging part is where you would put the client side stuff - this is the client asking the server to say something to all the players for them. You can literally pass any string into it and it will send a hint to all players.

I want to share a bit of advice given by a mentor to me in my professional life (I do web development) - But take time to experiment and try out the code and different approaches - dont be afraid to prototype new systems outside of your main script and get the very bare bones working and then take the lessons you learn from that prototype and implement it in your mission. Also always be aware that the biggest problem your programming skills are going to face is users - they will try a dozen different ways of accessing or putting inputs into something that you didnt expect and will try to break it - so always be aware of all the use cases of a function / input / etc. Unfortunately we are also working with the quirks left over of a dozen years of dozens of different programmers creating an api over four different games, which makes things a little more difficult ;).

If you need any help, feel free to private message me or jump on our unit's teamspeak - more than willing to help out.

Share this post


Link to post
Share on other sites

thnaks guys for your help - I am getting out of my depth here.

@ Imperator.

Just tried albeit quickly the following

Added this to my init

if (isServer) then {    
   // Create a Public 
   publicVariableServer "BroadcastMessage";
   "BroadcastMessage" addPublicVariableEventHandler {
       [_this] call pre_fnc_broadcastMsg;
   };

   pre_fnc_broadcastMsg = {
       private ["_broadcastString"];
       // Ensure a string is being passed
       _broadcastString = [_this, 0, "EMPTY STRING OR WRONG TYPE", [""]] call BIS_fnc_params;
       hint format["%1", _broadcastString];
   };
}

though it kicked up an error untill i added the last ;

and i made this my spawn something script

if (isPlayer) then {
// Message Content Here
_startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>"; 	
_titletuf  = "<t color='#FFFFFF' size='1.2' shadow='1' shadowColor='#000000' align='left'><br/>Mortor Support</t><br/>"; 
_texttuf   = "<t color='#58FA58' size='1.0' shadow='1' shadowColor='#000000' align='left'>A member of your sqaud is deploying a Mortor.<br/> <br/>It is marked with green smoke and chemlight. <br/><br/>";
// set our variable to send to the public variable.
_transmit = parseText (_startuf + _titletuf + _texttuf);

// Change the Public Variable - This triggers the publicVariablEvent Handler
BroadcastMessage = _transmitString;

but i get an error

line 3

Error in expression <\scripts\spawnmortor.sqf"

if (isPlayer) then {

_startuf = "<br/><img size='4>

Error position: <) then {

_startuf = "<br/><img size='4>

Error unexpected )

any idea?

Than agian

Share this post


Link to post
Share on other sites

I didn't look at ParseText before I used it in that script - looks like its for controls - I may be wrong again here but after a quick look I think you should probably just send replace the _transmit line with:

_transmit = _startuf + _titleuf + _textuf;

and see if that works.

Share this post


Link to post
Share on other sites
Imperator;2630632']I didn't look at ParseText before I used it in that script - looks like its for controls - I may be wrong again here but after a quick look I think you should probably just send replace the _transmit line with:

_transmit = _startuf + _titleuf + _textuf;

and see if that works.

Tried the above - still the same error

---------- Post added at 08:45 AM ---------- Previous post was at 08:17 AM ----------

No matter what I try with this

if (isPlayer) then { 
   // Message Content Here 
   _startuf  = "<img size='4' img image='icons\mortor1.paa' align='left'/><br/>";   
   _titletuf  = "<t color='#FFFFFF' size='1.2' align='left'><br/>Mortor Support</t><br/>"; 
   _texttuf   = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight.<br/><br/>";
    // set our variable to send to the public variable. 
  _transmit = parseText (_startuf + _titletuf + _texttuf); 
 // _transmit = _startuf + _titleuf + _textuf;
   // Change the Public Variable - This triggers the publicVariablEvent Handler
    BroadcastMessage = _transmitString;     
}
_mortor2s1 = "B_Mortar_01_F" createVehicle (position s1); 
_mortor2s1 setDir 0; 
sleep 1.0;

It always seem to produce the same error

spawnmortor.sqf' date=' line 1

Error in expression <\scripts\spawnmortor.sqf"[/color']

if (isPlayer) then {

_startuf = "<br/><img size='4>

Error position: <) then {

_startuf = "<br/><img size='4>

Error unexpected )

Thanks again in advance

Share this post


Link to post
Share on other sites

I don't know much about HTML, but that error says that is your problem. Take a look again and make sure you syntax is right?

Share this post


Link to post
Share on other sites

I am sure the syntax is right as its the same in other scripts and they display perfectly.

The error say line 1 doesnt that refer to if (isPlayer) then { ?

Its since I added this line to it that the erros occur

thx in advance

Share this post


Link to post
Share on other sites

Ah, good call. Sorry, I read it wrong. Anyway, your issue is that isPlayer doesn't work like isMultiplayer, isServer, etc, in that it requires an argument. IE,

if (isPlayer unitnamehere) then {

Share this post


Link to post
Share on other sites

Just tried the above but now nothing at all.

Something in the below bits of code is not working I have no idea why - probably gonna give up on it and find a work round. Its fustrating as it seems it should be something so easy to do - send a message to all players.

init.sqf.

if (isServer) then {    
   // Create a Public 
   publicVariableServer "BroadcastMessage";
   "BroadcastMessage" addPublicVariableEventHandler {
       [_this] call pre_fnc_broadcastMsg;
   };
   pre_fnc_broadcastMsg = {
       private ["_broadcastString"];
       // Ensure a string is being passed
       _broadcastString = [_this, 0, "EMPTY STRING OR WRONG TYPE", [""]] call BIS_fnc_params;
       hint format["%1", _broadcastString];
   };
};

spawn_mortor.sqf

if (isPlayer s1) then {  
   // Message Content Here
   _startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>";     
   _titletuf  = "<t color='#FFFFFF' size='1.2' align='left'><br/>Mortor Support</t><br/>"; 
   _texttuf   = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight. <br/><br/>";
   // set our variable to send to the public variable.
   _transmit = parseText (_startuf + _titletuf + _texttuf);
   // Change the Public Variable - This triggers the publicVariablEvent Handler
   BroadcastMessage = _transmitString;  
_mortor2s1 = "B_Mortar_01_F" createVehicle (position s1); 
_mortor2s1 setDir 0; 
sleep 1.0;

Someting is not right and I have no idea what.

Once again thanks for you help

Share this post


Link to post
Share on other sites

I strongly suggest you put a few "player sideChat "Test 1";" lines in various places to determine where the break is. This is a simple way to debug your own scripts.

Also, you never closed your scope. Meaning you have an open { at the top, but no closing } wherever you want the scope to end. I'm assuming you want it to look like the following. Give it a shot.

if (isPlayer s1) then {  
   // Message Content Here
   _startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>";     
   _titletuf  = "<t color='#FFFFFF' size='1.2' align='left'><br/>Mortor Support</t><br/>"; 
   _texttuf   = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight. <br/><br/>";
   // set our variable to send to the public variable.
   _transmit = parseText (_startuf + _titletuf + _texttuf);
   // Change the Public Variable - This triggers the publicVariablEvent Handler
   BroadcastMessage = _transmitString;  
};
_mortor2s1 = "B_Mortar_01_F" createVehicle (position s1); 
_mortor2s1 setDir 0; 
sleep 1.0;  

Share this post


Link to post
Share on other sites
Just tried the above but now nothing at all.

Something in the below bits of code is not working I have no idea why - probably gonna give up on it and find a work round. Its fustrating as it seems it should be something so easy to do - send a message to all players.

init.sqf.

if (isServer) then {    
   // Create a Public 
   publicVariableServer "BroadcastMessage";
   "BroadcastMessage" addPublicVariableEventHandler {
       [_this] call pre_fnc_broadcastMsg;
   };
   pre_fnc_broadcastMsg = {
       private ["_broadcastString"];
       // Ensure a string is being passed
       _broadcastString = [_this, 0, "EMPTY STRING OR WRONG TYPE", [""]] call BIS_fnc_params;
       hint format["%1", _broadcastString];
   };
};

spawn_mortor.sqf

if (isPlayer s1) then {  
   // Message Content Here
   _startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>";     
   _titletuf  = "<t color='#FFFFFF' size='1.2' align='left'><br/>Mortor Support</t><br/>"; 
   _texttuf   = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight. <br/><br/>";
   // set our variable to send to the public variable.
   _transmit = parseText (_startuf + _titletuf + _texttuf);
   // Change the Public Variable - This triggers the publicVariablEvent Handler
   BroadcastMessage = _transmitString;  
_mortor2s1 = "B_Mortar_01_F" createVehicle (position s1); 
_mortor2s1 setDir 0; 
sleep 1.0;

Someting is not right and I have no idea what.

Once again thanks for you help

_texttuf   = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight. <br/><br/>";

is missing the closing element for <t such as </t>

Share this post


Link to post
Share on other sites

@TomTurner - Thanks for pointing this out. I have been on this for four days now so gettinga bit code blind. Funny thing is the meesage dispalys either with or without the closing tag. Have added it just in case

@ Grimes - Thnaks for the updated version - it's getting there now this displays message and deploys mortor (though not checked on dedi yet) But it now kicks up this error in line 9 (all previous error were line 1). Is it something to do with the naming of _transmit , _transmitString and _broadcastString?

if (isPlayer s1) then {  
   // Message Content Here
   _startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>";     
   _titletuf  = "<t color='#FFFFFF' size='1.2' align='left'><br/>Mortor Support.</t><br/>"; 
   _texttuf   = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight.</t><br/><br/>";
   // set our variable to send to the public variable.
   _transmit = parseText (_startuf + _titletuf + _texttuf);
   // Change the Public Variable - This triggers the publicVariablEvent Handler
   BroadcastMessage = _transmitString;  
};
_mortor2s1 = "B_Mortar_01_F" createVehicle (position s1); 
_mortor2s1 setDir 0; 
sleep 1.0;

Error in expression <tletuf + _texttuf);

BroadcastMessage = _transmitString;

};

_mortor2s1 = "B_Mo>

Error position: <_transmitString;

};

_mortor2s1 = "B_Mo>

Error Undefined variable in expression: _transmitstring

This is the reference in the init

if (isServer) then {    
   // Create a Public 
   publicVariableServer "BroadcastMessage";
   "BroadcastMessage" addPublicVariableEventHandler {
       [_this] call pre_fnc_broadcastMsg;
   };
   pre_fnc_broadcastMsg = {
       private ["_broadcastString"];
       // Ensure a string is being passed
       _broadcastString = [_this, 0, "EMPTY STRING OR WRONG TYPE", [""]] call BIS_fnc_params;
       hint format["%1", _broadcastString];
   };
};

Share this post


Link to post
Share on other sites

You never defined "_transmitstring". That's exactly what your error tells you as well.

My guess is that _transmitstring is supposed to be _broadcaststring. On that note, you are doing this in a rather bizarre way. You are defining a function, but never calling it. So it makes sense that the first block of code is working, and the 2nd block IS working (rather, it will when you change from _transmitstring to _broadcaststring), but you won't see anything because you never call the function (or you haven't mentioned it).

If that makes sense, take it n' run. I have to go for now, but if you're still having trouble, I'll help you out in a few hours. Good luck!

Share this post


Link to post
Share on other sites

Still no luck

I have tried every variant I can think of with _transmit, _broadcaststring, _broadcast and nothing seems to make a difference

As for doing it a bizre way - yep :-) and god knows how I got to here but its the only way I know -- That said everything works absolutley perfectly on our dedi with this one damn exception that only the person using the addaction sees the message. It's not even integral to the mission as it is a private server and we are all on TS and can communicate. I just thought it would be a nice touch too add some messages / pix especially as I am using these messages throughout the mission on other scripts and they work well and broadcast to everyone it was as soon as I wanted to make them addactions that the trouble began.

If I had known how difficult it was going to prove for my limited skills I would not have bothered but now I got this far would be good to see it through and hopefully learn something on the way.

once again thanks

Share this post


Link to post
Share on other sites
Just tried the above but now nothing at all.

Something in the below bits of code is not working I have no idea why - probably gonna give up on it and find a work round. Its fustrating as it seems it should be something so easy to do - send a message to all players.

init.sqf.

if (isServer) then {    
   // Create a Public 
   publicVariableServer "BroadcastMessage";
   "BroadcastMessage" addPublicVariableEventHandler {
       [_this] call pre_fnc_broadcastMsg;
   };
   pre_fnc_broadcastMsg = {
       private ["_broadcastString"];
       // Ensure a string is being passed
       _broadcastString = [_this, 0, "EMPTY STRING OR WRONG TYPE", [""]] call BIS_fnc_params;
       hint format["%1", _broadcastString];
   };
};

spawn_mortor.sqf

if (isPlayer s1) then {  
   // Message Content Here
   _startuf  = "<br/><img size='4' img image='icons\mortor1.paa' align='left'/><br/>";     
   _titletuf  = "<t color='#FFFFFF' size='1.2' align='left'><br/>Mortor Support</t><br/>"; 
   _texttuf   = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight. <br/><br/>";
   // set our variable to send to the public variable.
   _transmit = parseText (_startuf + _titletuf + _texttuf);
   // Change the Public Variable - This triggers the publicVariablEvent Handler
   BroadcastMessage = _transmitString;  
_mortor2s1 = "B_Mortar_01_F" createVehicle (position s1); 
_mortor2s1 setDir 0; 
sleep 1.0;

Someting is not right and I have no idea what.

Once again thanks for you help

publicVariable* does not set up a variable for automatic broadcasting. It just broadcasts the current value the moment it's called.

It's not enough to set BroadcastMessage. You need to call publicVariable every time it needs to be broadcast. If you update it and want the new value to be synchronized to others, you need to call publicVariable again.

Simple example:

init.sqf:

// Set the variable to an empty string, just for good measure (Not required).
BroadcastMessage = "";

// Listen for changes to the BroadcastMessage variable. (All computers listen).
BroadcastMessage_EH =
{
   // Get index one of arguments: [VariableName, >VariableValue<]
   _msg = _this select 1;

   // Display the message on this computer.
   hint format ["Someone triggered a message: %1", _msg];
};
"BroadcastMessage" addPublicEventHandler BroadcastMessage_EH;

SendDaMessage =
{
   // Set the variable to the argument (Message to send).
   BroadcastMessage = _this;

   // Broadcast the new value to all computers.
   publicVariable "BroadcastMessage";

   // Public variable event handlers are NOT triggered for the computer broadcasting the value.
   // So we have to display it to ourselves here.
   // Simply call the event handler with the arguments it expects [VariableName, VariableValue].
   ["BroadcastMessage", _this] call BroadcastMessage_EH;
};

Then just:

"This is a message to show to everyone" call SendDaMessage;

Edited by MulleDK19
Taking local player into account

Share this post


Link to post
Share on other sites

Went through and edited it myself.

1. Found another missing semi colon. Really, really gotta check for those. Granted it was in the middle of a script that was given to you, but still. Always be checking. Besides, this becomes apparent in the errors.

2. Swapped it so that the function was defined before the PVEH. No effect I don't think, but just makes sense.

3. BIS_fnc_params does not exist. It is param, singular. This is why nothing was happening.

4. _transmitString was supposed to be _transmit. It's funny because it wasn't even transmitting a string.

5. publicVariable EHs only detect the public broadcast of a designated variable. They do not broadcast it automatically. So, I added the broadcast.

6. "img image ''" was redundant.

7. format[] doesn't seem to like including actual text (it wants a string/number/boolean). Changed that to a normal hint, structure maintained.

8. Not sure of the point of the BIS_fnc_param in this case, as a string is not being passed. Removed.

9. Removed check for isPlayer. Redundant. Only players will use the addAction.

10. I see you've been changing between player and s1 and s5. I changed it to _this select 1, which returns the caller of the action. Makes things easier.

Also to note: You have some spelling errors throughout. They're in your quotes so it doesn't effect anything, but still.

Below is the final:

init.sqf

if (isServer) then {
pre_fnc_broadcastMsg = {
	_broadcastString = _this select 0;
	hint _broadcastString;
};

"BroadcastMessage" addPublicVariableEventHandler {
	[_this select 1] call pre_fnc_broadcastMsg;
};
};

spawn_mortor1.sqf

//nul = execVM "spawn_mortor1.sqf";
//Spawn Mortor
playsound "drill";

_startuf = "<img size='4' image='icons\mortor1.paa' align='left'/><br/>";     
_titletuf = "<t color='#FFFFFF' size='1.2' align='left'><br/>Mortor Support.</t><br/>"; 
_texttuf = "<t color='#58FA58' size='1.0' align='left'>A member of your sqaud is deploying a Mortor.<br/><br/>It is marked with green smoke and chemlight.</t><br/><br/>";

_transmit = _startuf + _titletuf + _texttuf;
_transmit = parseText _transmit;

BroadcastMessage = _transmit;  
publicVariableServer "BroadcastMessage";

_caller = _this select 1;
_callerpos = getPos _caller;
_mortor2tuf = "Chemlight_green" createVehicle _callerpos;
_mortor2tuf setDir 0;
sleep 1;

_mortor2tufe = createVehicle ["SmokeShellGreen", _callerpos, [],1,"NONE"];
_mortor2tufe setDir 0;
sleep 1;

_mortor2tuff = "B_Mortar_01_F" createVehicle _callerpos;
_mortor2tuff setDir 180;
sleep 1;

This will work when any player uses an addAction that results in the exec of spawn_mortor1.sqf. If it is lacking anything for some reason or you have questions, please feel free to ask.

Edited by Grimes [3rd ID]

Share this post


Link to post
Share on other sites

Quick - reply to say "holy crap" thanks - going to test this now will get back to you

thanks

---------- Post added at 12:52 AM ---------- Previous post was at 12:39 AM ----------

ok Quick test

Spawns items ok but no message

if i change = parseText _transmit; to = hintparseText_transmit;

I get message but still error

Error in expression <arseText _transmit;

BroadcastMessage = _transmit;

publicVariableServer "Broad>

Error position: <_transmit;

publicVariableServer "Broad>

Error Undefined variable in expression: _transmit

File E:\My Documents\.....spawnmortor.sqf, line 12

Thanks for help almost 1.0am here so thats it for tonight

Share this post


Link to post
Share on other sites

I don't know what to tell you my friend. I even tested it again by pasting what I posted up, and it still works. I strongly recommend you go through your lines and make sure you're not missing anything. Delete anything you had related to this, and replace it with what I put in my most recent post.

In fact, here is a sample mission. Download it, open it and load in, scroll your mouse wheel and select the action titled "Hello". Click. You'll see what you're looking for. I assure you, it works. You just need to re-read through what you have.

For what its worth, this is working on the Stable version. Haven't tested on Dev, and don't care to.

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  

×