New NPC question

NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Locked
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

New NPC question

Post by Donfrow »

For the most part I tend to be able to find my answers when I'm not looking for them and looking for another answer, but this isn't one I've come across.

How exactly do I get a NPC to actually attack the avatar? I made a goblin, set him to hostile (which won't cause him to attack, just make avatar attack correct?)

Does the usecode for the NPC have to have him set to attack avatar, such as the UI_set_oppressor(Npc's number, avatar's number) ? I managed to get another NPC to attack the avatar after saying something in a conversation by using UI_set_schedule_type and then UI_set_oppressor, but even he wacks the avatar a few times then just walks off (without turning on avatars combat).

This is just adding another NPC to the existing SI world, nothing like a new mod or game but clearly I am missing something simple, can anyone clue me in?

Thanks!
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by marzo »

You have to (a) set the NPC to hostile, (b) put him in the combat schedule and (c) optionally set him to attack a NPC. For example:

Code: Select all

const int AVATAR = -356;
const int IN_COMBAT = 0;
const int HOSTILE = 2;

Goblin_conversation ()
{
    // Assuming that this is called from the goblin's usecode,
    // then 'item' will be the goblin.

    // The conversation goes here...
    // Fast-forwarding to the interesting bits

    set_alignment(HOSTILE);  // Alternativelly, "item->set_alignment(HOSTILE);"
    set_schedule_type(IN_COMBAT);  // Alternativelly, "item->set_schedule_type(IN_COMBAT);"
    set_opponent(AVATAR);  // Alternativelly, "item->set_opponent(AVATAR);"
}
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

Wee it works finally, albeit with a few second delay. I'm sure that's just because my limited experience with programming is from that awesome powerful language known as Turing (yes, that is sarcasm! :P)

One more quick thing... is there something in the list of intrinsics that make it so if you attack a friendly NPC all the other friendly NPC's come to assist? Or is that something else entirely.

Thanks a lot for the help!
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by marzo »

is there something in the list of intrinsics that make it so if you attack a friendly NPC all the other friendly NPC's come to assist?
No, there isn't; Exult does this automatically. And in the few cases where it doesn't (say, because you used usecode to kill an NPC -- for example, the Black Sword's kill power), you have to do it 'manually' by making each nearby NPC attack the party.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by marzo »

Oh, a quick addendum/shameless plug: you can obtain a list (with descriptions) of each and every Exult intrinsic in my website. See the "Usecode C" section for it.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by drcode »

Not sure if it's exactly what you want, but you can call the "attack_avatar" intrinsic from your usecode.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

I must be missing something then, I created a few friendly NPC's and I can walk around and kill them 1 by 1 without the others caring.

On the same vain, I take it there is an intrinsic that makes everyone attack the avatar? I noticed the one for BG for a thieving avatar, but haven't found one that triggers everyone attacking for completing an IF statement. Though, I suppose it could be done by making the above changes to each NPC for the attack mode and target.

And I love your shameless plug! I've been looking for more information all over the place, it's nice to see one that has a bunch in one location! Maybe now I can find out where the scroll/book text is stored haha.

Thanks again Marzo! It's fun to make little changes to the terrain, but it's not much use if you can't do anything other than have the NPC's there talk to you!
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

Well, DrCode sort of got my next question right in there! I did find the attack_avatar but from the description I thought it only had it attack if you are a thief, or does it not actually care about thievery and just makes them attack if called?
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by marzo »

Hey, that is true; I had forgotten about 'attack_avatar'. Hm. Makes me wonder why the U7 devs did it manually for the Black Sword...

Are you creating NPCs with a 'friendly' alignment?
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

As per the intrinsics it says it's for thievery, or does it not actually care about that and it is really just a "gang up and kill him regardless" when it's called?

Yes, they are all set to friendly alignment in the editor.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

Bah I thought I stopped my one post but it went in anyway, sorry about that.
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by drcode »

You're supposed to get attacked automatically if you fight friendly NPC's, as Marzo suggested.

The 'attack_avatar' is a way to manually get the avatar attacked. I can't recall where it's called from in U7's usecode, but it might be when you eat food that's not yours.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

Strange, I must have done something wrong to not let it somehow know they are friendly NPC's.

Or could a usecode in the patch directory that's just 2 NPC's cause it to not behave as it should? I've been looking at some of the source for those mods people have been making and I noticed the main usecode calls all the other function usecodes when needed (I think I worded that right).

Thanks again, and sorry for the dumb questions!
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

Actually, I've noticed that the NPC's don't actually fight back when I attack them as well. So along with the others not assisting, the target doesn't even care to defend himself!
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by drcode »

Does this also happen with other U7 NPC's? The behaviour should be the same.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by Donfrow »

Ok, I just went around and tried a bunch of different things. The real NPC's that came with the game don't attack back, they continue along their business like the ones I created.

I deleted my patch directory and the same behaviour was happening.

With the patch folder and without the patch folder I was able to attack the barkeeper in Fawn and have the guards lock me up in the jail. I was also able to steal from the apothocary in Moonshade and have the guards come and attack me. Pathos and the automation there also attacked me when I did that.

On another computer I uninstalled the same copy of U7 (it was doing the same thing), uninstalled Exult, and loaded it all up again using Exult 1.2 When I loaded my saved game before I started messing around with the studio and usecode the NPC's would attack fine. I updated to the current snapshot and they didn't attack anymore when attacked on the same savegame. However, I can't recall if I put my patch directory before I ran it for the first time on the first snapshot. Deleting the patch directory here didn't help as well.

I hope that all made sense.
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by drcode »

I'll give it a try with the latest snapshot. Maybe a bug got introduced at some point.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: New NPC question

Post by marzo »

I'll give it a try with the latest snapshot.
For the record, it seems to work in BG but not in SI.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Locked