Jump to content

Recommended Posts

Hello Everyone,

 

I'm making a PMC styled mission to go on the workshop, but I want to create a script that when a vehicle hits a spike strip (Razor wire that is flattened in-game) that the vehicles tyres blow out. I know how to do all of this using a trigger for example, but I want a more reliable way of doing it so the mission is more dynamic. So I thought of using an event handler to be attached to the razor wire, and when a tyre makes contact with it, the tyres blow out. However, I'm trying to make it that only the tyre that is hit blows out. So I looked at the event handler, "EpeContact". However, I cannot think of anyway to attach this to individual tyres for example. Anyone have any idea on how to do this?

 

Thanks! 

Share this post


Link to post
Share on other sites

Just a note on this. I can't seem to find any examples of this working :/ Even had a search through Killzone Kid's blog and nothing! 

Share this post


Link to post
Share on other sites

What did you try already?

I'd say using an eachframe eventhandler once the fence is up to check for nearentities and the distance to nearby tires could be a solution.

 

Cheers

Share this post


Link to post
Share on other sites

I would attach the EH to those spikes but the needed return values of this eh seem to be work in progress. I think u ve to wait for the finished version of it

sent from mobile using Tapatalk
 

Share this post


Link to post
Share on other sites

Great idea JetRise.  Please publish this script when you're done.  I'd love to use it.

 

If the optimal "EpeContact" EH solution isn't ready for prime time, you could always spawn a loop monitoring distance of vehicle front to the razor wire.   Once close enough, you determine which front tire is closer (or both) and blow them out.

Share this post


Link to post
Share on other sites
26 minutes ago, johnnyboy said:

Great idea JetRise.  Please publish this script when you're done.  I'd love to use it.

 

If the optimal "EpeContact" EH solution isn't ready for prime time, you could always spawn a loop monitoring distance of vehicle front to the razor wire.   Once close enough, you determine which front tire is closer (or both) and blow them out.

 

Yeah I'm working on it right now. I know you can do it with a loop, but obviously, you would always try and pick an event handler over a loop for performance, which is what I am trying to do right now. I'll get back to you if I get it working! 

Share this post


Link to post
Share on other sites
2 hours ago, johnnyboy said:

Great idea JetRise.  Please publish this script when you're done.  I'd love to use it.

 

If the optimal "EpeContact" EH solution isn't ready for prime time, you could always spawn a loop monitoring distance of vehicle front to the razor wire.   Once close enough, you determine which front tire is closer (or both) and blow them out. I'll have to use eachFrame.

 

3 hours ago, sarogahtyp said:

I would attach the EH to those spikes but the needed return values of this eh seem to be work in progress. I think u ve to wait for the finished version of it .Yep you are right!

 

3 hours ago, Grumpy Old Man said:

What did you try already?

I'd say using an eachframe eventhandler once the fence is up to check for nearentities and the distance to nearby tires could be a solution. Looks like I will have to use eachFrame. However, if what I was trying did work, it would be better for performance I believe.

 

 

I have a few problems with the Event Handler EpeContact. Before I delve into these problems, I just want to highlight that there has been no change to the return values of "select1" and "select2". Killzonekid updated the page in December of 2013 stating that the two select values only returned empty strings. This is still unfortunately the case. So, in reference to what I am working on, the next best step for me is using an EH like eachFrame as I cannot get the wheels on the car, not that I could ever get the car anyway which I will discuss next.

 

My first problem with the event handler, EpeContact, is that it doesn't return the object actually hitting it. You can see in the video at the bottom of this post showing me driving over the razor wire. It returns my player, not the car. You can also see the code I am using at the bottom of this post. On the wiki, it states for the object 2, which is what I am selecting, that object 2 is the, "Object which is colliding with object1.". Object1 being the object the EH is attached to. Well this isn't true at all. I may be the person who is causing the collision by applying acceleration, however, ultimately the object that is colliding and touching the razor wire is the car. So why isn't the car returned? I don't understand why this is the case. 

 

So, my next issue is how the EpeContact event handler decides what is and isn't a collision. You can see in the first half of the video that when I drive over the razor wire, the razor wire falls to the ground and at the same time, my player name is returned. However, in the second half of my video, you can see me setting the damage of the object to one, causing it to lie flat on the ground, which is what I intend the spike strips to look like. But, when I drive over this damaged razor wire, the event handler is not triggered. Well why not, am I not colliding with it? To summarise my point with the way this EH is triggered, unless the object position/movement has been changed, even though there has actually been a collision, this event handler will not be triggered. I find this quite annoying and doesn't make much sense to me. I understand PhysX is the element responsible for handling the way object move after a collision, however, collisions can still occur that do not cause an actual movement in the object.

 

Code:

this addEventHandler ["EpeContactStart", {_hint = _this select 1; hint format ["Vehicle: %1",_hint ];}];

Video:

 

 

 

Share this post


Link to post
Share on other sites

So with the AddEventHandler, can you do a Trigger instead of a game logic?

 

Share this post


Link to post
Share on other sites
3 minutes ago, Booker- said:

So with the AddEventHandler, can you do a Trigger instead of a game logic?

 

What do you mean? Do you mean put that code inside a trigger or?

Share this post


Link to post
Share on other sites

Possible solutions to avoid very ulgy loops and things like nearentities:

 

To know the vehicle which is colliding with the razor, as in your tests it seems to return the driver, just a simple check like "If (vehicle _this select 1 != _this select 1)" will confirm the thing is touching the razor is not a soldier, from there, you can assign a variable to the car, like "_car = vehicle (_this select 1); If (_car isKindOf "Car") then {do stuff}" Is very simple and will do the trick.

 

For the second issue, my suggestion is to place the razor wire dig in land, like wire setPosATL [getPosATL razor select 0,getPosATL razor select 1,-0.5] play with the third param to have a nice visual and from there test if the EH fires.

 

 

Share this post


Link to post
Share on other sites
On 2017-6-13 at 5:45 PM, pierremgi said:

did you get any epeContact on foot unit?

 

Sorry I've had exams recently, and only just seen this amongst other notifications. I will have a look by the end of this working week and get back to you on that! 

Share this post


Link to post
Share on other sites

I had a look at this and did get it to work using Epecontact, it isn't easy though as destroyed objects don't seem to work with the Eventhandler.

 

What I did was place the destroyed fence used for visual only and then sink the hidden wall into the ground and used that to trigger the Event.

I think I also had to flip it or tilt it for it to work, it did have to be proud of the ground just driving on it didn't work.

When it does work you actually get a little jump with the vehicle and a contact sound as if the tyre has blown.

 

After all that I found it only works for players AI drive straight through without any contact.

 

Share this post


Link to post
Share on other sites
On 2017-6-13 at 11:48 AM, barbolani said:

Possible solutions to avoid very ulgy loops and things like nearentities:

 

This is correct, but as I've experienced in the past, depending of the performance of the users pc, it can create anomalous results, for example, the client will drive over it but will not always register as being hit. 

Share this post


Link to post
Share on other sites

I hope you get it to work as desired, and there is some good learning about EpeContact being documented in this thread.  But if it was me, I'd say FIMO (f*** it, move on), and just use a loop with a distance check to the razor wire.  Add in tire popping sound fx, and maybe skid the car right or left a bit, and you have a cool script.  And the old saying "Perfect is the enemy of good" may apply also.  Sometimes fighting ARMA engine isn't worth additional time and effort.  Save that effort for the next challenge.  Of course that  is all up to you!  :)

  • Like 2

Share this post


Link to post
Share on other sites
21 minutes ago, johnnyboy said:

I hope you get it to work as desired, and there is some good learning about EpeContact being documented in this thread.  But if it was me, I'd say FIMO (f*** it, move on), and just use a loop with a distance check to the razor wire.  Add in tire popping sound fx, and maybe skid the car right or left a bit, and you have a cool script.  And the old saying "Perfect is the enemy of good" may apply also.  Sometimes fighting ARMA engine isn't worth additional time and effort.  Save that effort for the next challenge.  Of course that  is all up to you!  :)

Agree. On a same register, I gave up searching a smart solution avoiding collision between cars and units. No epeConctact works on foot units. disableCollisionWith doesn't work with nested loops. Checking for distances is not acceptable.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, f2k sel said:

What I did was place the destroyed fence used for visual only and then sink the hidden wall into the ground and used that to trigger the Event.

 

What do you mean about the wall? I'm a little confused by that... have you got any code you can show me?

 

Thanks! 

Share this post


Link to post
Share on other sites

Well I would show you but it just isn't going to work.

It looks like the Contact has to be made with the vehicles body not wheels and as vehicles have different heights some vehicles will trigger it others won't and some just stop dead.

 

I also tried using the red and white pole with transparent textures, it works for the Quad bike but stops a hunter dead unless going at speed.

Share this post


Link to post
Share on other sites

do you need this to work from many razor objects and vehicles universially or is it more a cinematic temporary thing?

 

if it's very specific, you could use intersect commands downwards from each wheel a short distance on each frame and that way see if there is and object of the type in question below. if the vehicle registers a hit the wheel the hit was on gets disabled. this might end up being the most accurate way. not sure about performance especially for many vehicles at the same time. hence the first distinction.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, bad benson said:

do you need this to work from many razor objects and vehicles universially or is it more a cinematic temporary thing?

 

if it's very specific, you could use intersect commands downwards from each wheel a short distance on each frame and that way see if there is and object of the type in question below. if the vehicle registers a hit the wheel the hit was on gets disabled. this might end up being the most accurate way. not sure about performance especially for many vehicles at the same time. hence the first distinction.

 

Excellent idea  :)

 

Building on what you say mate;

 

Instead of having each wheel of each vehicle, you could draw a line with lineintersectssurfaces across the stinger device OEF but say 0.1m above it.

 

Then if any vehicle intersects that line, you wipe out the wheels that are perpendicular to that intersection.

 

It's still accurate (not quite as accurate as yours) but it would reduce the amount of intersect checks drastically. (from "sum of vehicle wheels on the map" to "number of stingers on the map").

 

You could take it one step further and fire a line from each end of the stinger OEF which would make sure each side of the vehicle is checked instead of just one side and applying it to the other side.

  • Like 2

Share this post


Link to post
Share on other sites

If use of a mod is acceptable, how about a modified tripwire mine?

  • Like 1

Share this post


Link to post
Share on other sites

Probably not the best code, but for a razor wire fence:

 

if (isServer) then { 
  this spawn { 
    _dir = getdir _this; 
    _pos = getPos _this; 
    _bbr = boundingBoxReal _this; 
    _p1 = _bbr select 0;  
    _p2 = _bbr select 1;  
    _maxWidth = abs ((_p2 select 0) - (_p1 select 0));  
    _maxLength = abs ((_p2 select 1) - (_p1 select 1)); 
    _trg = createTrigger ["emptyDetector",_pos]; 
    _trg setTriggerArea [_maxWidth+5, _maxLength+10, _dir, true]; 
    _trg setTriggerActivation ["NONE", "PRESENT", true]; 
    _trg setVariable ["dimArea",[_pos,_maxWidth/2,_maxLength/2,_dir,true]]; 
    _trg setTriggerStatements ["count (vehicles inAreaArray thisTrigger)>0","thisTrigger spawn { 
        params ['_trg'];
        while {triggerActivated _trg} do { 
          _vehs = vehicles inAreaArray _trg; 
          if (count _vehs >0) then { 
            _veh = _vehs select 0;
            _hits =[]; 
            _points = getAllHitPointsDamage _veh;
            {_hits pushBack [_points select 0 select _foreachindex,_veh selectionPosition (_points select 1 select _foreachindex)]} forEach (_points select 0);
            _hitWheels = _hits select {['wheel',(_x select 0)] call bis_fnc_inString};
            { 
              if(_veh modelToWorldVisual (_hitWheels select _foreachindex select 1) inArea (_trg getVariable 'dimArea')) then { 
                _veh setHitPointDamage [_hitWheels select _foreachindex select 0,1] 
              } 
            } forEach _hitWheels; 
          }; 
          sleep 0.1 
        } 
      }","" 
    ]; 
  }; 
};

How it works, in init field of the razor fence:

- this script add a trigger with a wider area than bounding box real of the fence; (as far as it's impossible to guess what vehicle will be hit)

- detect any vehicles (should be land vehicle, but not seen wheel parts on plane/helicopter so far) in this area

- when activated, check if a wheel part is in real bounding box of the fence (x,y, not Z so far); here is the best precision with these models. Any other idea?

- apply damage 1 to each positive checked part. The tires are blown independently, as required in first post.

 

Obviously, you can apply the code to all fences with an array in init.sqf.

 

  • Like 1

Share this post


Link to post
Share on other sites

I don't think this will work in mp. 

Because setHitPointDamage  must be executed where the vehicle is local

And a vehicle becomes local to the player who is driving it, not to the server.

So i think you have to use remoteExec and (owner _veh) 

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, xjoker_ said:

I don't think this will work in mp. 

Because setHitPointDamage  must be executed where the vehicle is local

And a vehicle becomes local to the player who is driving it, not to the server.

So i think you have to use remoteExec and (owner _veh) 

 

 

Yes exactly, but there is no need for <owner....>

 

RemoteExec and it's impatient brother remoteExecCall can use the object as a param without that additional step.

Share this post


Link to post
Share on other sites
9 hours ago, xjoker_ said:

I don't think this will work in mp. 

Because setHitPointDamage  must be executed where the vehicle is local

And a vehicle becomes local to the player who is driving it, not to the server.

So i think you have to use remoteExec and (owner _veh) 

 

Corrected my former script to make it work in MP. (improved also fence detection).

 

On the other hand, remoteExec a command on a global trigger like this is not the best way  to save network load.

 

So, I tested something more convenient (I hope) making triggers on each PC (instead of server) but working locally, (without exchange with server if I'm right).

The command AL EG does the trick.

So, i think this following version is far better:

 

0 = this spawn {
    _dir = getdir _this;
    _bbr = boundingBoxReal _this;
    _p1 = _bbr select 0;  
    _p2 = _bbr select 1;
    _pos = _this modelToWorld (_p1 vectorAdd _p2 vectorMultiply 0.5);  
    _maxWidth = abs ((_p2 select 0) - (_p1 select 0));  
    _maxLength = abs ((_p2 select 1) - (_p1 select 1));
    _trg = createTrigger ["emptyDetector",_pos,false];
    _trg setTriggerArea [_maxWidth+5, _maxLength+10, _dir, true];
    _trg setTriggerActivation ["NONE", "PRESENT", true];
    _trg setVariable ["dimArea",[_pos,_maxWidth/2,_maxLength/2,_dir,true]];
    _trg setTriggerStatements ["count (vehicles inAreaArray thisTrigger)>0","thisTrigger spawn {
        params ['_trg'];
        while {triggerActivated _trg} do {
          _vehs = vehicles inAreaArray _trg;
          if (count _vehs >0) then {
            { _veh = _x;
              if (local _veh) then {
                _hits =[];
                _points = getAllHitPointsDamage _veh;
                {_hits pushBack [_points select 0 select _foreachindex,_veh selectionPosition (_points select 1 select _foreachindex)]} forEach (_points select 0);
                 _hitWheels = _hits select {['wheel',(_x select 0)] call bis_fnc_inString};
                {
                  if(_veh modelToWorldVisual (_hitWheels select _foreachindex select 1) inArea (_trg getVariable 'dimArea')) then {
                     [_veh,[_hitWheels select _foreachindex select 0,1]] remoteExec ['setHitPointDamage',_veh]
                 }
                } forEach _hitWheels;
            };
          } forEach _vehs;
        };
        sleep 0.1
        }
      }",""
    ];
  };

 

 

 

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

×