Aller au contenu

Photo

Learning script, I need an explanation


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

#1
Vaalyah

Vaalyah
  • Members
  • 953 messages
Hello everybody! I love NWN2, and I really would like to mod it. So in the last weeks, I was reading tons of tutorial. About 2 days ago, I started with scripting tutorial (before, they were just tutorial about the toolset).
I was speaking with Domi at the Gibberlings when I got a very unpleasant surprise. Please, have a look at this link, so I can avoid a long summary  :whistle:

http://forums.gibber...showtopic=20981

so, I am going to ask the same question also here, hoping to find someone with the answer. Does it exist a script able to do what I wrote in that example? ie: Checking all those variables, in order to avoid the triggering-area problems?
Please, I am learning about scripting for too less time. Speak as if I was 5 years old!

#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
You need to be more specific about how you'd like the convo to start. Do you want the dialogue to be started by the NPC himself, when you enter a certain trigger, for example? I can't speak to the delay problems Domi was talking about, but this is certainly possible. The Maimed God's Saga, for example, did this in many places.



On the other hand, do you want this option to appear, if certain conditions are met, in the regular conversation that starts up when the PC talks to the NPC? If so, you just nest your convo options correctly and place the appropriate conditions (in other words, checks) on the conversation node.

#3
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Are you trying to mod the OC, or a completely new mod?

If you're trying to mod the OC, things can be a bit more difficult, simply because you can't go in and redesign whole areas, you can only add bits and pieces to the existing campaign. That's why it's easier to add new conversation options to an existing convo, rather than create an entirely new conversation triggered by some other means. (I haven't actually tried modifying the OC, so maybe someone else with this experience can give you better details).



With new modules, though, there are a variety of ways to initiate conversations. I often use triggers that start a conversation between the PC and NPC when the PC walks over a certain spot, usually a chokepoint a few meters away from an area transition. Sometimes I use a script on the area's on-client enter to start a conversation. You can also re-write perception scripts so that NPCs will initiate a conversation when they first detect the PC.

The scripts themselves can use practically any kind of logic tree or calculation to determine whether or not to start the convo, and you can write your own gc_ scripts to test pretty much anything you want, including the current area, reputation, quest status, and inventory.




#4
Vaalyah

Vaalyah
  • Members
  • 953 messages
The problem raises speaking of the romance pack. Domi said that the only way to trigger a dialogue, was to tie it to an already existing dialogue.

I thought I could specify in my script something like:

1) is the PC in the Flagon?

2) has the PC finished the quest X?

3) is the PC a bard?

logical AND of the answers above, if TRUE then the NPC starts dialogue Y.



In this way, we could add a dialogue wherever we want and whenever we want.



SPOILER

in the romance pack, there's a dialogue tied just after the trial. You come back to the Flagon, the guy says that Aldanon wants to speak with you, and then, tied after that dialogue, comes the romance pack one.

Let's say I would like to create a dialogue that starts after the trial, as soon as you enter the Flagon if you have finished the Aldanon's quest. Is it possible or I still need a dialogue to which I have to tie mine?

END SPOILER



From what Domi said, it seems that since the dialogues are triggered with a sort of "painted area" on the map, we must paint all the areas. But of course, this would imply to do all the work again each time the game is patched.

#5
Vaalyah

Vaalyah
  • Members
  • 953 messages
Hmmm, maybe another sentence can help in understanding what I mean.



I would like to trigger dialogues on a "conditions" bases and not on a "trigger area" basis. Is it clearer in this way?

#6
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
I'd say you can, but it might be a bit difficult since you are learning how to script.



You can change how the game works to an amazing degree, but you cannot do that AND learn how the engine works AND learn scripting itself at the same time and not expect things to be overwhelming.



You can trigger a conversation entirely thru a script, the question though is how do you trigger the script to begin with.



You also need to define exactly what you are doing, and what you want to accomplish. After that you should get good advice on how to get from point A to point B. Very likely there is a way of doing it which you've not thought of.

#7
Vaalyah

Vaalyah
  • Members
  • 953 messages
Ok, that's the point. I don't know how the game triggers script.

I supposed that each time an area is loaded, the game would do a check for applicable scripts, but from what I've understood, it is not in this way that thing goes.



Of course, I know I am just learning, but my curiosity is overwhelming and since I am a theoretical, my mind works in this way: if I have a doubt, I have to solve it or I am not able to go forward! :-D So, can you please tell me in which way it is possible to trigger a script?

#8
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Each area has a set of scripts attached to it, that fire on different events (on-enter, on-client-enter, on-exit, on-heartbeat). You could open up the Flagon area, look at the area properties, find these scripts, and edit one of them (on-client-enter would probably be a good bet). Within that script, you could add in a new stretch of code that checked for the conditions you mentioned and started an appropriate conversation. That particular script is probably already really long and complicated, though, so you might not want to mess with it.

Another option, the one Domi is pointed to, would be to find the conversation you mentioned above, open it, and add in another conversation line with several gc_ scripts attached to it. There are already gc_ scripts that check for class, quest status, and you could create a custom script that checks for area.

Then, you either add in your new conversation off of this new line, or you use a ga_ script that starts a new conversation with the appropriate NPC.



To further pode's advice from above, the game can be really complicated, and opening up an existing campaign like the OC will probably just confuse you even more. Creating your own mini-module from scratch will probably be a better learning experience. You can even use the OC's companions and NPCs, their blueprints are all in the toolset.

#9
Vaalyah

Vaalyah
  • Members
  • 953 messages
I've understood, but following the "add to existing dialogue" option would lead exactly to the problem I would like to avoid: Have you ever played BG2? In case you did not, I am doing a short summary.



Focus on the romance options. You have a companion in your party. Let's number the days.

Day X, s/he starts a dialogue and speak about his/her life.

Day X+2 another dialogue, introducing the quest.

Day X+3 during the quest, another dialogue about the quest

Day X+8 comments on the quest related to another companion

Day X+15 dialogue during his/her quest

Day X+18 quest completed and another dialogue focused on this

Day X+20 starts the romance

from day X+21 to day X+40 random series of dialogues that deepens the romance

Day X+45 the NPC confess his/her feelings

from day X+46 more random dialogues



the problem with NWN2 is that you can't put a dialogue in a situation if there isn't already a dialogue (by the same NPC or by others) in that situations. I would like to find a way to overcome this problem.



Oh, believe me, in the miraculous case I would be able to make my toolset running, I would probably put trees and rivers in the middle of nothing for months! So, my days as modders are far to come. But still I am curious about the possibilities that scripting could give us.

#10
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
If you're just starting a conversation with a companion, it might be easier, since the companions always have the same tag no matter what area you're in.

So you write a set of new conversations, and now you just need a script to start the appropriate conversation at an appropriate time and place. You might be able to write something into the companion AI, maybe the companion heartbeat or a combination of the other scripts.

On the heartbeat script, for example, you could have a counter that serves as a timer. When 50 or so rounds have elapsed since the last romantic encounter, the script could start trying to initiate a new conversation/romantic encounter using a long list of conditions and a bit of randomness.

For example, It could first check to make sure the party's not in combat, enemies are nor nearby, not already in a conversation, etc, and then use a die roll to determine whether or not to start a conversation.

Once the die roll succeeds, then the script can look at quest status, reputation, and current area to figure out which particular conversation to initiate.

#11
Vaalyah

Vaalyah
  • Members
  • 953 messages
Hmm, ok, it seems to me that I finally was able to make my words understandable! :-)



Since I am just beginning with scripting, could you tell me what do you mean with "since the companions always have the same tag" and what is the heartbeat script? I read about it several time, but I still haven't understood what that script is supposed to do.



However, you have written exactly what I had in mind. Thank you very much!

Now, be prepared, because in the following days, you will hear a lot of question by me!

The first could be: where can I change the heartbeat script? Is it related to each NPC or to the area or the campaign or whatever...?

#12
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
In the toolset look at the blueprints for creatures and you will find the OC companions. Each companion has a set of scripts that control their behavior. They all share the same scripts. The companion heartbeat script is one of those. You could (not saying I recommend this) modify the companion heartbeat script to include logic that checks to see which companion it is running on and whether the conditions have met to initiate your new conversations. Your new companion heartbeat script would need to be installed in the OC campaign folder to prevent interference with other campaigns since the override folder affects everything that is run.



I wouldn't recommend this though because heartbeats are checked so frequently, so the more of these checks you add the more likely you will start to create performance issues. I think it would be better from a performance perspective to use the area heartbeat scripts instead and add into them the checks that are relevant to the particular area the party is in.



You can see the area heartbeat scripts by loading an OC module in the toolset (make sure you turn off autosaving in the toolset before doing this) and then opening an area and examining the area properties.



For compatibility with other mods (like the OC Makeover) I would avoid altering the companion conversation files, and instead add your own. Less risky too because the companion conversations can be pretty complicated and difficult to test.



You will not be able to alter areas in the OC although you can create your own areas in a new module and append them. I will be doing this in the MotB Makeover.



Regards

#13
Vaalyah

Vaalyah
  • Members
  • 953 messages
Ok, now I am confused again. From what I've understood, the problem is the triggering condition. If I have to "paint" the triggering area in the map, each time a new patch is release, I should paint again all the areas.

Is there a way to skip the painting part? To attach the trigger to time, instead than to place?

#14
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
Triggers are just a boundary for a portion of an area. They are painted on an area map by indicating their perimeter. Then you can initiate events when a PC crosses the edge and enters or exits the trigger. Triggers are used in the OC so that when the PC walks over that portion a conversation or conversation line is initiated. This is the most efficient way to initiate conversations.

That really isn't an option for modding the OC though because you cannot paint anything in the existing areas and you cannot put modified areas into the override folder. So the good news is you can forget about creating new triggers.

Heartbeat scripts are initiated every 6 seconds, so they are a mechanism for initiating events based on time.

I think your best options are:
- use area heartbeat scripts to initiate new conversations when conditions are met
- take advantage of existing triggers and modify their scripts to initiate your new conversations
- modify existing conversations to add in additional branches of dialogue

In my opinion the first option is best. It will be the easiest to do and the least risky. If I wanted to add a bunch of dialogue into the OC that is how I would do it.

As it is I think you should be practical. In BG2 only leading lines were generally spoken, but in the OC most companion lines are spoken. Therefore any modifications you do to companion banter are going to be a little jarring. You will also need to add lip flappers otherwise their lips won't move when they speak their new lines, which will be very noticeable in cutscenes, and the companions always use cutscenes.

Regards

Modifié par Kaldor Silverwand, 18 septembre 2010 - 05:20 .


#15
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
What scripts to modify depends largely on how you want the conversations to be triggered. If most of your conversations are tied to a particular area, then using the area heartbeat scripts might be a bit more efficient. If your conversations are going to be independent of the current area, then the companion heartbeat would be simpler. For example, if you want all this conversations to take place in the Sunken Flagon, then just find the Flagon area's heartbeat script and modify that.

Heartbeat scripts are indeed one of the easiest ways to mess up a module, but if you know what you're doing and economize the scripts as much as possible, it shouldn't be a problem. Besides, the companion heartbeat only runs on a few NPC's, so there's not much trouble you can get into.

Basically, I would have a snippet in the companion script that checks to see if the player is in the same area as the companion, that neither is in combat or conversation, and that neither has some conditiont that would prevent them from speaking (sleep, petrify, etc.). If so, you check the tag of the companion and use ExecuteScript to run a second script, one that's you've written for that particular companion. This second script contains all the other checks, including time, quest, reputation, area, etc, and starts different conversations (or other actions) as appropriate.

This can all get really complex, so start simple, get something working, and move on up from there. You might want to do a simple custom module to get a feel for scripting first, before you try inserting everything into the full OC. Just a companion in a room shouting various lines at random intervals, that sort of thing.

#16
Vaalyah

Vaalyah
  • Members
  • 953 messages
@ Kaldor: 1) where can I find some informations about heartbeat script?

2) If I want to add a heartbeat script for running dialogues, where should I put it? Override folder or wherever?

Thank you



@ Lugaid: so there are many different types of heartbeat scripts. Some for the NPCs, some for the area...

I think it would better having scripting related to time, so, no to the area, but that the NPC can start a dialogue if some conditions are met. ie: after n game-days, if you are not during a combat or during another speech, start this dialogue.



"Besides, the companion heartbeat only runs on a few NPC's" Are you saying that not all the companions have a hb script?



I think I would need a lot of time doing some easier things, before trying to modify the OC hb script. But I need an "address" to know where I am going and if there is something to find in that way ;-)

#17
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
By 'few' I meant that only the half-dozen or so companions would ever be running the script, as opposed to the hundreds of spawned creatures and ambient NPCs that inhabit a module. The pitfall with heartbeat scripts isn't that an individual script can be really taxing on the system, but if you multiply that one script over dozens of NPCs in a single area you can quickly get problems.



You can open up the toolset, pull up a companion blueprint, scroll down to the scripts, and open up the heartbeat script to see what's going on in there.

#18
Vaalyah

Vaalyah
  • Members
  • 953 messages
Thank you, now I have understood. By the way, is there a way to count day in the game? If I look at the sky, I can see sun or moon, but there isn't any "clock" in the game... Maybe a hb cycle multiplied for a specific number is equal to a day...

#19
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
The game does have a calender, with month, day, and hour. If you want to do 1 conversation/day it's very easy, you just store the current day as a local integer, and the heartbeat checks to see if the current day is different than the stored value. If it's a new day, start a new conversation. I don't know exactly how the OC handles the day-night cycle though, it might be effectively too long for your purposes (i.e. 1 day = 60 minutes of game time.)

#20
Vaalyah

Vaalyah
  • Members
  • 953 messages
You are officially my hero! ^^

Thank you very much! I am really starting to understand things a lot better.

Actually I am reading the www.nwn2scripting.com site, and I find it WONDERFULLY DONE.

But those are extremely basic concepts. Can you please suggest to me some "a bit but not too much" advanced resources available for learning?

Thank you again!

#21
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
All of the companions in the OC and MotB and likely any 3rd party campaigns people have downloaded use the same heartbeat script gb_comp_heart. If you alter that script and have users install it into their override folder then it will impact every companion in every game they play, not just the OC. So if you are intent on changing that script then you should instruct people to install your OC specific version of it directly into the OC campaign folder, rather than the override folder.



If you use area specific heartbeat scripts instead then they could be installed in the override folder because the area script names are unlikely to conflict with any other campaigns a person may have installed. Unfortunately in the OC it appears that area heartbeat scripts are not usually specified, which means you cannot add a hook into them. Instead module heartbeat scripts are used, usually the script k_mod_heartbeat. So to avoid modifying the companion heartbeat you would have to modify the k_mod_heartbeat script and have it check to see whether it is the appropriate time and place for new companion interjections. I suspect that most 3rd party campaigns also named their module heartbeat script k_mod_heartbeat, so if you have people install yours in the override folder it will interfere with other non-OC campaigns. so again, you would need it installed the OC campaign folder rather than override.



So the conclusion is that either way you will need to have people install in the OC campaign folder rather than the override folder. This will be necessary to prevent your changes from affecting other campaigns.



Regards

#22
Vaalyah

Vaalyah
  • Members
  • 953 messages
Thank you, Kaldor, I have understood that whichever option I choose, I have to put the modified file in the OC folder and not in the override one. But I am afraid I know too few things about hb script for being able to understand the whole of your post.

So, could you please tell me where I can find some more info, a tutorial, whatever, about the hb script? I need to learn a bit more for being able to fully understand this topic :-(

#23
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
Knightmare has a scripting tutorial here: http://nwvault.ign.c...s.Detail&id=124. It doesn't specifically cover module scripts or heartbeat scripts, but it covers scripting fundamentals.



I'm not aware of any tutorials that explain this stuff in any kind of detail.



Basically heartbeat scripts are just scripts that are initiated every 6 seconds by the game engine. When a module is loaded in the game the heartbeat scripts of all objects in the module are run every 6 seconds. The module heartbeat script can be used to manipulate objects in any area within the module, even the areas that the PC's are not in. Objects that are capable of having a heartbeat script have the name of the script specified in their properties in the toolset; this includes areas, modules, and creatures.



In the OC areas generally do not have a heartbeat script defined. Because this is an area property you cannot change it without altering the area. (It might be possible to assign a heartbeat script to an area from another script, but I haven't tried that and can't really say.) Because areas cannot be placed into the override folder you can't change them without replacing the whole module, and that would be a copyright violation.



In the OC the standard heartbeat script used by the modules is called k_mod_heartbeat. You can find this script in the campaign folder of the OC. It is possible that some modules have their own heartbeat script, and if so that would be specified in the module properties viewable in the toolset.



If I were going to attempt to change the OC in this way, I would create a test module and add it to the OC campaign. I would give that test module the same properties as a standard module used by the OC. Then I would copy the k_mod_heartbeat script and create a k_mod_heartbeat module script in the test module and use that to experiment with initiating dialogue. The current script does very little besides updating the clock, so it should be fairly easy to modify or have it execute another script. Alternatively you could modify the standard companion heartbeat script gb_comp_heart, but it is a more complicated script and if a companion is not using the default script then they will not work with your enhancements. (Of course, that is also true of the OC modules, so if you want to make sure changes to the module heartbeat script work in all the modules of the OC you should open each OC module in the toolset and verify that each uses the module heartbeat script k_mod_heartbeat.)



Regards

#24
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
i dynamically add heart beats. You can also set the rate of the heartbeat. Modify the following function, make a script named TG_EnviroControl ( or something else ), and the i point placeable is provided in the default game scripts. Another function allows you to slow down or speed up the rate this heart beat runs at.

At any point you can change heart beat scripts, and change the beat rate.

Please rename the function though if you use it, as it might cause conflicts if someone got my stuff working in SP.

string CSL_ENVIRO_HEARTBEAT_SCRIPT = "TG_EnviroControl";

/**  
* control object (invisible placeable)(ipoint) and heartbeat which manages environmental effects, thanks to nytirs system
* @author
* @param 
* @see 
* @return 
*/
object CSLEnviroGetControl( object oThingInTargetArea = OBJECT_SELF )
{
	object oModule = GetModule();
	object oEC = GetLocalObject( oModule, "ENVIRO_CONTROL" );
	if( !GetIsObjectValid(oEC) )
	{
		
		oEC = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_ipoint ", GetLocation( oThingInTargetArea ), FALSE, "plc_environmentcontrol"); 
		
		// Register New Battle Control
		SetPlotFlag(oEC, TRUE);
		SetEventHandler(oEC, SCRIPT_PLACEABLE_ON_HEARTBEAT, CSL_ENVIRO_HEARTBEAT_SCRIPT);
		SetLocalObject(oModule, "ENVIRO_CONTROL", oEC);
		
		SetFirstName(oEC, "Environment");
		SetLastName(oEC, "");
	}
	return oEC;
}


Modifié par painofdungeoneternal, 21 septembre 2010 - 12:05 .


#25
Vaalyah

Vaalyah
  • Members
  • 953 messages
@Kaldor: thanks for the link but... I've already read that tutorial. Definitely not my kind. I am a theoretical mind, so I need a theoretical approach, not an experimental one. Looking to already done scripts and trying to understand what does each piece mean, doesn't help me at all.

I love the "nwn2scripting" because the author starts from the basic and goes to the advanced features.



Instead, I think your explanation is extremely useful. Thanks.

From what I've understood, whatever thing in the game has a ht script. Something that simply "counts" the time that pass by. So I can trigger some events with it. ie: I tie a script for "doing something" to the hb script of an item. When the hb script verifies that some conditions have been satisfied (and this check happens every 6 seconds), then my script (the "doing something") starts.

Is it correct?



By the way, two questions:

1) from what I am reading, it seems to me that no-one has ever tried to modify the game in this way, is it correct?

2) BG series modders have added thousands of NPCs to the OC... I suppose it is impossible to do the same for NWN2... or not?



@Pain: O_O ok, I suppose I need... ehm, a bit more explanation on that! I think you are forgetting I am just STARTING with scripting :-D [Vaalyah is feeling a bit stupid!]