Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Frequently used script functions

Page: 1 of 1
 tk102
01-25-2005, 1:18 PM
#1
How can I make a creature do something?

// the some_action is a function that usually starts with "Action"
AssignCommand(oCreature,some_action)
How can I make something happen after awhile?

fDelayInSeconds=2.0;
DelayCommand(fDelayInSeconds,some_action);
How can I script an object into a container?
object oItem=CreateItemOnObject( "item_template", GetObjectByTag("container_tag"));
How can I script an object into my Inventory?
object oItem=CreateItemOnObject( "item_template", GetFirstPC());
How can I equip an item by scripting once I have it in my inventory?
AssignCommand(GetFirstPC(), ActionEquipItem(oItem, nInventorySlot);
How can I spawn an object at a a specific location?

/* Possible Object types:
OBJECT_TYPE_CREATURE
OBJECT_TYPE_ITEM
OBJECT_TYPE_TRIGGER
OBJECT_TYPE_DOOR
OBJECT_TYPE_WAYPOINT
OBJECT_TYPE_PLACEABLE
OBJECT_TYPE_STORE */

// for the 3 floats in the function below
// you can use the X, Y, Z coordintates from
// the whereami cheat code
vector vPosition=Vector(0.0, 0.0, 0.0);

location lWhereToSpawn=Location(vPosition,0.0);

CreateObject( OBJECT_TYPE_CREATURE,
"object_template",lWhereToSpawn);

How can I create an object right next to me?

// same OBJECT_TYPEs as above

CreateObject( OBJECT_TYPE_CREATURE,
"object_template", GetLocation(GetFirstPC()));
How can I give myself credits?
GiveGoldToCreature( GetFirstPC(),nAmount);
How can I take credits away from myself?
TakeGoldFromCreature(nAmount, GetFirstPC());
How can I give myself Light Side or Dark Side points?
/* Alignments:
ALIGNMENT_DARK_SIDE
ALIGNMENT_LIGHT_SIDE
ALIGNMENT_NEUTRAL */
AdjustAlignment( GetFirstPC(),ALIGNMENT_DARK_SIDE,nAmount);

How can I give myself experience points?

// you guessed it...
GiveXPToCreature(GetFirstPC(),nAmount);
How can I multiclass a character into a Jedi?
/*possible classes:
CLASS_TYPE_SOLDIER
CLASS_TYPE_SCOUT
CLASS_TYPE_SCOUNDREL
CLASS_TYPE_JEDIGUARDIAN
CLASS_TYPE_JEDICONSULAR
CLASS_TYPE_JEDISENTINEL
CLASS_TYPE_COMBATDROID
CLASS_TYPE_EXPERTDROID
CLASS_TYPE_MINION */

AddMultiClass( CLASS_TYPE_JEDIGUARDIAN, GetObjectByTag("Mission"));

How can I start a basic conversation?
void main() {
ActionStartConversation(GetFirstPC(),"dlg_filenamehere");
}

Canderis Edit:
If the above code does not work try defining the npc who will be talking:
void main()
{
object oNPC=GetObjectByTag("npc_tag");
AssignCommand ((oNPC), ActionStartConversation(GetFirstPC(),"npc_tag"));

}

How can I make an NPC walk up to me and start a conversation?

void main() {
object oNPC=GetObjectByTag("npc_tag");
location lMe=GetLocation(GetFirstPC());
ActionDoCommand(SetCommandable(TRUE,oNPC));
AssignCommand (oNPC,ActionForceMoveToLocation(lMe,FALSE));
AssignCommand (oNPC, ActionStartConversation(GetFirstPC()));
}


===============================
Kotor 2: TSL only - new practical functions:

* those functions can help you avoid .utc file conflicts that will crash the game or prevent plot advancement as explained in this thread (http://www.lucasforums.com/editpost.php?s=&action=editpost&postid=1765880)

Give a new feat to a creature:

// DJS-OEI 1/13/2004
// 786: Grants the target a feat without regard for prerequisites.
void GrantFeat( int nFeat, object oCreature );

Give a new Force power to a Creature:


// DJS-OEI 1/13/2004
// 787: Grants the target a spell without regard for prerequisites.
void GrantSpell( int nSpell, object oCreature );
Change the appearance of a creature:

// 850
// ChangeObjectAppearance
// oObjectToChange = Object to change appearance of
// nAppearance = appearance to change to (from appearance.2da)
void ChangeObjectAppearance( object oObjectToChange, int nAppearance );


Adjust attributes:
// 833
// AWD-OEI 7/06/2004
// This function adjusts a creatures stats.
// oObject is the creature that will have it's attribute adjusted
// The following constants are acceptable for the nAttribute parameter:
// ABILITY_STRENGTH
// ABILITY_DEXTERITY
// ABILITY_CONSTITUTION
// ABILITY_INTELLIGENCE
// ABILITY_WISDOM
// ABILITY_CHARISMA
// nAmount is the integer vlaue to adjust the stat by (negative values will work).
void AdjustCreatureAttributes(object oObject, int nAttribute, int nAmount);
Adjust skills:
// 869
// DJS-OEI 10/9/2004
// This function adjusts a creature's skills.
// oObject is the creature that will have its skill adjusted
// The following constants are acceptable for the nSkill parameter:
// SKILL_COMPUTER_USE
// SKILL_DEMOLITIONS
// SKILL_STEALTH
// SKILL_AWARENESS
// SKILL_PERSUADE
// SKILL_REPAIR
// SKILL_SECURITY
// SKILL_TREAT_INJURY
// nAmount is the integer value to adjust the stat by (negative values will work).
void AdjustCreatureSkills(object oObject, int nSkill, int nAmount);
 Darth333
01-26-2005, 9:02 AM
#2
Originally posted by tk102
How can I give myself Light Side or Dark Side points?
/* Alignments:
ALIGNMENT_DARK_SIDE
ALIGNMENT_LIGHT_SIDE
ALIGNMENT_NEUTRAL */
AdjustAlignment( GetFirstPC(),ALIGNMENT_DARK_SIDE,nAmount);

Here is a shortcut to give DS or LS points - jst refer to these scripts in the .dlg file

KotOR
*- for ds points:

k_act_darksml
k_act_darkmed
k_act_darkhigh

*- for ls points:
k_act_lightghigh
k_act_lightmed
k_act_lightsml

TSL
*- for ds points:
a_darkhigh
a_darkmed
a_darksml

*- for ls points:
a_lighthigh
a_lightmed
a_lightsml

the TSL scripts got nuked when the server "burped" ;) - ChAiNz.2da
Page: 1 of 1