Need help scripting rotating a wheel

Post » Sat May 28, 2011 7:51 am

http://planetelderscrolls.gamespy.com/View.php?view=Mods.Detail&id=8908.

In game, it just sits there, not moving at all. In NifSkope, it runs through all the different idle group speeds.

The idles go in order, to 7.
IDLE -> Dead stop - loops on itself.
IDLE2 -> Starts from a dead stop to a slow speed (speeds up and holds)
IDLE3 -> Transitions from a slow to a medium speed (speeds up and holds)
IDLE4 -> Transitions from a medium speed to a high speed (speeds up and holds)
IDLE5 -> Transitions from a high speed to a medium speed (slows down and holds)
IDLE6 -> Transitions from a medium speed to a slow speed (slows down and holds)
IDLE7 -> Transitions from a slow speed to a full stop (slows down and holds)

It needs to be treated like a series of loops in order to get the right acceleration/deceleration affect. That is, IDLE2 -> IDLE7/IDLE3, IDLE3 -> IDLE6/IDLE4, etc...

http://img530.imageshack.us/img530/1825/wheelscript.jpg is what it looks like in-game. There are 3 levers circled in red. Each one with a unique ID, crank1, crank2, crank3. I want each one to turn one rotation 90 degrees when you click on it, and then back 90 degrees when you click on it again. And when that happens, the wheel will go from stop to slow.

So it'd be like:

Turn crank 1 - wheel goes from stop to slow
Turn crank 2 - wheel goes from slow to medium
Turn crank 3 - wheel goes from medium to fast.

But I also want to have it so that you can't click on Crank 1 after clicking Crank 3, which would cause it to go from fast to sudden stop. So there would have to be some type of command to prevent the Player from activating the 2 previous levers. As in, you have to go crank 1 - 2 - 3 - 2 - 1.

So first I need scripts to rotate the cranks 90 degrees. Do I need to use their coordinates in that?
Then I need to figure out how to run the idle playgroups for the grinding wheel, which I have no clue how to do.




And as extra grinding wheels, how do I get one to just run continuously on one speed? If Idle 4 is fast, how to I keep the wheel on idle 4 loop?
Thanks to whoever can help me with this.
User avatar
Dona BlackHeart
 
Posts: 3405
Joined: Fri Dec 22, 2006 4:05 pm

Post » Sat May 28, 2011 8:51 am

http://img530.imageshack.us/img530/1825/wheelscript.jpg is what it looks like in-game.

That is one bulky apparatus. Too bad a simple spinning wheel foot pedal design was not employed with a single lever that could be moved between four different positions. *sigh* This will require scripts on each of the lever activators and a global variable to coordinate their movements. Before we attempt to script this functionality are you certain that those cranks are separate animated activators that can be scripted to turn? If that part of the grinding wheel design is a static, our work here is done... well, you could still overlay separate activators that could be scripted to change the rate of rotation of the wheel, but the crank animation is out.

Edit: clarification
User avatar
Prohibited
 
Posts: 3293
Joined: Tue Jun 12, 2007 6:13 am

Post » Sat May 28, 2011 3:26 am

haha, they're supposed represent being steam operated, so you need that big tank of water and pistons and levers to make it work, lore-wise.
Yes, they're all activators. The crank IDs are "PE_dwrv_crank01" through "PE_dwrv_crank18" and they're all at 90 degree angels so they'll rotate easily given the proper coordinates, i.e. rotate x-axis 90 degrees.

The wheel activator is "PE_stonewheel_anim2a" and the bulky dwemer activator machine is "PE_furn_dwrv_steam_00"
User avatar
He got the
 
Posts: 3399
Joined: Sat Nov 17, 2007 12:19 pm

Post » Fri May 27, 2011 9:20 pm

Oops. I had never seen the original. I did not realize this was your invention. I apologize for my comment, but it did strike me as a bit 'Rube Goldberg'. :blush2:

I hope that was a typo. Surely you do not have 18 cranks. I will continue on the assumption that there are only three (PE_dwrv_crank01, PE_dwrv_crank02 and PE_dwrv_crank03).

The following script is attached to the grinding wheel part of your device (the part that is animated to spin). For the purpose of this example I am using ID PE_stonewheel_anim2a for the grinding wheel as you specified. The global variable PE_dwrv_global (call it what you will) is updated by the script attached to each of the cranks.

Begin PE_dwrv_StoneWheelScript; Attached to PE_stonewheel_anim2a; short PE_dwrv_global ; global variableif ( PE_dwrv_global == 0 ) ; at rest    if ( PE_dwrv_global == 1 ) ; accelerate to low speed        set PE_dwrv_global to 10 ; at low        PlayGroup Idle2    endifelseif ( PE_dwrv_global == 10 ) ; spinning at low speed    if ( PE_dwrv_global == 2 ) ; accelerate to medium speed        set PE_dwrv_global to 20 ; at medium        PlayGroup Idle3    elseif ( PE_dwrv_global == -1 ) ; decelerate to rest        set PE_dwrv_global to 0 ; at rest        PlayGroup Idle7    endifelseif ( PE_dwrv_global == 20 ) ; spinning at medium speed    if (PE_dwrv_global == 3 ) ; accelerate to high speed        set PE_dwrv_global to 30 ; at high        PlayGroup Idle4    elseif ( PE_dwrv_global == -2 ) ; decelerate to low speed        set PE_dwrv_global to 10 ; at low        PlayGroup Idle6    endifelseif ( PE_dwrv_global == 30 ) ; spinning at high speed    if ( PE_dwrv_global == -3 ) ; decelerate to medium speed        set PE_dwrv_global to 20 ; at medium        PlayGroup Idle5    endifendifEnd PE_dwrv_StoneWheelScript

Here is the first crank's script:

Begin PE_dwrv_Crank01Script; Attached to PE_dwrv_crank01; short PE_dwrv_global ; global variableshort statefloat timerif ( OnActivate == 1 )    if ( state == 1 )        return ; do not activate while crank is turning    elseif ( state == 4 )        return ; do not activate while crank is turning    elseif ( PE_dwrv_global == 0 ) ; grinding wheel at rest        set state to 1    elseif ( PE_dwrv_global == 10 ) ; grinding wheel at low speed        set state to 4    else        return ; do not activate if conditions are not appropriate    endifendifif ( state == 1 ) ; valve opening    set timer to ( timer + GetSecondsPassed )    RotateWorld x 90    if ( timer < 1 )        return    endif    set timer to 0    set state to 2elseif ( state == 2 ) ; value opened    set state to 3    set PE_dwrv_global to 1 ; signals wheel to accelerate to lowendifif ( state == 4 ) ; valve closing    set timer to ( timer + GetSecondsPassed )    RotateWorld x -90    if ( timer < 1 )        return    endif    set timer to 0    set state to 5elseif ( state == 5 ) ; value closed    set state to 6    set PE_dwrv_global to -1 ; signals wheel to decelerate to restendifEnd PE_dwrv_Crank01Script

Here is the second crank's script:

Begin PE_dwrv_Crank02Script; Attached to PE_dwrv_crank02; short PE_dwrv_global ; global variableshort statefloat timerif ( OnActivate == 1 )    if ( state == 1 )        return ; do not activate while crank is turning    elseif ( state == 4 )        return ; do not activate while crank is turning    elseif ( PE_dwrv_global == 10 ) ; grinding wheel at low speed        set state to 1    elseif ( PE_dwrv_global == 20 ) ; grinding wheel at medium speed        set state to 4    else        return ; do not activate if conditions are not appropriate    endifendifif ( state == 1 ) ; valve opening    set timer to ( timer + GetSecondsPassed )    RotateWorld x 90    if ( timer < 1 )        return    endif    set timer to 0    set state to 2elseif ( state == 2 ) ; value opened    set state to 3    set PE_dwrv_global to 2 ; signals wheel to accelerate to mediumendifif ( state == 4 ) ; valve closing    set timer to ( timer + GetSecondsPassed )    RotateWorld x -90    if ( timer < 1 )        return    endif    set timer to 0    set state to 5elseif ( state == 5 ) ; value closed    set state to 6    set PE_dwrv_global to -2 ; signals wheel to decelerate to lowendifEnd PE_dwrv_Crank01Script

Here is the third crank's script:

Begin PE_dwrv_Crank03Script; Attached to PE_dwrv_crank03; short PE_dwrv_global ; global variableshort statefloat timerif ( OnActivate == 1 )    if ( state == 1 )        return ; do not activate while crank is turning    elseif ( state == 4 )        return ; do not activate while crank is turning    elseif ( PE_dwrv_global == 20 ) ; grinding wheel at medium speed        set state to 1    elseif ( PE_dwrv_global == 30 ) ; grinding wheel at high speed        set state to 4    else        return ; do not activate if conditions are not appropriate    endifendifif ( state == 1 ) ; valve opening    set timer to ( timer + GetSecondsPassed )    RotateWorld x 90    if ( timer < 1 )        return    endif    set timer to 0    set state to 2elseif ( state == 2 ) ; value opened    set state to 3    set PE_dwrv_global to 3 ; signals wheel to accelerate to highendifif ( state == 4 ) ; valve closing    set timer to ( timer + GetSecondsPassed )    RotateWorld x -90    if ( timer < 1 )        return    endif    set timer to 0    set state to 5elseif ( state == 5 ) ; value closed    set state to 6    set PE_dwrv_global to -3 ; signals wheel to decelerate to mediumendifEnd PE_dwrv_Crank01Script

These scripts have not been tested. All things considered there could be a number of problems. I chose an arbitrary duration for the cranks to fully open (one second). If you change the duration the rate of rotation must be changed following an inverse proportion (halve the duration to 0.5 seconds, double the rate of rotation to 180 units per second). There could be drift in the rotational position of the cranks after repeated use. I could slip in a SetAtStart, but I doubt the player will notice at all. I have not accounted for the duration of the wheel's animation groups (partially because I do not know them). I have limited the conditions that the player can activate the cranks, however it is possible that the player could click on cranks in rapid succession and see some abrupt changes in the wheel's rotation. Mitigating this potential problem may not be worth the trouble.

I was looking for an appropriate sound to play while the cranks are turning. The nearest thing I could find was PlaySound "Door Stone Open", but I have not included it. This is up to you.

I hope I have not overlooked something.
User avatar
Mashystar
 
Posts: 3460
Joined: Mon Jul 16, 2007 6:35 am

Post » Sat May 28, 2011 4:37 am

Whoa, thanks for writing all that out for me. Unfortunately, the only thing that worked was PE_dwrv_crank01 turning 90 degrees. Nothing else functioned. The wheel didn't spin and I wasn't able to turn the other two cranks nor can I click on the 1st one to have it rotate back.

I created a short global PE_dwrv_global with a value of 0. Was I supposed to make a global variable?
What else could be preventing the wheel from spinning?
User avatar
Esther Fernandez
 
Posts: 3415
Joined: Wed Sep 27, 2006 11:52 am

Post » Fri May 27, 2011 9:40 pm

You did everything as I instructed - apparently I did overlook something. I changed approaches part way through the wheel script and introduced a logical contradiction in the script. This is the script that should be placed on PE_stonewheel_anim2a:

Begin PE_dwrv_StoneWheelScript; Attached to PE_stonewheel_anim2a; short PE_dwrv_global ; global variableif ( PE_dwrv_global == 1 ) ; accelerate to low speed    set PE_dwrv_global to 10 ; at low    PlayGroup Idle2endifif ( PE_dwrv_global == 2 ) ; accelerate to medium speed    set PE_dwrv_global to 20 ; at medium    PlayGroup Idle3elseif ( PE_dwrv_global == -1 ) ; decelerate to rest    set PE_dwrv_global to 0 ; at rest    PlayGroup Idle7endifif ( PE_dwrv_global == 3 ) ; accelerate to high speed    set PE_dwrv_global to 30 ; at high    PlayGroup Idle4elseif ( PE_dwrv_global == -2 ) ; decelerate to low speed    set PE_dwrv_global to 10 ; at low    PlayGroup Idle6endifif ( PE_dwrv_global == -3 ) ; decelerate to medium speed    set PE_dwrv_global to 20 ; at medium    PlayGroup Idle5endifEnd PE_dwrv_StoneWheelScript


Edit: small, perhaps meaningless adjustment
User avatar
Kat Lehmann
 
Posts: 3409
Joined: Tue Jun 27, 2006 6:24 am

Post » Sat May 28, 2011 7:14 am

Now all the cranks turn correctly, which is good. But the wheel still remains still. Did you get a chance to download the mod from PES and take a look at it in NifSkope? I don't know if that would be necessary, though.
But the cranks work properly. Crank 3 won't turn unless crank 2 is turned, which won't turn unless crank 1 is turned first. Very good job, Cyran0. Thanks a bunch with what you've done so far. I was also going through the ReadMe and your name is credited also for the PE_AscadianAnvil_Entry script; the one that gives different text messages when you enter the interior cell. :)

We've almost got this completed. The wheel won't turn but the cranks turn just fine. Any other idea of why it's not spinning? The ID of the activator isn't important as you don't include it anywhere in the actual script. I mean you put it in the beginning but it's after the semicolon so it doesn't matter any ways. So really, I could attach this script to different ID wheels so long as they use the same mesh model.




In addition to solving this problem, how would you write a script to just have this wheel spinning continuously at Idle 4 so that it's constantly spinning fast?
User avatar
Madeleine Rose Walsh
 
Posts: 3425
Joined: Wed Oct 04, 2006 2:07 am

Post » Sat May 28, 2011 5:42 am

I am not certain why it does not work for you - I have tested the scripts successfully since my last scripting error. I do think there is a problem with the animation group for Idle7, but other than that it is fine. You are correct, the ID of the grinding wheel is irrelevant. I include it as a comment in my script because it can make debugging a mod after release a little easier when I annotate the script. Are you certain that the name of the global variable is the same in all four scripts (and is actually the name of the variable)? I have also tested by assigning values to PE_dwrv_global through the console (set PE_dwrv_global to 1) and it begins spinning quite nicely. I can send you my test plugin if you think it would help you, but they are the same scripts that I have posted (except for the naming prefix cyr_ …force of habit :shrug: ).

As for having the wheel continuously spin on high speed I think the other version of the stone wheel by Morovir was designed to do just that. However if this is intended as a different option for this same wheel you can use the following code:

if ( CellChanged == 1 ) ; when player enters cell    PlayGroup Idle4endif

The wheel shows a brief period of acceleration, but the player will not likely notice. It might be appropriate to play Morovir's sound of the squeaky axle as well.


Edit: Second thought.

It cannot be a discrepancy between the name of the global variable or it would not be updated by the wheel script to control the behavior of the crank scripts. It seems silly to ask since you were the one who told me which stone wheel to use, but are you using the 'second' one (stonewheel.anim2.nif)? If you are using the wheel that has only one animation (Idle) then that would explain why it does not respond to the PlayGroup calls.
User avatar
BRIANNA
 
Posts: 3438
Joined: Thu Jan 11, 2007 7:51 pm

Post » Sat May 28, 2011 7:07 am

It's weird though, because sometimes, when I enter the cell, the wheel will be already spinning. And it'll keep going for about 5 seconds and slowly come to a halt. Then if I keep reloading the savegame to test it, it won't do it again. It'll usually do this when I exit the game and then start it back up. FYI, I'm almost always testing this with new games, not saved games. I'll just save after I make a new game, though.

http://img51.imageshack.us/img51/6337/66510623.jpg

We'll do the sound axel noise last, since that's the least of my concern at the moment.

Well, I took Morovir's stonewheel_anim2.nif and removed the branch that had the wheel cranks on them. It should still spin. And that's why it's named stonewheel_anim2a.nif. Funny though, the anim2a is the one that will spin sporadically, not the original, which is very weird.

http://img689.imageshack.us/img689/811/35134850.jpg



EDIT: I decided to delete the custom chopped nif files that I made and just stick with the original ones that Morovir made. I deleted all their IDs from the construction set and just kept his original ones. And guess what, they freakin work!!! :D So lesson learned, don't remove branches in NifSkope if you're intending to use some type of animation. Statics are okay to remove branches from because they're just static. I removed many branches from all 5 dwemer activators for their nighttime off-periods.

Damn, well thanks a million Cyran0! I'm tremendously pleased with the work you've done with these scripts! It works so well too. When I pull a crank, it slowly spins faster, etc... and when going from medium to slow, and then slow to stop, it'll have a little jolt of fast speed in there for a second. But we can just say that it's the extra steam being forced through the ventilation shaft that the pistons are trying to thrust through. And the Idle 4 works pefectly fine as well.


Now onto getting this all to stop after 2000. The shop opens from 0800 to 2000. After that, the dwemer activators all cease (I used enable/disable to replace the ones with no steam or animation or sounds with the vanilla ones). And since the dwemer activators aren't active, that means there is no fire, water or steam being produced (lore-wise. Obviously this isn't real in the game). So there needs to be a Return command on crank01 so that you can't turn it from 2000 - 0800. This is just in case the play breaks in at night and wants to do that. This way, since crank01 won't be able to turn, neither will crank02 or crank03. And that'll solve that. So would you tweak PE_dwrv_crank01Script for me please?

And lastly, the sounds. I was listening to the squeaky_axle sounds and they sounds like they belong on a small rusted grinding wheel. And while the ones Morovir made do indeed look rusted, they look like they'd make a more low grunting rumble instead of a squeak. I was thinking maybe................... Door Stone Open? It has a grinding sound to it. Although, it's so freakin loud in the cell since I have 4 dwemer machines running, that you probably would not even hear the wheel going. So ya know what, let's just not worry about the sounds.
User avatar
Hilm Music
 
Posts: 3357
Joined: Wed Jun 06, 2007 9:36 pm

Post » Sat May 28, 2011 12:34 am

I am relieved that you discovered (and fixed) the problem. I can imagine your satisfaction. One of the joys of scripting is seeing the magic of it revealed in-game.

Here is a modified version of the script on the wheel that will prevent it from spinning during the night hour between 8 pm and 8 am:

Begin PE_dwrv_StoneWheelScript; Attached to PE_stonewheel_anim2a; short PE_dwrv_global ; global variableif ( Gamehour >= 20 )    SkipAnimelseif ( Gamehour < 8 )    SkipAnimendifif ( PE_dwrv_global == 1 ) ; accelerate to low speed    set PE_dwrv_global to 10 ; at low    PlayGroup Idle2endifif ( PE_dwrv_global == 2 ) ; accelerate to medium speed    set PE_dwrv_global to 20 ; at medium    PlayGroup Idle3elseif ( PE_dwrv_global == -1 ) ; decelerate to rest    set PE_dwrv_global to 0 ; at rest    PlayGroup Idle7endifif ( PE_dwrv_global == 3 ) ; accelerate to high speed    set PE_dwrv_global to 30 ; at high    PlayGroup Idle4elseif ( PE_dwrv_global == -2 ) ; decelerate to low speed    set PE_dwrv_global to 10 ; at low    PlayGroup Idle6endifif ( PE_dwrv_global == -3 ) ; decelerate to medium speed    set PE_dwrv_global to 20 ; at medium    PlayGroup Idle5endifEnd PE_dwrv_StoneWheelScript

In testing I set Gamehour through the console. The spinning wheel stopped instantly at night, but did not begin spinning during the day except after a cell change. That is probably suitable although I have very little experience with this sort of thing - I cannot say if it is normal.

A similar block of code could be used to prevent each of the cranks from being activated. It would be less cumbersome than disabling them. Something like this could be inserted at the top of each crank script (below the declarations):

if ( Gamehour >= 20 )    returnelseif ( Gamehour < 8 )    returnendif

User avatar
Gwen
 
Posts: 3367
Joined: Sun Apr 01, 2007 3:34 am

Post » Sat May 28, 2011 12:06 am

Thank you. That tiny block of code was all I wanted because I wanted the cranks to not be usable at night. If the engines are off and there is no steam coming through, then you're not going to be able to turn the cranks. Well I guess in real life you could but nothing would happen. But for the game, this will do just fine. Thanks again for all you've done!
User avatar
Sarah Kim
 
Posts: 3407
Joined: Tue Aug 29, 2006 2:24 pm


Return to III - Morrowind