Aller au contenu

Photo

Simple "I see you stealing" script not working


  • Veuillez vous connecter pour répondre
21 réponses à ce sujet

#1
Nasher_AOB

Nasher_AOB
  • Members
  • 35 messages

Hi guys,

 

I just started learning how to script and I'm trying to create one where the owner of the chest/door/locket/etc. will run to the player and start a conversation with him/her if him/her open the flagged chest/door/locket/etc.

 

This work just fine:

//Put this script OnOpen
void main()
{


object oPC = GetLastOpenedBy();


if (!GetIsPC(oPC)) return;


SetLocalInt(oPC, "tenta", 1);


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


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


}

All good, but this means that the owner will run to the player even if he/she is not seeing the PC stealing. I tried something with GetLastPerceived(), but even if the script works and compiles (I know this because the dialog is set to the localInt "tenta" 1 as intended), the owner never runs to the player and starts the dialog.

 

How can I write this so the owner of the chest/door/locket/etc. will only run if he/she sees the PC trying to steal his/her stuff? Thanks!

 



#2
rjshae

rjshae
  • Members
  • 4 491 messages

Can GetObjectSeen be used? The PC should only get away with it if they are not currently visible to the owner.



#3
kamal_

kamal_
  • Members
  • 5 250 messages
http://neverwinterva...ript/prr-3-nwn2
  • rjshae aime ceci

#4
rjshae

rjshae
  • Members
  • 4 491 messages

That project had the wrong game set. I fixed it here:

 

http://neverwinterva...ript/prr-3-nwn2



#5
Tchos

Tchos
  • Members
  • 5 054 messages

As a simple solution, you could just run an opposed spot/hide check at the moment that the chest is opened.



#6
rjshae

rjshae
  • Members
  • 4 491 messages

As a simple solution, you could just run an opposed spot/hide check at the moment that the chest is opened.

 

Spot checks should have a distance modifier, so it may not be so simple to compute.



#7
Nasher_AOB

Nasher_AOB
  • Members
  • 35 messages

I tried the prr-3-nwn2 but as soon the toolset import the erf I get a lot of compile erros: http://postimg.org/image/d4czfzz25/



#8
Nasher_AOB

Nasher_AOB
  • Members
  • 35 messages

I never used GetObjectSeen, and I don't know how to insert it on my script. Can you help on that rjshae?



#9
Dann-J

Dann-J
  • Members
  • 3 161 messages

The x0_i0_position include file contains a function called IsDirectionWithinTolerance() that can be used to check whether one creature is facing another within a specified viewing angle.



#10
rjshae

rjshae
  • Members
  • 4 491 messages

I tried the prr-3-nwn2 but as soon the toolset import the erf I get a lot of compile erros: http://postimg.org/image/d4czfzz25/

 

I'm not sure what's wrong there. Maybe just run a Compile All and see what happens?



#11
kevL

kevL
  • Members
  • 4 061 messages

I never used GetObjectSeen, and I don't know how to insert it on my script.


just like so

void main()
{
    object oPC = GetLastOpenedBy();
    if (!GetIsPC(oPC)) return;

    SetLocalInt(oPC, "tenta", 1);

    object oTarget = GetObjectByTag("c_elf");

    if (GetObjectSeen(oPC, oTarget))
        AssignCommand(oTarget, ActionStartConversation(oPC, "peguei"));
}


#12
Dann-J

Dann-J
  • Members
  • 3 161 messages

GetObjectSeen() should return TRUE If you are within the creature's perception range, and there is nothing blocking line of sight between you and them. I don't know what happens if the creature has been disabled in some way (blinded, stunned, asleep). Those sorts of effects may clear out a creature's visibility list, but unless the creature is hostile then it's unlikely that you can inflict such effects on them yourself (except via script from a conversation node).

 

If you enter stealth mode before coming into their perception range, and they don't spot you, then you should remain unseen as far as that function is concerned.

 

There is also the GetObjectHeard() function, that can be used to see if a creature has at least heard the thief (even if they haven't been seen).

 

Building in a check to see if the creature is currently within the area of effect of a Darkness spell would give tieflings an advantage. :)



#13
rjshae

rjshae
  • Members
  • 4 491 messages

I never used GetObjectSeen, and I don't know how to insert it on my script. Can you help on that rjshae?

 

Selecting the routine in the Script Assist should present a message showing the variables.



#14
Nasher_AOB

Nasher_AOB
  • Members
  • 35 messages


just like so
 

void main()
{
    object oPC = GetLastOpenedBy();
    if (!GetIsPC(oPC)) return;

    SetLocalInt(oPC, "tenta", 1);

    object oTarget = GetObjectByTag("c_elf");

    if (GetObjectSeen(oPC, oTarget))
        AssignCommand(oTarget, ActionStartConversation(oPC, "peguei"));
}

 

Hi KevL,

 

Your script worked just fine. I tried, then, to elaborate it a little bit, giving my NPC an ambient script so he will walk around. If the player is patience enough, he/she can wait until the NPC moves to another room and then open the chest. But your script isn't firing even if the NPC is walking around the PC. I'm using this script OnSpawn of the creature:

 

#include "NW_O2_CONINCLUDE"
#include "NW_I0_GENERIC"

void main()
{
// OPTIONAL BEHAVIORS (Comment In or Out to Activate ) ****************************************************************************
     //SetSpawnInCondition(NW_FLAG_SPECIAL_CONVERSATION);
     //SetSpawnInCondition(NW_FLAG_SPECIAL_COMBAT_CONVERSATION);
                // This causes the creature to say a special greeting in their conversation file
                // upon Perceiving the player. Attach the [NW_D2_GenCheck.nss] script to the desired
                // greeting in order to designate it. As the creature is actually saying this to
                // himself, don't attach any player responses to the greeting.

     //SetSpawnInCondition(NW_FLAG_SHOUT_ATTACK_MY_TARGET);
                // This will set the listening pattern on the NPC to attack when allies call
     //SetSpawnInCondition(NW_FLAG_STEALTH);
                // If the NPC has stealth and they are a rogue go into stealth mode
     //SetSpawnInCondition(NW_FLAG_SEARCH);
                // If the NPC has Search go into Search Mode
     //SetSpawnInCondition(NW_FLAG_SET_WARNINGS);
                // This will set the NPC to give a warning to non-enemies before attacking

     //SetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING);
     SetSpawnInCondition(NW_FLAG_APPEAR_SPAWN_IN_ANIMATION);
     //SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS);
     SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);
                //This will play Ambient Animations until the NPC sees an enemy or is cleared.
                //NOTE that these animations will play automatically for Encounter Creatures.

    // NOTE: ONLY ONE OF THE FOLOOWING ESCAPE COMMANDS SHOULD EVER BE ACTIVATED AT ANY ONE TIME.
    //SetSpawnInCondition(NW_FLAG_ESCAPE_RETURN);    // OPTIONAL BEHAVIOR (Flee to a way point and return a short time later.)
    //SetSpawnInCondition(NW_FLAG_ESCAPE_LEAVE);     // OPTIONAL BEHAVIOR (Flee to a way point and do not return.)
    //SetSpawnInCondition(NW_FLAG_TELEPORT_LEAVE);   // OPTIONAL BEHAVIOR (Teleport to safety and do not return.)
    //SetSpawnInCondition(NW_FLAG_TELEPORT_RETURN);  // OPTIONAL BEHAVIOR (Teleport to safety and return a short time later.)

// CUSTOM USER DEFINED EVENTS
/*
    The following settings will allow the user to fire one of the blank user defined events in the NW_D2_DefaultD.  Like the
    On Spawn In script this script is meant to be customized by the end user to allow for unique behaviors.  The user defined
    events user 1000 - 1010
*/
    //SetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT);        //OPTIONAL BEHAVIOR - Fire User Defined Event 1001
    //SetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT);         //OPTIONAL BEHAVIOR - Fire User Defined Event 1002
    //SetSpawnInCondition(NW_FLAG_ATTACK_EVENT);           //OPTIONAL BEHAVIOR - Fire User Defined Event 1005
    //SetSpawnInCondition(NW_FLAG_DAMAGED_EVENT);          //OPTIONAL BEHAVIOR - Fire User Defined Event 1006
    //SetSpawnInCondition(NW_FLAG_DISTURBED_EVENT);        //OPTIONAL BEHAVIOR - Fire User Defined Event 1008
    //SetSpawnInCondition(NW_FLAG_END_COMBAT_ROUND_EVENT); //OPTIONAL BEHAVIOR - Fire User Defined Event 1003
    //SetSpawnInCondition(NW_FLAG_ON_DIALOGUE_EVENT);      //OPTIONAL BEHAVIOR - Fire User Defined Event 1004
    //SetSpawnInCondition(NW_FLAG_DEATH_EVENT);            //OPTIONAL BEHAVIOR - Fire User Defined Event 1007

// DEFAULT GENERIC BEHAVIOR (DO NOT TOUCH) *****************************************************************************************
    SetListeningPatterns();    // Goes through and sets up which shouts the NPC will listen to.
    WalkWayPoints();           // Optional Parameter: void WalkWayPoints(int nRun = FALSE, float fPause = 1.0)
                               // 1. Looks to see if any Way Points in the module have the tag "WP_" + NPC TAG + "_0X", if so walk them
                               // 2. If the tag of the Way Point is "POST_" + NPC TAG the creature will return this way point after
                               //    combat.
    GenerateNPCTreasure();     //* Use this to create a small amount of treasure on the creature
}

I can't figure out why your script isn't firing if I give this OnSpawn script to my NPC. It works without it =/



#15
kevL

kevL
  • Members
  • 4 061 messages

it's probably the WalkWayPoints() ...

lets add, ClearActions to the GetObjectSeen() scope, and add some debug:


// ...

SendMessageToPC(GetFirstPC(FALSE), "run PCSeen");
if (GetObjectSeen(oPC, oTarget))
{
    SendMessageToPC(GetFirstPC(FALSE), "PC is Seen");

    AssignCommand(oTarget, ClearAllActions());
    AssignCommand(oTarget, ActionStartConversation(oPC, "peguei"));
}


#16
Loki_999

Loki_999
  • Members
  • 430 messages

The x0_i0_position include file contains a function called IsDirectionWithinTolerance() that can be used to check whether one creature is facing another within a specified viewing angle.

 

Goddamn, wish i had known that. When i was creating sneak attack for spells i was using vectors to determine whether the caster could be seen by the target.  Took me ages to figure out the code for that.



#17
Nasher_AOB

Nasher_AOB
  • Members
  • 35 messages

Hey KevL,

 

Again you solved the problem, thanks. I just give it an observation to reset the NPC dialog if oPC is not seen and now it is working like I wanted. In the end I got this:

 

void main()
{
    object oPC = GetLastOpenedBy();
   
    if (!GetIsPC(oPC)) return;
     SetLocalInt(oPC, "tenta", 1);

    object oTarget = GetObjectByTag("c_elf");

    if (!GetObjectSeen(oPC, oTarget))
     SetLocalInt(oPC, "tenta", 0);

       else 

         AssignCommand(oTarget, ClearAllActions());
         AssignCommand(oTarget, ActionStartConversation(oPC, "peguei"));

}

The way it is set, the NPC will always talk to you if you keep opening the chest in front of him/her. Is there a way to prevent this script from firing again after the NPC saw you messing with his goods (after all, he/she is already angry with you)?



#18
kevL

kevL
  • Members
  • 4 061 messages

heya, good to hear. but I want to point out a quirk of your syntax -- in the script above, the conversation will start even if oPC is not seen. It breaks down like so

if (!GetObjectSeen(oPC, oTarget))
{
    SetLocalInt(oPC, "tenta", 0);
}
else
{
    AssignCommand(oTarget, ClearAllActions());
}

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

( spaces and indents don't matter in NwScript, as they do in some other languages ) So the last AssignCommand should be grouped/ scoped within the else{}

if (!GetObjectSeen(oPC, oTarget))
{
    SetLocalInt(oPC, "tenta", 0);
}
else
{
    AssignCommand(oTarget, ClearAllActions());
    AssignCommand(oTarget, ActionStartConversation(oPC, "peguei"));
}


part2: all you need do is set a 'done' condition as a local variable on the chest:
void main()
{
    object oPC = GetLastOpenedBy();

    if (!GetIsPC(oPC)) return;
    if (GetLocalInt(OBJECT_SELF, "bDone") == TRUE) return; // here

    SetLocalInt(oPC, "tenta", 1);

    object oTarget = GetObjectByTag("c_elf");

    if (!GetObjectSeen(oPC, oTarget))
    {
        SetLocalInt(oPC, "tenta", 0);
    }
    else
    {
        SetLocalInt(OBJECT_SELF, "bDone", TRUE); // and here

        AssignCommand(oTarget, ClearAllActions());
        AssignCommand(oTarget, ActionStartConversation(oPC, "peguei"));
    }
}

  • Nasher_AOB aime ceci

#19
Nasher_AOB

Nasher_AOB
  • Members
  • 35 messages

You know, that is really strange. I can guarantee to you that the script is working as intended without those brackets: the NPC only runs towards the PC and talks if he/she sees the PC. But of course I'll do it the right way.

 

Anyway, I'll try your "done" condition and see the results. Thanks for now!



#20
kevL

kevL
  • Members
  • 4 061 messages

the reason it works the wrong way is because the original 'bug' is helping things along

:P


  • Nasher_AOB aime ceci

#21
Nasher_AOB

Nasher_AOB
  • Members
  • 35 messages

You see, things aren't so alien for me now. It's pure logic when you look to this script "tree" and understand the way its read by the game.

 

This script is complete now. Thank you very much for everything!



#22
kevL

kevL
  • Members
  • 4 061 messages

ok

'pleasure