The worker.src speech bug.

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 096.
Note: Core 096 is no longer officially supported.
Post Reply
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

The worker.src speech bug.

Post by Yukiko »

OK, I looked and looked and searched and could not find the thread under which I thought this bug was posted. Then it occurred to me that it had never been posted here.

Datus and I were discussing the worker.src speech problem tonight on the phone. This has bothered me ever since he emailed me about it. For the benefit of those who may not have been privy to his emial (which I hope are all of you *grins*) I am posting the bug and the fix here.

The bug:
In the POL 0.95 Distro there's an AI script named worker.src. This script is supposed to respond to various speech events such as [NPCName} + "train" or "hire" and so on. The problem is that it doesn't. I have looked at this before but was unable to determine the problem. Well, as I said I was discussing this with Datus and decided to look again.

I admit I was on a mission with this one. After fixing the pack animal problem this one was sticking in my crop and I just had to get it working.
*smiles wryly*
Yeah it was a matter of pride I guess.

The bug originates in the very beginning of the script. It's in the EnableEvents function call. Here is the code that is in error:

Code: Select all

program CastleGuard()
  run_script_to_completion("NPCKeeper", me);
  drop_anchor();
  EnableEvents(SYSEVENT_SPEECH + SYSEVENT_ENGAGED + SYSEVENT_DISENGAGED + SYSEVENT_DAMAGED);
Now I have looked at this over and over along with all the other parts of the script dealing with speech and never saw the problem.

So I asked myself "What AI script do I know of that handles speech properly?" The answer was tamed.src.

Upon opening tamed.src I first looked at the case statement that parses the speech and found nothing unusual there. So I then looked at the function EnableMainEvents and found this curious item, there is an additional parameter passed along with the EnableEvent function call when enabling speech. There's an integer that's passed along. That integer is the listening range. You will note in the above code snippet from worker.src there is no such parameter passed.

The fix for this is by far easier than that for the pack animal one. Simply change the above code to this:

Code: Select all

program Worker()
  run_script_to_completion("NPCKeeper", me);
  drop_anchor();
  EnableEvents(SYSEVENT_SPEECH, 3);
  EnableEvents(SYSEVENT_ENGAGED + SYSEVENT_DISENGAGED + SYSEVENT_DAMAGED);
Voilla! It now works.

Note also the change to the name from CastleGuard to Worker. This has no effect on functionality. It's just good programming practice to not be lazy when borrowing script templates for use in other scripts.

I have not taken the time to research the other EnableEvents function calls to see if they are properly formatted. If anyone sees a problem with the other ones please post the fix here.

Once again anyone running POL 0.95 Distro converted to POL 0.97 should take note of this bug.
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

I found a similar bug in the employed.src script.

Look in that script at line 531. Change that line to:

Code: Select all

  EnableEvents(SYSEVENT_SPEECH, 8);
I figured 8 was a good range as this is a script for a human NPC in your employ rather than an animal NPC as in the tamed script.
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Here are more scripts that have speech enable errors like the one above:

townPerson.src
pirate.src
person.src
mainLoopMeek.inc
mainLoopGood.inc
escortee.src

Once again if you are using converted 0.95 Distro scripts take note of these fixes.
User avatar
Datus
Apprentice Poster
Posts: 58
Joined: Tue Sep 19, 2006 6:27 am

Post by Datus »

*profound joy and excitement*

Damn you're good... and all this time I was worried I'd have to learn Spanish or Deutsch or something. :)

So in EnableEvents(SYSEVENT_SPEECH, 3); I'm assuming the integer is tile distance?
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

That's correct as far as I remember. Enabling the speech event requires a range parameter. I am almost certain other events require that as well to enable them but I haven't had time yet to research it.
*laughs*
You can tell I have never written any scripts that use events.

Oh and no I am not that good, trust me. I can't whip out an entire boat package in one evening like Austin can. It's just that I was irritated that I couldn't figure that one out and like I said it was a matter of pride.
Post Reply