Jump to content

Home

Some scripting questions...


Ancharos

Recommended Posts

I'm not to good with scripting, Mostly becasue I jsut copy and Paste everything. Now I actually want to know whats going on in scripting.

Just a few questions...

 

1. How would I make that gives me health?

 

2. I've only ever used multiple dialog nodes to use multiple scritps. So i was wondering, what do I use to combine those scripts together into one script?Would it be like this (as an example):

 

Void Main ()  
  {
     AddAvailbleNPC(42, P_dingy)
     RemoveAvailbeNPC(42)
     AddavailibleNPC(6352, G_hiore)
   }

 

3. How to I make an NPC just move to an area?

 

4.How Do I warp the PC using Rabid trasit, like in the holowan spire mod where you talked to the Sithy then got warped to the spire?

 

5.In fred Tetras Module editor, Theres a trigger section, what do I do to use those? Do triggers have anything to do with scripting?

 

6. Can I poisen the Pc through Scripts?

 

7. Can I start a script by opening a door, on the door GFF's theres a "OnOpen" section, could i use that?

 

EDIT: Forgot One last thing

 

8. Can I change the music in a specific area of a module, Just not the whole module's music?

Link to comment
Share on other sites

1. How would I make that gives me health?

 

Healing is best handled by using a Heal effect and applying it to the creature that should be healed (the main character in this case). This can be done like:

 

void main() {
   // Creature to be healed.
   object oPC = GetFirstPC();

   // Calculate how much healing is needed to reach full health.
   int nHealth = GetMaxHitPoints(oPC) - GetCurrentHitPoints(oPC);

   // Create heal effect that heals the above calculated amount.
   effect eHeal = EffectHeal(nHealth);

   // Apply the heal effect to the target to make it happen.
   // Since healing happens once, use Instant as effect duration.
   ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oPC);
}

 

2. I've only ever used multiple dialog nodes to use multiple scritps. So i was wondering, what do I use to combine those scripts together

 

You use some text editor (there's one built into KotorTool if you don't have one) to edit the NSS (source code) files and add together the relevant parts into one file, which you then recompile.

 

Just how you would go about adding the scripts together depends on how the scripts are written. There is no "one size fits all" answer to that. You'll have to examine what the different scripts do to determine that.

 

 

3. How to I make an NPC just move to an area?

 

Only the player character, party members (and party puppets in TSL) may move between areas/modules. Any other instance you see where an NPC appears to move between areas are handled by creating new and separate instances of that NPC in both areas, either by pre-placing them in both areas, or using the CreateObject() script function to spawn them. To move the player/party to a new area you use StartNewModule() like described below.

 

 

4.How Do I warp the PC using Rabid trasit, like in the holowan spire mod where you talked to the Sithy then got warped to the spire?

 

"Rapid transit" can be handled in two ways depending on if you want to "teleport" the player within the same area or to another area. To teleport the player within the current area, you could use:

 

void main() {
   // Creature to teleport...
   object oPC = GetFirstPC();

   // Location to teleport to in X, (10.0) Y (20.0) and Z (0.0) coordinate.
   // Z is irrelevant when jumping creatures since they will always
   // be snapped to the walkmesh and cant be jumped into the air.
   location lDest = Location(Vector(10.0, 20.0, 0.0), GetFacing(oPC));

   // Make them stop what they currently are doing.
   AssignCommand(oPC, ClearAllActions());

   // Teleport them to the location set above.
   AssignCommand(oPC, JumpToLocation(lDest));
}

 

To get the destination coordinates, use the "whereami" console command (in KotOR1), or some scripted solution like Darth333's WhereAmI-armband (for KotOR2:TSL) in game when standing at the destination spot.

 

To teleport between modules, you could use:

void main() {
   // Go to module/area 200TEL (Citadel Station) and appear at
   // the waypoint with the tag "ArrivalWaypointTag".
   StartNewModule("201TEL", "ArrivalWaypointTag");
}

 

You first specify the name of the module containing the area you wish to go to. You can check the module named with KotorTool. "ArrivalWaypointTag" would be replaced by the Tag of a waypoint existing within that area where you want the player to appear. This parameter can be left out, causing the player to appear at the pre-set module starting location.

 

 

5.In fred Tetras Module editor, Theres a trigger section, what do I do to use those? Do triggers have anything to do with scripting?

 

A standard trigger is a "hot zone" that can be placed on a map that will fire events that can be used to trigger scripts when the player enters the zone or leaves the zone. What exactly a trigger does when a player (or any creature really) trips it depends on the scripts assigned to those events. See the last question for an example use of trigger scripts.

 

On a side note: Mines and Area Transitions are two special cases of Triggers which have pre-determined behavior not controlled by scripts.

 

 

6. Can I poisen the Pc through Scripts?

 

You can assign any effect that Force Powers, grenades or droid guns do through scripts (since those use scripts to do their thing). A simple script to poison the player could look like:

void main() {
   // Set the target of the effect to the main character.
   object oPC = GetFirstPC();

   // Create the pioson effect. The parameter corresponds to the line number
   // in poison.2da of the type of poison to use. 5 for example is "Virulent Damage".
   effect ePoison = EffectPoison(5);

   // Apply the poison effect to the Victim. Poison effects should always be
   // applied as "Permanent" as their duration is determined in poison.2da by the type.
   ApplyEffectToObject(DURATION_TYPE_PERMANENT, ePoison, oPC);
}

 

 

7. Can I start a script by opening a door, on the door GFF's theres a "OnOpen" section, could i use that?

 

Yes, you set the resref (filename without extension) of the script to fire in the OnOpen event slot of the door to make the script fire whenever the door is opened. If you do this in the door template you should create a new custom template for your door, since many door templates are re-used for multiple instances of that door type. If you aren't careful your script might end up on many different doors.

 

 

8. Can I change the music in a specific area of a module, Just not the whole module's music?

 

You could create something to that effect by placing a trigger that covers the desired area and then set the OnEnter script to change the music, and the OnExit script of the trigger to change it back to what it was before. An OnEnter script could look like:

void main() {
   // Only trigger script if the main character trips the trigger
   if (GetEnteringObject() != GetFirstPC()) 
       return;

   // Set area to change music for to the Player's area.
   object oArea = GetArea(GetFirstPC());

   // Line number in ambientmusic.2da for new track to play.
   int nMusic = 12;

   // Store what track is currently used.
   SetLocalNumber(OBJECT_SELF, 1, MusicBackgroundGetDayTrack(oArea) + 1);

   // Change to the new music track.
   MusicBackgroundStop(oArea);
   MusicBackgroundChangeDay(oArea, nMusic);
   MusicBackgroundChangeNight(oArea, nMusic);
   MusicBackgroundPlay(oArea);
}

...with the corresponding OnExit script:

void main() {
   // Only trigger script if the main character leaves the trigger
   if (GetExitingObject() != GetFirstPC()) 
       return;

   // Set area to change music for to the Player's area.
   object oArea = GetArea(GetFirstPC());

   // Get the track that was used before entering trigger area.
   int nMusic = GetLocalNumber(OBJECT_SELF, 1) - 1; 

   // Change back to the old music track.
   MusicBackgroundStop(oArea);
   MusicBackgroundChangeDay(oArea, nMusic);
   MusicBackgroundChangeNight(oArea, nMusic);
   MusicBackgroundPlay(oArea);
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...