View Single Post
Old 01-25-2005, 01:18 PM   #1
tk102
Well past expiration date
 
tk102's Avatar
 
Join Date: Jan 2004
Posts: 5,766
Current Game: Dragon Age: Origins
Forum Veteran Helpful! Notable contributor 
Frequently used script functions

How can I make a creature do something?
Code:
// the some_action is a function that  usually starts with "Action"
AssignCommand(oCreature,some_action)
How can I make something happen after awhile?
Code:
fDelayInSeconds=2.0;
DelayCommand(fDelayInSeconds,some_action);
How can I script an object into a container?
Code:
object oItem=CreateItemOnObject( "item_template", GetObjectByTag("container_tag"));
How can I script an object into my Inventory?
Code:
object oItem=CreateItemOnObject( "item_template", GetFirstPC());
How can I equip an item by scripting once I have it in my inventory?
Code:
AssignCommand(GetFirstPC(), ActionEquipItem(oItem, nInventorySlot);
How can I spawn an object at a a specific location?
Code:
/* 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?
Code:
// same OBJECT_TYPEs as above

CreateObject( OBJECT_TYPE_CREATURE,
"object_template", GetLocation(GetFirstPC()));
How can I give myself credits?
Code:
GiveGoldToCreature( GetFirstPC(),nAmount);
How can I take credits away from myself?
Code:
TakeGoldFromCreature(nAmount, GetFirstPC());
How can I give myself Light Side or Dark Side points?
Code:
/* Alignments:
ALIGNMENT_DARK_SIDE
ALIGNMENT_LIGHT_SIDE
ALIGNMENT_NEUTRAL */
AdjustAlignment( GetFirstPC(),ALIGNMENT_DARK_SIDE,nAmount);
How can I give myself experience points?
Code:
 // you guessed it...
 GiveXPToCreature(GetFirstPC(),nAmount);
How can I multiclass a character into a Jedi?
Code:
/*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?
Code:
void main() {
ActionStartConversation(GetFirstPC(),"dlg_filenamehere");
}
Canderis Edit:
If the above code does not work try defining the npc who will be talking:
Code:
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?
Code:
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

Give a new feat to a creature:
Code:
// 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:

Code:
// 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:
Code:
// 850
// ChangeObjectAppearance
// oObjectToChange = Object to change appearance of
// nAppearance = appearance to change to (from appearance.2da)
void ChangeObjectAppearance( object oObjectToChange, int nAppearance );
Adjust attributes:
Code:
 
// 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:
Code:
// 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);

Last edited by Canderis; 06-28-2013 at 03:25 PM. Reason: Added an alternate code
tk102 is offline   you may: quote & reply,