Server Totals
Le'Or - (2)
Mikona - (2)
Visimontium - (1)
Ferrell - (0)
Elysia - (0)
M'Chek - (0)
Deglos - (0)
Wilderness - (0)
Underdark - (0)
Total players: 5
Gallery

Links Menu

newbie scripter: Door switch

Moderators: Nighthawk4, Dungeon Masters

newbie scripter: Door switch

PostAuthor: JollyOrc » Sat May 03, 2003 11:45 am

Hi

I want to have a lever that operates two doors.

if switched it locks the one door, and unlocks the other, and giving a message which one is locked now.

If switched again, it unlocks the first, and locks the other, again giving a message.

I've puzzled out how to do if, but how to query the states of objects is beyond me, I've just started looking at the scripting thing.

so I want to do:

if (door1.locked)
door2.lock
door1.unlock
tell "Door 1 open now"
else
door1.lock
door2.unlock
tell "door 2 open now"
fi

how to do that in NWNScripting ?

Have I seen that right that there isn't an "else" in NWNScripting ?
User avatar
JollyOrc
QA Resource
 
Posts: 3900
Joined: Fri Jan 17, 2003 11:41 am
Location: Germany
Timezone: GMT+1

PostAuthor: Lafferty » Sat May 03, 2003 2:41 pm

there is an else ... e.g.

int bAlpha = FALSE;
int bBravo = FALSE;
if (bAlpha)
{
// statement 1 ...
}
else if (bBravo)
{
// statement 2 ...
}
else
{
// statement 3 ...
// in this example, this is the code that is executed becase
// both bAlpha and bBravo are FALSE
}


there also is a switch statement which is not used often... i dont know why as it can make scripts quite readable:


The following examples have the same effect:
int x = 0;
// if block - silly!
if (x == 0)
{
// statements ...
}
else if (x == 1)
{
// statements ...
}
else if (x == 2)
{
// statements ...
}
else
{
// statements ...
}

// switch block
// the above if/else block is functionally equivalent to the below
// switch statement
switch (x)
{
case 0:
// statements ...
// without a break testing would continue
// in this example if we didn't use a break, the default
// condition would also evaluate as true if x == 0
break;
case 1:
// statements ...
break;
case 2:
// statements ...
break;
default:
// statements ...
break;
}


You might want to have a look here: http://www.reapers.org/nwn/reference/

it is also available as CHM file : http://nwvault.ign.com/Files/other/data ... 1708.shtml
Tool for crafters Do you want some human to your salt? nomanisanisland.monolar.de
User avatar
Lafferty
Scholar
 
Posts: 1130
Joined: Tue Feb 11, 2003 5:08 pm
Location: look at my hands... they are HUGE. And they cant touch themselves...

PostAuthor: Lafferty » Sat May 03, 2003 3:04 pm

FUCK:!! I just lost my session! i had it ready! damn it... sorry.... i know this is for the rants and raves!
Tool for crafters Do you want some human to your salt? nomanisanisland.monolar.de
User avatar
Lafferty
Scholar
 
Posts: 1130
Joined: Tue Feb 11, 2003 5:08 pm
Location: look at my hands... they are HUGE. And they cant touch themselves...

PostAuthor: Lafferty » Sat May 03, 2003 3:27 pm

ok, but this one is tested:

Maybe there is a simpler way to do it.

You need the two doors (with tags: "MyDoor_1" and "MyDoor_2") and a lever. Put this script in the OnUsed part of the placeable lever.

Set the initial state of one door to locked and can be relocked and plot would also make sense.
The other door should also be plot and check the can be relocked property

I think that way the door could still be lockpicked, haven't tested it

void main()
{
object oDoor1 = GetObjectByTag("MyDoor_1");
object oDoor2 = GetObjectByTag("MyDoor_2");
object oPC = GetLastUsedBy();

ActionCloseDoor(oDoor1);
ActionCloseDoor(oDoor2);
if (GetLocked(oDoor1))
{
DelayCommand(1.5, SetLocked(oDoor1, FALSE));
DelayCommand(1.5, SetLocked(oDoor2, TRUE));
DelayCommand(2.5, ActionOpenDoor(oDoor1));
DelayCommand(1.5, FloatingTextStringOnCreature("Door1 unlocked, Door2 locked", oPC));
}
else
{
DelayCommand(1.5, SetLocked(oDoor2, FALSE));
DelayCommand(1.5, SetLocked(oDoor1, TRUE));
DelayCommand(2.5, ActionOpenDoor(oDoor2));
DelayCommand(1.5, FloatingTextStringOnCreature("Door2 unlocked, Door1 locked", oPC));
}


All the delays are necessary to give the doors the time to get closed if they are open. I'm not sure if they are really necessary. Could be that nwscript allows a door to be locked even if it is still open...
Tool for crafters Do you want some human to your salt? nomanisanisland.monolar.de
User avatar
Lafferty
Scholar
 
Posts: 1130
Joined: Tue Feb 11, 2003 5:08 pm
Location: look at my hands... they are HUGE. And they cant touch themselves...

PostAuthor: Lafferty » Sat May 03, 2003 3:35 pm

ok, just tested it. set the doors properties to "key needed to lock or unlock" and leave the key field empty. That way the doors cannot be lockpicked
Tool for crafters Do you want some human to your salt? nomanisanisland.monolar.de
User avatar
Lafferty
Scholar
 
Posts: 1130
Joined: Tue Feb 11, 2003 5:08 pm
Location: look at my hands... they are HUGE. And they cant touch themselves...

PostAuthor: Lafferty » Sat May 03, 2003 3:42 pm

ok, you also dont need all the DelayCommands. The script looks then like this.

void main()
{
object oDoor1 = GetObjectByTag("MyDoor_1");
object oDoor2 = GetObjectByTag("MyDoor_2");
object oPC = GetLastUsedBy();

ActionCloseDoor(oDoor1);
ActionCloseDoor(oDoor2);
if (GetLocked(oDoor1))
{
SetLocked(oDoor1, FALSE);
SetLocked(oDoor2, TRUE);
ActionOpenDoor(oDoor1);
FloatingTextStringOnCreature("Door1 unlocked, Door2 locked", oPC);
}
else
{
SetLocked(oDoor2, FALSE);
SetLocked(oDoor1, TRUE);
ActionOpenDoor(oDoor2);
FloatingTextStringOnCreature("Door2 unlocked, Door1 locked", oPC);
}
Tool for crafters Do you want some human to your salt? nomanisanisland.monolar.de
User avatar
Lafferty
Scholar
 
Posts: 1130
Joined: Tue Feb 11, 2003 5:08 pm
Location: look at my hands... they are HUGE. And they cant touch themselves...

PostAuthor: JollyOrc » Sat May 03, 2003 4:09 pm

Lafferty wrote:ok, you also dont need all the DelayCommands. The script looks then like this.


many thanks. I will try it at once.

*edit*

Yay, it works !
User avatar
JollyOrc
QA Resource
 
Posts: 3900
Joined: Fri Jan 17, 2003 11:41 am
Location: Germany
Timezone: GMT+1

PostAuthor: Dhalmoh » Fri Jun 13, 2003 8:14 am

i didnt understand jackshit.
I have NO clue about scripting, and i need serious help

Dhalmoh
Prince of Bloated Discourse
 
Posts: 193
Joined: Sat Jun 07, 2003 4:12 pm

PostAuthor: JollyOrc » Fri Jun 13, 2003 8:58 am

ok, once you understand the basics, it's easy:

Code: Select all
object oDoor1 = GetObjectByTag("MyDoor_1");


defines the object oDoor1 and assigns the door with the tag "MyDoor_1" to this object.

Code: Select all
object oPC = GetLastUsedBy();


defines another oject. This time, it gets assigned the PC that has last used the object that calls this script. Confusing ? Let's assume that this line is part of a script that is bound to a lever. Now Joe Hero pulls that lever. The script is placed in the OnUsed event, and is thus now executed.

This line of code now determines who exactly was the idiot that pulled that lever. So the variable oPC now points neatly to Joe Hero.

Code: Select all
ActionCloseDoor(oDoor1);


should be selfexplanatory. I explain it nonetheless: this command causes the object oDoor1 (that's the door with the tag "MyDoor_1", remember ?) to do the action "CloseDoor". The door closes, neat and simple.

Code: Select all
SetLocked(oDoor1, TRUE);


locks the object, in this case again our trusty "MyDoor_1".

Code: Select all
if (GetLocked(oDoor1))
{
FloatingTextStringOnCreature("Door 1 locked", oPC);
}
else
{
FloatingTextStringOnCreature("Door1 unlocked", oPC);
}


this looks a bit complicated, but is easy. The term GetLocked(oDoor1) checks if that door is actually locked. if it is, it executes the part between the first set of { } - brackets.

If not, it executes the second set.

Both sets contain essentiallly the same command, only with slightly different values.

The command FloatingTextStringOnCreature causes the string in the first variable in the ()-brackets to be displayed above the creature which is pointed at with the second variable, in this case that's probably Joe Hero.

Play around with these things, they are easier than they look.
User avatar
JollyOrc
QA Resource
 
Posts: 3900
Joined: Fri Jan 17, 2003 11:41 am
Location: Germany
Timezone: GMT+1


Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Google [Bot], Moredo, Pekarion