Help with this simple script

Post » Fri May 27, 2011 6:42 pm

I just want this script to activate all the time and not just once when I enter the door. What do I need to change? It's attached to an activator that is underneath a door in an armorer shop.
And how much distance is 1? I have getdistance < 100 but how far exactly is just 1 distance? Like the width of a wickwheat grain or something?

Begin PE_superiorblacksmith_entryshort statefloat timershort buttonif ( MenuMode == 1 )    returnendifif ( OnActivate >= 1 )    returnendifif ( state == 0 )    if ( GetDistance Player < 100 )        set state to 1        MessageBox "You smell the scent of leather and oil."    endifendifif ( state == 1 )    set button to GetButtonPressed    if ( button == 0 )    set state to -1    elseif ( button == 1 )    set state to -1    endifendifendifEnd PE_superiorblacksmith_entry

User avatar
Veronica Martinez
 
Posts: 3498
Joined: Tue Jun 20, 2006 9:43 am

Post » Fri May 27, 2011 6:28 pm

I am not certain that I understand your circumstances. If the only purpose of this script is to display a message each time the player enters the smith's shop I do not see why it is necessary for the player to activate the object (or even how since it is located under the door)... and why have you declared a timer? If it is a simple matter of displaying the message regularly, then I propose the following approach. I have a 1 second delay for the player to feel established in the cell before noticing the familiar aroma of the armorer's trade.

Begin PE_superiorblacksmith_entryshort statefloat timerif ( menumode == 1 )    returnendifif ( CellChanged == 1 )    set state to 1endifif ( state == 1 )    set timer to ( timer + GetSecondsPassed )    if ( timer < 1 )        return    endif    set timer to 0 ; reset for next time    set state to -1    messagebox "You smell the scent of leather and oil."endifEnd PE_superiorblacksmith_entry

This script has not been tested.
User avatar
Greg Swan
 
Posts: 3413
Joined: Tue Jun 05, 2007 12:49 am

Post » Fri May 27, 2011 11:25 pm

It works perfectly. Thanks! And I like how you give it a delay. When I go into a car shop, I don't smell automotive parts and grease the split nanosecond I walk in.
Although I'm not entirely happy with the message. I'm sure it could be better. If you were to enter a blacksmith shop, what would you expect to hear or smell? Like maybe: "You hear the peening of hammers and sharpening of broadswords. The smell of leather and oil fills the air." ????

Would there be a way to get it to say different messages at different times when you entered? Like for at night from 2000 through 0700 it could say "The air is silent and still. A cockroach scurries past your feet." And then have it return to the normal message from 0700 - 2000.
User avatar
Stefanny Cardona
 
Posts: 3352
Joined: Tue Dec 19, 2006 8:08 pm

Post » Sat May 28, 2011 12:41 am

I like the idea having the player experience a variety of impressions depending on the circumstance - yes it can be done. Here is the script with your late/early hour message and accommodations for three random messages, but it could be expanded further. I wonder if you need something for after the player murders the smith? "You are struck by an eerie quiet, and then the powerful stench of rotting flesh." ;)

Begin PE_superiorblacksmith_entryshort statefloat timerif ( menumode == 1 )    returnendifif ( CellChanged == 1 )    set state to 1endifif ( state == 1 )    set timer to ( timer + GetSecondsPassed )    if ( timer < 1 )        return    endif    set timer to 0 ; reset for next timer    set state to -1    if ( GameHour >= 20 )        messagebox "The air is silent and still... something scurries past your feet."    elseif ( GameHour < 7 )        messagebox "The air is silent and still... something scurries past your feet."    elseif ( Random100 < 33 )        messagebox "You hear the familiar sound of the peening of a hammer - a smith at his craft."    elseif ( Random100 < 67 )        messagebox "The air is thick with the pungent smell of leather and oil."    else        messagebox "You hear the long, smooth sound of a blade being honed."    endifendifEnd PE_superiorblacksmith_entry

As before this script has not been tested.
User avatar
Harry Hearing
 
Posts: 3366
Joined: Sun Jul 22, 2007 6:19 am

Post » Fri May 27, 2011 9:45 pm

That works perfectly.

I like those three. Although I'd like to give them a third of a probability of appearing. Does elseif ( Random100 < 33 ) mean that it has a 33% chance of appearing and something like elseif ( Random100 < 67 ) means it has a 67% chance of appearing? Or do I have it backwards?

Why do you have to put the "The air is silent and still" message twice for the two different times? I'm just curious as to why it wouldn't fit under a single command that would say if after this time but before this time.

Begin PE_superiorblacksmith_entryshort statefloat timerif ( menumode == 1 )    returnendifif ( CellChanged == 1 )    set state to 1endifif ( state == 1 )    set timer to ( timer + GetSecondsPassed )    if ( timer < 1 )        return    endif    set timer to 0 ; reset for next timer    set state to -1    if ( GameHour >= 20 )        messagebox "The air is silent and still... something scurries past your feet."    elseif ( GameHour < 7 )        messagebox "The air is silent and still... something scurries past your feet."    elseif ( Random100 < 33 )        messagebox "You hear the familiar sound of the peening of a hammer - a smith at his craft."    elseif ( Random100 < 34 )        messagebox "The air is thick with the pungent smell of leather and oil."    elseif ( Random100 < 33 )        messagebox "You hear the long, smooth sound of a blade being honed."    endifendifEnd PE_superiorblacksmith_entry

User avatar
sw1ss
 
Posts: 3461
Joined: Wed Nov 28, 2007 8:02 pm

Post » Fri May 27, 2011 10:26 pm

elseif construct general (language independent) rules:
The first (and only the first) elseif expression (if any) that evaluates to true would be executed.
The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to false, and the current elseif expression evaluated to true (there may be glitches as usual in Morrowind scripting (forcegreeting...), but that's another story)
    elseif ( Random100 < 33 )        messagebox "You hear the familiar sound of the peening of a hammer - a smith at his craft."    elseif ( Random100 < 34 )        messagebox "The air is thick with the pungent smell of leather and oil."    elseif ( Random100 < 33 ); this will never be executed, because there is a previous elseif evaluating true (same condition by the way, a nonsense with elseifs)        messagebox "You hear the long, smooth sound of a blade being honed."    endifendif


I like those three. Although I'd like to give them a third of a probability of appearing. Does elseif ( Random100 < 33 ) mean that it has a 33% chance of appearing and something like elseif ( Random100 < 67 ) means it has a 67% chance of appearing? Or do I have it backwards?

A simple rule: when using < in comparisons, use increasing order; when using >, use decreasing order.
example:
if ( Random100 < 33 )    MessageBox "< 33"elseif ( Random100 < 33 )    MessageBox "You will never see me"elseif ( Random100 < 66 )    MessageBox "< 66"else  ; in any other case, no extra condition needed    MessageBox ">= 66"endifif ( Random100 > 66 )    MessageBox "> 66"elseif ( Random100 > 70 )    MessageBox "You will never see me too"elseif ( Random100 > 33 )    MessageBox "> 33"else    MessageBox "<= 33"endif

User avatar
Darrell Fawcett
 
Posts: 3336
Joined: Tue May 22, 2007 12:16 am

Post » Sat May 28, 2011 2:13 am

I still don't understand it. But the scripts are working perfectly fine so all is good. Thank you!
User avatar
glot
 
Posts: 3297
Joined: Mon Jul 17, 2006 1:41 pm

Post » Sat May 28, 2011 12:13 am

I do not think I can explain it better than abot, but I think the source of your confusion is not the structure of the code but a proper understanding of Random100 and how it works. It is a global variable that is set every frame (that the menu is not open) to a value between 0 and 99 inclusive. The script does not set a range of percentages for the condition to be true (33% or 67%), but checks the value currently stored in Random100. When grouped as in my script the first check is for a value less than 33 (a one-third chance). If that fails it goes to the next check looking for a value less than 67. Since the first check failed Random100 cannot be between 0 and 32, so this check is only true when Random100 is between 33 and 66 (another one-third chance). If that fails Random100 must be a value between 67 and 99 (true one-third of the time). The else conditional picks up those. So each of the non-nighttime messages does have an equal chance of occurring.

The reason I checked for Gamehour >= 20 and had a separate check for Gamehour < 7 is because there is no solution for the condition of Gamehour both greater than 20 and less than 7. Since our human concept of time and readily see that those number (hours) bracket the nighttime it is an easy mistake to make. Together those two checks cover the nighttime hours and so they should display the same message.

Anyway, I am glad it is working for you.
User avatar
Emma Copeland
 
Posts: 3383
Joined: Sat Jul 01, 2006 12:37 am


Return to III - Morrowind