Jump to content
phronk

[Release] Fleeing Civilians

Recommended Posts

uYCZtj8.png

By Phronk

 

DESCRIPTION:
Adds a "firedNear" eventHandler to all civilians in mission to flee into a random nearby house and also play a random frightened animation. (Check example on how to make it work for spawned civilians)

VIDEO:

 

FEATURES:

  • Supports a few maps by default:
    -Stratis
    -Altis
    -Tanoa
    -Chernarus
    -Takistan
    -Zargabad
  • Adding support for other maps is easy
  • Civilians will flee into a random nearby house when they hear a gunshot
  • Upon hearing the gunshot, civilians will play random frightened animation

 

TO DO LIST:

  • Improve efficiency
  • Add ArmA 1 maps from CUP:Terrains
  • Delete civilian's waypoints before ordering them to move
  • Possibly replace doMove with addWaypoint command

 

KNOWN BUGS:

  • Sometimes the civilian can't get into the house
  • Sometimes the civilian can walk through objects/structures
  • Civilian may continue to next waypoint if he already has one, after running to a nearby house

 

INSTALLATION:

NOTE: Demo mission requires CUP:Terrains & TalibanFighters, the script is standalone and does not require any scripts to use
 

  1. Copy & Paste "init.sqf" from demo mission to your mission, if you only want the civilians already placed in the mission to be effected
  2. Done!
  3. (OPTIONAL) If you want spawned civilians to be effected, do the following:
    1-1. Also copy & paste this code into your "init.sqf", in addition to the rest of the above example:
civFlee={_this select 0 addEventHandler["FiredNear",{
	_civ=_this select 0;		
			 switch(round(random 2))do{
		  case 0:{_civ switchMove "ApanPercMstpSnonWnonDnon_G01";_civ setSpeedMode "FULL";};
		  case 1:{_civ playMoveNow "ApanPknlMstpSnonWnonDnon_G01";_civ setSpeedMode "FULL";};
		  case 2:{_civ playMoveNow "ApanPpneMstpSnonWnonDnon_G01";_civ setSpeedMode "FULL";};
		  default{_civ playMoveNow "ApanPknlMstpSnonWnonDnon_G01";_civ setSpeedMode "FULL";};};		

		//nearestObjects[ PositionOrTarget, ["List","Of","Classnames","To","Look","For"], MaxDistanceToSearchAroundTarget ];
		_nH=nearestObjects[_civ,nH_List,100];		


		_H=selectRandom _nH;//Pick an object found in the above nearestObjects array		

		_HP=_H buildingPos -1;//Finds list of all available building positions in the selected building		

		_HP=selectRandom _HP;//Picks a building position from the list of building positions		

		_civ doMove _HP;//Orders the civilian to move to the building position		

		//Remove the eventHandler to prevent spamming
		_civ removeAllEventHandlers "FiredNear";}];};


1-2. In your civ spawning script, right after the civ is created (Example: _unit=createVehicle["C_Man_01",_pos,[],0,""];) paste this after:

 

[_unit]call civFlee;


1-3. Done!

 

v0.1 (Jan 1, 2017)
DOWNLOAD LINK - (Google Drive)

DOWNLOAD LINK - (Armaholic)

Change-Log:
(2017.1.1)

  • Initial Release
  • Like 16

Share this post


Link to post
Share on other sites

If you want guaranteed random number between 0 and 2 you use floor

floor random 3

will give you 0, 1 or 2 every time

However in your case you can just 
 

_unit playMove selectRandom ["anim1", "anim2", "anim3",......"anim1209370129378"];

 

  • Like 1

Share this post


Link to post
Share on other sites

Possible MP problems

most likely the civilians are local to server.

object switchMove "anim" - object can be remote, effect of this command is  local

object playMoveNow "anim" - object cant be remote, effect of this command is global

Share this post


Link to post
Share on other sites

Works fine in my MP mission tested on a dedicated server with spawned civilians (Civ spawning script used: Engima's Civilians) but the only difference was the 'civFlee' function was defined in it's own script containing functions.

Share this post


Link to post
Share on other sites

You can use 

_nH = nearestObjects [_civ, ["house"], 100];

for general class of house, that way you dont need to have separate list for each map (vannila, cup, ...)

 

  • Like 1

Share this post


Link to post
Share on other sites

"house" will also return objects with no house positions, as will "house_F" and so on.

And since I know it will be suggested, I know about the method to check if object has no building positions and exclude it, but in my experience it could glitch out and return map coordinates [0,0,0] as the building position (lower left corner of map) anyway.  It's a somewhat rare occurrence, but it can happen and I don't know why.  That's why I have predetermined arrays of houses to look for; guarantees avoidance of objects we don't want which don't have house positions.

Share this post


Link to post
Share on other sites

Can it be used with areas with no house? "nearestObjects" return empty array?

 

I am aware that you are using this with enigma's civilian script, but this should be more "in general use" for wider usage.

 

BTW I like this idea of fleeying civilians in terror very much :) Nice immersion.

  • Like 1

Share this post


Link to post
Share on other sites

At the moment, the unit will play a random frightened animation but won't move anywhere if there are no valid nearby houses.  I could add an additional block to make them run in a random direction, if that is the case.

Share this post


Link to post
Share on other sites

This looks great.  But I'm not a script person.  I'm a mods person.  Is there any chance you could chat with they guy who makes TPW mods, and see if this could get added? (with appropriate credit to you for this item, of course)  Here's to hoping!   :-)

-V

Share this post


Link to post
Share on other sites

Worked for me in editor preview, put the same mission on a dedicated and nothing.  Anyone else having a similar problem?

Share this post


Link to post
Share on other sites

@phronk Thanks for releasing this. I built an ambient civilian script manager for my Shadow Fall campaign, but couldn't get civilians to flee to gunfire reliably. They tended to run in place which looks very cartoonish, hehe. I would like to incorporate at least part of what you did into my scripts. 

  • Like 1

Share this post


Link to post
Share on other sites

Go for it.  Use it, modify it, whatever you want. :)

  • Like 3

Share this post


Link to post
Share on other sites

what are these animations?! are they in the game? i've never seen those and they look exactly what i was looking for a while back.

 

also great script.

 

as for the [0,0,0] output. why would you let that determine your ways so much? you can just do a check, if the position is [0,0,0] to see if there is a valid one, right? either use "isEqualTo" for array comparison or turn both into strings using "str" and compare those. i'd try to avoid predefined lists whenever possible.

Share this post


Link to post
Share on other sites

Because it would still return [0,0,0] no matter what sometimes and it annoys me.  Couldn't figure out why it was happening with my cache/intel script, until I replaced the [0,0,0] check with an array of houses and stuck to that.  Problem was solved.  Like I said, I know about these methods but for some reason they caused major issues with my cache script (Well actually, Hazey and Sacha Ligthert made the cache script I'm using atm but you know what I mean).

Share this post


Link to post
Share on other sites
3 hours ago, bad benson said:

what are these animations?! are they in the game?


Apparently

Share this post


Link to post
Share on other sites

yea i saw the class names now. still i wonder about the first part of my question. did BI start working on ambient civs? maybe for Combat Patrol? that would be great news.

 

EDIT: did some snooping around in the configs. apparently this is a whole set of actions and not just some cutscene animations. so it's set up with its own action set and animation transitions and all that. jsut in case someone else was wondering.

 

very interesting. i wonder if that is some abandoned stuff or, if it's new. anyways, sorry for brief hijack.

Share this post


Link to post
Share on other sites
38 minutes ago, bad benson said:

yea i saw the class names now. still i wonder about the first part of my question. did BI start working on ambient civs?


Most likely byproduct of SP and COOP efforts

Share this post


Link to post
Share on other sites

The animations were added in the Apex expansion, I believe.  Probably part of the new campaign, which I've STILL never even started lol.  I think BI is very slowly-but-surely improving the animations in the game and how they function and these might be on the side until they add it as a base action.  Who knows.  Then again, they've had animations for stuff like mounting/dismounting weapon attachments in the game forever and never did anything with them.  Some day?  Maybe?

Sorry about the script not being perfectly efficient.  I'll update it some other time to be a little better, but for the time being it works fine enough as is.

Share this post


Link to post
Share on other sites

no need to apologise. just making suggestions. good thing about not using fixed lists is that you never need to come back and add stuff. but i don't think your way is less efficient in terms of code speed unless you declare the class name array everytime.

 

as for the MP implications, i don't think switchmove having local effect will be an issue due to how the EH works. so all good. thx for bringing thse anims to my attention. you uncovered a real gem for me!

  • Like 1

Share this post


Link to post
Share on other sites

 

52 minutes ago, bad benson said:

as for the MP implications, i don't think switchmove having local effect will be an issue due to how the EH works.

 

I already told that because i have done quite the same realistic simulation in the past,

including civilian drivers and i spend dozen of hours for testing it in MP environment.

Some of the commands which switching animations need to be broadcasted over network to allow all clients see the effects.

 

Share this post


Link to post
Share on other sites

Is there any way to switch affected civillians to their normal behavior?

Well, aparently I need to switch some of them to their normal animation sets with PlayMoveNow in other script, but I am eventually not good with arma animations at all :/

Edited by Delta547

Share this post


Link to post
Share on other sites
19 minutes ago, davidoss said:

 

 

I already told that because i have done quite the same realistic simulation in the past,

including civilian drivers and i spend dozen of hours for testing it in MP environment.

Some of the commands which switching animations need to be broadcasted over network to allow all clients see the effects.

 

 

i meant the opposite though. in his video he is adding the EHs in the init.sqf without a server check using allunits. so each client will have their own EHs added. hence it working for him in MP.

 

you are probably right about it eventually probably being a good idea to do it differently though. i assume he was just trying to have a simple example for demonstration. either way. the code is in the first post ready to be grabbed and modified.

Share this post


Link to post
Share on other sites

 

Quote

Is there any way to switch affected civillians to their normal behavior?

Well, aparently I need to switch some of them to their normal animation sets with PlayMoveNow in other script, but I am eventually not good with arma animations at all :/

 

Just switchMove it to ""

 

I will give you example how to handle animations in MP:

 

Lets say we have an civilian local to server

now in case that unit should switch move and the script runs on server you need to do that in this way:

 

null = [_civ,_anim] remoteExec ["switchMove", 0, _civ];
// we remoteexec this anmation switch to all even server.
// in case the unit should stay in this animation for long time we need to add this to JIP queue too.

Now this part was easy but what if we want to let the players interact with civilians?

 

Now we need to keep in mind that :

playMove or playMoveNow  is arguments_local.gifeffects_global.gif which minds the civ need to be local to the pc where this command is fired and the effect is broadcast over network.

switchMove  is arguments_global.gifeffects_local.gif  which minds the civ can be remote to the pc where this command is fired and the effect is not broadcast over the network.

In that circumstances  we need to do  like  this :   

//this code runs on client which call the action
null = [(_this select 0),"Acts_ExecutionVictim_Unbow"] remoteExec ["playMove", 2, false];
//(_this select 0) is the civ unit (remote) to client ,
// we remote the command to the server only 
//because this need to be executed where the civ is local and the efect will be broadcast from server

 

//this code runs on client which call the action
null = [(_this select 0),"Acts_AidlPsitMstpSsurWnonDnon_out"] remoteExec ["switchMove", 0, false];
//(_this select 0) is the civ unit (remote) to client ,
// we remote the command to everybody
//because switchMove can be executed where the civ is local or remote and the efect stay local to everybody

This is little bit of-topic but shows the problem very well .

 What you need to knew more is which animations should run with which command.

  • Like 2

Share this post


Link to post
Share on other sites

@phronk great job with this, I've been able to incorporate it with the "TPW" addon. I'll have to play around with the code a little more to get it working perfectly with "TPW", the civilians don't play one of the three animations before taking off, they just take off and run.

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

×