Aller au contenu

Photo

Script questions


  • Veuillez vous connecter pour répondre
19 réponses à ce sujet

#1
Barnabas2

Barnabas2
  • Members
  • 65 messages
Hi all. After a view months I tried to build some maps with the NWN2 toolset. While creating some conversations I noticed stuff like "global int" and "local int". What is the difference between them?

#2
The Fred

The Fred
  • Members
  • 2 516 messages
Locals are variables stored on a specific object.
Globals can be accessed from anyone at any point in the game (even cross-module, I think).

#3
Barnabas2

Barnabas2
  • Members
  • 65 messages
So for example, if I want that a NPC remembers the playerchar after the 1st conversation, I have to set the local int?

#4
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Check out my Scripting tutorial linked in signature below. Should help you with this and a bunch of other learning scripting stuff.

#5
rjshae

rjshae
  • Members
  • 4 491 messages

Barnabas2 wrote...

So for example, if I want that a NPC remembers the playerchar after the 1st conversation, I have to set the local int?


Yes, typically I think that globals are good for plot status tracking; locals are useful for individual or area-specific interactions.

#6
Barnabas2

Barnabas2
  • Members
  • 65 messages
Atm I try to create a script, that gets active, if the player uses a door/area transition. When the player tries to use the transition, a conversation should start, before the transition works. For this I tried to create a Onuse script for the door that contains the transition. So far I did the following:

void main()
{

object oPC = GetLastUsedBy();
string NPC_Tag = GetLocalString (OBJECT_SELF, "NPC_Tag");
string oconversation = GetLocalString (OBJECT_SELF, "oconversation")

if (!GetIsPC(oPC)) return;

object oTarget;
oTarget = GetObjectByTag("NPC_Tag");
oconversation = ?????

AssignCommand(oTarget, ActionStartConversation(oPC, "oconversation"));

}

The problem I have so far is, that I don´t know how to include a variable for the conversation, because I want to use the script on different places with different conversations....
What I do not understand: how can I get the conversationfile, becuse the conversation will be get by the filename and not by the tag...


EDIT: Ok, the script looks like this now:
void main()
{

object oPC = GetLastUsedBy();
string NPC_Tag = GetLocalString (OBJECT_SELF, "NPC_Tag");
string sConversation = GetLocalString (OBJECT_SELF, "sConversation");

if (!GetIsPC(oPC)) return;

object oTarget;
object oconversation;
oTarget = GetObjectByTag("NPC_Tag");
oconversation = GetObjectByTag ("sConversation");

AssignCommand(oTarget, ActionStartConversation(oPC, "oconversation"));

}

I set it as the OnUse script of a door and set the variables NPC_Tag and sConversation in the door properties and as expected it didn´t work :-(

Modifié par Barnabas2, 13 octobre 2011 - 11:21 .


#7
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
First off, a converstaion is not an "object" - objects are those things you can physically place down or manipulate in a toolset area (creatures, placeables, triggers, waypoints, items, etc.). Change you one line to this:

AssignCommand(oTarget, ActionStartConversation(oPC, "name of conversation file here"));

This will make the object play the convo file specified.

Doors are a bit different than other placeable type things since they default to being opened/closed/transition when used, try putting the script in the OnLeftClick slot instead.

#8
Barnabas2

Barnabas2
  • Members
  • 65 messages

_Knightmare_ wrote...

First off, a converstaion is not an "object" - objects are those things you can physically place down or manipulate in a toolset area (creatures, placeables, triggers, waypoints, items, etc.). Change you one line to this:

AssignCommand(oTarget, ActionStartConversation(oPC, "name of conversation file here"));

This will make the object play the convo file specified.

Doors are a bit different than other placeable type things since they default to being opened/closed/transition when used, try putting the script in the OnLeftClick slot instead.


Thanks for the fast answer, I´ll try that, but do I have to modify the line

object oPC = GetLastOpenedBy();

too?
And am I able to set the conversation as a variable, so that I can use the script on other doors and with with other conversations too?

#9
Dann-J

Dann-J
  • Members
  • 3 161 messages
GetLastOpenedBy will return a 'creature' (such as the PC). Creatures are considered 'objects', so you won't have to change that line. Although if you put that script in the door's OnLeftClick slot, and the door starts out closed, then it may fire before the door opens (which means that no-one last opened it). Perhaps GetLastUsedBy would be a better option?

You can have the script use a string variable to define the conversation name. Just make sure you don't enclose the string variable in quotes inside ActionStartConversation. In the script above, it would be:

AssignCommand(oTarget, ActionStartConversation(oPC, sConversation));

#10
Morbane

Morbane
  • Members
  • 1 883 messages
GetClickingObject() is good for on clicked event

#11
The Fred

The Fred
  • Members
  • 2 516 messages
I think a lot of these are actually just synonymous with GetEnteringObject(), but yes, GetClickingObject() is, I think, what you're after.

#12
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
This Referencing Object In Scripts has a complete reference, but they are all basically synonyms, what you use depends on the type of script or event.

#13
Barnabas2

Barnabas2
  • Members
  • 65 messages
Finally my problems got solved with all your help. Thank you very much. Unfortunally I´m confronted with another problem now and again I need your help: In my module I want the players only be able to rest when they use a bed. For this I made my areas norest. Is there a way to create beds with a rest option (script) without another hakpack?

#14
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
You need to have a way of marking the player as on a bed ( perhaps using whatever code implements the kemo sleeping in a bed animation )

Then you need to implement a way to block resting entirely, and make an exception when your given flag is set.

How to do this is basically described here

Modifié par painofdungeoneternal, 14 octobre 2011 - 07:06 .


#15
Morbane

Morbane
  • Members
  • 1 883 messages
You can also put a script in the bed onused event with ForceRest() being called in it

#16
Barnabas2

Barnabas2
  • Members
  • 65 messages

Morbane wrote...

You can also put a script in the bed onused event with ForceRest() being called in it


I´m experimenting with this command yet, and it works well, but I´m faced with, what I think, the main problem for everyone, who´s experimanting with sleepable beds. How am I able to place the char into the bed. Until now I´ve made the following script:

void main()
{

    object oPC = GetLastUsedBy();
    string oWP = GetLocalString (OBJECT_SELF, "oWP");
    object oWayP = GetObjectByTag (oWP);

    if (!GetIsPC(oPC)) return;

    AssignCommand(oPC, ClearAllActions());
    AssignCommand(oPC, JumpToObject(oWayP));
    DelayCommand(1.0, AssignCommand(oPC, PlayAnimation(ANIMATION_LOOPING_DEAD_FRONT, 1.0, 99999.0)));
    AssignCommand(oPC, SpeakString("Ihr ruht euch nun aus."));
    DelayCommand(2.0, SetCommandable(FALSE, oPC));
    DelayCommand(25.0, AssignCommand(oPC, ForceRest(oPC)));
    DelayCommand(25.1, AssignCommand(oPC, SpeakString("Ihr seid nun ausgeruht.")));
    DelayCommand(24.8, SetCommandable (TRUE, oPC));
}

With the JumptoObject Command, I tried to place the char onto the bed, but he jumps into the bed and lays down at the floor.  Then I tried to place the char on a static object. Unfortunally it doesn´t work neither. No I ask myself if it is possible, to let the player hover?

EDIT:
I got it!

Here

Modifié par Barnabas2, 15 octobre 2011 - 09:41 .


#17
Dann-J

Dann-J
  • Members
  • 3 161 messages
Did you use a raised walkmesh helper perhaps?

#18
Barnabas2

Barnabas2
  • Members
  • 65 messages
Yes. I hid stairs in the bed and modified the script above.

#19
The Fred

The Fred
  • Members
  • 2 516 messages
Sweet. This is something I've been meaning to get 'round to doing for a while.

#20
Barnabas2

Barnabas2
  • Members
  • 65 messages
I made a guide to show how I made the bed. Also it contains the final script.

Look here.