Jump to content
Sign in to follow this  
mtuckner

Activate a Trigger when Retrieving a Weapon

Recommended Posts

I would like to dynamically create a task / objective that completes with a trigger that creates a new task when the player takes a rifle from a vehicle. I know how to create the tasks, the problem is how do I get a trigger to check or activate when the player grabs the item(s) from the vehicle?

Anyone know what to put in the condition or how this could work, if it even can?

---------- Post added at 04:29 PM ---------- Previous post was at 04:11 PM ----------

I got it, changed up my search criteria.

Share this post


Link to post
Share on other sites

How about a trigger that goes off when the player(s1) and an ai unit(s3) place one weapon each into the cargo of a vehicle(veh1)?

In this case one weapon is the M3 tripod(ACE_M3TripodProxy) from ACE2 and the M2(ACE_M2HBProxy) from ACE2.

Share this post


Link to post
Share on other sites
How about a trigger that goes off when the player(s1) and an ai unit(s3) place one weapon each into the cargo of a vehicle(veh1)?

In this case one weapon is the M3 tripod(ACE_M3TripodProxy) from ACE2 and the M2(ACE_M2HBProxy) from ACE2.

Use getMagazineCargo.

Share this post


Link to post
Share on other sites

Shall I add that my scripting knowledge is almost nil. I know about that about I can't figure out how to set it up. Looking at that page does not help me since I've got little scripting knowledge. Hell I can barely figure out what the first example says. I'm not asking for the where but the how.

Thanks though. Any help from somebody else would be greatly appreciated.

Share this post


Link to post
Share on other sites

"getMagazineGargo car" will return an array. The array is in form [[weapon1, weapon2, weapon3, ... ,weaponn], [magazine1, magazine2, magazine3, ..., magazinen]], so if you want to check if a specific weapon is in a cargo you'll have to check the first array inside that array. If "'weaponclassname' in (getMagazineCargo car select 0)" returns true, the weapon is in a cargo compartment, else it isn't.

Share this post


Link to post
Share on other sites

I get that but I still don't know how to set that up. Thanks though.

What would I do? I have know clue how to start this. Put this in the condition line of a trigger?

[[ACE_M3TripodProxy, ACE_M2HBProxy], [ACE_M2_CSWDM, ACE_M2_CSWDM, ACE_M2_CSWDM, ACE_M2_CSWDM]] getmagazinecargo = true;

Then the trigger OnActivation line is:

hint "Weapons loaded"; nul = []execVM "Tasks\task2b.sqf";

This is clearly not right but again my scripting is very basic. I'm learning though and someone showing me how to do this would greatly help me learn. I'm better at learning by ripping something basic apart, figuring out what it does/mean and then modifying it. Give instructions for this stuff just goes way over my head. I try though.

What would the trigger set up look like? A snippet of code is what I need. My apologies but my scripting knowledge is seriously basic. If someone else knows off hand I'd greatly appreciate the help.

Edited by Manzilla

Share this post


Link to post
Share on other sites

Whoops. I must be too tired. I meant getWeaponCargo, of course...

Put this to triggers condition:

"ACE_M2HBProxy" in (getWeaponCargo car select 0) && "ACE_M3TripodProxy" in (getWeaponCargo car select 0)

Share this post


Link to post
Share on other sites

Sweet thank you. What exactly does this do?

car select 0

How does the trigger know which vehicle I want? What happens if the vehicle is a piece of armor like a Bradley? The select 0 thing is what gets me.

For armor would it be something like:

"ACE_BAF_L2A1Proxy" in (getWeaponCargo [b][size="3"]armor[/size][/b] select 0) && "ACE_M3TripodProxy" in (getWeaponCargo [b][size="3"]armor[/size][/b] select 0)

I'm assuming the select 0 has something to do with telling the script which vehicle to select but I'm not understanding it's meaning/use. I've seen it before and used it but never really grasped the concept.

Also for magazine would I just use "getMagazineCargo" like this?

"ACE_BAF_L2A1Proxy" in (getWeaponCargo car select 0) && "ACE_M3TripodProxy" in (getWeaponCargo car select 0) && "ACE_M2_CSWDM" in (getMagazineCargo car select 0) && "ACE_M2_CSWDM" in (getMagazineCargo car select 0);

ACE_M2_CSWDM being the M2's magazine classname.

Thanks for the help.

EDIT:

This doesn't work:

Condition:

"ACE_M3TripodProxy" in (getWeaponCargo teamVeh1) && "ACE_BAF_L2A1Proxy" in (getWeaponCargo teamVeh1);

OnAct:

hint "Armaments loaded!";

also used this with car in the trigger area:

Condition:

"ACE_BAF_L2A1Proxy" in (getWeaponCargo car select 0) && "ACE_M3TripodProxy" in (getWeaponCargo car select 0);

OnAct:

hint "Armaments loaded!";

The car is a BAF Jackal 2 L2A1 named teamVeh1

Edited by Manzilla

Share this post


Link to post
Share on other sites

"car" is the name of the object. So if you have a bradley named "vehicle_1" put "vehicle_1" instead of "car". Or if the bradley is named "armor" put "armor" instead of "car".

Select 0 is that it selects the first (n-1) element and checks if "ACE_M2HBProxy" is in that array.

If you want the trigger to activate when there are 1 M2, 1 tripod and 2 magazines it is little bit trickier. Put this to the init-line of the vehicle:

nul = [this] execVM "scriptname.sqf";

Create scriptname.sqf (You can name it to anything) and put that to the mission folder. Put this to the mission folder:

_car = _this select 0;

waitUntil {"ACE_M2HBProxy" in (getWeaponCargo _car select 0) && "ACE_M3TripodProxy" in (getWeaponCargo _car select 0)};
waitUntil {((getMagazineCargo _car select 0) find "ACE_M2_CSWDM") > -1};
_element = (getMagazineCargo _car select 0) find "ACE_M2_CSWDM";
while {(getMagazineCargo _car select 1 select _element) < 2} do {
_element = (getMagazineCargo _car select 0) find "ACE_M2_CSWDM";
sleep 0.1;
};
vehicleLoaded = true;

Create a trigger. Put this to the condition:

vehicleLoaded

And put to the on activation whatever you want to happen after the weapon, tripod and at least two magazines are in the trunk.

Note that there is an awful bug: If you put the weapon, tripod and ONE magazine to the trunk and then take the magazine out it will activate the trigger. And if you take either the M2 or the tripod away after putting one magazine to the trunk it isn't counted (The trigger will activate when you put one more mag, no matter if the weapon is in the trunk or not). And alot more, to be sure.

It would be much easier if it would be only one mag, then it would be:

"ACE_M2HBProxy" in (getWeaponCargo car select 0) && "ACE_M3TripodProxy" in (getWeaponCargo car select 0) && "ACE_M2_CSWDM" in (getMagazineCargo car select 0)

Sorry, way way way too tired to code anything more efficient. :(

Share this post


Link to post
Share on other sites

Hey man thanks a lot! This is really helpful. I'll learn a lot from this. I'll give it a try and let you know. Get some sleep! ;)

Note that there is an awful bug: If you put the weapon, tripod and ONE magazine to the trunk and then take the magazine out it will activate the trigger. And if you take either the M2 or the tripod away after putting one magazine to the trunk it isn't counted (The trigger will activate when you put one more mag, no matter if the weapon is in the trunk or not). And alot more, to be sure.

Edit:

About this. Isn't there a way to delete the trigger just after the stuff is loaded? This is basically just for an objective in a mission. After it is loaded the next objective will be to drive somewhere and unpack the loaded weapons once you've arrived. So it's only necessary to load the vehicle up once.

Edit 2:

Tried your method and it worked. I think I see what you mean with the bug. I had the 2 weapons in there and once I placed just one of the 2 magazines the hint that was in the OnAct line of the vehicleLoaded trigger popped up. I just needed to load magazine not 2.

Edited by Manzilla

Share this post


Link to post
Share on other sites

It is (kind of) deleted after the variable is set. The problem is not the trigger, but the .sqf code.

If you only need to load one magazine I recommend you don't use the script. The other method has no bugs at all, doesn't eat processing power as much and is much cleaner (You don't have n+1 different .sqf files in the mission folder).

Glad to help (And yes, heading to bed real soon!).

Share this post


Link to post
Share on other sites

If you only need to load one magazine I recommend you don't use the script.

I'm thinking that's what I'm gonna do. I'll just have a hint that says the player may want to bring a few more magazines and just keep the actual trigger condition at the tripod, the L2A1 and only 1 magazine in the vehicle to complete the objective. As you suggest, no need to be too complicated. :rthumb:

Thanks again. I appreciate the help. Good night.

Edited by Manzilla

Share this post


Link to post
Share on other sites

I suggest you browse BI wiki, and especially the list of Arma 2 commands. Just use ctrl+f and find a keyword (For example if you wonder how can you attach something just ctrl +f and search for "attach". The Best Way To Learn scripting. Trust me. :)

Share this post


Link to post
Share on other sites

Thank you. Yes I've used that page often but I had my book marks erased and forgot to look for it again. That helps.

One more question.

Before this objective I have one that has the player and my AI teammate grab the L2A1 and the tripod from crates.(So they can load them into the vehicle for the other objective you just helped me script.) I can get this to work with out trouble but I can't figure out how to add the magazine to the condition.

In a trigger I have this in the condition line:

player hasWeapon "ACE_M3TripodProxy" && s6 hasWeapon "ACE_BAF_L2A1Proxy";

And the OnAct line just has:

hint "Weapons collected";

s6 is the grenadier in my team.

I see the hasWeapon command but I'm not sure what to use for a magazine. I see there isn't a similar hasMagazine command. :confused: I'm assuming this will probably take some scripting above and beyond my ability to accomplish. :)

Share this post


Link to post
Share on other sites

I suggest you put the condition to:

(player hasWeapon "ACE_M3TripodProxy" && s6 hasWeapon "ACE_BAF_L2A1Proxy") || player hasWeapon "ACE_BAF_L2A1Proxy" && s6 hasWeapon "ACE_M3TripodProxy")

Then it doesn't matter which takes which. Say, what if the player would take the weapon instead of tripod? The AI doesn't know how to take the other one. So I would make a condition that first it will try to take the weapon, but if there is no weapon it would take the tripod instead (Check the cargo of the ammo crate. If there is no CSW weapon then make the AI to take the tripod. You already know the command for this one, ay? :) )

And about the magazines... Sure, there isn't command "hasMagazine", but use ctrl+f and search for "magazine": 17 hits. Now browse them through until you find the right one (senizagam :tnih).

Try the different commands by placing a radio trigger: Condition "this" and on activation "hint format ["%1", command_and_variables]", for example ["%1", unitPos s6];

This way you will find out how different commands works, what will they return and maybe during the testing you will get a bright idea of a new way to make something really fancy.

(Brushed my teeths already. Yes, about to go to bed) ;)

Share this post


Link to post
Share on other sites

hint format ["%1", magazines player] will show you which magazines you are carrying. Now you'll only have to check if the specific magazine is in the inventory.

In other words, you'll have to check if the magazasine is in array.

Share this post


Link to post
Share on other sites
hint format ["%1", magazines player] will show you which magazines you are carrying. Now you'll only have to check if the specific magazine is in the inventory.

In other words, you'll have to check if the magazasine is in array.

No clue how to do that. I'm trying but my scripting knowledge is not that in depth yet.

hint format ["%1", magazines player] if magazine is in [s1]

Obviously that doesn't work.

EDIT:

Or

if ("ACE_M2_CSWDM" in _Magazinesplayer) then hint format ["%1", magazines player];

Edited by Manzilla

Share this post


Link to post
Share on other sites

What I meant was that try out different commands by using "hint format ["%1", command]". You will see what the command returns. So, put this to the trigger init field (Condition can be radio alpha for example):

hint format ["%1", magazines player];

You will get a hint. It will show you the returning value of "magazines player". In this case it will show you an array, and each element in that array represenets a magazine in your inventory.

I help you out on this one. Put this to the trigger condition:

"magazineclassname(whatever it is...)" in magazines player

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  

×