Jump to content
Sign in to follow this  
igneous01

Pick up object script - If Player is running then drop cargo?

Recommended Posts

As the titles says, i cant figure out how to get the player to drop his cargo if he is running too fast.

I just finished making a simple mission involving a crashed cargo truck having players pick up the scattered boxes and dumping them into the water.

So far this works, however I cannot get it to check the speed at which that unit is going. I want it to drop the cargo if he is running, jogging, and stays so long as hes walking.

I know that load in and carry commands exist in domination, with the same features built in. So there must be a way.

Here is what I have so far on my script, its not MP-Worked yet, but i am working on that. I am using this in tandem with the generic actions script that converts the arguments into code.

PickupObjects.sqf

private ["_unit", "_objects", "_actionid"];
_objects = _this select 0;
_actionid = _this select 2;
_unit = _this select 1;
_unit setvariable ["carrying", 0];

// attach the object
_objects attachTo [_unit,[0,2,0.3]];
_unit setvariable [_unit getVariable "carrying", 1];
_unit setvariable ["object", _objects];

// remove pickup action
_objects removeaction _actionid;

// add drop action
_unit addAction ["Drop Cargo","gen_action.sqf", "detach ((_this select 0) getvariable 'object'); (_this select 0) setvariable [((_this select 0) getVariable 'carrying'), 0]; (_this select 0) removeaction (_this select 2)"];

waitUntil { (_unit getvariable "carrying") == 0 };
_unit setvariable [_unit getvariable "object", nil];
// add original action again
_objects addaction ["Pick up Cargo", "PickupObjects.sqf"];

Edited by Igneous01

Share this post


Link to post
Share on other sites

Problem solved: In case people are wondering how this is done, you need to use speed to check how fast a unit is moving, and you can use forcewalk to keep them from jogging (not sprinting ofcourse)

first script (part of the mission)

[player, _Cargo1, _Cargo2, _Cargo3, _Cargo4, _Cargo5, _obj1] spawn {
_Cargo1 = _this select 1;
_Cargo2 = _this select 2;
     _Cargo3 = _this select 3;
     _Cargo4 = _this select 4;
     _Cargo5 = _this select 5;
     _obj1 = _this select 6;
     player setVariable ["carrying", 0];
     player sidechat "setting carriar variable to 0";

     while {(taskstate _obj1) != "SUCCEEDED"} do {
      player sidechat "in loop";
	_AID1 = _Cargo1 addaction ["Pick up Cargo", "PickupObjects.sqf"];
	_AID2 = _Cargo2 addaction ["Pick up Cargo", "PickupObjects.sqf"];
	_AID3 = _Cargo3 addaction ["Pick up Cargo", "PickupObjects.sqf"];
	_AID4 = _Cargo4 addaction ["Pick up Cargo", "PickupObjects.sqf"];
	_AID5 = _Cargo5 addaction ["Pick up Cargo", "PickupObjects.sqf"];
	waitUntil {(player getVariable "carrying") != 0};
	hint "carrying something";
	_Cargo1 removeaction _AID1;
	_Cargo2 removeaction _AID2;
	_Cargo3 removeaction _AID3;
	_Cargo4 removeaction _AID4;
	_Cargo5 removeaction _AID5;
	waitUntil {(player getVariable "carrying") == 0};
	sleep 1;
};
};

PickupObjects.sqf

private ["_unit", "_objects", "_actionid", "_carrying"];
_actionid = _this select 2;
_unit = _this select 1;
_objects = _this select 0;
_unit setvariable ["carrying", 0];

// attach the object
_objects attachTo [_unit,[0,2,0.3]];
_unit setvariable ["carrying", 1];
_unit setvariable ["object", _objects];
_unit forceWalk true;

// remove pickup action
_unit removeaction _actionid;

// add drop action
_DA = _unit addAction ["Drop Cargo", "DropObjects.sqf"];

[_unit] spawn {
private ["_unit"];
_unit = _this select 0;
_FEHandle = _unit addEventhandler ["fired", {(_this select 0) setVariable ["carrying", 0]}]; 

while {(_unit getVariable "carrying") == 1} do {
	if ((speed _unit) > 7) then {
		_unit setvariable ["carrying", 0];
	};
	sleep 1;
};
_unit RemoveEventHandler ["fired", _FEHandle];
};

waitUntil { (_unit getvariable "carrying") == 0 };
detach _objects; 
_unit removeaction _DA;
_unit setvariable ["object", nil];
_unit forcewalk false;

DropObjects.sqf

_unit = _this select 0; 
_id = _this select 2; 
detach (_unit getvariable "object"); 
_unit setvariable ["carrying", 0]; 

its rough, but it wasnt intended to be a standalone script, just something for the purposes of my mission.

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  

×