Jump to content
Sign in to follow this  
A-SUICIDAL

Drag Carry Ammobox

Recommended Posts

I got this working, except when dragging the ammobox - if you hit either the enter key or shift key the player will then go into a new animation sequence. Actually, I just want to be able to drag and drop the ammobox, but I'm open for carry suggestions, it's just most the carry animations looked weird when used for an ammobox. I tried examining Norrin's revive scripts for dragging an unconscious player and he uses a "displayAddEventHandler ["KeyDown"....." function, but I can't seem to make it work in my sample mission. I haven't given up yet, but I was kind of hoping somebody could help me. I'm also trying to figure out how to make it so a player cannot drop the ammobox if he is within 4 meters of any object, with a hint warning incorporated - to prevent the player from droping the ammobox inside of a wall or a rock. Lastly, I have a couple of triggers that detach the ammobox if either player s1 or s2 are killed while dragging the ammobox, but this system is my poorman scripting way of getting them to drop it when killed, so I need to find a better way to do that if possible. I'm trying to use the drag and drop ammobox script in a 2 man coop stealth mission that I am making, but I want to get it bug free and usable in future missions that have more than 2 players. It's a good script, any help with perfecting it would be most appreciated. I know there are alot of scripts like it, but I'm not looking to carry artillery pieces around, lol. After a C130 drops the ammobox, I want to be able to drag the ammobox full of rockets behind a big rock before the convoy of tanks spots me rearming in the open.

Anyway, here's my script so far

First, I added this to my init.sqf file:

if (isServer) then {

attached = false;
publicVariable "attached";

};

I placed an ammo box and named it "ammobox" and put this in the init:

this allowDamage false; this addAction ["Drag Ammobox","drag_ammobox.sqf",nil,1,false,false,"","!attached and player distance _target<5"];

drag_ammobox.sqf

_box = _this select 0;
_unit = _this select 1;
_act = _this select 2;

_unit removeAction _act;
_unit playMove "acinpknlmstpsraswrfldnon";
sleep 2;
_box attachTo [_unit,[0,1,0.2]];
attached = true;
publicVariable "attached";
_actionId = _unit addAction ["Drop Ammobox", "drop_ammobox.sqf", [], -1, false, true, "", "(attached and (_target == _this))"];

drop_ammobox.sqf

_box = _this select 0;
_unit = _this select 1;
_act = _this select 2;

_unit removeAction _act;
// if I use... detach _box ...it doesn't work. hmm.
detach ammobox;
_box setpos [(getpos _box) select 0, (getpos _box) select 1, 0];
_unit switchMove "";
attached = false;
publicVariable "attached";

Sample Mission

I'm going to keep trying to get this KeyDown stuff working, but I've about given up. I might leave it as it is - if I can't get the few bugs worked out.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I'm not sure where you want to use the Keypress. Once you have the box do you want to change animation?

For the dead part an eventhandler would be the best option I think.

Add to the end of the drag_ammo.sqf file

_unit setvariable ["ammo",_box];
_unit addMPEventHandler ["MPkilled", {detach ( _this select 0) getvariable "ammo",attached=false;publicVariable "attached";hint format ["ammo box detached from %1",( _this select 0) ];}];

Share this post


Link to post
Share on other sites

Take a look at this:

http://forums.bistudio.com/showthread.php?94280-R3F-Artillery-and-Logistic-Manual-artillery-and-advanced-logistic-(mission-script)

This script includes ability to move objects and even put them inside vehicles. Has lots of configuration options.

Oh and about KeyDown stuff, sometimes findDisplay doesn't return display properly and you can't (obviously) add event handlers to it. Here is how I solve this problem:

[] spawn {
private ["_display"];
_display = null;
disableSerialization;
while {true} do {
	_display = findDisplay 46;
	if(!isNull(_display)) exitWith {};
	sleep 1;
};
_display displaySetEventHandler ["KeyDown", "hint ""KeyDown"";"];
};

It basically tries to get display indefinitely each second until it finds it and adds event handler

Edited by SaMatra

Share this post


Link to post
Share on other sites

Thanks guys, and sorry I have been away for a few days, I had some unexpected business that I needed to tend to, but I am back working hard on my mission now. I will try everything that you guys suggested. I am more confident now that I will get it working correctly thanks to all your help. I will come back and let you know how it's working out.

Share this post


Link to post
Share on other sites

F2k Sel, I am now using your script to get the player to drop the ammobox when the player is killed. It works great. Thank you very much.

Giallustio, unfortunately you script will not help me in this case, but I do use your script in other missions and I think it is one of the best scripts out there. I remember searching forever for a good lift script and finally came across yours and it worked great and I use it in every mission I make where I need choppers to lift vehicles. I also gave credit to you in my "Co-14 Infiltration" mission: http://www.armaholic.com/page.php?id=15990, which you can see if you scroll down the page.

SaMatra, I tried using your script and when testing it worked and the hint appeared, so I then chose the action to drop the ammobox, but I could not get the hint to stop appearing on every keypress from then on.

What I would like to do is... if either the "Enter" key or "Shift" key is pressed while the player is currently dragging the ammobox, I want to then exec the "drop_ammobox.sqf" or do the things that are in the "drop_ammobox.sqf" file (basically just get the player to drop the box). Is there a way to make this possible?

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I just had a quick look and got the following to work.

save as "drag_ammobox.sqf"

_box = _this select 0;
_unit = _this select 1;
_act = _this select 2;

player setvariable ["drop",[_box,_unit,_act],true];

_unit removeAction _act;
_unit playMove "acinpknlmstpsraswrfldnon";
sleep 2;

_box attachTo [_unit,[0,1,0.26]];
_box setdir 90;


attached = true;
publicVariable "attached";
_actionId = _unit addAction ["Drop Ammobox", "drop_ammobox.sqf", [], -1, false, true, "", "(attached and (_target == _this))"];

_unit setvariable ["ammo",_box];
_unit addMPEventHandler ["MPkilled", {detach ( _this select 0) getvariable "ammo",attached=false;publicVariable "attached";hint format ["ammo box detached from %1",( _this select 0) ];}];

disableSerialization;
(findDisplay 46) displayAddEventHandler ["KeyDown","if ((_this select 1) == 42) then {hint 'drop'; [] execvm 'drop_ammobox.sqf'};false"]; 

save as "drop_ammobox.sqf"

_temp = player getvariable "drop";
_box =  _temp select 0;
_unit = _temp select 1;
_act = _temp select 2;

_unit removeAction _act;
_unit removeMPEventHandler ["killed",0]; 
//hint format ["%1",_temp];

detach ammobox;
_box setpos [(getpos _box) select 0, (getpos _box) select 1, 0];
_unit switchMove "";
attached = false;
publicVariable "attached";

Edited by F2k Sel

Share this post


Link to post
Share on other sites

First I just want to thank you for all the help you've been giving me.

I tested the script and when I am dragging the box and I press my "Enter" key, I still have the problem where the player stops dragging the box and begins to try to carry the box on his back as if it is a wounded soldier. If I press the "Right Shift" key while dragging the box, the player stops dragging and returns to a kneeling position with gun raised and box still attached.

I think I know why this is happening. I have all of my key controls re-binded in Arma 2. Basically I do not use any of the default keys. Normally - in every first person shooter that I've been playing over the past 20 years I've been using the 6 keys above the arrow keys as my main directional movement controls. This allows me to have easier access to all the surrounding keys. I use the "Enter" key for "UP" which makes me stand up, and I use "Right Shift" to "CROUCH". Maybe it's not so much the "Enter" key and "Right Shift" that is causing the problem, but instead it might just be that the problem is being caused by the player hitting "CROUCH" or "UP" while dragging the ammobox. So maybe what I need to do is block "UP" and "CROUCH" some how while the player is dragging the ammobox.

Try the script yourself and while you are dragging the ammobox, hit your "UP" (standup) key or "CROUCH" key and you will see what I am talking about.

---------- Post added at 01:09 PM ---------- Previous post was at 12:38 PM ----------

Also, I tried adding some extra stuff to detect if the ammobox is withing 4 meters of an object and if it is - to then give a hint warning that the player needs to find a clear area to drop the box. I don't know how to script this correctly. I've never used "nearObjects" before. Anyway, this is what I tried to do, but it gave me errors. The whole idea is... to prevent the player from dropping the ammobox into a wall, rocks, vehicle and then loses the ability to use the ammobox at all.

_temp = player getvariable "drop";
_box =  _temp select 0;
_unit = _temp select 1;
_act = _temp select 2;

_list= position _box nearObjects ["ALL",4];
if (_list > 0) then {
hint "There are objects in the way. Find a clear area to drop the ammobox.";

} else {

_unit removeAction _act;
_unit removeMPEventHandler ["killed",0]; 
//hint format ["%1",_temp];

detach ammobox;
_box setpos [(getpos _box) select 0, (getpos _box) select 1, 0];
_unit switchMove "";
attached = false;
publicVariable "attached";  
};

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

You are close but the player and the box will need to be allowed for.

if ( count _list > 2) then {

I'm going to start a new thread about disabling key as I've seen it mentioned but never found a working example.

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  

×