jakerod 254 Posted September 16, 2011 (edited) Garrison House Area Script (Pastebin) (Updated v1.2) First off I would like to apologize for not being able to post the script directly to the forum but it is about 6 times too long to fit here. This is my first scripting project and I hope that you guys find it useful. What It Does: The script places men inside houses at windows, doors, and on rooftops and balconies. The men can have a probability of presence. It presently only works for buildings on Takistan, Shapur, Desert, Zargabad, and some on Proving Grounds. Limitations: There is a small amount of down time when the script is called where the men are created and placed in position. The more men you want the longer it will take for the script to place them. The Airport Control Tower is not present in the present version due to an issue I am having figuring out positions for it. May cause lag, depending on unit count, if used during mission. MP effects unknown. Group Limit Applies Guys presently look off in random directions. Tips: Best results if script is run at the beginning of the mission. Future Plans (if I have time): Men will hopefully face the right direction. Trigger Area and/or Marker Area based instead of Radius based. Cleaner Code, easier customization. Chernarus, Utes, and Proving Ground Buildings How It Works Requires 2 Markers (1 that is used as a center around which men will appear in buildings and another for where the men should spawn) At least 1 Unit of the Side that you are creating or a Side Center There are 7 different inputs needed when running the script: garrison_01 = ["marker_name",radius,%_of_buildings,%_of_positions,min_skill,max_skill,faction#,"marker_name_2",window#,door#,roof#,balcony#] execVM "jsp_garrison_radius.sqf"; "marker_name" - the marker around which you want the placement to be centered. radius - the radius around the marker that you want buildings to be occupied in. %_of_buildings - the percentage of buildings that you want to have occupied. .1 = 10%: .5 = 50%. Any number 0 - 1 should work.***New/Fixed v1.2 %_of_positions - the percentage of positions that you want to have occupied. .1 = 10%: .5 = 50%. Any number 0 - 1 should work. min_skill - the minimum amount of skill for the units. max_skill - the maximum amount of skill for the units. faction# - the number for the faction that you want created (Found Below). "marker_name_2" - defines where the units spawn before they are placed into the buildings. window# - defines whether units spawn in windows (0 = Off/No; 1 = On/Yes) ***New v1.1 door# - defines whether units spawn in doors (0 = Off/No; 1 = On/Yes) ***New v1.1 roof# - defines whether units spawn on the roof (0 = Off/No; 1 = On/Yes) ***New v1.1 balcony# - defines whether units spawn on balconies (0 = Off/No; 1 = On/Yes) ***New v1.1 Faction Numbers: 0 - Takistan Militia 1 - Takistan Army 2 - Takistan Militia and Takistan Army 3 - Takistan Locals 4 - Takistan Miltia and Takistan Locals (Allied) 5 - US Army 6 - UK Army 7 - CDF 8 - Chedaki (Insurgents) 9 - NAPA (Guerillas) 10 - Russian Army 11 - US Marines 12 - Czech Army 13 - United Nations (UNO) 14 - PMC 15 - UK Army Desert 16 - UK Army Green The script detects the houses within the given radius and finds the ones that are located in the library. The script then reads several pieces of data including the minimum and maximum skill that were entered and the percentage of positions that are filled. Each position has an array of one of five types attached to it; rifleman, anti-tank, machinegun, anti-tank/machinegun, and sniper. These arrays are located in the "Faction Unit Library". The script takes a random unit from the Unit Array and selects him for the given position and then, if a position probability of less than 1 was selected determines if the unit should be created. If the unit is created then he will be created at the Spawn Marker ("marker_name_2") and teleported into his position in the house. The units for each group are told to not leave the house and attack and to stop where they are. This prevents them from leaving the building in most situations. The only time I have observed them leaving is if they are under a lot of fire or if they run out of ammo. They will fire at targets. gFDsT31FLs8&edit (Note it is easy to hide the guys from the player's view when they are appearing) Quick Start 1.) Place Trigger 2.) Set to Radio Alpha 3.) In On Activation Line type: garrison_test = ["mkr2",100,1,1,1,1,1,"squad1",1,1,1,1] execVM "jsp_garrison_radius.sqf"; 4.) Close Trigger 5.) Place Marker 6.) Name mkr2 7.) Place 2nd Marker 8.) Name squad1 9.) Place OPFOR unit on map 10.) Place Player Unit (Must be group leader for this example) 11.) Save Map 12.) Paste Code from Pastebin into notepad file. 13.) Save as "jsp_garrison_radius.sqf" (with quotes) and select All Files 14.) Put above script file into mission folder 15.) Go Back into Editor 16.) Hit Preview 17.) Hit 0 - 0 - 1 18.) Men should be created and placed into building. Example Mission (Updated to v1.2) Customization (How to Coming Soon) Edited September 21, 2011 by Jakerod Share this post Link to post Share on other sites
loyalguard 15 Posted September 16, 2011 Congrats on the release! I know a lot of hard work went into this. Share this post Link to post Share on other sites
The Hebrew Hammer 10 Posted September 16, 2011 Awesome! Share this post Link to post Share on other sites
Tankbuster 1746 Posted September 16, 2011 (edited) If you've told them not to attack, will they still look for and fire at targets? Edit: Also, could a future version be made to prioritise inside positions in the buildings, ie, not rooftops? Edited September 16, 2011 by Tankbuster Share this post Link to post Share on other sites
jakerod 254 Posted September 16, 2011 (edited) If you've told them not to attack, will they still look for and fire at targets?Edit: Also, could a future version be made to prioritise inside positions in the buildings, ie, not rooftops? They will still fire at targets. They will just not go running off on their own to do it. There are some issues with glass windows on certain models but I am hoping the next patch fixes it. I was actually hoping to make roofs optional but I didn't manage to get it into this release because I was trying to find a good way to do it but I haven't thought of one yet. I will try to find a good way to go about it. Edited September 16, 2011 by Jakerod Share this post Link to post Share on other sites
Tankbuster 1746 Posted September 16, 2011 Excellent. I'm looking at how to graft this onto my Domi edit right now. Having played insurgency, one of the things I love about that is going house to house, clearing out. I think I'll have some of my enemies inside using this and some outside using the domi spawn scripts. ---------- Post added at 10:08 PM ---------- Previous post was at 09:54 PM ---------- Wow. That's a lot of code you've written there! Some painstaking research has clearly been done. Respect. :) One more question - does your script actually spawn the guys and move them, or does it move an existing squad members? Share this post Link to post Share on other sites
jakerod 254 Posted September 16, 2011 Excellent. I'm looking at how to graft this onto my Domi edit right now. Having played insurgency, one of the things I love about that is going house to house, clearing out. I think I'll have some of my enemies inside using this and some outside using the domi spawn scripts. ---------- Post added at 10:08 PM ---------- Previous post was at 09:54 PM ---------- Wow. That's a lot of code you've written there! Some painstaking research has clearly been done. Respect. :) One more question - does your script actually spawn the guys and move them, or does it move an existing squad members? It spawns them and then moves them. If you watch the video the marker I named "squad1" is where they all spawn and that is why they are appearing and disappearing in front of me in the video. About the research, the worst part (and a funny story) was the building that is under construction in Zargabad. There were initially 70 something positions I found in it. Then I realized that there was a minor issues when I was finding them. I was apparently finding some of them relative to the two cranes outside instead of the building. So when I tried to spawn the guys the first time half of them spawned in the air and all of a sudden there were bodies all around me raining down, hitting the ground, and dying. Then I went back through, refound all the positions plus 24 more or something like that. Now there are like 94 or something in that building. It was a pain in the ass but it was mildly entertaining. Share this post Link to post Share on other sites
twirly 11 Posted September 16, 2011 (edited) Well done that you got it working. That's a huge amount of code! Look in the spoiler for code that will place any number (144 limit) of squads in any buildings with positions...on any island. You might be able to get ideas from it. Feel free to hack and chop as you see fit. It's well commented... so should be easy enough to follow. bldg_placeunits.sqf /* bldg_placeunits.sqf TWIRLY - 15th September 2011 Call with:- nul = [center,[squad1,squad2,squad3],100,TRUE] execVM "bldg_placeunits.sqf"; Where:- center = the object around which to find buildings [squad1,squ...] = the squads to place in the buildings...array 100 = the distance from center to find buildings TRUE = draw markers at the position of the placed units...this is optional and the default is FALSE This will find all positions in buildings within 100m radius and place the units from the squads randomly at these locations. It will also draw markers at the position of the placed units. */ private ["_center","_squads","_radius","_marker","_builds","_units","_squad","_unit","_build","_numplaced","_i","_j", "_posarray","_rndpos","_pos","_cnt","_mkr","_m"]; _center = _this select 0; //the center object around which to search _squads = _this select 1; //the squads to place _radius = _this select 2; //the radius for finding buildings _marker = if (count _this >3) then {_this select 3} else {false}; //boolean...optional...for marker at position....default is false //finds buildings closeby _builds = nearestObjects [_center,["Building"],_radius]; _units = []; //collect all units for "_i" from 0 to ((count _squads) - 1) do { _squad = _squads select _i; for "_j" from 0 to ((count (units _squad)) -1) do { _unit = (units _squad) select _j; _units set [count _units,_unit]; sleep 0.01; }; }; _posarray = []; _pos = []; //collect all positions in all buildings for "_i" from 0 to ((count _builds) - 1) do { _build = _builds select _i; _cnt = 0; //as long as building position _cnt not equal to "[0,0,0]" keep looping while {format ["%1", _build buildingpos _cnt] != "[0,0,0]" } do { _pos = _build buildingpos _cnt; //select building position _cnt _posarray = _posarray + [_pos]; //add the position to the list _cnt = _cnt + 1; //increment counter sleep 0.01; }; sleep 0.01; }; _rndpos = []; _numplaced = 0; //keep looping till all objects placed while {_numplaced <= ((count _units) -1) and count _posarray >=1} do { //select a unit _unit = _units select _numplaced; //select a random position _indx = floor (random (count _posarray)); _rndpos = _posarray select _indx; //remove that position from the list....use workaround to remove an array from an array! _posarray set [_indx,"delete"]; //set the element to something else _posarray = _posarray - ["delete"]; //easy to remove now!! //move the unit into the position...make stop and set to standing or kneeling _unit setpos _rndpos; doStop _unit; _unit setunitpos (["middle","up"] select (floor (random 2))); //middle or up //do marker if required if (_marker) then { _mrk = format ["%1", diag_ticktime]; _m = createMarkerLocal [_mrk, _rndpos]; _m setMarkerTypeLocal "mil_dot"; _m setMarkerColorLocal "colorORANGE"; _m setMarkerSizeLocal [1, 1]; _m setMarkerAlphaLocal 1; //_m setMarkerTextLocal format ["%1", _numplaced]; }; //increment the number of placed objects _numplaced = _numplaced + 1; sleep 0.1; }; Note: This is not posted in order to "rain on your parade"... but to try to help you in the future. Edited September 16, 2011 by twirly Clarity Share this post Link to post Share on other sites
hellfire257 3 Posted September 16, 2011 (edited) Interesting... I'll take a look at this tomorrow. Good work Jakerod! EDIT: I recommend this pastebin: http://pastebin.jonasscholz.de/ It has SQF syntax support. ;) Edited September 16, 2011 by Hellfire257 Share this post Link to post Share on other sites
jakerod 254 Posted September 16, 2011 Well done that you got it working. That's a huge amount of code!Look in the spoiler for code that will place any number (144 limit) of squads in any buildings with positions...on any island. You might be able to get ideas from it. Feel free to hack and chop as you see fit. It's well commented... so should be easy enough to follow. bldg_placeunits.sqf /* bldg_placeunits.sqf TWIRLY - 15th September 2011 Call with:- nul = [center,[squad1,squad2,squad3],100,TRUE] execVM "bldg_placeunits.sqf"; Where:- center = the object around which to find buildings [squad1,squ...] = the squads to place in the buildings...array 100 = the distance from center to find buildings TRUE = draw markers at the position of the placed units...this is optional and the default is FALSE This will find all positions in buildings within 100m radius and place the units from the squads randomly at these locations. It will also draw markers at the position of the placed units. */ private ["_center","_squads","_radius","_marker","_builds","_units","_squad","_unit","_build","_numplaced","_i","_j", "_posarray","_rndpos","_pos","_cnt","_mkr","_m"]; _center = _this select 0; //the center object around which to search _squads = _this select 1; //the squads to place _radius = _this select 2; //the radius for finding buildings _marker = if (count _this >3) then {_this select 3} else {false}; //boolean...optional...for marker at position....default is false //finds buildings closeby _builds = nearestObjects [_center,["Building"],_radius]; _units = []; //collect all units for "_i" from 0 to ((count _squads) - 1) do { _squad = _squads select _i; for "_j" from 0 to ((count (units _squad)) -1) do { _unit = (units _squad) select _j; _units set [count _units,_unit]; sleep 0.01; }; }; _posarray = []; _pos = []; //collect all positions in all buildings for "_i" from 0 to ((count _builds) - 1) do { _build = _builds select _i; _cnt = 0; //as long as building position _cnt not equal to "[0,0,0]" keep looping while {format ["%1", _build buildingpos _cnt] != "[0,0,0]" } do { _pos = _build buildingpos _cnt; //select building position _cnt _posarray = _posarray + [_pos]; //add the position to the list _cnt = _cnt + 1; //increment counter sleep 0.01; }; sleep 0.01; }; _rndpos = []; _numplaced = 0; //keep looping till all objects placed while {_numplaced <= ((count _units) -1) and count _posarray >=1} do { //select a unit _unit = _units select _numplaced; //select a random position _indx = floor (random (count _posarray)); _rndpos = _posarray select _indx; //remove that position from the list....use workaround to remove an array from an array! _posarray set [_indx,"delete"]; //set the element to something else _posarray = _posarray - ["delete"]; //easy to remove now!! //move the unit into the position...make stop and set to standing or kneeling _unit setpos _rndpos; doStop _unit; _unit setunitpos (["middle","up"] select (floor (random 2))); //middle or up //do marker if required if (_marker) then { _mrk = format ["%1", diag_ticktime]; _m = createMarkerLocal [_mrk, _rndpos]; _m setMarkerTypeLocal "mil_dot"; _m setMarkerColorLocal "colorORANGE"; _m setMarkerSizeLocal [1, 1]; _m setMarkerAlphaLocal 1; //_m setMarkerTextLocal format ["%1", _numplaced]; }; //increment the number of placed objects _numplaced = _numplaced + 1; sleep 0.1; }; Note: This is not posted in order to "rain on your parade"... but to try to help you in the future. Thanks Twirly! I'll take a look at it. Interesting...I'll take a look at this tomorrow. Good work Jakerod! EDIT: I recommend this pastebin: http://pastebin.jonasscholz.de/ It has SQF syntax support. ;) Thanks.I just tried to do it in that and it seems that the number of characters or lines is too small though. It only goes up to 1864 and then it cuts it off it seems. I tried pasting it here too but it was like 20,000 characters too long. Share this post Link to post Share on other sites
Guest Posted September 17, 2011 Release frontpaged on the Armaholic homepage. Garrison House Area Script Share this post Link to post Share on other sites
Laqueesha 474 Posted September 17, 2011 Nice script; been waiting for something like this for a while now. ;) Share this post Link to post Share on other sites
Gunter Severloh 4064 Posted September 17, 2011 Cool, this will help add interesting CQC features to a misson. Nice work! Share this post Link to post Share on other sites
darkxess 60 Posted September 18, 2011 Mind making a demo mission? ... thanks for release :) Share this post Link to post Share on other sites
jakerod 254 Posted September 18, 2011 Mind making a demo mission? ... thanks for release :) Example Mission Share this post Link to post Share on other sites
orcinus 121 Posted September 18, 2011 Example Mission Hi Jakerod Thank you very much for the script & the example mission. I'm new to mission editing & have been struggling with getting units to take up positions in a cluster of buildings - this seems like hopefully it will make the task easy :) Cheers Orcinus Share this post Link to post Share on other sites
jakerod 254 Posted September 18, 2011 A little update: I'm presently working on it so that you can turn on/off the following things: Men in Windows Men on Roofs Men on Balconies Men in Doors Share this post Link to post Share on other sites
Tankbuster 1746 Posted September 18, 2011 Just a thought... for making the guys face in the right direction.. Supposing the given location of the building is it's dead centre (and I don't know that it is or isn't), could you make the units look right at the dead centre, then rotate them 180? Share this post Link to post Share on other sites
jakerod 254 Posted September 18, 2011 Just a thought... for making the guys face in the right direction..Supposing the given location of the building is it's dead centre (and I don't know that it is or isn't), could you make the units look right at the dead centre, then rotate them 180? That isn't always going to work though. Guys at corners for example. I might do that as a temporary measure though. The only problem is that setdir doesn't work. I have to tell them to watch a specific position I believe. That is the difficult part. Share this post Link to post Share on other sites
Tankbuster 1746 Posted September 18, 2011 Ah no, you're right. Can your script tell which guys are in windows, doorways and balconies? If so, those need to look away from the building centre, while guys in internal corners and spaces need to look towards the building centre. I didn't know setDir is broken, but the CIT mentions it. Have you tried setFormDir? Share this post Link to post Share on other sites
Muzzleflash 111 Posted September 18, 2011 (edited) setDir won't work because it is not meant to tell a unit what to do. It is only meant to orientate stuff. Logically the unit will change to do what his leader wants instead. setFormDir most likely won't work either because that is for groups. The group can only be facing one direction. Of course this isn't an issue if you just make a lot of 1-man groups. However, then you will run out of groups soon and every will be dumb because they don't share information. doWatch might work, I don't know. Or perhaps you can "separate" a unit from it's group with doStop and then try setDir on it. Edited September 18, 2011 by Muzzleflash Share this post Link to post Share on other sites
jakerod 254 Posted September 18, 2011 (edited) Ah no, you're right. Can your script tell which guys are in windows, doorways and balconies? If so, those need to look away from the building centre, while guys in internal corners and spaces need to look towards the building centre.I didn't know setDir is broken, but the CIT mentions it. Have you tried setFormDir? I'm fairly sure that will change the direction of everyone in the building because they are all in the same group. I just tried dostop and then SetDir with no luck. I think that for the time being the direction isn't a huge issue. I will work on it but generally speaking the men will see or hear you after your first shot and will orient themselves correctly. I don't think I can force them to watch an area no matter what without disabling their ability to target you. I updated the script now. ***Ability to Enable/Disable Roof Units Added ***Ability to Enable/Disable Window Units Added ***Ability to Enable/Disable Balcony Units Added ***Ability to Enable/Disable Door Units Added Edited September 18, 2011 by Jakerod Share this post Link to post Share on other sites
Tankbuster 1746 Posted September 18, 2011 You can apply setFormDir to individual units, not just groups, but I'll stop banging on about it now. :) Share this post Link to post Share on other sites
Muzzleflash 111 Posted September 18, 2011 You can apply setFormDir to individual units, not just groups, but I'll stop banging on about it now. :) Yes you can. But it still effects the units group. Share this post Link to post Share on other sites
jakerod 254 Posted September 18, 2011 Yeah I just tried doing setFormDir for each guy but they all just go off the leader or something. I actually managed to get it to work of a group of 4 guys by doing this setFormDir 0;dostop this and changed the 0 for each to other numbers. That worked then but not in the script for some reason. Share this post Link to post Share on other sites