Skip to content

Changing a placeables state

HaddoxHaddox Member Posts: 9
edited November 2023 in Builders - Scripting
Hello, I'm trying to figure out how to have a placeable (a door) change it's state from closed to opened when clicked and I just can't get it to work.

It's possible to change initial states between closed/opened/destroyed so I'm assuming that it's possible somehow. :S
Post edited by Haddox on

Comments

  • ProlericProleric Member Posts: 1,316
    Assuming the placeable or door is running the script,
    PlayAnimation(ANIMATION_PLACEABLE_OPEN);
    

    The full set of codes for placeables is at the end of this list.
  • HaddoxHaddox Member Posts: 9
    I knew I should've just asked here instead of spending time (way to much) trying to figure this out on my own..

    It worked perfectly! Thank you so much @Proleric

    I asked ChatGPT to throw together a check for a open/closed variable cause I'm a lazy boy

    Leaving it here for anyone that might need it
    void main()
    {
        object oPlaceable = OBJECT_SELF;  // Assuming the script is attached to the placeable itself.
        
        int nState = GetLocalInt(oPlaceable, "State");
        
        // Check the current state and toggle it
        if (nState == 0) // 0 represents closed state
        {
            PlayAnimation(ANIMATION_PLACEABLE_OPEN);
            nState = 1; // Set the state to opened
        }
        else if (nState == 1) // 1 represents opened state
        {
            PlayAnimation(ANIMATION_PLACEABLE_CLOSE);
            nState = 0; // Set the state to closed
        }
        
        // Update the state
        SetLocalInt(oPlaceable, "State", nState);
    }
    
  • TarotRedhandTarotRedhand Member Posts: 1,481
    edited November 2023
    Why use a variable when you can check via the function -

    int GetIsOpen(object oObject);
    

    returns TRUE on Open and False when closed. The parameter is the door/chest/whatever openable thing you are checking.

    FWIW, have you got the scripting FAQs (Frequently Asked Questions with answers)? If not see - Just The FAQs, ma'am. 100+ common questions answered + tutorials, etc.

    TR
  • HaddoxHaddox Member Posts: 9
    Why use a variable when you can check via the function -

    int GetIsOpen(object oObject);
    

    returns TRUE on Open and False when closed. The parameter is the door/chest/whatever openable thing you are checking.

    TR

    Oh!

    I see, yeah I guess that is way easier.

    I'm just learning by doing atm so it's what was closest in mind for me.

    I'll try that for sure :)
  • ProlericProleric Member Posts: 1,316
    I've seen reports that ChatGBT can be unreliable because it doesn't fully understand that NWscript is just a subset of C++ with its own rules. It has been suggested that training it would be unreasonably time-consuming.

    Then again, ChatGBT will have seen the same reports...
  • HaddoxHaddox Member Posts: 9
    edited November 2023
    Proleric wrote: »
    I've seen reports that ChatGBT can be unreliable because it doesn't fully understand that NWscript is just a subset of C++ with its own rules. It has been suggested that training it would be unreasonably time-consuming.

    Then again, ChatGBT will have seen the same reports...


    So far it's been doing what I've asked it to do with varying success. But yeah, it can perform and solve quite a few problems and seems to be aware of basic NWscript so far. However, it does have a tendency to make up its own functions when there's not any material for it to reference to.

    Have you tried it out yourself? I found it to be quite trainable, but it does need source material from the lexicon and manuals when you need it to sort out scripts on its own.

    I just use it for compiling as an alternative to LilacSoul's script generator or to my own already sketchy scripts..


  • ProlericProleric Member Posts: 1,316
    Haven't tried it myself. Other reports concur with yours, e.g. inventing functions.
  • HaddoxHaddox Member Posts: 9
    edited November 2023

    FWIW, have you got the scripting FAQs (Frequently Asked Questions with answers)? If not see - Just The FAQs, ma'am. 100+ common questions answered + tutorials, etc.

    TR

    Oh missed this as well, awesome resource. Thank you!

Sign In or Register to comment.