Jump to content
Sign in to follow this  
dreadedentity

[CODE SNIPPET / RELEASE] Code for base builders

Recommended Posts

Hello all,

Earlier today someone was asking about building a base. Being the good guy that I am I started working on something that would make it easy to build bases. Rather than making ~30 edits to the code over the course of an hour like I usually do, I got it to a point where it works then posted it. Then I lazily beefed it up a little more over the course of the past few hours. This is the ultimate result. Working in the current release of Arma 3 at the time of this posting.

Copy this and paste it into the Debug Console, then click "Local Exec"

actionStatus = false;
{
removeAllActions _x;
removeAllActions player;
}forEach (allMissionObjects "ALL" - [player]);
{
_x addAction ["Pick Up",
{
	if (!actionStatus) then
	{            
		(_this select 0) attachTo [(_this select 1)];
		(_this select 0) setUserActionText [(_this select 2), "Drop"];
		heldObject = (_this select 0);
		heldObjectDir = (direction(_this select 0));
		currentAction = _this select 2;
		rotateEvent = (findDisplay 46) displayAddEventHandler ["keyDown",
		"
			if (_this select 1 == 51) then
			{
				heldObjectDir = heldObjectDir - 1;
				heldObject setDir heldObjectDir;
			};
			if (_this select 1 == 52) then
			{
				heldObjectDir = heldObjectDir + 1;
				heldObject setDir heldObjectDir;
			};
			if (_this select 1 == 207) then
			{
				detach heldObject;
				actionStatus = false;
				heldObject setUserActionText [currentAction, ""Pick Up""];
				player removeAllEventHandlers ""keyDown"";
			};
			if (_this select 1 == 211) then
			{
				detach heldObject;
				deleteVehicle heldObject;
				actionStatus = false;
			};
			if (_this select 1 == 210) then
			{
				createVehicle [typeOf heldObject, getPos heldObject, [], 0, ""CAN_COLLIDE""];
			};
		false;"];
	}else
	{
		detach (_this select 0);
		(_this select 0) setUserActionText [(_this select 2), "Pick Up"];
		player removeAllEventHandlers "keyDown";
	};
	actionStatus = !actionStatus;
},[],6,true,true,"",""];
}forEach (allMissionObjects "ALL" - [player]);

player addAction ["Save to clipboard",
{
clipboard = "";
{
	if (typeOf _x != "Logic" && {typeOf _x != "Snake_random_F"} && {typeOf _x != "FxWindPollen1"} && {typeOf _x != "FxWindGrass2"}) then
	{
		pos = getPos _x;
		pos set [2, round (pos select 2)];
		clipboard = clipboard + format["_obj = createVehicle [""%1"", %2, [], 0, ""NONE""]:_obj setDir %3:", typeOf _x, pos, round direction _x];
	};
}forEach (allMissionObjects "ALL" - [player]);
copyToClipboard clipboard;
}];

TO USE THIS: First you need to put some things down in the editor. Place more than you need. You can delete stuff you don't want by picking it up and pressing "delete". You can also rotate objects by picking them up and pressing either < or >. They are bound like you think they would be, < rotates counter-clockwise and > rotates clockwise (like arrows pointing). Note: For some reason infantry doesn't like to be rotated, they will turn back to where they started (from what I could tell, the output is unaffected by their stupid behavior).

ADDED: 2 new buttons; "Insert" will create a duplicate of the currently held object but you need to go back to the Debug Console and click "Local Exec" again (or click it a few times, I've already sorted out the issues with this) or else there won't be options to pick up the duplicated objects. "End" is an emergency drop button, I realize that for some objects you will not be able to "drop" them because the option doesn't show up. Just press "End" and the object will be dropped right where it is (I have also already sorted out the issues with this).

TO SAVE: Select the "Save to Clipboard" option, then open notepad and paste the result. Press "ctrl + h" and replace all colons ( : ) with semicolons ( ; ). After that point you can then copy it again and paste the code right into your script. Wham, bam, easy peasy.

A NOTE ABOUT SAVING: There are many random objects that get picked up when you use "allMissionObjects" for some reason (like snakes), I did a quick test and made a filter for a few of these items. If you are using this piece of code and you notice some random classname in the output, comment back here and I'll add it to the filter.

For other scripters: For some reason, if you put a unit down, you are still able to rotate it until you pick up another unit. This is a bug due to my lack of knowledge of removing a display event handler. There is a piece of code in there that needs to be replaced, but the code still runs and without problem so I left it in as a guide on what to replace.

Enjoy

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Nice. Is this similar to the objgrabber for making custom compositions (layouts) ?

Share this post


Link to post
Share on other sites
Nice. Is this similar to the objgrabber for making custom compositions (layouts) ?

I'm not sure what the object grabber is, but if there's a built-in tool for this I'm going to feel pretty stupid. lol...

Basically, this is just some little code you run in the debug console, it'll apply a pick-up/drop action to every editor-placed and mission-spawned object on the map except for the player. You can move them about and rotate them to your hearts content then save everything. I tried filtering out the mission-spawned objects like snakes and leaves (also for some reason there's a Logic module), but I can't be sure I got them all since I didn't do much testing on that. It doesn't mess with the output very much, just a few extra createVehicles to delete :)

Share this post


Link to post
Share on other sites

It seems objectGrabber.sqf is missing from C:\Program Files (x86)\Steam\SteamApps\common\Arma 3\Addons\modules_f\DynO in Arma 3. We had it built in back in A2. but the script still works for A3.

obectGrabber returns a list in rpt containing for each object

format : [_type, [_dX, _dY, _z], _azimuth, _fuel, _damage, _vehicleinit]

example: ["I_Heli_Transport_02_F",[124.377,51.0967,-0.0558586],129.986,1,0,{}],

Where as yours is returning a list to clipboard containing for each object

example: _obj = createVehicle ["Land_HBarrierBig_F", [-5000,-5000,0], [], 0, "NONE"]

scriptName "objectGrabber.sqf";
/*
File: objectGrabber.sqf
Author: Joris-Jan van 't Land

Description:
Converts a set of placed objects to an object array for the DynO mapper.
Places this information in the debug output for processing.

Parameter(s):
_this select 0: position of the anchor point
_this select 1: size of the covered area

Returns:
Success flag (Boolean)

init:
null = [getpos this,200] execvm "objectGrabber.sqf";
*/

//Validate parameter count
if ((count _this) < 2) exitWith {diag_log "Log: [objectGrabber] Function requires at least 2 parameter!"; false};

private ["_anchorPos", "_anchorDim"];
_anchorPos = _this select 0;
_anchorDim = _this select 1;

//Validate parameters
if ((typeName _anchorPos) != (typeName [])) exitWith {diag_log "Log: [objectGrabber] Anchor position (0) must be an Array!"; false};
if ((typeName _anchorDim) != (typeName 0)) exitWith {diag_log "Log: [objectGrabber] Covered area size (1) must be an Number!"; false};

private ["_objs"];
_objs = nearestObjects [_anchorPos, ["All"], _anchorDim];

diag_log "#####################################";
diag_log "### Log: objectGrabber: StartGrabbing";
diag_log "#####################################";

for "_i" from 0 to ((count _objs) - 1) do
{
 private ["_obj", "_type"];
_obj = _objs select _i;

_type = typeOf _obj;

//Exclude human objects.
private ["_sim"];
_sim = getText (configFile >> "CfgVehicles" >> _type >> "simulation");
if !(_sim in ["soldier"]) then
{
	private ["_objPos", "_dX", "_dY", "_z", "_azimuth", "_fuel", "_damage", "_vehicleinit"];
	_objPos = position _obj;
	_dX = (_objPos select 0) - (_anchorPos select 0);
	_dY = (_objPos select 1) - (_anchorPos select 1);
	_z = _objPos select 2;
	_azimuth = direction _obj;
	_fuel = fuel _obj;
	_damage = damage _obj;
	_vehicleinit = if (isnil {_obj getvariable "vehicleinit"}) then {{}} else {_obj getvariable "vehicleinit";};
	// _obj setvariable ["vehicleInit",_vehicleInit];

	diag_log text(format ["%1,", [_type, [_dX, _dY, _z], _azimuth, _fuel, _damage, _vehicleinit]]);
};
};
diag_log "###################################";
diag_log "### Log: objectGrabber: EndGrabbing";
diag_log "###################################";

true

Yours is nice in that you can reposition objects in real time but how do you set elevation?

Also changing

player removeAllEventHandlers "keyDown";

to

(finddisplay 46) displayRemoveAllEventHandlers "KeyDown";

fixed the rotating after object drop thing.

Edited by Jigsor

Share this post


Link to post
Share on other sites
I'm not sure what the object grabber is, but if there's a built-in tool for this I'm going to feel pretty stupid. lol...

Basically, this is just some little code you run in the debug console, it'll apply a pick-up/drop action to every editor-placed and mission-spawned object on the map except for the player. You can move them about and rotate them to your hearts content then save everything. I tried filtering out the mission-spawned objects like snakes and leaves (also for some reason there's a Logic module), but I can't be sure I got them all since I didn't do much testing on that. It doesn't mess with the output very much, just a few extra createVehicles to delete :)

Meh.. kind of an inbuilt tool I guess you could say. Works nicely once you get the hang of it, BUT... still leaves alot to be desired. I think a more "streamlined" version is welcomed. What it does is allow you to create and store custom object compositions, which can then be placed anywhere on the map, facing any direction.

@Jigsor - With light modification you can still use objectGrabber from A2. Delete some obsolete vehInit commands and such.

Edited by Iceman77

Share this post


Link to post
Share on other sites
Yours is nice in that you can reposition objects in real time but how do you set elevation?

There actually are a couple of kinks to work out, this being one of them. There's no elevation functionality in this code, basically I was thinking you would just put the object underneath, save the code, then change elevation manually. I could easily add that tomorrow when I wake up, but there is a host of other problems with that (like how far to increment, rounding issues, etc...)

Thanks for the explanation of ObjectGrabber, I thought about saving the information to the .rpt but I really don't know much about it, not even it's location in my computer's files. copyToClipboard is really basically the only other native command in A3 that can let you get information out of the game. But of course the clipboard is extremely volatile, and just accidentally copying something can make your entire base disappear :(

Share this post


Link to post
Share on other sites

That reminds me... BIS had premade object compositions in A2. They were very handy, if you didn't feel like making your own. Idk why they didn't include some in A3 =(

---------- Post added at 22:51 ---------- Previous post was at 22:47 ----------

Ahhh this is a "3d editor" / "logistics" function of a sort? You should totally write a dynamic composition function.

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  

×