Jump to content

How do I code my NPC going hostile?


Guest Keldon

Recommended Posts

Maybe this might help. I've got some script that I use to turn an NPC hostile under very specific conditions. She's a spell-caster, so her code gets fairly complicated fairly quickly, but there are some other bits of code I can pinch from somewhere else that might tie it together.

 

Here it is, line by line:

 

IF
 Global("B!NeutralValeria","LOCALS",0) //the NPC is still neutral. She has not yet been spoken to.
 OR(6)
See(Player1) //If she sees anyone in the party
See(Player2)
See(Player3)
See(Player4)
See(Player5)
See(Player6)
THEN
 RESPONSE #100  //This is the only response she will have
SetGlobal("B!NeutralValeria","LOCALS",1) //Ensures that this block will only run once, preventing script loops
StartDialog("B!VALER",Player1) //Valeria, the NPC in question, will initiate dialogue with Player1. She will not approach the NPC, and she will speak from a distance. Most of the time when you use StartDialogueNoSet(Player1), the NPC will approach the PC to start conversation. I wanted her to stay where she was. Her dialogue file is B!VALER.dlg
END

IF
 Global("B!QuestAttack2Floor","GLOBAL",1) //this variable gets set during the course of dialogue
THEN
 RESPONSE #100
SetGlobal("B!QuestAttack2Floor","GLOBAL",2) //closes the variable, preventing script loops
Enemy() // Changes her to a red circle.
END

 

This next bit isn't actually her code, since she's a spellcaster, but if she were a fighter, this would do it.

 

IF
Global("B!QuestAttack2Floor","GLOBAL",2) //she's an enemy, and the fight is begun
THEN
RESPONSE #100
SetGlobal("B!QuestAttack2Floor","GLOBAL",3) //prevents looping
Attack(Player1)  //no quotes, because Player1 never gets them
Continue()  //keeps the script running
END

Note that the Continue() is needed to keep reading script after this point, but until this block is resolved, i.e. combat is over, you will not be able to check for the B!QuestAttack2Floor variable value at 3.

 

It might also help you to see the dialogue that gets the whole thing moving:

IF ~Global("B!WhyAreYouStillHere","GLOBAL",1)~ THEN BEGIN BWhyAreYouStillHere
SAY ~Why are you still here? Can it be that you are determined to provoke me? You have succeeded. If you will not leave, then you will die!~
IF ~~ THEN DO ~SetGlobal("B!QuestAttack2Floor","GLOBAL",1)~ EXIT
END

Link to comment

Hello,

 

Ok, here is the coding I have to tell my NPC to go hostile and attack the PC, but instead she just goes hostile and refuses to attack or defend herself.

 

// this is the stuff in the .d

 

IF ~~ wannajoin

SAY ~she says bla bla.~

= ~she says bla bla!~

= ~she says bla bla.~

++ ~haha! you suck too bad to join me.~ + youdie

++ ~ok.~ + LikeYou

++ ~How good are you?~ + ok

END

 

IF ~~ youdie

SAY ~she says bla bla.~

= ~she says bla bla~

= ~she says bla bla!~

IF ~~ THEN DO ~Enemy()~ EXIT

END

 

 

this is the stuff in .baf (in NPCName folder)

 

IF

See(NearestEnemyOf())

THEN

RESPONSE #100

Attack(NearestEnemyOf())

END

 

 

 

Any idea what is wrong here?

 

Thank you

Keldon :)

Link to comment

Hello Berelinde and Miloch,

 

I want to say that I really am very appreciative of the help you are giving me.

Both of you last posts I believe will help me a lot.

I added what Miloch suggested to the TP2 and it installed no prob.

It took me a while to understand Berelinde's suggestion, but now I think I do and will be adding that tonight. Hopefully.

I will let you guys know how this works out.

 

Keldon :)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...