Home   Help Search Login Register  

Author Topic: WIP Scripted elevator system (JTD dev group)  (Read 3710 times)

0 Members and 2 Guests are viewing this topic.

Offline Trexian

  • Members
  • *
WIP Scripted elevator system (JTD dev group)
« on: 24 Jun 2008, 16:31:22 »

Ok guys, here's what my questions have been about. :)  Basically, a scripted elevator solution.  I'm posting now because, with serious help from you guys, :) it is actually at a working proof-of-concept stage.

The idea is this:
- a multifloor building (since there aren't too many single-story buildings with elevators)
- a room in the building that is identical on each floor (the "elevator") that is basically an elevator shaft, but with floors.
- a trigger in "front" of the doors to the room that is the "call elevator" trigger - really just a script with a delay before it triggers the door animation
- a trigger that is the same size as the room (will take some trial and error) that is the elevator script

Here's a screenshot of the idea for the setup of the elevator trigger.

The mission designer will have two choices.  He can put the number of floors in the trigger execVM and the script will automagically generate the heights of the floors (for the hotel I'm using to test, a factor of *3.5 seems to work well).  There is also a commented guide in the script in case someone has a building model with inconsistent floor heights (like a tall atrium on the first floor or something).

The "elevator" script generates the addactions.


Code: (elevator.sqf) [Select]
// Elevator script 01d
// by Trexian for JTD (with help from OFPEC)
//
// This is triggered when the player moves into the trigger that
// defines the "inside" of the elevator.
// hint "started";
// sleep 2;

// variable defines
_numFloors = _this select 0;
addedActions = [];

// Loop from 1 to _numFloors - used as index for addedActions array and floor selection display.
for "_i" from 1 to _numFloors do
{
    _index = player addAction [format["Floor %1", _i], "JTDFloorSelect01c.sqf", _i, 10, false, false, ""];
    addedActions = addedActions + [_index];

};

/* ----------------Manual version
You must define how many floors you have.  Notice the third parameter is the floor number, also.

elevAddAct1 = player addAction ["First floor", "JTDFloorSelect.sqf",1,10,false,false,""];
elevAddAct2 = player addAction ["Second floor", "JTDFloorSelect.sqf",2,10,false,false,""];
elevAddAct3 = player addAction ["Third floor", "JTDFloorSelect.sqf",3,10,false,false,""];
elevAddAct4 = player addAction ["Fourth floor", "JTDFloorSelect.sqf",4,10,false,false,""];
elevAddAct5 = player addAction ["Fifth floor", "JTDFloorSelect.sqf",5,10,false,false,""];
*/
exit;

Then the "transporter" script moves the z position (right now just of the player).

Code: (transporter.sqf) [Select]
// Elevator floor transporter
// by Trexian for JTD
// This is called by the addactions and actually transports the player.

_flrSel = _this select 3;  // the floor selected by the addaction

_Here = getpos player;

//this section gets the xyz of the player to keep xy constant

_Plx=_Here select 0;
_Ply=_Here select 1;
_Plz=_Here select 2;
_Newz = 0;    // sets the scope and beginning value of the new height
_flrSel = _flrSel -1;  // subtracts one from the floor selected so the math works

// Easiest way to do it, but have to change string to numeric
_Newz = _flrSel * 3.5;

//--------------- Manual way to set the height of the floors
/*
_Newz = switch (_flrSel) do  // sets the switch to define the new height based on which addaction
// new height = the value in the "case" that corresponds to the selected floor
{
case 1:
{
0.0014 // this is the z height for the first floor
};
case 2:
{
3  // this is the z height for the second floor
};
case 3:
{
6.75  // and so on
};
case 4:
{
10.5
};
case 5:
{
14.25
};
case 6:
{
14
};
};
*/

player setpos [_Plx,_Ply,_Newz];  // sets the player same xy, new z

hint "trigger door animation";
sleep 2;

hint "remove actions";    // removes the actions since the player is at selected floor
{ player removeAction _x } forEach addedActions;
addedActions = nil;
sleep .5;
//--------------- Manual version, you have to remove the actions
// for each elevAddAct#, you'll need a:
// player removeAction elevAddAct#;

exit;

I remove the addactions after arriving at the desired location for now.

Then, the on deactivation script to remove the addactions if the player gets out of the elevator/off the trigger:
Code: (elevDeactivate.sqf) [Select]

// Elevator remove action script
// by Trexian for JTD
// removes addactions when player moves off of trigger

hint "remove actions";
{ player removeAction _x } forEach addedActions;
addedActions = nil;
sleep 1;
hint "end";
exit;

/*
//--------------- Manual version, you have to remove the actions
for each elevAddAct#, you'll need a:
player removeAction elevAddAct#;
*/

exit;

Moving forward, there are still many things to do:
1) generate list of units "in" the elevator/on the trigger into an array, and change all of their z positions;
2) make/get a model with the right kind of elevator "shaft" (might just modify one of the BI models);
3) properly animate the doors;
4) have the script be able to trigger the correct door;
5) get it to work in MP also.

Yeah, I'm probably only about 10% done. :D

Any advice, warnings, insight will be greatly appreciated!

And thanks for all the help getting this n00b this far. :)

PS - Ok... I have no idea why it is putting the whole post in a code bracket. :doh:
PPS - Whew - worked out the whole code tag thing. :)
« Last Edit: 24 Jun 2008, 16:47:48 by Trexian »
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: WIP Scripted elevator system (JTD dev group)
« Reply #1 on: 24 Jun 2008, 19:12:42 »
Nice idea. Those stairs have been giving me sore feet!

I think you'd be better off not using a case statement for checking the height, since the values are not always that exact. You should really ask for an array parameter of heights, rather than expecting people to edit your code. e.g. [0, 5, 10, 15], which you can pass via the actions:
Code: [Select]
_floorHeights = _this select 0;
_numFloors = count floorHeights;

addedActions = [];

// Loop from 1 to _numFloors - used as index for addedActions array and floor selection display.
for "_i" from 1 to _numFloors do
{
    _index = player addAction [format["Floor %1", _i], "JTDFloorSelect01c.sqf", [_i, _floorHeights select _i], 10, false, false, ""];
    addedActions = addedActions + [_index];
};

Then in the transporter:
Code: [Select]
_parameters = _this select 3
_flrSel = parameters select 0;  // the floor selected by the addaction
_floorHeight = parameters select 1;

You could only offer actions for the floors you are not on, rather than all of them.

exit doesn't do anything in SQF scripts. Use "if (true) exitWith {};" if you really feel you need to exit (though no script NEEDS to be exited from at the end. They only need it if you want to exit in the middle).

Everyone knows that floors run Ground, 1st, 2nd, 3rd, etc. (at least we do, here in the UK ;P).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: WIP Scripted elevator system (JTD dev group)
« Reply #2 on: 24 Jun 2008, 19:32:02 »
LOL on the floor "numbering" issue. ;)  I'd forgotten about that.  Truly, the RL array for you guys starts at zero. :D

The "case" was an option for the mission designer.  In some rough testing, I found the *3.5 to be pretty good at setting the right height.

Also, I didn't realize (well, it didn't even occur to me) that you could pass an array in that third parameter.  Let me make sure I understand the use of _floorHeights.  The trigger code would be something like [15, 5, 5, 5, 8] execVM "JTDElevator.sqf" - so the first/ground floor would be 15 (like a tall lobby) then the next three floors would be 5, then to get to the roof would be an additional 8.  So, in the transport script, the _Newz = _floorHeight, or really just use that parameter in the new setpos.  That would clean up a bunch of code and make the "manual" way obsolete.  :good:

My "gut reaction" concern is that if someone comes along with a 20 story building, that would be alot of floors to input with all likely the same height. :)

Realistically, though, I don't know if there are any buildings more than 5 -7 stories in ArmA?  (Building Zoning on Sahrani must be VERY strict....)

Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: WIP Scripted elevator system (JTD dev group)
« Reply #3 on: 24 Jun 2008, 20:51:00 »
It is best to do it with the actual height, not the relative height, since then you don't need to pass through the whole array. Thus, rather than [15, 5, 5, 5, 8], you would do [15, 20, 25, 30, 38] (though remember you have a ground floor near 0m off the ground). You also would do:
Code: [Select]
[[15, 20, 25, 30, 38]] execVM "elevator.sqf";
Since you want to pass the array as a single parameter, not as the whole list of parameters.

You could move a game-logic to each buildingPos of the building and collect all the heights from getPosing it. From that you could make a list of the possible floor heights. Not sure whether that would work, but
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: WIP Scripted elevator system (JTD dev group)
« Reply #4 on: 24 Jun 2008, 21:17:46 »
That's a good point.  I've seen some proof of concepts where modelers are making "buildings" that basically have step-ups to look like terrain, so they can build in tunnels, basements, etc.  So, the best case would be for the initialization array to be something like [[0, 5, 12, 19, 30]] that way each element of the select 0 would be the actual height for the z coordinate.

Thinking ahead, I'll need a list <triggername> to create an array of units in the trigger, then a foreach unit in the trigger, getpos the unit, then set newz at selected floorheight.  I don't think I can use thislist, though, because it'll be in a script that wasn't directly called by the trigger?
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: WIP Scripted elevator system (JTD dev group)
« Reply #5 on: 24 Jun 2008, 22:20:00 »
Yes, you'd need to use list myTrigger, rather than thisList.

Remember that if you want to make the script MP compatible (rather than just carrying the local player and any of his AI followers), you'll need to run the setPosing on every machine.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: WIP Scripted elevator system (JTD dev group)
« Reply #6 on: 24 Jun 2008, 22:29:04 »
Thanks. :)  I'm sure we'll be coming back to that. :D

Once I get it to do the whole group on the elevator, I'm going to look at the model/animation side, then come back to MP.

(Unless someone suggests otherwise.  What can I say?  I'm easily influenced by others.)   :blink:

Edit:
In considering this more, is there some way to pass the name of the trigger to the second script?  Like:
_trigName = name this

Then, if _trigname is <null> or I guess "" then name it to something like elevTrigger.  (Just looked in ComRef and did a quick search and don't see any ability to do this.)

Ok.  Barring that, the mission editor has to name the trigger something.  Shouldn't there be a way to get the trigger name and pass it to the second script?

Orrrr... use the thislist to create an array, and pass that to the second script?

I'm just trying to figure out a way that the mission editor isn't forced to:
1) use a specific name;
2) edit the script.

I'm sure you understand. :)

Edit2:
Success.  Took FAR longer than it should have.  The dreaded double-underscore!  Kept getting that scalar error and couldn't figure out why the variable wasn't matching up!  Also, I was having trouble parsing the array passed as element 3 of the addaction.  Then I realized that I didn't really need to know the floor selected, since we're passing the heights from the command line.  So, that simplified things.  Me and an AI buddy went from floor 1 to floor 5 almost instantaneously.

Next step, and will likely take awhile, is to create the necessary model and figure out the animations.
 :good:
« Last Edit: 25 Jun 2008, 07:10:25 by Trexian »
Sic semper tyrannosauro.

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: WIP Scripted elevator system (JTD dev group)
« Reply #7 on: 25 Jun 2008, 23:10:54 »
 hmm , i like the idea its very nice , but have you not tried The mlod from bis and just add the correct rtms to the model ?
 I opened it up sometime ago and it seemed to have everything it needs, i guess they too didnt like the jerky anims when traveling in an upwards motion using rtms :(.

 keep up the  good work.
 JTD dev team sounds  very professional, whats this a new group ? who is involved ?whats your Goals ?
I love ofp

Offline Trexian

  • Members
  • *
Re: WIP Scripted elevator system (JTD dev group)
« Reply #8 on: 25 Jun 2008, 23:36:44 »
Thanks for the kind words. :)  This morning, just scant hours after my last edit, I woke up and found my main PC has a boot failure.  :doh:  A few tries later, it is now running, so I'm in the process of backing up EVERYTHING.  :clap:

Yeah, my thought was to open up the BIS model of the hotel and see what the elevator "shafts" look like.  I found that the upper interior rooms are fully skinned, even if it is impossible to open the door from the outside. :)  So, I'm hopeful the elevators have textures.  If so, it is just a matter of rtm-ing (which is new to me) the doors appropriately. :)

JTD is me and a couple other guys who've been around various game/modding communities for awhile and have decided to work more or less together.  Our skills complement each other well.  More or less, it is just for fun for now.  :)  We're basically starting small, and working up to the big things.  Our "goals" such as they are, would include things like realism, emergent behavior, and fun. :)  (Those are subject to change without warning, of course.) ;)

I'm probably the weakest link of the lot of us, so I pulled the short straw and got "scripting." ;)
Sic semper tyrannosauro.

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: WIP Scripted elevator system (JTD dev group)
« Reply #9 on: 25 Jun 2008, 23:51:42 »
Sounds like you got a good crew for fun in arma then , good luck ,i look forward to see your work here .

 a few things i would say is and i apologise if you already know.

 There is massive problem that roadway lod (it is what we walk on in arma) , even if it is on a roof ,will return a height of
 zero so it is always hard to mess with these kind of scripts , especially where a dedicated serve is inolved. there are 1000 work arounds , but i wont confuse you  even getposasl etc i have seen never been consistent to this day. (i think its problem why ai and bridges evovlved).

 my advice is to get hotel mlod take from it just the ,elevator section and give it a roadway lod and look up  , this way
 you can see if you can get nice values of already hardcoded source animation in the direction you require , ignore my rtm comment , its because i am using them alot at the moment, although if it was possible to activate an RTM with a user action it would be a nice smooth way to do it. i do have an idea for how this could be obtained . but its a messy one .
I love ofp

Offline Trexian

  • Members
  • *
Re: WIP Scripted elevator system (JTD dev group)
« Reply #10 on: 26 Jun 2008, 00:01:27 »
Hmmm... I hadn't even considered that you might not be able to call an animation from a script....

I'm not above creating separate models for the doors and setposing them, I guess.

My mantra for the foreseeable future, though, is "one step at a time." :D

I cannot overstate how much help the tutorials/resources/forum searches here have been.  I haven't posted much because, frankly, I've been able to find most of my answers without posting. :)

I've done some modeling - in Blender orignally, but more recently in O2 - so I'm familiar with the "parts" of ArmA lods.  Putting that into action is a whole different kettle of fish, though. ;)

Thanks for the tip on the roadway lod.  I didn't know that.   :good:

Edit:
Ok, I thought I knew what I was doing.  I want to (continue to) use this model for the testing:
http://www.ofpec.com/COMREF/cfg_images/ArmA/Land_Hotel.jpg
I used Eliteness to de-pbo the buildings.pbo, and it looks like it works.  There's even the hotel.p3d.

But, when I open it with O2PE, I get an error that it is still a binarized p3d.  Any way to fix that?

Edit2:
Ahhh!  Thanks Planck!  Got it sorted.  Had forgotten about those downloads. :D
« Last Edit: 26 Jun 2008, 16:12:50 by Trexian »
Sic semper tyrannosauro.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: WIP Scripted elevator system (JTD dev group)
« Reply #11 on: 26 Jun 2008, 14:52:13 »
DePBOing any of the games PBOs will only net you ODOL models which you cannot load into O2.

You need MLOD versions and as luck would have it BI has provided MLOD models for almost all game models.

Try Here

and here

and also here.
http://

Planck
I know a little about a lot, and a lot about a little.

Offline Trexian

  • Members
  • *
Re: WIP Scripted elevator system (JTD dev group)
« Reply #12 on: 27 Jun 2008, 15:31:06 »
Opened up the mlod (one last ArmA shot before I replace the hard drive).  The elevator "floors" are labeled (in Czech, I think) but it is basically a true elevator shaft - no "floors" at each floor.  It looks like they intended to actually have the elevators rise to each floor.  If it is like I saw in a vid someplace, I do suspect that the interiors are skinned, though.

So, if the floor of the elevator is a named selection, can I move it with a setpos?  If not, I'll just copy the polys and put them in the right place.  Actually, that's probably the best way.

Also, the doors do not appear to have any animations applied.  In looking at animation stuff, the type would be "translation" which says that it moves in one plane.  But then, there are different types to lock in each plane.  If I know I want the doors to slide in one plane, any tips on using just the generic "translation" or if I should use one of the "locked" versions?

TIA,
T
Sic semper tyrannosauro.

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: WIP Scripted elevator system (JTD dev group)
« Reply #13 on: 27 Jun 2008, 15:45:38 »
I am really busy in rl now but i can give you some pointers.

 when you open the mlod hotel.p3d , open a new file at the same time (blank oxygen file). in each lod copy the selection Vyath2. then paste in the appropiatley named resolution ,shadow , view  and roadway lod in your new file. do the same for any memmory points relating to it (you will have to study what memmory points are allocated to lift buttons doors etc by studying the buildings config , the will be commented out i believe mostly.)

 with the geometry and fire geometry you cannot copy and paste because you will only get the vertices points , someone else may explain why this is , but i remember i deleted everything but the vytah2 selection in feo and firegeo and selected all then pasted to my new file .

 when you do this i would suggest you look in Bis forums under the configs thread for a section on translations by GNAT , where he describes and provides a config for his elevator on a ship.

 use this as a base for your lift and then work out all the  maths of how each user action will animate the lift to each floor precisely.

 sorry if i have omited or explained badly but like i say i have not much time.

 good luck ,wish i had more time to help.
 all i can say is i have done it using rtms but not user sourced translation anims , they can be very jerky and i think thats why bis abandoned it to be honest. rtms are smooth but for now we have no way to access them via a menu other than to setdammage an object under building class and have it play the resulting RTM.

 good luck

DB


I love ofp

Offline Trexian

  • Members
  • *
Re: WIP Scripted elevator system (JTD dev group)
« Reply #14 on: 27 Jun 2008, 15:55:15 »
That's awesome!

Will likely have more questions, but will start with that.   :good:

The memory points aren't as important (I think) because I'll be adding actions by script, rather than the model?  :)  A less elegant solution, to be sure, but it might actually work. ;)
Sic semper tyrannosauro.