Jump to content
Sign in to follow this  
loyalguard

Using setHit to Damage Multiple Hit Points with the Same Hit Point Name

Recommended Posts

I have slowly been working on my ArmA Electrical Grids simulation for A3. I have basic functionality ported over from A2 working on Stratis, but since switchLight does not seem to be not working (or just not enabled) yet, there is nothing to release yet.

In the meantime, I have been looking to add some functionality to AEG and have been looking at disabling lighthouse lights, runway lights, and possibly other light sources not affected by switchLight. For lighthouses, the best method I have come up with so far is to use setHit to damage the appropriate selections/hitpoints of the lighthouse to turn off the lamp without damaging the lighthouse as a whole. I cannot use setHitPointDamage because there is no class HitPoints in Land_Lighthouse_F, so I am just using setHit on the hitpoint entry ("Main_Light_hitpoint") in class Reflectors. The problem is that...

object setHit ["Main_Light_hitpoint", 1];

(where object is a pointer to the actual lighthouse object)

...has no visible effect. So, I added a dammaged event handler to the lighthouse, shot the light, and eventually got a result (via hint) confirming that "main_light_Hitpoint" is the correct selection. Just for kicks, I tried setHit 0 and even though the light did no turn back on (no apparent light emitted from the lamp) there was a single lit area on the ground (not the normal three) that moved as if it was "on" (see screenshots comparing before damage/after damage but also with setHit 0):

lighthouse.jpg

So, I did some deeper debugging and outputted the the event handler to the .rpt and noticed whenever I damaged the lamp, I got four outputs. So then it clicked, there are four reflectors in class Reflectors (Reflector_1, Reflector_2, Reflector_3, and Cabin_Lumination) that all inherit from the first (Reflector_1) and as such all have "main_light_Hitpoint" as their hitpoint (there is technically a fifth reflector (the door lamp) but it has a different hitpoint and I can setHit 1 and 0 with no problems.) So I assume that when I use setHit, it is only affecting one instance of "main_light_Hitpoint" (as supported by using setHit 0 after manual damage only turning back on part of the lighting) but actual physical damage (bullets and such) all get damaged. Just to be thorough, I also tried the selection name "Main_Lights" and Ilooked through the model config to see if there were other possible selections/points I was missing.

So assuming I am correct on the multiple instances, any ideas on how to overcome using this setHit such as cycling through the different reflectors or some other way of getting all of the instances of the hitppoint? Could I be wrong and just approaching this incorrectly? Thanks!

Edit:

So I have found one alternative to using setHit. I spawn individuals bullets and direct them towards the light to destroy it. This was inspired by code posted in the past by Twirly and Big Dawg KS:

private ["_object","_sPos","_tPos","_bullet","_bPos","_heading","_velocity"];

_object = lh; // In this case a named object but can be determined via nearestBuilding or other similar methods.
_sPos = _object selectionPosition "light_4_pos"; // The selection position of the center of the main light in model space.
_tPos = _object modelToWorld _sPos;  // The center of the main light in world space.

//Run a loop that creates five .50cal bullets and then direct each one to hit the main light
for "_i" from 0 to 4 do
{
   _bullet = "B_127x99_Ball" createVehicle _tPos;
   _bPos = getPosASL _bullet; 
   _heading = [_bPos,_tPos] call BIS_fnc_vectorFromXToY; 
   _velocity = [_heading, 1000] call BIS_fnc_vectorMultiply; 
   _bullet setVectorDir _heading; 
   _bullet setVelocity _velocity; 
};

It only takes four bullets but I added the fifth just to be safe. You can hear glass breaking if you are close enough which is a little unrealisitc for power switching off but I can live with that. I the just setDamage the whole lighthouse back to 0 to get the lights to turn back on.

If someone still has a solution via setHit I would still welcome it. Thanks!

Edited by Loyalguard
Possible solution added.

Share this post


Link to post
Share on other sites

I have made some changes to the lighthouse model. You should now be able to use the following set of commands to control the lights in the top cabin:

object setHit ["Light_1_hitpoint", 1];
object setHit ["Light_2_hitpoint", 1];
object setHit ["Light_3_hitpoint", 1];
object setHit ["Cabin_illumination_hitpoint", 1];

The first three lights are the reflectors illuminating outside terrain (numbered counterclockwise in top-down view). Each of these control given dynamic light, light shaft outside the cabin and a circular glow on the surface of the cabin windows.

The fourth light (cabin illumination) controls the dynamic light that illuminates interior of the lighthouse cabin and emissive materials on the main lamp. In other words it doesn't represent a "standalone" light source; it has only a support role to achieve the overall visual impression. That means you will probably want to turn this one off when (and only when) all three of the reflectors are off as well.

These changes should be now available on Steam in the Development build.

I should note though that nothing is final and things may still change anytime before the release (eg. adjusting the amount of dynamic lights on lighthouse).

Share this post


Link to post
Share on other sites

Wow! That is fantastic Tilion! Thank you! I understand that it is not final and I will remain flexible. I cannot wait to modify my code to take advantage of this. This type of feedback and attention is what makes BIS so great!

Share this post


Link to post
Share on other sites

New method works great! I plugged the new code in and instant success!

Share this post


Link to post
Share on other sites

Have there been any alternatives found yet to bothering a dev for a fix in the configs?

Having the same issue for a mission I'm building where the front headlights/rangelights on the hunter can't all be disabled without spawning bullets to "shoot" them out.

Any ideas?

Share this post


Link to post
Share on other sites

Sorry guys (for highjacking your thread),

I´m a scripting noob, so what Do I have to write in which field?

I want to switch off the lights in the lighthouse at Cape Strigla (Altis).

I set a generator at the bottom near the lighthouse an added the following script (which of course is not working with the lighthouse-lights):

(see this thread, solved by Gekkibi)

if (!isNull player) then {
[] spawn {
	nul = player addAction ["Power off!", {lightsOut = true; publicVariable "lightsOut";}, [], 0, false, true, "", "_this distance Generator < 2 && isNil 'lightsOutVariable'"];
	waitUntil {!isNil "lightsOut"};
	1000 cutText ["Power off - now!","PLAIN DOWN", 2];
	sleep 2;
};
};

if (isServer) then {
waitUntil {!isNil "lightsOut"};
sleep 10;
{
	_x setDamage 0.97;
	sleep 0.01;
} forEach (getPos Generator nearObjects ["Lamps_Base_F", 50]) + (getPos Generator nearObjects ["PowerLines_base_F", 50]);
};

The above script works well within cities: Go to the object named "Generator", use the action menü and turn off the lights. Great effect.

So how can I Use the action menü with just the lighthouse.

Or maybe the lighthouse and the buildings around 100m ...?

So where do i have to write the

object setHit ["Light_1_hitpoint", 1];
object setHit ["Light_2_hitpoint", 1];
object setHit ["Light_3_hitpoint", 1];
object setHit ["Cabin_illumination_hitpoint", 1];

And how do I link this to that one lighthouse at Cape Strigla?

I cant give a name to the lighthouse.

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  

×