lfnetwork.com mark read register faq members calendar

Thread: become hostile script.
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 08-12-2007, 10:56 AM   #1
Darth Balor
Junior Member
 
Darth Balor's Avatar
 
Join Date: Sep 2006
Location: Malachor V
Posts: 295
become hostile script.

I need a script to make a character attack that can be fired by dialoge

Also how do you get dialoge to fire when the NPC see's you insted of having to click him.

Darth Balor is offline   you may: quote & reply,
Old 08-12-2007, 11:46 AM   #2
stoffe
Network Caretaker
 
stoffe's Avatar
 
Status: Administrator
Join Date: Apr 2002
Posts: 5,833
Helpful! 10 year veteran! Notable contributor 
Quote:
Originally Posted by Darth Balor
I need a script to make a character attack that can be fired by dialog
If this is for KOTOR 2 you can do something like this:
Code:
// ST:  st_a_attack.nss

// ST: Needs the AI include files from scripts.bif to compile.
#include "k_inc_generic"

void Attack(object oTarget=OBJECT_INVALID);


// ST: Main function
void main() {
    object oVictim = GetObjectByTag(GetScriptStringParameter());

    DelayCommand(0.5, Attack(oVictim));
}


// ST: Support function, go hostile and attack.
void Attack(object oTarget=OBJECT_INVALID) {
    if (!GetIsObjectValid(oTarget)) {
        oTarget = GetFirstPC();
    }

    // ST: Turn hostile if not already that
    if (!GetIsEnemy(oTarget)) {
        if (IsObjectPartyMember(oTarget)) {
            ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE_1);
        }
        else {
            int iFac = GetStandardFaction(oTarget);
            if ((iFac == STANDARD_FACTION_HOSTILE_1) || (iFac == STANDARD_FACTION_HOSTILE_2)) {
                ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_FRIENDLY_1);
            }
            else {
                ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE_1);
            }
        }
    }

    // ST: Start combat against the victim
    GN_DetermineCombatRound(oTarget);
}
Set the String Param field for the script of the dialog node to the Tag of the NPC the dialog owner should attack, or leave it blank to make him/her attack the player character.

Quote:
Originally Posted by Darth Balor
Also how do you get dialoge to fire when the NPC see's you insted of having to click him.
You can either give the NPC a custom OnPerception event script that initiates dialog when the player is spotted, or, if the NPC always is in the same location, you can place a trigger that starts the conversation when the player trips it.

Here is an example of an OnPerception event script that would start conversation with the player as soon as the NPC sees them for the first time:
Code:
void main() {
    if (!GetLocalBoolean(OBJECT_SELF, 40)
        && GetLastPerceptionSeen()
        && (GetFirstPC() == GetLastPerceived()))
    {
        ClearAllActions();
        SetLocalBoolean(OBJECT_SELF, 40, TRUE);
        ActionStartConversation(GetFirstPC(), "", FALSE, CONVERSATION_TYPE_CINEMATIC, TRUE);
    }
    else {
        ExecuteScript("k_ai_master", OBJECT_SELF, 1002);
    }
}


Last edited by stoffe; 08-12-2007 at 12:14 PM.
stoffe is offline   you may: quote & reply,
Old 08-12-2007, 12:45 PM   #3
Darth Balor
Junior Member
 
Darth Balor's Avatar
 
Join Date: Sep 2006
Location: Malachor V
Posts: 295
Quote:
// ST: Needs the AI include files from scripts.bif to compile.
What does that mean?

Ok I'm still having problems.

What I'm trying to do is.

*Have NPC spawn in, walk to pc when spotted(works fine)
*NPC start dialoge when sees PC(doesn't work, I have to select the NPC to initiate dialoge!)
*NPC become hostile after the last dialoge node.(doesn't work)
I was trying to use one script to have him spawn, walk to, and intiate dialoge. spawning and walking works, but he doesn't begin dialoge.
and at the end of the dialoge he doesn't become hostile. also i tried using you'r onPerception script to no avail.

script for spawning
Code:
void main() 
{
//do a whereami cheat to get the coordinates of the location 
//where you want the npc to spawn
float x=0.28780;  
float y=-46.47008;
float z=11.00560;
//unless you want something specific, forget about orientation
float r=0.00;
vector vecNPC=Vector(x,y,z);
location locNPC=Location(vecNPC, r);
 //insert your npc tag instead of my_creature_resref. Don't remove the quotes and do not exceed 16 chars.
object oNPC=CreateObject(OBJECT_TYPE_CREATURE,"g_201thug",locNPC);
object oPC=GetFirstPC();
AssignCommand(oNPC,ActionMoveToObject(oPC));
//replace my_dlg by the name of the dlg file the npc is supposed to use
AssignCommand(oNPC,ActionStartConversation(oPC,"durothug"));
}
become hostile script.
Code:
// ST:  st_a_attack.nss

// ST: Needs the AI include files from scripts.bif to compile.
#include "k_inc_generic"

void Attack(object oTarget=OBJECT_INVALID);


// ST: Main function
void main() {
    object oVictim = GetObjectByTag(GetScriptStringParameter());

    DelayCommand(0.5, Attack(oVictim));
}


// ST: Support function, go hostile and attack.
void Attack(object oTarget=OBJECT_INVALID) {
    if (!GetIsObjectValid(oTarget)) {
        oTarget = GetFirstPC();
    }

    // ST: Turn hostile if not already that
    if (!GetIsEnemy(oTarget)) {
        if (IsObjectPartyMember(oTarget)) {
            ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE_1);
        }
        else {
            int iFac = GetStandardFaction(oTarget);
            if ((iFac == STANDARD_FACTION_HOSTILE_1) || (iFac == STANDARD_FACTION_HOSTILE_2)) {
                ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_FRIENDLY_1);
            }
            else {
                ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE_1);
            }
        }
    }

    // ST: Start combat against the victim
    GN_DetermineCombatRound(oTarget);
}


Last edited by Darth Balor; 08-12-2007 at 02:20 PM.
Darth Balor is offline   you may: quote & reply,
Old 08-12-2007, 03:06 PM   #4
Mindtwistah
Junior Member
 
Mindtwistah's Avatar
 
Join Date: Apr 2007
Location: Derka Derka
Posts: 470
Why the long script? You can just use this:

Code:
void main()
{
ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE_1);
}
Although I have only used it in K1, it should work in TSL to.


Mindtwistah is offline   you may: quote & reply,
Old 08-12-2007, 03:27 PM   #5
Darth Balor
Junior Member
 
Darth Balor's Avatar
 
Join Date: Sep 2006
Location: Malachor V
Posts: 295
Well apparently it does with a little altering.

Darth Balor is offline   you may: quote & reply,
Old 08-12-2007, 04:39 PM   #6
stoffe
Network Caretaker
 
stoffe's Avatar
 
Status: Administrator
Join Date: Apr 2002
Posts: 5,833
Helpful! 10 year veteran! Notable contributor 
Quote:
Originally Posted by Darth Balor
I was trying to use one script to have him spawn, walk to, and intiate dialoge. spawning and walking works, but he doesn't begin dialoge.
and at the end of the dialoge he doesn't become hostile. also i tried using you'r onPerception script to no avail.
If I understand you correctly things should happen in separate stages, so it's best to use separate scripts for it, IMO. So, if I understand correctly you want this to happen?
  1. The NPC spawns into the area and just waits around until the player happens to come by.
  2. Whenever the player gets within sight of the NPC, move to them and start conversation.
  3. At the end of the conversation, attack the player.


Quote:
Originally Posted by Darth Balor
*Have NPC spawn in, walk to pc when spotted(works fine)
I assume the NPC should hang around the area to begin with, waiting for the player to come close? If so you'd spawn it in with a script from somewhere (another dialog, Area OnEnter event script, whatever) like:

st_spawnthug.nss
Code:
#include "st_inc_util"

void main() {
    ST_SpawnNPC("g_201thug", 0.29, -46.47);
}
Quote:
Originally Posted by Darth Balor
*NPC start dialoge when sees PC(doesn't work, I have to select the NPC to initiate dialoge!)
A more specialized variant of the OnPerception AI script should work for this. Compile it and in then open the UTC template of the NPC with KotorTool, go to the scripts tab and set the name of the script in the OnNotice box (st_ai_thugperc in the below example since the script is called st_ai_thugperc.ncs). This assumes that durothug.dlg is the dialog file to use.

st_ai_thugperc.nss
Code:
void main() {
    object oPC = GetFirstPC();
    if (!GetLocalBoolean(OBJECT_SELF, 140)
        && GetLastPerceptionSeen()
        && (oPC == GetLastPerceived()))
    {
        SetLocalBoolean(OBJECT_SELF, 140, TRUE);
        SetLocalBoolean(OBJECT_SELF, 87, TRUE);
        ClearAllActions();
        ActionForceMoveToObject(oPC, TRUE);
        ActionDoCommand(SetLocalBoolean(OBJECT_SELF, 87, FALSE));
        ActionStartConversation(oPC, "durothug");
    }
    else if (!GetLocalBoolean(OBJECT_SELF, 87)) {
        ExecuteScript("k_ai_master", OBJECT_SELF, 1002);
    }
}
Quote:
Originally Posted by Darth Balor
*NPC become hostile after the last dialoge node.(doesn't work)
Set the name of a script like compiled from the below example as action script on the last dialog node after which the NPC should attack.

st_ai_thugperc.nss
Code:
#include "st_inc_util"

void main() {
    ST_Attack();
}
(Or in this case you could just use the standard script a_atkonend that comes with the game already which does pretty much the same thing for this purpose. )




The above scripts require a file named st_inc_util.nss to be present in the override folder (if you use KotorTool's script compiler to produce the NCS files) to work, whose content (the relevant parts of it anyway) should look like:

Excerpt from include file: st_inc_util.nss
Code:
#include "k_inc_generic"

object ST_SpawnNPC(string sResRef, float x, float y, float fAngle = 0.0);
void   ST_Attack(object oTarget=OBJECT_INVALID);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Wrapper function: Spawn NPCs into the game a bit quicker
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
object ST_SpawnNPC(string sResRef, float x, float y, float fAngle = 0.0) {
    return CreateObject(OBJECT_TYPE_CREATURE, sResRef, Location(Vector(x, y, 0.0), fAngle));
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: Support function, make caller go hostile to oTarget and attack them.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ST_Attack(object oTarget=OBJECT_INVALID) {
    if (!GetIsObjectValid(oTarget)) {
        oTarget = GetFirstPC();
    }

    // ST: Turn hostile if not already that
    if (!GetIsEnemy(oTarget)) {
        if (IsObjectPartyMember(oTarget)) {
            ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE_1);
        }
        else {
            int iFac = GetStandardFaction(oTarget);
            if ((iFac == STANDARD_FACTION_HOSTILE_1) || (iFac == STANDARD_FACTION_HOSTILE_2)) {
                ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_FRIENDLY_1);
            }
            else if ((iFac == STANDARD_FACTION_FRIENDLY_1) || (iFac == STANDARD_FACTION_FRIENDLY_2)) {
                ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE_1);
            }
            else {
                ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_GIZKA_1);
                ChangeToStandardFaction(oTarget, STANDARD_FACTION_GIZKA_2);
            }
        }
    }

    // ST: Start combat against the victim
    GN_DetermineCombatRound(oTarget);
}

Quote:
Originally Posted by Mindtwistah
Why the long script?
To make a generic, multipurpose script that you can reuse later in any number of similar situations (to make an NPC attack any other NPC or the player in this case) without any changes to the script itself. It may be more work initially, but if you do a lot of scripting you won't have to re-invent the wheel over and over if you make yourself a collection of generic dialog conditional/action scripts for common operations, and a set of include files with reusable, generic utility functions for common, often needed situations and tasks.

In the examples I used above I have an utility include file, st_inc_util.nss, which contains a bunch of custom made generic functions for various tasks such as spawning NPCs, initiating combat, making NPCs turn and move around, party management, healing, manipulating effects and force powers etc. As seen it reduces the whole "spawn an NPC" and "attack a target" scripts to one fairly short line whenever you need to do that as long as you just include your utility include file.

(That, and I tend to like convoluted solutions to simple problems )


Last edited by stoffe; 08-23-2007 at 04:21 PM.
stoffe is offline   you may: quote & reply,
Old 08-12-2007, 06:24 PM   #7
Darth Balor
Junior Member
 
Darth Balor's Avatar
 
Join Date: Sep 2006
Location: Malachor V
Posts: 295
Yes it works. thanks.

Darth Balor is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Knights of the Old Republic > Editing / Modding > Holowan Laboratories > become hostile script.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:49 PM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.