Jump to content
Sign in to follow this  
Sokoloft

How to have a vehicle open it's door at a certain speed?

Recommended Posts

I would like in my vehicles init a code snippet that determines once the vehicle is at speed 0/stopped, it opens it's door? How do I do that? :(

 

As well as I'm down to make it a fnc call as well! idc, and name it fnc_checkSpeed

 

I would of imagined this would be a BIS_fnc, however I have yet to find it if it is >_<

 

Edit:
 

I feel what I'm looking for is a getSpeed command, but that isn't correct, is it?

 

Edit2:

 

Would I have to have 2 getPos commands, and then have some logic in between to determine the speed?? Then have it do animateDoor command? As well as how do I determine what the door I'm trying to open is? Door_L, Door_R, Door_F? As well as I'm currious if this is going to do the same as when the player opens the door via the addaction option. When the player does it the infantry disembark, so if triggering animateDoor doesn't, then I need a way to tell a unit to do a addAction option? Going to go test that now.

Share this post


Link to post
Share on other sites

These two should help.

https://community.bistudio.com/wiki/speed

https://community.bistudio.com/wiki/animateDoor

 

I'm not certain of your use case, but I'd somehow put in a sleep to only open the door after the vehicle has been stopped for a period of time.  Maybe 3-5 seconds.

 

Pseudo code:

if (this speed == 0; sleep 5; this speed == 0;) then {open the doors}

  • Like 1

Share this post


Link to post
Share on other sites

So, using this:

if (this speed == 0; sleep 5; this speed == 0;) then {(this animateDoor ["Door_???", 1];)}

Now the real question is, how would I go about figure out what "Door_???" Is? I would imagine panning through the mod I'm using folder and look for a "class AnimationSources" were would that be defined? Is there a better way? Thanks!

 

PS: I'd like to call this via a fnc, so fnc_checkSpeed.sqf, then add it to the vehicles init.

Share this post


Link to post
Share on other sites

Trying to use this in a game logic init:

_nObject = getPos player nearestObject "Obj_Var_Name_Here??"; 

and couldn't get it to do anything. Said there was an issue with a script from a mod I have installed. Any idea? As well as do I have to look for anything in the RPT log? Currently have noLogs on.

 

Should I disable said mod and try again?

Share this post


Link to post
Share on other sites
I think you can check vehicle doors selection name only in model, but I have found some that you may use:

 

Tested with Hunter and works perfect, everything in quotes refers to model selection.

 

vehicle player animateDoor ["Door_RF", 1]; 

vehicle player animateDoor ["Door_LM", 1]; 

vehicle player animateDoor ["Door_RM", 1]; 

vehicle player animateDoor ["Door_rear", 1];

 

Remember that not all A3 Vehicles has animated doors.

  • Like 1

Share this post


Link to post
Share on other sites

@riten I had already tried guessing unfortunately, and what comes to mind that would make sense unfortunately doesn't work. Is there any other way? Possibly in the mod folder that the vehicle is in might contain the answer, however which file is it defined in is the true question. As it says in the animateDoor documentation in the desc. :(

 

Edit:

 

As well as, I'm not sure if animateDoor will work for my application or not, since when a player triggers to open the door via a addaction command, it opens the door, and has all the units in the vehicle disembark, calling animateDoor might not make them disembark, so how do I have the script trigger the addaction command that the player would normally trigger???

Share this post


Link to post
Share on other sites

If you're using A3 vehicles then those selection I've already sent should work, if you're using mods then it's more complicated. You can find door selection name in model.cfg, but then again it's complicated, because if it is binarized (p3d + model.cfg) you'll need tools like "elitness" to able to read model.cfg. So you need to find out how author of model named door part in his mod to be able to animate it (if it has animation in model.cfg).

  • Like 1

Share this post


Link to post
Share on other sites

Yeah they're binarized :( Well, could the work around be to do the addaction option as described in my last post? As I said idk if animateDoor is even going to work in the way I want.

 

Update:

Well I posted a question asking for what to call in the mod authors discord, waiting for them to get back to me atm. Doesn't seem like it's going to be today however. :(

Share this post


Link to post
Share on other sites

Well, contacting the author got me a little further. In game there is a splendid config viewer, and in there I found the vehicle and found it's animation sources. From what I found there I tried the following:

vehicle player animateDoor ["ramp_rotate", 0];

Tried changing the 0 to different values as well, 1,2 no luck. Talking to someone on Discord and they say that if you shoot at the vehicle I'm talking about, they disembark and open the door. So how's about a trigger, and in it's condition put the pseudo code from second post:

if (this speed == 0; sleep 5; this speed == 0;) then {Disembark units}

But what would I need for {Disembark units}   ? Would that even work?

 

Edit:

 

Did a search on the community wiki, came up with this = https://community.bistudio.com/wiki/unassignVehicle

Share this post


Link to post
Share on other sites

Hey @theend3r! How's it going? Thanks for the info! I tried animationNames and It went through fine in my debug console, however I get nothing back, do I need to have RPT logs on? Currently have them disabled, if so I'll go get a log viewer app and enable logs again. Thanks!

Share this post


Link to post
Share on other sites

Hey @theend3r! How's it going? Thanks for the info! I tried animationNames and It went through fine in my debug console, however I get nothing back, do I need to have RPT logs on? Currently have them disabled, if so I'll go get a log viewer app and enable logs again. Thanks!

Nah, just

copyToClipboard animationNames vehicle;

and paste is somewhere. It's going to have quite a lot of them so since you're using NP++ (afaik) use the exteded search mode and replace all commas with \r\n to make it more user friendly.

 

I remember trying animationNames command a while back but it didn't help me with what I needed. Still, it doesn't hurt to try.

  • Like 1

Share this post


Link to post
Share on other sites

I still can't get animationNames to work, figured I'd try to get them to disembark but I can't even get that to work as a fnc. I tried the following:

//Author - Sokoloft

//fnc_checkSpeed.sqf


if (speed _x = 0) then {

sleep 5; 

};


if (speed _x = 0) then {

{unassignVehicle _x} forEach vehicleArray;
};

As well as I have vehicleArray and vehicleArray1 defined in my init now instead of the trigger :D From the previous post about AI spawning. Idk, let me know were I went wrong >_< Ugh.

Share this post


Link to post
Share on other sites

I still can't get animationNames to work, figured I'd try to get them to disembark but I can't even get that to work as a fnc. I tried the following:

//Author - Sokoloft

//fnc_checkSpeed.sqf


if (speed _x = 0) then {

sleep 5; 

};


if (speed _x = 0) then {

{unassignVehicle _x} forEach vehicleArray;
};

As well as I have vehicleArray and vehicleArray1 defined in my init now instead of the trigger :D From the previous post about AI spawning. Idk, let me know were I went wrong >_< Ugh.

This

if (speed _x = 0)

is completely wrong, you need to use == (or better yet isEqualTo or something like < 1)

 

To have the units disembark, do

_handler = [] spawn {
   waitUntil {sleep 5; speed someVehicle isEqualTo 0};
   {unassignVehicle _x} forEach crew someVehicle;
};

Share this post


Link to post
Share on other sites

why what are you making? i remember back in arma 2 they had a Mi24A with doors that would open after a condition was met which was when the vehicle had its gears down and its AGL alt was zero. I thought it was a rather silly and dumb thing to add in because it looked rather unnatural as it would flap open and close like a bird some times. of course this depends on what you are making, personally I rather have the doors open with the menu on command and have the doors animate open and close when a character enters / exits with a 5 to 10 second timer on closing this way you wont have the doors open every time the vehicle has stopped and it looks rather realistic... think about it like this when you have a group of AI exiting the vehicle they will all exit in a orderly manner the timer will reset after the character, so when the last AI leave the door will close behind him  and when there are players which wont be as orderly as the AI there will be a varying times of people disembarking and embarking and the players can always close to open and close the door on command which is an added befit.  

Share this post


Link to post
Share on other sites

Alright, @theend3r I could not get the following to work :( It does not throw any errors, but just doesn't do what it's supposed to. Even putting it on the vehicles init.

 _handler = [] spawn {
   waitUntil {sleep 5; speed VARNAMEHERE isEqualTo 0};
   {unassignVehicle _x} forEach crew VARNAMEHERE;
};

As well as @veles-zv animDoor isn't going to work for my application. I had hoped that when triggering that, it would be similar to when the player triggers opening the door. However it is not. It does no sound or animation and just toggles it in place. As well as it doesn't disembark the troops like it normally does when the player opens the door. As well as I can't get into too many details about what the application is for or else it would give away my mission, however if you look hard enough you could probably figure out what it is ;)

 

As well as I found out animateDoor wouldn't work, animateSource was what I was looking for.

Share this post


Link to post
Share on other sites

Well I just tried this in testing and I got units to disembark by doing either of these two things via just putting it in the vehicles init.

doGetOut _x

doGetOut this

Not sure which one did it, but they got out. However, they did not open the door as I hoped for, and animateSource doesn't look right, so now I think what needs to be looked into is how do I open the door in a script exactly like the player does? As driver of the boat, there is an open door scroll wheel option, and when you open the door, the gate drops and the units disembark, it's quite a sight to see honestly if you're the driver. xD

Share this post


Link to post
Share on other sites

As driver of the boat, there is an open door scroll wheel option, and when you open the door, the gate drops and the units disembark, it's quite a sight to see honestly if you're the driver. xD

 

Why don't you use the config viewer to see what action is triggered there and use that in your script ?

 

Oh and as far as speed goes, better not compare it against 0. The vehicle might still be sliding around slightly.

 

 

One more thing:

Never use just "doGetOut". Make sure you also unassign them or they will often try to get back into the vehicle right away.

https://community.bistudio.com/wiki/unassignVehicle

  • Like 1

Share this post


Link to post
Share on other sites

Hey! I've been messing with the code that @theend3r gave me and I've come up with this:

_handler = [] spawn {
waitUntil {sleep 5; speed VARNAME isEqualTo 4};
{unassignVehicle _x} forEach crew this;
VARNAME animate ["ramp_rotate",1];
waitUntil {sleep 5; speed VARNAME isEqualTo 5};
VARNAME animate ["ramp_rotate",0];
};

However, on the waituntil line it tells me that after speed "VARNAME"(Was "this") isn't the right variable. Bare with me, I have a vehicleArray = [bunch,of,Var,Names] defined in my init, how would I make it to were it does it to all of the vehicles in the vehicleArray? Tried replacing "VARNAME" with vehicleArray however it throws errors again. Would it be _x and were? Essentially what I want is a fnc that will disembark/open the door once any defined vehicle in the vehicleArray is below 4 kmh. (only in trigger zone) If it goes over 5 kmh(only in trigger zone), the door will close. However, I need this to only work in a specific area, so the fnc would be called by a trigger, and any vehicle defined in the vehicleArray that enters that trigger zone has that fnc applied to it? Still new to all of this, so how would I go about doing that? Thanks!

 

As well as @Tajin I realized you can copy paste from the cfg viewer. Looking at the open door statement, is a long string with many different fnc being called. Not really sure what it all means and I don't think that I can make it applicable to my application. I was just wondering if there was any simple way of doing a player action to simplify things. Like a fnc_doplayerAction or something. Would be handy for simple workarounds like this! So instead of my animate commands, I could use the fnc instead, Ex:

 

["VARNAME/ARRAY", open_ramp] call fnc_doplayerAction

["VARNAME/ARRAY", close_ramp] call fnc_doplayerAction

 

As well as when the player opens the door, the units auto disembark, therefore I wouldn't have to have the unassignVehicle command or doGetOut. Forgot to put doGetOut as well in the script.

 

Is there a fnc out there that already does that? If so which one?? Thanks again!

Share this post


Link to post
Share on other sites

You could basically copy the code from that "open_ramp"-action and then call it like a function. (while passing the parameters that an action would expect)

 

 

For the speed-check and disembarking I would use this code (init.sqf):

// [this,triggername,speedlimit,roles]
fnc_autounload = {
    params ["_vehicle", "_trigger", "_spd","_roles"];
    waitUntil {sleep 1; (speed _vehicle < _spd) && (_vehicle inArea _trigger)};
    _vehicle animate ["ramp_rotate",1];
    sleep 1;
    {
        if ((_x select 1) in _roles) then {
            _unit = _x select 0;
            unassignVehicle _unit;
            doGetOut _unit;
            _unit action ["Eject",_vehicle];
            sleep 0.5;
        };
    } forEach fullCrew _vehicle;
    waitUntil {sleep 1; (speed _vehicle > _spd)};
    _vehicle animate ["ramp_rotate",0];
};

 
Name your trigger "missionarea" and then put the following in each applicable vehicle-init:

[this, missionarea, 5, ["cargo","gunner","turret","commander"]] spawn fnc_autounload;

The last parameter defines which crew-roles should exit the vehicle.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the reponse! Trying this now, however I had to change spawn to call to be able to put it into the vehicles init. I loaded in and it says there is an error on line 9 missing ; line 9 = animate ["ramp_rotate",1];

 

to get that command working in game in my testing, I had to use it's defined name I gave it in the editor, so boat1 for example, so:

 

boat1 animate ["ramp_rotate",1];

 

however, all the boats are defined via an array, in my init, since I have a script that spawns AI into them that way. init line is structured like this:

 

vehicleArray = [boat1, boat2, boat3]

 

how would I make it to were animate uses the vehicle array? is it a different command? I just want it to work at this point, not looking for anything fancy! xD So:

 

vehicleArray animate ["ramp_rotate",1];

 

???

 

Many Thanks!

 

Edit

 

Doing that actually would open all the boats doors >_> Which is not what I want, would it just be "this" instead?

 

Edit2: Just ran the following through my dev console and it went through, gonna check:

 

this animate ["ramp_rotate",1];

Share this post


Link to post
Share on other sites

Thanks for the reponse! Trying this now, however I had to change spawn to call to be able to put it into the vehicles init.

Call doesn't work with scripts containing sleep so that won't work.

To use spawn in the init line, assign it to some var, e.g.:

nul = [this] spawn {systemChat format ["Initializing %1", vehicleVarName (_this select 0)]};
  • Like 1

Share this post


Link to post
Share on other sites

My bad, forgot to put the variables before animate :P

 

*fixed it in my previous post* just copy it again and be sure to use spawn, like theend3r already said.

  • Like 1

Share this post


Link to post
Share on other sites

Well it's a good thing to know I'm learning, had already added the _vehicle in front of the animate commands but copied it over again for good measure and still no luck. I'm calling it how @theend3r said, with nul = . However it does nothing, I have a trigger named missionarea, does it need to be a marker or anything different? Not even getting an error :/

 

I'm calling it via the following in my vehicles init

nul = [this, missionarea, 5, ["cargo","gunner","turret","commander"]] spawn fnc_autounload;

It just dawned on me that the array might not be configured correctly for my aplication, the boat has 36 passenger seats, and 1 driver seat, so I would imagine I would want ["passenger","driver","cargo"] , gonna go test. Is cargo passenger's because they aren't even getting out :(

 

edit: loading up atm trying:

 nul = [this, missionarea, 5, ["cargo","driver","passenger"]] spawn fnc_autounload;

edit2: Still no luck, any idea's?

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  

×