Page 1 of 1

Script: Sit in Chair on Use

Posted: Mon Jun 24, 2002 4:49 pm
by Silk
This script will make PCs sit in a seat when used.

Make the chair useable and put this script in the OnUse event

Code: Select all

void main()
{
    object oPlayer = GetLastUsedBy();
    if (GetIsPC (oPlayer))
    {
        if (GetIsObjectValid( OBJECT_SELF) && !GetIsObjectValid( GetSittingCreature(OBJECT_SELF)))
        {
            AssignCommand(oPlayer, ActionSit(OBJECT_SELF));
        }
    }
}

Posted: Mon Jun 24, 2002 5:18 pm
by Orleron
Cool, hey, question, what does it mean when there's an exclamation point in front of the function like in:

!GetIsObjectValid(GetSittingCreature(OBJECT_SELF))

??

Posted: Mon Jun 24, 2002 7:33 pm
by Prophet
! usually means NOT, but don't hold me to that. Looks like it might be right though.

Posted: Mon Jun 24, 2002 7:56 pm
by Silk
yes, logical NOT

This is what the script means (I speak logic):

> object oPlayer = GetLastUsedBy();

Return the Player that used the chair.

> if (GetIsPC (oPlayer))

If the player is a PC then do the following

> if (GetIsObjectValid( OBJECT_SELF) && !GetIsObjectValid(GetSittingCreature(OBJECT_SELF)))

If the chair exists and there is nothing sitting in it, then do the following (nested if here)

> AssignCommand(oPlayer, ActionSit(OBJECT_SELF));

Make the player sit in the chair.

Posted: Mon Jun 24, 2002 8:36 pm
by Orleron
Why does your GetSittingCreature function call OBJECT_SELF. Aren't you supposed to be checking is other objects are sitting in it?

Posted: Mon Jun 24, 2002 8:41 pm
by Silk
Originally posted by Orleron
Why does your GetSittingCreature function call OBJECT_SELF. Aren't you supposed to be checking is other objects are sitting in it?
OBJECT_SELF is the used item (in this case the chair), GetSittingCreatures returns any creature that is sitting in the used item (the chair).

Posted: Tue Jun 25, 2002 4:15 am
by MacLeod
Orleron, and other newbie scripters/programmers:

To reiterate what Silk just said in non-code terms, the ! logical not operator simply reverses the result of the values it's attached to, so:

Not false is equal to true
!false == true //statement is true
Not true is equal to false
!true == false

also:
true is not equal to false
true != false // statement is true

false is not equal to true
false != true // statement is true



The logical operators are something extremely important to understand, as you're going to have a <I>lot</i> of decision making code.

Unless somehow writing optimized code becomes a high priority (which I doubt for this), write everything to be highly readable, you're probably going to be changing things a lot. For the same reason, use assloads of comments, describing what you're doing at every important decision.

Posted: Thu Sep 16, 2004 6:29 am
by myzmar
Ok, total n00b as regards scripting here. Should I use this script when I make a useable chair, or do we have something more fitting with all that happened in the last two years?

Posted: Thu Sep 16, 2004 7:42 am
by JollyOrc
myzmar wrote:Ok, total n00b as regards scripting here. Should I use this script when I make a useable chair, or do we have something more fitting with all that happened in the last two years?
indeed.

head over to the housing info thread. There you can download a nice package with a lot of scripts fit for player housing. there's one called sitdown, which does the desires effect :)

Posted: Thu Sep 16, 2004 7:44 am
by myzmar
JollyOrc wrote:head over to the housing info thread. There you can download a nice package with a lot of scripts fit for player housing. there's one called sitdown, which does the desires effect :)
thanks!

Posted: Thu Sep 16, 2004 8:10 am
by Wyrmwing
IIRC, there's a standard bioware script now that does the same.. somewhere in the x2_.. pile.

Posted: Thu Sep 16, 2004 9:19 am
by Sindol
Most CEP chairs already have a sitdown script attached. That is a CEP script and can be found in their hakpaks, but it does basically the same as the Avlis script. So if you need an example on how to set up a chair, just have a look at the existing chairs in the CEP repetoire.

Posted: Thu Sep 16, 2004 9:25 am
by KaiRal Windspar
What about for chairs that are not for bipeds?

Is there a script for 'sit on floor' that can be used for mats and cushion piles and such?