Jump to content
Sign in to follow this  
Ice_Rhino

Two Players carrying a Create?

Recommended Posts

Is it possible to simulate or actually allow two human players to carry a crate from insertion to an overwatch position? I ideally I would like one on each side carrying it

Hope to hear soon

T

Share this post


Link to post
Share on other sites

I wouldn't know exactly how to do it, but conceptually in my head I see the addAction on the crate calling a script that will "attachTo" the player and then has a waitUntil command checking that the crate is attached to 2 players at which point a variable or some sort of allow move type command changes to give the ability for the crate to be moved by the players.

Share this post


Link to post
Share on other sites

Try this:

(_this select 0) setVariable ["carriedBy", [], true];
(_this select 0) addAction ["Pick up crate",
{
_carried = (_this select 0) getVariable "carriedBy";
if (!(_this select 1) in _carried) then
{
	_carried pushBack (_this select 1);
	(_this select 0) setVariable ["carriedBy", _carried, true];
	(_this select 1) setUserActionText [_this select 2, "Drop crate"];		
}else
{
	_carried = _carried - (_this select 1);
	(_this select 0) setVariable ["carriedBy", _carried, true];
	(_this select 1) setUserActionText [_this select 2, "Pick up crate"];
};
if (count _carried == 2) then
{
	[_this select 0, _carried] spawn =
	{
		(_this select 0) attachTo [(_this select 1) select 0, [0,2,0]];
		waitUntil {count ((_this select 0) getVariable "carriedBy") < 2};
		detach (_this select 0);
	};
};
}, [], 6, true, false, "count (_target getVariable ""carriedBy"") < 2"];

I have no idea if it will work because I script solo so it's literally impossible to test this. But I'd like to say it's just crazy enough to work.

Add that code to a script and call it like this:

If in editor:

0 = [this] execVM "whateveryounamedthescript.sqf"

If you want to dynamically spawn crates:

//well you should already know what to do, but I'll try explaining it
_obj = createVehicle ["crate or something", position wherever, [], 0, "CAN_COLLIDE"];
0 = [_obj] execVM "whateveryounamedthescript.sqf"

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Thanks DE,

Tried your suggestion but doesn't seem to do anything. A couple of questions;

1. Does the crate need to be named?

2. Do I have to specify the player names?

The way I tried your code was to create a carrycrate.sqf in the mission folder. Create a 2m round trigger around the crate with group link to the player 'Any group member present'

Thanks in advance

T

Thanks

Share this post


Link to post
Share on other sites

No, you don't, but anyway just put this line in the init of your crate in the editor...

0 = [this] execVM "carrycrate.sqf"  

Share this post


Link to post
Share on other sites

To your #1:

The crate doesn't have to be named just put the script call line in the init field of the crate, the script does all the check work, no need for your trigger activation.

#2:

Same for naming the players, the script should do that on it's own, the reason for his "impossible to test because I script solo" comment is due to the fact that the script needs TWO people to have it work completly, so you will need a friend or someone else to test it out. The script adds "action text" to the crate via an addAction line, except as he has it, it's essentially it's own unique action criteria based on the variable "carriedBy". So until "carriedBy" equals 2, meaning two people have used the action, the crate can't be carried and moved, etc.

BTW DE, I like the logic behind it all, just really looked closely at it, makes sense, but the real question is if Arma can make sense of it :p.

Edited by JShock

Share this post


Link to post
Share on other sites

OK, I tried it with the init line in the crate, but if it requires two people I will have to wait until my friend comes online later. When I approached the crate there was no option to pick up crate so I assume this is the two player thing again. Damn, now I have to wait for 7 hours to test it :(

Thanks anyway for all the help so far. I will of course report back

T

Share this post


Link to post
Share on other sites

Well to clarify, you can do it by yourself, it's just that the crate won't be "moveable" until you have two people. So not having an action at all is still a problem, but I'm unsure of the issue, and currently pressed for time, so I can't look at it too closely, sorry :(.

Share this post


Link to post
Share on other sites

@Ice_Rhino you need to have -showScriptErrors in your startup parameters. The reason the action didn't show up is because I had 3 easily debugged errors in the code, here is the version with them fixed.

(_this select 0) setVariable ["carriedBy", [], true];
(_this select 0) addAction ["Pick up crate",
{
_carried = (_this select 0) getVariable "carriedBy";
if (!((_this select 1) in _carried)) then
{
	_carried pushBack (_this select 1);
	(_this select 0) setVariable ["carriedBy", _carried, true];
	(_this select 1) setUserActionText [_this select 2, "Drop crate"];		
}else
{
	_carried = _carried - [(_this select 1)];
	(_this select 0) setVariable ["carriedBy", _carried, true];
	(_this select 1) setUserActionText [_this select 2, "Pick up crate"];
};
if (count _carried == 2) then
{
	[_this select 0, _carried] spawn
	{
		(_this select 0) attachTo [(_this select 1) select 1, [0,2,0]];
		waitUntil {count ((_this select 0) getVariable "carriedBy") < 2};
		detach (_this select 0);
	};
};
}, [], 6, true, false, "_target getVariable ""carriedBy"" < 2"];

It actually should completely work now, but the action text doesn't change so I'm going to explore a better way to do this later

Share this post


Link to post
Share on other sites

Yeah, I do not even get the option to pickup crate on the mouse wheel roll menu

Share this post


Link to post
Share on other sites
Yeah, I do not even get the option to pickup crate on the mouse wheel roll menu

I just posted a version with the errors fixed, tested on my machine. And all this tells me is something is wrong in 14 lines of code...

-showScriptErrors

Share this post


Link to post
Share on other sites

I just tried it with my friend online and we both had the option to pick up Crate. Only one of us could do it and when one of us did it, then we were pushing it up hill like a hockey puck out in front of us on the ground.

Heading in the right direction but not quite there.

Thanks

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  

×