Jump to content
Sign in to follow this  
OB1

addAction

Recommended Posts

small problem. My scripting skills are really crap, but you brainy people should have no problems with this one I hope :)

I need to add an action to a soldier but the action will not show unless under these parameters:

-

player is an engineer class;

Player is looking at and is close to a vehicle;

Vehicle has at least 20% damage;

-

Action calls a .sqf

and thats it. Help would be much appreciated :)

Share this post


Link to post
Share on other sites

Untested but I came up with this:

private ["_fixact","_nObjects","_nVeh"];
if (vehicle player isKindOf "USMC_SoldierS_Engineer" || vehicle player isKindOf"US_Soldier_Engineer_EP1" || vehicle player isKindOf "BAF_Soldier_EN_MTP") then
{
   while {alive player} do 
   {
       _nObjects = nearestObjects [player, ["vehicles"], 10];
       _nVeh = nearestObject [player, _nObjects];
sleep 1;
};

if ((damage _nVeh)>0.2) then
{
_fixAct = _nVeh addAction [("<t color=""#FF3300"">" + ("Repair Vehicle") +"</t>"), "repair_vehicle.sqf", [], 0, false, true];
   hint "Nearest vehicle is damaged";
};
waitUntil {not alive player || (damage _nVeh)==0 || (player distance _nVeh)>10};
_nVeh removeAction _fixAct;
};

EDIT: DOESNT WORK - class and logic incorrect.

Edited by PELHAM

Share this post


Link to post
Share on other sites

Try this:

 _action = player addaction ["Action name","file.sqf",[],1,false,true,"","vehicle player isKindOf ""US_Soldier_Engineer_EP1"" && (({damage _x > 0.2} count (nearestObjects [player, [""vehicles""], 5])) > 0)"];

Share this post


Link to post
Share on other sites

thanks for helping.. now for some dumb questions

Pelham - do I execVM that from a units init ?

Giallustio - Doesnt seem to work, still testing with it.. It obviously works when I cut it down to

action = player addaction ["Action name","file.sqf",[],1,false,true]

But that takes out the desired parameters. I have been testing it in the units init, should I be doing it another way ??

Share this post


Link to post
Share on other sites

Best would be to use the addAction's condition parameter.

Use this in it's condition:

getNumber (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') == 1 && cursorTarget isKindOf 'car' && (_target distance cursorTarget) < 20 && damage cursorTarget <= 0.2

Edited by Mondkalb
fixed link to addAction page, again!

Share this post


Link to post
Share on other sites

Ignore my 1st solution it doesn't work due to class mismatch and other things - will have another look at it.

This works though: Thanks Mondkalb and well spotted Muzzleflash:

man1 addAction [("<t color=""#FF3300"">" + ("Repair Land vehicle") +"</t>"), "repair_vehicle2.sqf", [], 0, true, true, "","getNumber (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') == 1 && cursorTarget isKindOf 'landvehicle' || cursorTarget isKindOf 'car' && (_target distance cursorTarget) < 2 && damage cursorTarget >= 0.2"];
man1 addAction [("<t color=""#FF3300"">" + ("Repair Air vehicle") +"</t>"), "repair_vehicle2.sqf", [], 0, true, true, "","getNumber (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') == 1 && cursorTarget isKindOf 'air' || cursorTarget isKindOf 'car' && (_target distance cursorTarget) < 2 && damage cursorTarget >= 0.2"];

These addActions have to be attached to the engineer called man1 for the _target variable to work. Changed it so it triggers to fix any land or air vehicle. Distance changed to 2. Edit - it only partially works, the distance and damage checks don't work.

Edited by PELHAM

Share this post


Link to post
Share on other sites

What Mondkalb suggests except one small change:

[color="#006400"]getNumber (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') == 1 && cursorTarget isKindOf 'car' && (_target distance cursorTarget) < 20 && damage cursorTarget [/color][color="#FF0000"]>[/color][color="#006400"]= 0.2[/color]

Share this post


Link to post
Share on other sites
What Mondkalb suggests except one small change:

[color="#006400"]getNumber (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') == 1 && cursorTarget isKindOf 'car' && (_target distance cursorTarget) < 20 && damage cursorTarget [/color][color="#FF0000"]>[/color][color="#006400"]= 0.2[/color]

There is still something wrong with it though, any idea what it is?

cursorTarget isKindOf 'car'

on it's own does not work

in my example if you remove the 2nd part, || cursorTarget isKindOf 'car'

cursorTarget isKindOf 'Air' || cursorTarget isKindOf 'car'

it stops working, baffling but true.

Edited by PELHAM

Share this post


Link to post
Share on other sites

Not sure if this helps - adds the action to the vehicle rather than the player

not sure about the actual levels of damage - but im guessing 0.2 = 20% damage, with 1 being 100 percent damaged

the only thing about this script is that possibly (not tested - just guessing) if an engineer class is stood next to you then the action will appear.

stick this in the init of all and any vehicles you want it to apply to...

veh = [this] execVM "repairscript.sqf";

just tested it on single player, if it doesnt work on multiplayer let me know.

repairscript.sqf

sleep 1;
_target = _this select 0;
hint "called";
_unit = player;
fix_active = false;
	while {true} do 
	{				
		waitUntil {!fix_active && (damage _target >= 0.2) && (count (nearestObjects [_target, ["US_Soldier_Engineer_EP1"], 3]) >=1)};
		 fix_action= _target addAction [("<t color=""#66FFFF"">" + ("repair damaged vehicle") +"</t>"), "repaircar.sqf",[],1,false,true];

		 waitUntil {fix_active || (damage _target <= 0.2) || (count (nearestObjects [_target, ["US_Soldier_Engineer_EP1"], 3]) <1)};
		 _target removeAction fix_action;

	};

repaircar.sqf

_damagedvehicle = _this select 0;

fix_active = true;
hint "repairing";
_damagedvehicle setdamage 0;

sleep 2;
fix_active = false;

Share this post


Link to post
Share on other sites

Why would you want to solve this with very expensive loops and scripts, when the addAction parameter works just fine. :confused:

Phelam seemed to had some problems with it, so I just took the condition I posted earlier and pasted it into the condition parameter from the addAction example from the wiki. It worked without any problem.

this addAction ["View radar", "mission\radar\viewRadar.sqf",  ["forwardRadar", 8], 1, false, true, "teamSwitchPrev", "getNumber (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') == 1 && cursorTarget isKindOf 'car' && (_target distance cursorTarget) < 20 && damage cursorTarget >= 0.2"];

The only change I did make to the condition is swapping around the >=

If you want that this action menu entry is only visible to the owner of it, add this to the condition:

&& driver _this == _target

Share this post


Link to post
Share on other sites

Thanks for your brain storming guys,

Mikie - I have tested in single your idea but I cannot seem to make it work as you have done, I get a call message as soon as I enter the game but no action appears when it should. I am using the correct soldier, using the vehicles init field all scripts have been copied directly from here, but no joy. Any Idea where I'm going wrong ?

Mondkalb - That one seems to work perfectly thanks. Modified it to suit my needs;

this addAction ["Repair", "repairscript.sqf", ["Tank", 8], 1, false, true, "teamSwitchPrev", "getNumber (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') == 1 && cursorTarget isKindOf 'tank' && (_target distance cursorTarget) < 5 && damage cursorTarget >= 0.1"];

So far so good. I am continuing testing and I'll let you know I a problem occurs.

edit - In addition to this is there a way to disable bis' standard engineer script ?

Edited by OB1

Share this post


Link to post
Share on other sites

yeah, my bad -

waitUntil {fix_active || [color="#FF0000"](damage _target < 0.2)[/color] || (count (nearestObjects [_target, ["US_Soldier_Engineer_EP1"], 3]) <1)};
		 _target removeAction fix_action;

should be <2 - and not <= 0.2 as noted - that will work

In any event Mondkalb's method is much cleaner and simple - Use that

Mondkalb - point taken - cheers.

Share this post


Link to post
Share on other sites

no problem thanks, 1 more thing. (configFile >> 'cfgVehicles' >> typeOf _target >> 'engineer') where can I find the list of different 'typeOf' 's if i was to change who gets this ability ?

thanks.

Share this post


Link to post
Share on other sites

typeOf _target returns the classname of the object to which the addaction is on. eg US_Soldier_Engineer_EP1

I think 'engineer' refers to the Displayname in the config but I was going to test that when I had a moment. If that is so, in theory that line would work for any soldier with the Displayname 'engineer'. The PMC engineer is called a 'Field Technician' so it wouldn't work for that. Have a look at the Displaynames in the Six Config Browser, 3rd link below and try changing them and add the action to the corresponding unit placed in the editor? You may have to change _target to player to get it to work, not sure.

typrOf:

http://community.bistudio.com/wiki/typeOf

http://community.bistudio.com/wiki/Category:Scripting_Commands_ArmA2

Full cfgVehicles for Class men is here:

=faction&options[sort_by]=name&options[faction]=&options[vehicleclass]=Men"]http://browser.dev-heaven.net/cfg_vehicles/classlist?version=58&commit=Change&options[group_by]=faction&options[sort_by]=name&options[faction]=&options[vehicleclass]=Men

eg spotter:

http://browser.dev-heaven.net/cfg_vehicles/show/1489204

Share this post


Link to post
Share on other sites
The PMC engineer is called a 'Field Technician' so it wouldn't work for that.

Yes, it would also work for the Field Technician.

The config test used in my example does not check for >> 'displayName' but for >> 'engineer', which is the config value enabling the "Repair Vehicle" function.

class BAF_Soldier_EN_MTP: BAF_Soldier_base_EP1
{
scope = 2;
accuracy = 3.9;
model = "\ca\characters_d_BAF\BAF_Soldier_Engineer_BAF";
[color="#FF0000"]displayName = "$STR_BAF_CFGVEHICLES_BAF_SOLDIER_EN_MTP0";[/color]
picture = "\ca\characters_d_baf\Data\i_eng_ca.paa";
threat[] = {1,0.5,0.1};
canDeactivateMines = 1;
canCarryBackPack = 0;
[color="#FF0000"]engineer = 1;[/color]
...

Regarding typeOf:

If you were to place the BAF engineer (Config above), each of the following would return true:

player typeOf "BAF_Soldier_EN_MTP";
player typeOf "BAF_Soldier_base_EP1";
player typeOf "SoldierWB";
player typeOf "CAManBase";
player typeOf "Man";

Share this post


Link to post
Share on other sites

Thanks guys, also changing "typeOf _target >> 'engineer') == 1" to "==0" allows it to be used in any unit and because I'm only using it in the init field I can get away with it to be specific to that unit.

Share this post


Link to post
Share on other sites
Yes, it would also work for the Field Technician.

The config test used in my example does not check for >> 'displayName' but for >> 'engineer', which is the config value enabling the "Repair Vehicle" function.

Thanks for clearing that up, I got the notion from the Six Config Browser which lists displayName as other things. I will have to dePBO the CfgVehicles next.

Share this post


Link to post
Share on other sites

Ok I have encountered a problem while testing..

Im using the R3F_revive script, now as I said before im using this addaction line in the init field of my specified units. When you die and respawn you no longer have the ability. the R3F_revive doesnt seem to have an option to include init lines for respawn and even then I have to make it only available to the specific unit.. Is there any way around this ? Maybe away of implementing this without using the init line ?

Share this post


Link to post
Share on other sites

omg! thanks brain fart cleared.

---------- Post added at 10:22 PM ---------- Previous post was at 09:27 PM ----------

Ok I thought this was easy but I cant seem to get this working... removeAction now..

Just for the sake of this discussion lets say we are trying to remove an action using radio alpha in a trigger...

unitName removeAction action;

should this not work ?

Share this post


Link to post
Share on other sites

the action I created has an id ? where do I get that from ?

Share this post


Link to post
Share on other sites
_id = player addAction ["Switch on generator", "activate_generator.sqf"];
player removeAction _id;

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  

×