Jump to content
Sign in to follow this  
allarvendla

Little Bird Deathmatch - messages to clients

Recommended Posts

Hello,

I have been scratching my head for a while now conserning a little MP DM "mission" I am working on.

The probleem is that I want to send messages via Chat if their helo is not able to fly anymore. And also add some smoke efect to the bird when it has failed.

Here is the main code that respawns helos and sends messages:

	_heli = _this select 0;
_pos = [((getPos _heli) select 0) + random 15 - random 15, ((getPos _heli) select 1) + random 15 - random 15, ((getPos _heli) select 2) + 0.1];
_dmg = getDammage _heli;
_type = typeOf _heli;
_loopServer = true;
_loopClient = true;
if (isDedicated)
then {
while{_loopServer}
do{	
	if (!canMove _heli)
	then{
		sleep (5 + (random 25));
		_heli setdammage 1;
		sleep 1;
		_new = _type createVehicle _pos;
		_new setPos _pos;
		nul = [_new] execVM "heli_respawn.sqf";
		_new setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""", _heli];
		processInitCommands;
		_loopServer = false;
	};
};
};
while{_loopClient}
do{
	if (!canMove _heli)
	then{
		[_heli, 3, time, false, true] spawn BIS_Effects_Burn;
		Vehicle _heli vehiclechat "Engine is on fire!";
		Vehicle _heli vehiclechat "It might explode at any moment!";
		sleep 0.2;
		_heli sideChat format["I am going down!"];
		_loopClient = false;
	};
};
};

As can be seen, first half of it runs on the server side of things - so I don't get multiple helos spawned. The second half runs or should run on client.

I tried using

if (isMultiplayer) then ..blabla 

for the second half. But it did not help. "Works" the same without it.

The script itself is attached to every helo on the map. So multiple instances of it run at the same time but each helo has its own name.

Everything works as it should until first respawn for each bird.

I don't know if there is a solution to what I'm asking or if anyone even understood my problem, but I hope that someone just might know how to help me.

I am quite new to scripting :/

So I would really appreciate any help I can get :)

I also made a little video of it:

http://www.twitch.tv/allavett/b/506866092

Share this post


Link to post
Share on other sites

Sorry for that, did not manage to ask a proper question indeed :/

I'll explain it a little further.

My goal is to respawn helos that can't fly anymore. To achieve this, I use the script shown in OP. This script is attached to every helo on the map. So if the mission starts this script will run on each helo to check it's ability to fly.

If helo gets damaged it will explode at a random moment and then respawn. This is done on the first half of the script, that will only run on server:

if (isDedicated)
then {
while{_loopServer}
do{	
	if (!canMove _heli)
	then{
		sleep (5 + (random 25));
		_heli setdammage 1;
		sleep 1;
		_new = _type createVehicle _pos;
		_new setPos _pos;
		nul = [_new] execVM "heli_respawn.sqf";
		_new setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""", _heli];
		processInitCommands;
		_loopServer = false;
	};
};
};

And the second half will run on client to set helo on fire and give notification to player that it is wise to eject.

while{_loopClient}
do{
	if (!canMove _heli)
	then{
		[_heli, 3, time, false, true] spawn BIS_Effects_Burn;
		Vehicle _heli vehiclechat "Engine is on fire!";
		Vehicle _heli vehiclechat "It might explode at any moment!";
		sleep 0.2;
		_heli sideChat format["I am going down!"];
		_loopClient = false;
	};
};
};

The problem is that after respawn the second half of the script will not run on client but on server. And so players won't see the messages or the smoke.

How could I force the second half to run again on clients?

Share this post


Link to post
Share on other sites

This is a quick mockup of how I would do it:


//Execute script only on players, assuming you run this as dedicated.
//Run this only once on every client, you can put this in init.sqf
if (!isDedicated) then {

//Keep a loop running constantly, but do stuff only when necessary.
while {true} do {
	waitUntil {sleep 0.5; (vehicle player != player);};
	while {vehicle player != player} do {
		_heli = vehicle player;
		if (!canMove _heli) then {
			[_heli, 3, time, false, true] spawn BIS_Effects_Burn; 
			_heli vehiclechat "Engine is on fire!"; 
			_heli vehiclechat "It might explode at any moment!"; 
			sleep 0.2; 
			_heli sideChat format["I am going down!"]; 
		};
		sleep 1;
	};
};
};

Share this post


Link to post
Share on other sites

Thank you Viba!

This is almost what I want. But there are slight "problems" with it.

Helos, that are unmanned won't run this script and therfore will not start burning.

Using your idea I wrote this:

if (isMultiplayer) then {
   while {true} do {
	_damage1 = getDammage heli1;
       if (!canMove heli1 and _damage1 < 0.9) then {
		heli1 setDammage 0.95;
           [heli1, 3, time, false, true] spawn BIS_Effects_Burn; 
           heli1 vehiclechat "Engine is on fire!"; 
           heli1 vehiclechat "It might explode at any moment!"; 
           sleep 0.2; 
           heli1 sideChat format["I am going down!"]; 
       };
	_damage2 = getDammage heli2;
       if (!canMove heli2 and _damage2 < 0.9) then {
		heli2 setDammage 0.95;
           [heli2, 3, time, false, true] spawn BIS_Effects_Burn; 
           heli2 vehiclechat "Engine is on fire!"; 
           heli2 vehiclechat "It might explode at any moment!"; 
           sleep 0.2; 
           heli2 sideChat format["I am going down!"]; 
       };
	_damage3 = getDammage heli3;
	etc..
};	
};

to check each helo one by one. This will give me the result I am going for. But I have 12 helos on the map and I wonder if there is some way I could use arrays to solve it?

Seems a bit stupid to write all this code. And making changes to it will be really tedious :/

Share this post


Link to post
Share on other sites

What about this? Changed the ands to ors in the if, otherwise if the chopper is broken but damage not over 0.9 it wouldn't do anything.

//Execute script only on players, assuming you run this as dedicated.
//Run this only once on every client, you can put this in init.sqf
if (!isDedicated) then {

//Keep a loop running constantly, but do stuff only when necessary.
while {true} do {
	waitUntil {sleep 0.5; (vehicle player != player);};
	while {vehicle player != player} do {
		_heli = vehicle player;
		if (!(canMove _heli) || ((damage _heli) > 0.9)) then {
			_heli vehiclechat "Engine is on fire!"; 
			_heli vehiclechat "It might explode at any moment!"; 
			sleep 0.2; 
			_heli sideChat format["I am going down!"]; 
		};
		sleep 1;
	};
};
};  

//Run a check on the server for helis, if unable to fly make them burn.
//Also works by putting in init.sqf
if (isDedicated) then {
while {true} do {
	_helicopters = [heli1,heli2,heli3]; //add all the helis here
	{
		_heli = _x;
		if (!(canMove _heli) || ((damage _heli) > 0.9)) then {
			[_heli, 3, time, false, true] spawn BIS_Effects_Burn;
		}; 
	} forEach _helicopters;
	sleep 1;
};
};

Share this post


Link to post
Share on other sites

Viba, thank you, thank you, thank you!

Kiitos! Aitäh!:rolleyes:

My final script looks like this:

BIS_Effects_Burn=compile preprocessFileLineNumbers "\ca\Data\ParticleEffects\SCRIPTS\destruction\burn.sqf";

//Run a check on the server for helis, if unable to fly make them burn. 
if (isMultiplayer) then { 
   while {true} do { 
       _helicopters = [heli1, heli2, heli3, heli4, heli5, heli6, heli7, heli8, heli9, heli11, heli12]; //add all the helis here 
       { 
           _heli = _x; 
		_fuel = fuel _heli;
           if (!(canMove _heli) && (_fuel > 0)) then {
			_heli setHit ["motor", 1];
			_heli setFuel 0;
			[_heli, 3, time, false, true] spawn BIS_Effects_Burn;
			_heli vehiclechat "Engine is on fire!";  
               _heli vehiclechat "It might explode at any moment!";  
               _heli sideChat format["I am going down!"];
			sleep 0.01; 
           };  
       } forEach _helicopters; 
   }; 
}; 

And it seems to work perfectly! :)

I could not have done it without your help!

Now I have to get some friends and test it out for real.

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  

×