Kydoimos 916 Posted June 18, 2015 (edited) Hi all, This should be a pretty simple problem to resolve but I'm actually finding it a bit harder than expected. Basically, I've created a template for a specific building by attaching objects to the specific layout of this building. But how would I assign a variable to the same building in the editor, to allow me to attach the template? I don't really want to have to hide the building and then create the same building in its position with the objects attached :) I've played around with the nearestObjects command but haven't had much luck! ---------- Post added at 20:43 ---------- Previous post was at 20:42 ---------- Here's the template SQF anyhow! // Shop V2 _Shop = Shop_02; // Shop Sign _positions_Sign = [ [[4.075,-2,0.6105], [0, "Resist\Images\Objects\Shop_Sign_02\Sign_Text_02_01_co.paa"]], [[4.075,-1,0.6105], [0, "Resist\Images\Objects\Shop_Sign_02\Sign_Text_02_02_co.paa"]], [[4.075,0,0.6105], [0, "Resist\Images\Objects\Shop_Sign_02\Sign_Text_02_03_co.paa"]], [[4.075,1,0.6105], [0, "Resist\Images\Objects\Shop_Sign_02\Sign_Text_02_04_co.paa"]], [[4.075,2,0.6105], [0, "Resist\Images\Objects\Shop_Sign_02\Sign_Text_02_05_co.paa"]] ]; _sign_Letters = []; { private ["_sign"]; _sign = "UserTexture1M_F" createVehicle position _shop; _sign attachTo [_shop, _x select 0]; _sign setDir -90; _sign setObjectTexture (_x select 1); _sign_Letters pushBack _sign; } forEach _positions_Sign; // Tables _positions_Tables = [ [2,-2.75,-2.295], [-0.5,-2.75,-2.295], [2,-2.75,1.585], [-0.5,-2.75,1.585], [-2.5,-2.75,1.585], [-0.5,0,1.585], [-2.5,0,1.585] ]; _tables = []; { private ["_table"]; _table = "Land_RattanTable_01_F" createVehicle position _shop; _table attachTo [_shop, _x]; _tables pushBack _table; } forEach _positions_Tables; // Chairs _positions_Chairs = [ [[2,-2,-2.125], 0], [[2,-2,-2.125], 0], [[2,-3.65,-2.125], 180], [[-0.5,-3.65,-2.125], 180], [[0.35,-2.85,-2.125], 90], [[-0.5,-3.65,1.75], 180], [[-2.5,-3.65,1.75], 180], [[2,-1.95,1.75], 0], [[-0.5,-1.95,1.75], 0], [[-2.5,-1.95,1.75], 0], [[-2.5,0.85,1.75], 0], [[-0.5,0.85,1.75], 0], [[2,-3.65,1.75], 180], [[-3.5,0.05,1.75], -90], [[0.5,0.05,1.75], 90] ]; _chairs = []; { private ["_chair"]; _chair = "Land_RattanChair_01_F" createVehicle position _shop; _chair attachTo [_shop, _x select 0]; _chair setDir (_x select 1); _chairs pushBack _chair; } forEach _positions_Chairs; // Counter _desk = "Land_CashDesk_F" createVehicle position _shop; _desk attachTo [_shop, [0,1.675,-2.695]]; _desk setDir -90; _iceBox = "Land_IceBox_F" createVehicle position _shop; _iceBox attachTo [_shop, [-0.065, -0.125, -2.15]]; _iceBox setDir -90; // Shop Board _positions_Boards = [ [[-2.3235,-3.5,-0.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_01_co.paa"]], [[-2.3235,-3.5,-1.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_02_co.paa"]], [[-2.3235,-2.5,-0.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_03_co.paa"]], [[-2.3235,-2.5,-1.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_04_co.paa"]], [[-2.3235,-1.5,-0.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_05_co.paa"]], [[-2.3235,-1.5,-1.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_06_co.paa"]], [[-2.3235,-0.5,-0.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_07_co.paa"]], [[-2.3235,-0.5,-1.5], [0, "Resist\Images\Objects\Sign_Board\Sign_Board_01_08_co.paa"]] ]; _boards = []; { private ["_board"]; _board = "UserTexture1M_F" createVehicle position _shop; _board attachTo [_shop, _x select 0]; _board setDir -90; _board setObjectTexture (_x select 1); _boards pushBack _board; } forEach _positions_Boards; // Boarded Windows _positions_Panels = [ [3.735,3.65,-1], [3.735,1.65,-1], [3.735,-1.85,-1], [3.735,-3.85,-1] ]; _panels = []; { private ["_panel"]; _panel = "Land_Shoot_House_Panels_F" createVehicle position _shop; _panel attachTo [_shop, _x]; _panel setDir -90; _panels pushBack _panel; } forEach _positions_Panels; // Graffiti _positions_Graffiti = [ [[3.82265,2.75,-2], [0, "Graffiti_01.paa"]], [[3.82265,-2.75,-2], [0, "Graffiti_02.paa"]] ]; _graffiti = []; { private ["_graffito"]; _graffito = "UserTexture10M_F" createVehicle position _shop; _graffito attachTo [_shop, _x select 0]; _graffito setDir -90; _graffito setObjectTexture (_x select 1); _graffiti pushBack _graffito; } forEach _positions_Graffiti; ---------- Post added at 20:57 ---------- Previous post was at 20:43 ---------- Seems I can use nearestObjects to spawn the template on the position of the building - but not to attach the objects? Maybe I'm missing something really obvious! :p Edited June 18, 2015 by Kydoimos Share this post Link to post Share on other sites
Jona33 51 Posted June 18, 2015 Try https://community.bistudio.com/wiki/nearestBuilding Share this post Link to post Share on other sites
Kydoimos 916 Posted June 19, 2015 @Jona33 - ah, that sounds like it might do the trick! Thanks man! I'll test it this evening! Share this post Link to post Share on other sites
Kydoimos 916 Posted June 19, 2015 Hmm - nearestBuilding didn't seem to work - objects just spawned at the building's centre! Had a gameLogic with this in its init.: Shop_02 = nearestBuilding this Share this post Link to post Share on other sites
Greenfist 1863 Posted June 19, 2015 (edited) I didn't know you could even attach objects to buildings? You could just setpos them and find the relative position with modelToWorld. _relpos = _shop modelToWorld _x; _table setposasl _relpos; But what about the setdir? What if the shop's direction is not 000? You'd need something like: _chair setdir ((getdir _shop) + 90) Edited June 19, 2015 by Greenfist Share this post Link to post Share on other sites
Kydoimos 916 Posted June 19, 2015 Thanks for the response Greenfist! I'll look into it! :) Share this post Link to post Share on other sites
Greenfist 1863 Posted June 19, 2015 ModelToWorld should be the same as what you have already defined for attachTo, so it'll be easy to fit in your existing script. Share this post Link to post Share on other sites
inlesco 233 Posted June 20, 2015 So basically you want to populate all buildings of a single type with this template? What's the building's classname? Share this post Link to post Share on other sites
Kydoimos 916 Posted June 20, 2015 @Inlesco - hi matey! Not all buildings - just one which is near a gameLogic or something. The building classname is "Land_i_Shop_02_V1_F". Share this post Link to post Share on other sites
Larrow 2823 Posted June 21, 2015 What have you used to create those offsets Kydoimos, I notice a lot of large negative height values in there e.g [-0.5,-2.75,-2.295]. Attaching anything to the shop with that value is going to make the object underground. It looks like you need to invert your Z offset. multiply it by -1. (edit - that most likely wont do, i think maybe all values would need inverting, not sure without testing) If you still have your mockups it may be easier to redo them using _house worldToModel getpos _object and then as Greenfist has shown use the opposite to respawn them _house modelToWorld _offset. Heres the functions i use for saving and test respawning my building layouts. getObjects.sqf //player addaction [ "save", { nul = [] execVM "getObjects.sqf"; }]; _house = nearestBuilding player; _objects = player nearEntities 5; //capture radius _houseRot = getDir _house; _housePos = getPosATL _house; objInfo = []; { if !( isPlayer _x ) then { _type = typeOf _x; _offset = _house worldToModel ( getPosATLVisual _x ); _rot = getDir _x; objInfo pushBack [ _type, _offset, _rot ]; }; }forEach _objects; setObjects //player addaction [ "load", { nul = [] execVM "setObjects.sqf"; }]; _house = nearestBuilding player; _houseRot = getDir _house; _housePos = getPosATL _house; { _objType = _x select 0; _offset = _x select 1; _rot = _x select 2; _item = createVehicle [ _objType, [ 0, 0, 0 ], [], 0, "CAN_COLLIDE" ]; _item setDir ( _houserot + _rot ); _item setPosATL ( _house modelToWorldVisual _offset ); }forEach objInfo; Change as needed, i usually just place a building of the type i want without rotation while as zues in a VR map, do all my placement, then save it using getObjects whilst walking around inside, hence the ignore player if statement :). Share this post Link to post Share on other sites
kbbw123 115 Posted June 21, 2015 the way we did it was to place a marker around the are of the house. next there is a list of coding to do ;) _House = "Markername"; // the place the script will start to look for the building _thishousepos = getmarkerpos _House; // this is done so that we can use multiple buildings with a diffrent script that have divvrent markers on them bit more complicated _Building = _thishousepos nearestobject "Land_i_Shop_02_V1_F"; // this tells the script what building it is its lookig for /* now in order to get everything right you will have to do the following to every object.*/ _item1 = "itemclass name or unit classname" createvehicle _thishousepos; _offset = [0,0,0]; //depending where you want it if you have all the items and offsets allready ready would say make a massive array shomwhere annd call them from there _Itempos = _building modeltoworld _offset; _item1 setpos _Itempos; _item1 setdir getdir _building+10; //direction. number depends where you want it directing to hope this helps Share this post Link to post Share on other sites
Greenfist 1863 Posted June 21, 2015 What have you used to create those offsets Kydoimos, I notice a lot of large negative height values in there e.g [-0.5,-2.75,-2.295].Attaching anything to the shop with that value is going to make the object underground. Isn't the center [0,0,0] the physical model center, so on a taller 2 story house it's probably somewhere above the first floor? So the negative values might be correct? Share this post Link to post Share on other sites
Kydoimos 916 Posted June 21, 2015 Ah, thanks Larrow! Interesting! :D To get the offsets, I spawned the house on a gameLogic and attached them directly to the house, thinking I could just substitute the house variable name for the name assigned to the house in the editor via a gameLogic or something! Didn't quite work out! :p ---------- Post added at 11:17 ---------- Previous post was at 11:16 ---------- Isn't the center [0,0,0] the physical model center, so on a taller 2 story house it's probably somewhere above the first floor? So the negative values might be correct?[/Quote]It is a two-story shop :D ---------- Post added at 11:19 ---------- Previous post was at 11:17 ---------- @KBBW123 - Thanks man! I'll take a look at that! Cheers! Share this post Link to post Share on other sites
Larrow 2823 Posted June 21, 2015 Isn't the center [0,0,0] the physical model center, so on a taller 2 story house it's probably somewhere above the first floor? So the negative values might be correct? All depends on how the offsets were calculated.If they were done by getposatl house - getposatl chair then the house [0,0,0] would be the point used for object placement which is generally were the ground plane is. If they were got via house worldToModel ( getPosATLVisual chair ) then they would be based of the models boundingCenter. Which as you say is generally in the center of the model. No matter what i do with those original values of Kydoimos they are always to high or low for the floors in a "Land_i_Shop_02_V1_F". The code below is the closest i can get, works for any "Land_i_Shop_02_V1_F" but if you watch the furniture spawn in it is way above the floor and can sometimes topple over. house = nearestBuilding player; housePos = house modelToWorld [ 0, 0, 0 ]; houseDir = getDir house; positions_Tables = [ [2,-2.75,-2.295], [-0.5,-2.75,-2.295], [2,-2.75,1.585], [-0.5,-2.75,1.585], [-2.5,-2.75,1.585], [-0.5,0,1.585], [-2.5,0,1.585] ]; tables = []; { pos = _x; table = createVehicle [ "Land_RattanTable_01_F", ( house modelToWorld pos ) , [], 0, "CAN_COLLIDE" ]; table setDir houseDir; tables pushBack table; } forEach positions_Tables; positions_Chairs = [ [[2,-2,-2.125], 0], [[2,-3.65,-2.125], 180], [[-0.5,-3.65,-2.125], 180], [[0.35,-2.85,-2.125], 90], [[-0.5,-3.65,1.75], 180], [[-2.5,-3.65,1.75], 180], [[2,-1.95,1.75], 0], [[-0.5,-1.95,1.75], 0], [[-2.5,-1.95,1.75], 0], [[-2.5,0.85,1.75], 0], [[-0.5,0.85,1.75], 0], [[2,-3.65,1.75], 180], [[-3.5,0.05,1.75], -90], [[0.5,0.05,1.75], 90] ]; chairs = []; { pos = _x select 0; chairDir = _x select 1; chair = createVehicle [ "Land_RattanChair_01_F", ( house modelToWorld pos ), [], 0, "CAN_COLLIDE" ]; chair setDir ( houseDir + chairDir ); chairs pushBack chair; } forEach positions_Chairs; Share this post Link to post Share on other sites