Jump to content
Sign in to follow this  
odyseus

Script check dead bodies then crows flying over it

Recommended Posts

I need a script that will check for any dead bodies, then it will count a specific time, if body still there then it will set crows over it. if body is removed them crows disappear. Any ideas? is it even possible?

Share this post


Link to post
Share on other sites

u could attach a killed eventhandler to check if they're alive or not, as soon as they're killed the eh starts a function which is spawning such crows, or do any other weird stuff... but i'm not sure if it's possible to spawn crows...

Share this post


Link to post
Share on other sites
u could attach a killed eventhandler to check if they're alive or not, as soon as they're killed the eh starts a function which is spawning such crows, or do any other weird stuff... but i'm not sure if it's possible to spawn crows...

How do i go about doing this eventhandler?

Does anybody know if it is possible to spaw crows or seagull or something?.. :D Ok guys i just found this http://community.bistudio.com/wiki/BIS_fnc_crows so i think it is possible. now i just need to figure out how to make a script that will check for dead bodies.

Edited by Odyseus

Share this post


Link to post
Share on other sites

This has not been tested -

make sure you have function module on map

init of each person you want the crows to be added to

this addEventHandler["Killed", {[(_this select 0)] execVM "crows.sqf"; }];

crows.sqf

waituntil { !isNil "BIS_fnc_init" };
_deaddude = _this select 0;
bis_crows = [_deaddude,20,8,20] call bis_fnc_crows;

Share this post


Link to post
Share on other sites

1.

Crow_array = [];

Nevermore = 
{
_tgt = _this select 0;

_tooMuch = false;

	{
	if ((_tgt distance _x) < 200) exitwith {_tooMuch = true}
	}
foreach Crow_array;

if (_tooMuch) exitwith {};

Crow_array set [(count Crow_array),_tgt];

sleep 600 + (random 300);

_crows = [];

if not (isNull _tgt) then {_crows = [_tgt,20 + (random 10),8 + (round (random 8)),15 + (random 20)] call bis_fnc_crows}; 

waituntil
	{
	sleep 1;
	(isNull _tgt)
	};

{deleteVehicle _x} foreach _crows
};


{
_x addEventHandler ["killed", {nul = _this spawn Nevermore}]
}
foreach AllUnits;

2.

_eaten = [];

Crow_array = [];

while {(true)} do
{
sleep 30;
_yum = Alldead - _eaten;

	{
	_eaten set [(count _eaten),_x];
	[_x] spawn
		{	
		_tgt = _this select 0;

		_tooMuch = false;

			{
			if ((_tgt distance _x) < 200) exitwith {_tooMuch = true}
			}
		foreach Crow_array;

		if (_tooMuch) exitwith {};

		Crow_array set [(count Crow_array),_tgt];

		sleep 600 + (random 300);

		_crows = [];

		if not (isNull _tgt) then {_crows = [_tgt,20 + (random 10),8 + (round (random 8)),15 + (random 20)] call bis_fnc_crows};

		waituntil
			{
			sleep 1;
			(isNull _tgt)
			};

		{deleteVehicle _x} foreach _crows
			}
	}
foreach _yum
};

3.

_cntr = getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition");

_rd = 1.5 * (_cntr select 0);

Crow_array = [];

while {(true)} do
{
sleep 30;

_somethingIsRottenHere = selectBestPlaces [_cntr,_rd,"deadBody",15,10];

	{
	_pos = _x select 0;
	_val = _x select 1;
	_tooMuch = false;

		{
		if ((_pos distance _x) < 200) exitwith {_tooMuch = true}
		}
	foreach Crow_array;


	if (not (_tooMuch) and (_val > 0.3)) then
		{
		Crow_array set [(count Crow_array),_pos];
		[_pos] spawn
			{	
			_tgt = _this select 0;

			sleep 600 + (random 300);

			_crows = [_tgt,20 + (random 10),8 + (round (random 8)),15 + (random 20)] call bis_fnc_crows;
				}
		}
	}
foreach _somethingIsRottenHere
};

(will add up to 10 flocks every 30 seconds if not "handled" yet bodies are found no closer, than about 200 meters from nearest already existing flock.)

All tested (without function module) and spawning works (not tested removing crows after removing body), but tests was short, so I'm not sure, if this will be always reliable, this goes especially for third method, where also isn't check after sleep, if body is still there (can be added somehow), and there is no flock removing when body is no longer (probably also can be somehow added). Note also added distance check, so minimum distance between any flock should be around 200 meters (seems to be needed for places with many bodies to avoid too many flocks in one place, distance can be of course changed; if not desired at all - set limit to 0 meters or delete these lines). Time before crows spawning is each time randomly selected from range 10-15 minutes. This was quite hasty scripting, so probably can be done better/cleaner.

Edited by Rydygier

Share this post


Link to post
Share on other sites

thx guys, hey rydygier .what is the best way to run this script and why did you divide in 3 parts?

Share this post


Link to post
Share on other sites
thx guys, hey rydygier .what is the best way to run this script and why did you divide in 3 parts?

I think they are 3 ways of doing the it.

Share this post


Link to post
Share on other sites

These aren't three parts, but three alternative solutions. I suggest first or second one, third is rather for curiosity, as is based on another approach. The way: put chosen code into text file named eg "Crows" then change extension from .txt to .sqf, and paste this .sqf file into yours mission folder (or just prepare sqf file via Squint, AEdit or another such editor). Then put this into init field of any unit on map or into init.sqf file, if present in mission folder:

nul = [] execVM "Crows.sqf";

Code will be executed automatically at mission start.

Share this post


Link to post
Share on other sites
This has not been tested -

make sure you have function module on map

init of each person you want the crows to be added to

this addEventHandler["Killed", {[(_this select 0)] execVM "crows.sqf"; }];

crows.sqf

waituntil { !isNil "BIS_fnc_init" };
_deaddude = _this select 0;
bis_crows = [_deaddude,20,8,20] call bis_fnc_crows;

tested and worked!! good job and thx brother!! now the question is how can i do so i dont have to put this line in every unit i have. may i something that will look for all dead units with in the map? any ideas? There is also the fact that crows stay there even if unit is deleted. how could i fix it.

---------- Post added at 01:06 AM ---------- Previous post was at 01:04 AM ----------

These aren't three parts, but three alternative solutions. I suggest first or second one, third is rather for curiosity, as is based on another approach. The way: put chosen code into text file named eg "Crows" then change extension from .txt to .sqf, and paste this .sqf file into yours mission folder (or just prepare sqf file via Squint, AEdit or another such editor). Then put this into init field of any unit on map or into init.sqf file, if present in mission folder:

nul = [] execVM "Crows.sqf";

Code will be executed automatically at mission start.

Hey brother

I follow all your instructions, but some how it did not work. well on 1 ans 2 only one crow show up. so i cont know for sure if worked. any ideas?

Share this post


Link to post
Share on other sites

One crow? Very strange. If code is wrong, then there shouldn't be any crow, if is good, then should be 8-16 crows per flock... Well, it is working for me (tested without long sleep), so maybe give me here a repro mission with this problem, so I can check this, without it I can't say anything, cause currently haven't any info about this problem and do not want to guess blindly.

Share this post


Link to post
Share on other sites
One crow? Very strange. If code is wrong, then there shouldn't be any crow, if is good, then should be 8-16 crows per flock... Well, it is working for me (tested without long sleep), so maybe give me here a repro mission with this problem, so I can check this, without it I can't say anything, cause currently haven't any info about this problem and do not want to guess blindly.

Ok brother I will try to make one. Until there. do you think this would work??

I would put this on the init of the mission

nul = [] execVM "deadbodies.sqf";

this would be the script but i m sure it it not right. :D

_x addEventHandler ["killed",{[(deadbodies=true)] hint "unit is dead"}] foreach allUnits;

If (deadbodies) then {

sleep 10;

_flies = [_deadude,0.05,1.5] call bis_fnc_flies;

sleep 20;

_crows = [_deaddude, 20,8,20] call bis_fnc_crows;

}

Share this post


Link to post
Share on other sites

Ok guys i got it!!! But i still need some help.

This is what i got so far.

I put a trigger on the map. i set it to true and on the action box i put

{_x addEventHandler ["killed", {[(_this select 0)] execVM "deadbodies.sqf"}]}foreach allUnits

Then i use the code that Mike boy gave me to make an deadbodies.sqf file. Thx brother :D

waituntil { !isNil "BIS_fnc_init" };

_deaddude = _this select 0;

bis_crows = [_deaddude,20,8,20] call bis_fnc_crows;

So here is what i still need. I need to know how to add fies and how to remove both them ones the body is gone.

I found this online but i dont have a clue how to use it. Please help! :D thx to all who have try to help me so far. As you all can see i m new to this. :D

Share this post


Link to post
Share on other sites

Yep, this trigger way of EH adding is also good.

You can try such code of deadbodies.sqf (untested):

waituntil { !isNil "BIS_fnc_init" };
_deaddude = _this select 0;

sleep (10 + (random 5));
_flies = [(position _deaddude),0.05 + (random 0.05),1 + (random 1)] call bis_fnc_flies;//randomized params
sleep (20 + (random 10));
_crows = [_deaddude,20 + (random 10),8 + (round (random 8)),15 + (random 20)] call bis_fnc_crows;//randomized params

waitUntil {sleep 1; (isNull _deaddude)};//I hope this will make, that script will wait for vanishing of the body before deleting, but I'm not quite sure of this

sleep (10 + (random 5));//some delay

{deleteVehicle _x;sleep (random 5)} foreach _flies;//removing flies with some intervals

sleep (20 + (random 10));//another delay

{deleteVehicle _x;sleep (random 10)} foreach _crows;//removing crows with some delays between each delete

Note one important thing: added "_" before variable containing all crow objects for given flock. Why? Because without it it is a global variable. This means, that each next flock will overwrite previous, so only last one can be deleted, and will be deleted regardless, which body is gone. So this "_" makes variable local to given script (body) to avoid such problems...

Note also, that in [] brackets before "call" added some randomization for better effect, this can be replaced by default or any other values, if randomization is not desired. Sleeps also can be randomized, so instead of always same 10 second delay can be used random value from eg 10-15 range. Properly used randomization can add to mission some nice flavour.

Now this is quite similar to my first method plus these flies... Still be awared, that there is no distance limitation, so if you will have eg 12 bodies close together, there will be really lots of crows and flies over them. This may have impact on performance and may look weird. So still in my opinion would be the best to use my method, eg first. Flies can be easily added here.

---------- Post added at 12:02 ---------- Previous post was at 10:22 ----------

I'm preparing some small demo. One "issue" - noticed, that crow flock is replenished after each deletion, will try to do something about this... There is no such problem with flies.

Edited by Rydygier

Share this post


Link to post
Share on other sites

Checked crow function code. Well. There is fsm loop for each spawned crow, so when crow is deleted, immediately new is created instead. Do not see any chance for external interruption of this loop. I see only three options: to write own crows function, or extract and use after modification function from A2 pbo's or do not delete crows, but to hide them via hideObject comand. Visual effect will be same, but crows will be still there, will be heard and will affect performance, so I'm not happy with this. Anyway here is demo with such "hiding" version:

Crows&Flies

Note:

1. Function module on map seems to be necessary only beacuse of flies function. Crow function works also without it;

2. First kill the soldier in front of you;

3. Wait, and come closer to see, that soon will appear flies; after another delay also crows will show up;

4. To remove body use 0-0-0 key combination (Juliet radio channel);

5. After that plus short delay flies will be removed;

6. After longer delay crows will be hided one by one until all become invisible.

EDIT: oh, you can also setPos each crow far, far away, plus maybe limit speed, so they will fly back long enough, but, this method is, well, hmm, :annoy:

---------- Post added at 15:17 ---------- Previous post was at 14:07 ----------

I think, that I have far better solution for crows removing. What, if flock will be not deleted/hidden, but just fly away (really very, very far, so shouldn't return fo very long)? After some test came to this version, seems to be quite fine:

Crows&Flies

Only problem is, that with every next crow present on map impact on performance will be minimal greater, as none of them will be deleted...

Idea for more advanced scripting: do not spawn any new crows, but to use crows already present on map (or maybe add some initially for that purpose) and let them to be dynamically and randomly attracted by places with bodies...

Edited by Rydygier
small code fix

Share this post


Link to post
Share on other sites

I see that is a big problem. Since I m planing to use it on Multiplayer.

My initial idea was after 10 min someone dies flies would spaw over the body. the number of flies would increase every 30 min, if body still there. then crown would spawn. number of crow did not have to increase with time. but it should be visible from up far so a fair number of it would be enough. too bad you can delete it after after body is gone.

What do you think the best solution is?

Are you gonna post that demo with our first code?? I m dying to see it how it look. It is true i try my with more them one body and it looks crazy! :D

Edited by Odyseus

Share this post


Link to post
Share on other sites

Do not know much about MP scripting, but I would try to use custom crow spawner instead of BIS' if deletion is necessary, simpliest - same code, but modified. Also know little about fsms, but maybe is needed only small change: some possibility of breaking re-spawn loop on demand or automatically, when body object passed into such modified function become null (disappear).

Share this post


Link to post
Share on other sites

See my post 15:17, second link - this is my demo. In this demo crows just fly away. Best would be in my opinion to combine both solutions - flock is flying away, and then removed... I do not know, if time will allow me, if so, then may try to mess a little with crows function as kind of FSM coding practice.

---------- Post added at 22:05 ---------- Previous post was at 20:57 ----------

OK. Check this:

C&F

This contains modified by me BIS crow function (heh, my first FSM editing, hope that I did not broke anything). Seems, that works fine. Now flock will fly away and every crow will be deleted at distance more than 1000 meters from body. Also added new flies source every 30 minutes up to 8 times after four houres. So now probably only time before flies and crows appearing need to be adjusted. And perhaps minimum distance between flocks and flies swarms. Now is set 150 meters for crows and 20 for flies (if within this radius already exists flock/swarm, new one will be not created over given body).

EDIT: still must do some tests for this minimum distance check, seems to be not optimal.

EDIT2: So made some adjustments: distances are now 100 and 10 and should be checked more reliable, crows are flying a bit higher...

Edited by Rydygier

Share this post


Link to post
Share on other sites

Brother.... What can i say? You rock! :D Good job and a big thx. So far from what i tested i worked perfect!

Share this post


Link to post
Share on other sites

Great. However noticed, what SaOk said in nearby thread - indeed, good idea to make crows to fly in from somewhere. So added such thing into my version, in my way: each crow will be spawned at some distance (800-1400 meters) in random direction and will fly towards area with body (this will take additional seconds of course). Next - same: will circle as long, as body exist, when body is removed - all crows, this time together, as flock, will fly away towards randomly chosen "somewhere", and will be removed at 1000 meters.

C&F

In my opinion final effect is very nice and looks natural: crows gather progressively over the body.

Edited by Rydygier
re-upload

Share this post


Link to post
Share on other sites

At first, I'm sorry for gravediggin this thread.

I'm extremely interested into the Script, postet by Rydygier, but it seems the Linked file is down.

If someone has the file(s) laying on his Harddrive, I would really appreciate it, if this person could take the time to re upload and link it here.

Greez KiloSwiss

Share this post


Link to post
Share on other sites

This should be the proper version, I hope... (updated also link above)

Prepared today revisioned version:

C&F 1.1

Should have significantly lowered CPU/scheduler cost, fixed one bug, added longer random time before flies appear.

Edited by Rydygier

Share this post


Link to post
Share on other sites

Thank You for the fast reply and also for sharing Your work and knowledge with the community!

The script works like a charm in mulitplayer.

I only changed the amount of crows {2 + (random 3)} and added it to my 404WASTELAND Takistan Mission.

The crows and flies leave the position of the dead body as soon as it disappears.

I also use Celerys CLY Remove Dead script to make dead bodys disappear after a short while.

Greez KiloSwiss

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  

×