Author Topic: Small Script Request...  (Read 417 times)

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Small Script Request...
« on: August 31, 2011, 04:13:22 pm »


               I don't know which event to use, never really messed around much with NPC events..

Basically I want to, when a PC clicks on a NPC (to talk to them), that the NPC speks a line, and then attacks the PC after X seconds (Probably 3.0 seconds).

I need the default even scripting as part of the script too, so I know where to place it in my script, again don't know which event script to place it in, sorry.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Small Script Request...
« Reply #1 on: August 31, 2011, 04:27:03 pm »


               NPC wont fire any event OnClick but if you click on NPC your character move towards this NPC (unless close already) and try to speak with it which fires OnConversation event. See more in lexicon but its doable in this event very well.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Small Script Request...
« Reply #2 on: September 01, 2011, 12:18:59 am »


               Yeah just do an action taken on the first Npc conversation line.  ChangeToStandrdFactionHostile
and then ActionAttack oPC previously defined as GetPCSpeaker or just use that.  Slap a delay command in front of that action attack.  That is if you want the PC to get a slight warning, i.e. the Npc will turn red just before they attack.  Of course you could also give a hint by having the Npc say something insulting to the PC.  Like 'Why the heck are you bothering me, hey you're the guy/gal who killed my brother.'
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Small Script Request...
« Reply #3 on: September 01, 2011, 01:48:04 am »


               That's the way I set it up, but I want the NPC to just speak the line... not start a conversation..

Is that possible?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Small Script Request...
« Reply #4 on: September 01, 2011, 02:21:50 am »


               

_Guile wrote...

That's the way I set it up, but I want the NPC to just speak the line... not start a conversation..

Is that possible?


NoBody said anything about startibg a conversation.    You asked what event fires when a PC clicks on an NPC, The answer was given.    The OnConversation event fires.   That is not a conversation, It is the event on the NPC that fires.  
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Small Script Request...
« Reply #5 on: September 01, 2011, 03:34:15 am »


               

Lightfoot8 wrote...

NoBody said anything about starting a conversation.    You asked what event fires when a PC clicks on an NPC, The answer was given.    The OnConversation event fires.   That is not a conversation, It is the event on the NPC that fires.  


Let me restate the question for you then...

How do I script the NPC to speak a line and then attack the PC, from that event (OnConversation)?


This was my original request...

_Guile wrote...
Basically
I want to, when a PC clicks on a NPC (to talk to them), that the
NPC speks a line, and then attacks the PC after X seconds (Probably 3.0
seconds).

I need the default even scripting as part of the script
too, so I know where to place it in my script, again don't know which
event script to place it in, sorry.


In case you missed that part...
               
               

               


                     Modifié par _Guile, 01 septembre 2011 - 02:36 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Small Script Request...
« Reply #6 on: September 01, 2011, 04:12:56 am »


               //OnConversation
#include "nw_i0_generic"
void main()
{
    object oPC = GetLastSpeaker();
    ActionSpeakString("Who do you think you're talking to punk!?");
    DelayCommand(3.0, DetermineCombatRound(oPC));
}

And then probably just throw in an ExecuteScript line somewhere in there to execute the default converersation script if you need it to.
               
               

               


                     Modifié par GhostOfGod, 01 septembre 2011 - 03:17 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Small Script Request...
« Reply #7 on: September 01, 2011, 04:40:40 am »


               Ty sir. '<img'>
               
               

               
            

Legacy_Aradan Kir

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
Small Script Request...
« Reply #8 on: September 01, 2011, 09:09:30 am »


               As I recently discovered, you'll need to put something at the start of your script that gets called OnConversation, else any speech anywhere near the NPC that it hears (ie two PCs speaking, or even just one PC talking to themselves) will fire the OnConversation event, and the NPC will attack.  Which is perhaps not what you want.

Lightfoot's suggested way around this, which should help:

Lightfoot8 wrote...

You neeed to filter what runs in the script using Function - GetListenPatternNumber .
If the event is ran by clicking on the npc the function will return a
value of -1.   If it is ran by hearing someone speak it will return a
valid listening pattern number.


So, this at the start of your script would allow only a click on an NPC to initiate the rest of your script:

// if the conversation is not via a Click to start a conversation (ie it's just overheard), exit script
int nMatch = GetListenPatternNumber();
if(nMatch != -1)
   { return; }
               
               

               


                     Modifié par aradankir, 01 septembre 2011 - 08:11 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Small Script Request...
« Reply #9 on: September 01, 2011, 10:19:52 am »


               

aradankir wrote...

As I recently discovered, you'll need to put something at the start of your script that gets called OnConversation, else any speech anywhere near the NPC that it hears (ie two PCs speaking, or even just one PC talking to themselves) will fire the OnConversation event, and the NPC will attack.  Which is perhaps not what you want.

Lightfoot's suggested way around this, which should help:

Lightfoot8 wrote...

You neeed to filter what runs in the script using Function - GetListenPatternNumber .
If the event is ran by clicking on the npc the function will return a
value of -1.   If it is ran by hearing someone speak it will return a
valid listening pattern number.


So, this at the start of your script would allow only a click on an NPC to initiate the rest of your script:

// if the conversation is not via a Click to start a conversation (ie it's just overheard), exit script
int nMatch = GetListenPatternNumber();
if(nMatch != -1)
   { return; }


Are you sure this isn't only when using the listening patern functions. I just tested with above script by walking around the npc and chatting up a storm. He just stood there...until I clicked on him. I even added the ExecuteScript line with the default conversation script and then started chit chatn with myself and nothing.
               
               

               


                     Modifié par GhostOfGod, 01 septembre 2011 - 09:27 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Small Script Request...
« Reply #10 on: September 01, 2011, 07:31:12 pm »


               Works perfectly ghost, thanks. '<img'>


I would think GetListeningPatter() would actually tell the NPC to listen, which I spoke with the NPC nearby, nothing happened, but the moment I click on her, she spoke and then attacked me. '<img'>
               
               

               


                     Modifié par _Guile, 01 septembre 2011 - 06:33 .
                     
                  


            

Legacy_Aradan Kir

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
Small Script Request...
« Reply #11 on: September 01, 2011, 08:58:28 pm »


               Could be that the NPCs I was edited are set to listen, so causing the issue.  Guess if they're not then you don't need to check for it and code against it.

Interesting ... will need to check that out
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Small Script Request...
« Reply #12 on: September 01, 2011, 09:30:42 pm »


               

aradankir wrote...

Could be that the NPCs I was edited are set to listen, so causing the issue. Guess if they're not then you don't need to check for it and code against it.

Interesting ... will need to check that out


You may want to read the last post I made in your other thread. OnConversation event queries
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Small Script Request...
« Reply #13 on: September 02, 2011, 04:38:33 am »


               

aradankir wrote...

Could be that the NPCs I was edited are set to listen, so causing the issue.  Guess if they're not then you don't need to check for it and code against it.

Interesting ... will need to check that out


Well if you SetListeningPatter() then yeah, the NPC will be listening, but I don't remember on hand which event you do that in (maybe OnSpawn?)