PDA

View Full Version : Checking a doors state (and other scripting questions)


glovemaster
04-05-2007, 05:22 AM
Hi, i need a script to check if a door is open, and then another script to check if a door is closed. Please.

Thanks ~GM

Pavlos
04-05-2007, 06:03 AM
Hi, i need a script to check if a door is open, and then another script to check if a door is closed. Please.

Thanks ~GM

You could use something like this to check if it is open:

int StartingConditional()
{

object oDoor = GetObjectByTag("MyDoorTag");
return (GetIsOpen(oDoor));

}

And this to check if it is closed:

int StartingConditional()
{

object oDoor = GetObjectByTag("MyDoorTag");
return (GetIsOpen(oDoor) == FALSE);

}

They should work. If you're doing this for KotOR II and it is for a dialogue then you will only need one of these and you can make use of the not logic option :).

glovemaster
04-05-2007, 06:06 AM
Thanks, those should work fine.. I'll test them in a moment, can some one correct me on this please?

OpenStore(my_store, OBJECT_SELF, 0, 0);


Thanks again, GM

Pavlos
04-05-2007, 06:17 AM
Thanks, those should work fine.. I'll test them in a moment, can some one correct me on this please?

I presume that your store doesn't open? I'm presuming this is just a sample of the script where the problem lies? Rather than OBJECT_SELF you may wish to try GetPCSpeaker().

There is a tutorial written by stoffe here (http://www.lucasforums.com/showthread.php?t=147231). You may as well just use the scripts provided by it - they should work :).

glovemaster
04-05-2007, 07:08 AM
Ah that helps, thanks im going to test now.

--EDIT----------
Results: It works fine now. I can start and stop a force field from a terminal. I am still having problems with the store opening. I use the script:
void main() {
object oStore = GetObjectByTag("TAG");

if (!GetIsObjectValid(oStore))
oStore = CreateObject(OBJECT_TYPE_STORE, "RESREF", GetLocation(OBJECT_SELF));

if (GetIsObjectValid(oStore))
DelayCommand(0.5, OpenStore(oStore, GetPCSpeaker()));
}

Whats wrong with it?
I have the dialogue file in a seperate module file that the script but thats by "_DLG" and "_S"

stoffe
04-05-2007, 08:11 AM
void main() {
object oStore = GetObjectByTag("TAG");

if (!GetIsObjectValid(oStore))
oStore = CreateObject(OBJECT_TYPE_STORE, "RESREF", GetLocation(OBJECT_SELF));

if (GetIsObjectValid(oStore))
DelayCommand(0.5, OpenStore(oStore, GetPCSpeaker()));
}

Whats wrong with it?
I have the dialogue file in a seperate module file that the script but thats by "_DLG" and "_S"

Have you replaced TAG with the tag of your store object, and RESREF with the name of the UTM file containing its template?

glovemaster
04-05-2007, 08:17 AM
I think i have found the problem, im using "GetPcSpeaker()" and the speaker is the computer.. lol
I'll change it so that the script executes on a line where my PC is speaking

stoffe
04-05-2007, 08:22 AM
I think i have found the problem, im using "GetPcSpeaker()" and the speaker is the computer.. lol
I'll change it so that the script executes on a line where my PC is speaking

GetPCSpeaker()is the player character that an NPC is in conversation with. OBJECT_SELF is the NPC that "owns" the dialog (i.e. the one that has it set in its template who the player clicked on to start conversation, or the one running an ActionStartConversation() action). It doesn't matter if the script is run from an Entry or Reply node.

If the script isn't run inside a conversation you should use GetFirstPC() or GetObjectByTag() instead.

glovemaster
04-05-2007, 08:55 AM
Thanks i've got that all sorted now :D

Thanks again! ~GM

glovemaster
04-05-2007, 02:08 PM
Does any one know if it would be possible to change the weather from a script?

stoffe
04-05-2007, 02:15 PM
Does any one know if it would be possible to change the weather from a script?

There are no functions to modify the weather in an area in the KOTOR version of NWScript, as far as I know. NWN has such functions, but since weather works differently in TSL (it can be set independently for rooms) those functions are missing here.

Only way I can think of would be to have two otherwise identical areas with different weather and switch transitioning between them depending on what weather should be used. Though that's quite a bit of work if it doesn't have any bearing on the story.

glovemaster
04-05-2007, 02:19 PM
Ah thanks, that should work aswell. :D

Thanks.. again! :lol:

glovemaster
04-06-2007, 10:43 AM
:lol: does any one know how to check if the PC has an item?

Thanks! GM

stoffe
04-06-2007, 11:00 AM
:lol: does any one know how to check if the PC has an item?



int ST_HasItem(string sTag, object oOwner=OBJECT_SELF) {
return GetIsObjectValid(GetItemPossessedBy(oOwner, sTag));
}

void main() {
if (ST_HasItem("MyItemTag", GetFirstPC())) {
// Player has the item with the tag MyItemTag.
}
}


Replace MyItemTag with the tag of the item you want to check for.

glovemaster
04-06-2007, 01:05 PM
Thank you! :D

glovemaster
04-07-2007, 08:03 AM
Last question, (i hope)
I need a script to make sure that the party leader has not got an item.

I'm using this script:

void main()
{
GetIsObjectValid(GetItemPossessedBy(GetPartyLeader (), "my_item")) == FALSE;
}

It compiles properly so i assume its a working script, but its not doing the job.. :(

Also, can someone check this over for me please?


void main()
{

CreateItemOnObject( "my_item", GetPartyLeader(), 1 );

}

Thanks, GM

stoffe
04-07-2007, 08:15 AM
Last question, (i hope)
I need a script to make sure that the party leader has not got an item.


Do you mean that the character should have the item equipped in one of their inventory slots, or just in the "backpack" inventory?

Also, part members share the inventory of the main character while they are in the party. The GetPartyLeader() function will return the character that the player is currently in control of, which is not necessarily the main character (Revan/Exile), it could be another party member that the player has clicked on the portrait of, or used tab to switch to.

Thus, as long as they are in the party you should check the inventory of the main character (GetFirstPC()) instead, unless you are looking for an item equipped in an inventory slot.

If this is to be used in dialog keep in mind that you're always in conversation with the main character regardless of which party member you control when you initiate conversation with some NPC.

glovemaster
04-07-2007, 10:58 AM
Thanks Stoffe but It doesnt seem to be working. :(
I've just read through it this thread and i must admit, i havent been very clear.. Which i guess isn't always helpful :S.

I want to give the PC an item from a terminal (dialogue). But i want it so that the PC can't get the item more than once. On the dialogue node i have the conditional script:

void main()
{
GetIsObjectValid(GetItemPossessedBy(GetFirstPC(), "item")) == FALSE;
}

So that the PC can only select that option if they dont have the item
And then from that node i use the script:

void main()
{
CreateItemOnObject( "item", GetFirstPC(), 1 );
}

Im note sure if the give item script is correct as i am not getting the option in the dialogue.

Can someone please correct me?

Thanks, GM

stoffe
04-07-2007, 11:18 AM
On the dialogue node i have the conditional script:

void main()
{
GetIsObjectValid(GetItemPossessedBy(GetFirstPC(), "item")) == FALSE;
}

So that the PC can only select that option if they dont have the item

That's not a valid conditional script, since the main() function does not return anything (void). Conditional scripts must use a StartingConditional() function instead and return true or false. Like:


int StartingConditional() {
return !GetIsObjectValid(GetItemPossessedBy(GetFirstPC(), "item"));
}


That script would make the dialog node it's called from available it the player does not have an item with the tag item in their inventory.

glovemaster
04-07-2007, 03:59 PM
Thanks, that worked perfectly! :D

glovemaster
04-10-2007, 05:27 AM
this isn't a script but, would it be possible to add option to the menu on a door with "security" and those options? Im guessing i have to edit a 2da file? lol

Pavlos
04-10-2007, 06:11 AM
this isn't a script but, would it be possible to add option to the menu on a door with "security" and those options? Im guessing i have to edit a 2da file? lol

I'm not sure what you mean. Do you want to know how to lock the door? If so:

Open up your UTD (your door) in KotOR Tool and click on the "Lock" tab. Check the box labelled "Locked" and then you can set the DC of the lock to increase or decrease the security skill level required to open it.

glovemaster
04-10-2007, 06:15 AM
I mean when you target/hover cursor over a door, you get an option selectable by "2" on the keyboard (by default) and it has options such as "security", I want to add an option to the menu, is that possible? I can't find a 2da file for it?

Pavlos
04-10-2007, 06:37 AM
I mean when you target/hover cursor over a door, you get an option selectable by "2" on the keyboard (by default) and it has options such as "security", I want to add an option to the menu, is that possible? I can't find a 2da file for it?

Provided the door has a faction of Hostile_1 (Hostile_2 should work fine too, though) and is locked then all the correct menus (bash, unlock, mine) should fill in.

glovemaster
04-10-2007, 06:40 AM
So how would you add an option to the menu?
So you would have: unlock, bash, *custom*, etc..

Tupac Amaru
04-10-2007, 08:44 AM
I don't think you can add a new option directly to that menu. What you can do is start a dialogue that makes your custom option available. Put the name of the .dlg file in the 'Conversation' field of the door template and make a simple script to start the conversation:
void main() {
ActionStartConversation(GetFirstPC());
}The script should be triggered by either the door's 'OnClick' or 'OnFailToOpen' event. Set the 'Locked', 'Not Blastable' and 'Key required to unlock or lock' flags so that the player has to go through the dialogue.

glovemaster
04-10-2007, 08:50 AM
The problem there is that i would have to edit every door in the game. I'll just leave this out. It doesn't seem as easy as i assumed. Isn't there a 2da file like spells.2da that has the door options? If not ill leave it.. Im too lazy :lol:

Pavlos
04-10-2007, 08:54 AM
The problem there is that i would have to edit every door in the game. I'll just leave this out. It doesn't seem as easy as i assumed. Isn't there a 2da file like spells.2da that has the door options? If not ill leave it.. Im too lazy :lol:

No, not to my knowledge. You could create a new item with the baseitem type of a security spike. That would bring it up in the central menu. What exactly do you want your new option to do?

glovemaster
04-10-2007, 08:56 AM
Well, I released my "handy force powers" mod on KotOR II Files and someone suggested that i change it so that the "OpenDoor" option appeared in the doors menu rather than in the Force Powers menu. I think the Item is a good idea, ill try that.

Thanks ~GM