Script: Sit in Chair on Use

Moderator: Event DM

Post Reply
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Script: Sit in Chair on Use

Post by Silk » Mon Jun 24, 2002 4:49 pm

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));
        }
    }
}
Silk

Member of the MadK@t lover's group.
Orleron
World Advisor, Co-founder
World Advisor, Co-founder
Posts: 15149
Joined: Fri Sep 14, 2001 9:48 pm
Timezone: GMT-5
Contact:

Post by Orleron » Mon Jun 24, 2002 5:18 pm

Cool, hey, question, what does it mean when there's an exclamation point in front of the function like in:

!GetIsObjectValid(GetSittingCreature(OBJECT_SELF))

??
"Truth has no form."
--Idries Shah
Prophet
Apprentice Scholar
Posts: 579
Joined: Sat Oct 13, 2001 3:11 pm

Post by Prophet » Mon Jun 24, 2002 7:33 pm

! usually means NOT, but don't hold me to that. Looks like it might be right though.
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Mon Jun 24, 2002 7:56 pm

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.
Silk

Member of the MadK@t lover's group.
Orleron
World Advisor, Co-founder
World Advisor, Co-founder
Posts: 15149
Joined: Fri Sep 14, 2001 9:48 pm
Timezone: GMT-5
Contact:

Post by Orleron » Mon Jun 24, 2002 8:36 pm

Why does your GetSittingCreature function call OBJECT_SELF. Aren't you supposed to be checking is other objects are sitting in it?
"Truth has no form."
--Idries Shah
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Mon Jun 24, 2002 8:41 pm

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).
Silk

Member of the MadK@t lover's group.
MacLeod
Apprentice Scholar
Posts: 586
Joined: Fri Jan 11, 2002 11:29 pm
Contact:

Post by MacLeod » Tue Jun 25, 2002 4:15 am

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.
Duncan MacLeod,
Chessie Mage

"Alright now you sunsofbitches, you know how I feel"
~Jackyl, Open Invitation
myzmar
Apprentice Scholar
Posts: 998
Joined: Tue Feb 04, 2003 9:52 am
Location: Warsaw, Poland (GMT +1 or +2, depends :)

Post by myzmar » Thu Sep 16, 2004 6:29 am

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?
If I ever edit a post it most probably cause of the typos. I make a hell lot of them when I write.
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Thu Sep 16, 2004 7:42 am

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 :)
myzmar
Apprentice Scholar
Posts: 998
Joined: Tue Feb 04, 2003 9:52 am
Location: Warsaw, Poland (GMT +1 or +2, depends :)

Post by myzmar » Thu Sep 16, 2004 7:44 am

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!
If I ever edit a post it most probably cause of the typos. I make a hell lot of them when I write.
Wyrmwing
Team Member; Retired with Honors
Posts: 5827
Joined: Mon Aug 25, 2003 6:41 pm
Location: Croissant Country
Contact:

Post by Wyrmwing » Thu Sep 16, 2004 8:10 am

IIRC, there's a standard bioware script now that does the same.. somewhere in the x2_.. pile.
Sadako Sasaki wrote:I will write peace on your wings, and you will fly all over the world.
User avatar
Sindol
Team Member; Retired with Honors
Posts: 6479
Joined: Mon Jan 06, 2003 4:23 pm
Location: Nijmegen - Netherlands (GMT+1)
Contact:

Post by Sindol » Thu Sep 16, 2004 9:19 am

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.
So much fun,
yet so little time to enjoy it.
- Sindol
User avatar
KaiRal Windspar
Elder Sage
Posts: 3635
Joined: Fri Jun 11, 2004 5:36 am
Location: Seattle
Contact:

Post by KaiRal Windspar » Thu Sep 16, 2004 9:25 am

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?
Post Reply