You are here

Need help with script - NPC to not move

3 posts / 0 new
Last post
andgalf
Need help with script - NPC to not move

Maybe I should have posted this in the Toolset forum. I don't know. However, it is a script issue I believe.

I have a situation where I want to start a conversation when the PC sits down on a chair. The NPC is already sitting on a chair. It almost works at the moment, however when the conversation starts the NPC moves from the chair and goes to the PC. I would like the NPC to do nothing, I mean to sit still when the conversation starts.

I am using this guy's sittable chairs: https://neverwintervault.org/project/nwn2/script/sit-objects-v176

I use his script that is in the OnUsed slot. I have however added to the end of his script that the conversation shall start when the PC sits on the chair. Here is the script

(The brown-red lines at the end of the scipt is what I added):

 

//::///////////////////////////////////////////////
//:: OnUse: Sit
//:: pat_sitted
//:://////////////////////////////////////////////
/*
    Simple script to make PCs sit on a placeable
*/
//:://////////////////////////////////////////////
//:: Created By: Patcha
//:: Created On: 2006-12-08
//:: v1.76 By: Patcha
//:: v1.73 On: 2007-06-15
//:: dates: aaaa-mm-gg
//:://////////////////////////////////////////////

void ActionPlayCustomAnimation(object oObject, string sAnimationName, int nLooping, float fSpeed = 1.0f)
{
    PlayCustomAnimation(oObject, sAnimationName, nLooping, fSpeed);
}

// float GetNormalizedDirection(float fDirection):
// * This script returns a direction normalized to the range 0.0 - 360.0
// * Copyright (c) 2002 Floodgate Entertainment
// * Created By: Naomi Novik
// * Created On: 11/08/2002
float GetNormalizedDirection(float fDirection)
{
    float fNewDir = fDirection;
    while (fNewDir >= 360.0) {
        fNewDir -= 360.0;
    }
    while (fNewDir <= 0.0) {
        fNewDir += 360.0;
    }

    return fNewDir;
}

void main()
{
    object oChair = OBJECT_SELF;
    object oSitter = GetLastUsedBy();
    object oLastSitter = GetLocalObject(oChair, "lastsitted");
    string sChair = GetTag(oChair);
    string sAutofit = GetLocalString(oChair, "autofit");
    int iHeading  = GetLocalInt(oChair, "degree");
    int iPC_size  = GetLocalInt(oChair, "size");
    //Assign the heading degrees
    location lChair_o = GetLocation(oChair);
    location lChair = Location(GetArea(oChair), GetPositionFromLocation(lChair_o), GetNormalizedDirection(GetFacingFromLocation(lChair_o) + iHeading));
    
    //Check if seat is free
    if(GetDistanceBetween(oLastSitter, oChair) == 0.0f && GetArea(oLastSitter) == GetArea(oChair))
    {
        SetLocalInt(oChair, "taken", 1);
        SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
    }
    else //if seat is free...
    {
        SetLocalInt(oChair, "taken", 0);

        //Check for Character Race with original Creature Size
        switch (iPC_size)
        {
        case 0:
            //Check for Character Race with original Creature Size
            if(    ((GetRacialType(oSitter) == RACIAL_TYPE_ELF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HALFELF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HALFORC) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HUMAN) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetSubRace(oSitter) == RACIAL_SUBTYPE_AASIMAR) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetSubRace(oSitter) == RACIAL_SUBTYPE_TIEFLING) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)))
            {
                if(GetIsObjectValid(oChair) && GetIsObjectValid(oSitter))
                {
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
            }
            else
            {
                if(sAutofit != "")
                {
                    AssignCommand(oChair, SetIsDestroyable(TRUE, FALSE, FALSE));
                    AssignCommand(oSitter, DestroyObject(oChair));
                    oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_low_" + sAutofit, lChair_o, FALSE, sChair);
                    if(!(GetIsObjectValid(oChair)))
                        oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_low_stool01", lChair_o, FALSE, sChair);
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalString(oChair, "autofit", sAutofit);
                    SetLocalInt(oChair, "degree", iHeading);
                    SetLocalInt(oChair, "size", 1);
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
                else
                SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
            }
            break;

        case 1:
            //Check for Character Race with original Creature Size
            if(    ((GetRacialType(oSitter) == RACIAL_TYPE_DWARF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_GNOME) && (GetCreatureSize(oSitter) == CREATURE_SIZE_SMALL)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HALFLING) && (GetCreatureSize(oSitter) == CREATURE_SIZE_SMALL)))
            {
                if(GetIsObjectValid(oChair) && GetIsObjectValid(oSitter))
                {
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
            }
            else
            {
                if(sAutofit != "")
                {
                    AssignCommand(oChair, SetIsDestroyable(TRUE, FALSE, FALSE));
                    AssignCommand(oSitter, DestroyObject(oChair));
                    oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_mid_" + sAutofit, lChair_o, FALSE, sChair);
                    if(!(GetIsObjectValid(oChair)))
                        oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_mid_stool01", lChair_o, FALSE, sChair);
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalString(oChair, "autofit", sAutofit);
                    SetLocalInt(oChair, "degree", iHeading);
                    SetLocalInt(oChair, "size", 0);
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
                else
                SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
            }
            break;

        default:
            //Character with no original Race and/or Creature size
            SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
            break;
        }
        object oPC = GetLastUsedBy();

        if (!GetIsPC(oPC)) return;

        object oTarget;
        oTarget = GetObjectByTag("Athine");

        AssignCommand(oTarget, ActionStartConversation(oPC, "athine_conv_sit"));


    }
}



   Is there a way to make the NPC, her name is Athine in this case, to not move and go to the PC, but instead remain on the chair? I tried with replacing the oTarget to the tag of the chair that the PC sits on but that made him sit in the air instead (even if the NPC doesn't move and that's great). My guess is that it has to do with him talking to his own chair, and that's why the game make him move from the chair into the air beside him instead...
But...I also tried changing the oTarget to the tag of the chair of the NPC. Weirdly enough that makes the PC also sit on thin air instead.

  

  • up
    50%
  • down
    50%
andgalf

I actually managed to solve it on my own! smiley

I used the oTarget tag of the chair of the NPC. Then I used the DelayCommand and then it worked. So the script looked like this in the end:

 

//::///////////////////////////////////////////////
//:: OnUse: Sit
//:: pat_sitted
//:://////////////////////////////////////////////
/*
    Simple script to make PCs sit on a placeable
*/
//:://////////////////////////////////////////////
//:: Created By: Patcha
//:: Created On: 2006-12-08
//:: v1.76 By: Patcha
//:: v1.73 On: 2007-06-15
//:: dates: aaaa-mm-gg
//:://////////////////////////////////////////////

void ActionPlayCustomAnimation(object oObject, string sAnimationName, int nLooping, float fSpeed = 1.0f)
{
    PlayCustomAnimation(oObject, sAnimationName, nLooping, fSpeed);
}

// float GetNormalizedDirection(float fDirection):
// * This script returns a direction normalized to the range 0.0 - 360.0
// * Copyright (c) 2002 Floodgate Entertainment
// * Created By: Naomi Novik
// * Created On: 11/08/2002
float GetNormalizedDirection(float fDirection)
{
    float fNewDir = fDirection;
    while (fNewDir >= 360.0) {
        fNewDir -= 360.0;
    }
    while (fNewDir <= 0.0) {
        fNewDir += 360.0;
    }

    return fNewDir;
}

void main()
{
    object oChair = OBJECT_SELF;
    object oSitter = GetLastUsedBy();
    object oLastSitter = GetLocalObject(oChair, "lastsitted");
    string sChair = GetTag(oChair);
    string sAutofit = GetLocalString(oChair, "autofit");
    int iHeading  = GetLocalInt(oChair, "degree");
    int iPC_size  = GetLocalInt(oChair, "size");
    //Assign the heading degrees
    location lChair_o = GetLocation(oChair);
    location lChair = Location(GetArea(oChair), GetPositionFromLocation(lChair_o), GetNormalizedDirection(GetFacingFromLocation(lChair_o) + iHeading));
    
    //Check if seat is free
    if(GetDistanceBetween(oLastSitter, oChair) == 0.0f && GetArea(oLastSitter) == GetArea(oChair))
    {
        SetLocalInt(oChair, "taken", 1);
        SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
    }
    else //if seat is free...
    {
        SetLocalInt(oChair, "taken", 0);

        //Check for Character Race with original Creature Size
        switch (iPC_size)
        {
        case 0:
            //Check for Character Race with original Creature Size
            if(    ((GetRacialType(oSitter) == RACIAL_TYPE_ELF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HALFELF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HALFORC) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HUMAN) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetSubRace(oSitter) == RACIAL_SUBTYPE_AASIMAR) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetSubRace(oSitter) == RACIAL_SUBTYPE_TIEFLING) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)))
            {
                if(GetIsObjectValid(oChair) && GetIsObjectValid(oSitter))
                {
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
            }
            else
            {
                if(sAutofit != "")
                {
                    AssignCommand(oChair, SetIsDestroyable(TRUE, FALSE, FALSE));
                    AssignCommand(oSitter, DestroyObject(oChair));
                    oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_low_" + sAutofit, lChair_o, FALSE, sChair);
                    if(!(GetIsObjectValid(oChair)))
                        oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_low_stool01", lChair_o, FALSE, sChair);
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalString(oChair, "autofit", sAutofit);
                    SetLocalInt(oChair, "degree", iHeading);
                    SetLocalInt(oChair, "size", 1);
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
                else
                SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
            }
            break;

        case 1:
            //Check for Character Race with original Creature Size
            if(    ((GetRacialType(oSitter) == RACIAL_TYPE_DWARF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_GNOME) && (GetCreatureSize(oSitter) == CREATURE_SIZE_SMALL)) ||
                ((GetRacialType(oSitter) == RACIAL_TYPE_HALFLING) && (GetCreatureSize(oSitter) == CREATURE_SIZE_SMALL)))
            {
                if(GetIsObjectValid(oChair) && GetIsObjectValid(oSitter))
                {
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
            }
            else
            {
                if(sAutofit != "")
                {
                    AssignCommand(oChair, SetIsDestroyable(TRUE, FALSE, FALSE));
                    AssignCommand(oSitter, DestroyObject(oChair));
                    oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_mid_" + sAutofit, lChair_o, FALSE, sChair);
                    if(!(GetIsObjectValid(oChair)))
                        oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_mid_stool01", lChair_o, FALSE, sChair);
                    AssignCommand(oSitter, ActionJumpToLocation(lChair));
                    AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));
                    SetLocalString(oChair, "autofit", sAutofit);
                    SetLocalInt(oChair, "degree", iHeading);
                    SetLocalInt(oChair, "size", 0);
                    SetLocalObject(oChair, "lastsitted", oSitter);
                }
                else
                SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
            }
            break;

        default:
            //Character with no original Race and/or Creature size
            SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);
            break;
        }
        object oPC = GetLastUsedBy();

        if (!GetIsPC(oPC)) return;

        object oTarget;
        oTarget = GetObjectByTag("pat_mid_chairat");

        DelayCommand(1.0, AssignCommand(oTarget, ActionStartConversation(oPC, "athine_conv_sit")));


    }
}

  • up
    50%
  • down
    50%
andysks

I wonder what would happen if you had set the parameter of the NPC to immovable (or something like that). If I remember correctly there is an option to make NPC non bumpable, immovable and perhaps it would be a simpler solution. However, kudos to you for making the script work :D.

  • up
    50%
  • down
    50%