Usecode Order Execution?

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
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Usecode Order Execution?

Post by Knight Captain »

I am trying to get the guard on the western entrance of Skullcrusher to be "alive" rather than just standing there Waiting. There is existing code for him that asks if you have a Medallion of Order, which the item doesn't exist in the game, so he attacks.

His starting Current Activity is Waiting, and his schedule is set to repeat this at 6AM (Dawn) each day, so the only way to talk to him is cheat via F2.

So my goals for this bit of code are to:
1) Change his schedule so he's not stuck in Waiting but always in StandThere.
2) Trigger him to approach the Avatar when the gate is opened.
3) Then use the existing Usecode to bark and talk to the Avatar using the existing conversation text.

I'm running into a number of problems trying to get this to work. I've even submitted a bug for some parts of it.

My code is below. What I'm seeing is the schedule change does not take place per Flag 3 being set, but only when I double-click on the NPC. If I'm reading the code right, shouldn't that happen without needing to double-click on him? Is there a way to do this without checking any flags short of editing the map?

I haven't set the StartedTalking event, but shouldn't that be handled by the existing Usecode here?

The Proximity doesn't seem to work, I can walk the Avatar in circles around him and he doesn't change.

Code: Select all

void Guard17 object#(0x4be) () // Automaton at entrance, NPC 190, Guard17, should talk when gate is opened. Flag 613 to test.
// Door open = Shape 936, sliding door frame 1, Quality 91. Non-open door is 303, same quality

{
    if (gflags[STARTING_SPEECH]) // Need an event here to check, this is flag is set automatically during the opening sequence.
    UI_set_new_schedules(GUARD17, DAWN, STANDTHERE, [0x03C2, 0x0415]); // Replaces Waiting schedule with same for StandThere at 0962, 1045.
        {
        if (event == DOUBLECLICK)
            {
            UI_set_schedule_type(GUARD17, TALK);
            //delayedBark(GUARD17, "@Halt! Intruder!@", 0); // Existing Origin Usecode already handles this.
            gflags[FOUND_FISHNETS] = true; // Testing only.
            } 

        if (event == PROXIMITY)
            {
            UI_set_schedule_type(GUARD17, TALK);
            //delayedBark(GUARD17, "@Halt! Intruder!@", 0); // Existing Origin Usecode already handles this.
            gflags[FOUND_FISHNETS] = true; // Testing only.
            } 
        }
    Guard17.original(); // His existing speech is well-done by Origin.
}
I had also tried to get an event that causes him to recognize when the sliding door is opened. The game uses two shapes for this. The closed and opening door is Shape 303, but the fully-opened door is Shape 936, frame 1. In both cases the Quality is 91. Nothing that I've tried for this has worked either.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode Order Execution?

Post by Knight Captain »

If I trim everything back to just this, the new schedule only happens if I double-click on the NPC.

Code: Select all

void Guard17 object#(0x4be) ()

{
    if (gflags[STARTING_SPEECH]) // Need an event here to check, this is flag is set automatically during the opening sequence.
    UI_set_new_schedules(GUARD17, DAWN, STANDTHERE, [0x03C2, 0x0415]); 
}
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode Order Execution?

Post by Knight Captain »

Removing the IF clause there causes the same behavior, the new schedule only takes effect if the NPC is double-clicked.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode Order Execution?

Post by marzo »

Let's see, you are setting a schedule for dawn. This means it will take effect at... dawn. This is 6AM on the in-game clock, but NPCs do update schedule hourly.

You can use run_schedule intrinsic to force the change to happen sooner.

FYI, using "Guard17" (the name of the function) will use the functions's number (in this case, 0x4be) instead of the NPC's number. In object# and shape# functions you can also use "item" to refer to the object which called Usecode. When calling intrinsics without the "UI_" bit, "item" is implied as tthe first parameter.

Also, usecode generally does not get executed "at random". It is executed in certain events, such as double-clicks, scripted calls and so on. Some schedules trigger proximity calls as well, and patrol schedule can make calls to usecode functions. And eggs can execute usecode in a variety of conditions you can see in Exult Studio. But usecode is not executed at the start of the game, or periodically.

If you want to change this NPC's starting schedule, just edit it in Exult Studio and save the map (but do start Exult in edit mode, start a new game, make the changes, and return to where you were at the start before saving).
------
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]
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode Order Execution?

Post by Knight Captain »

So if I wanted to trigger an action from the opening of that sliding door, how could I do it? It sounds like I'd need to add an egg to the map that triggers on the opening?
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode Order Execution?

Post by marzo »

Eggs can only trigger based on avatar or party position, or if something is placed on them/removed. To "trigger" something like that you will need to change the usecode that opens the door to detect if it is the door you want, then do the action.
------
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]
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode Order Execution?

Post by Knight Captain »

Ah, so not based on the NPC's position then.

So it sounds like I'd have to drop an egg for "Avatar near" with Auto-reset by the gate, then when triggered, have Usecode check for the open sliding door (Shape 936) and then have the automation respond to that?

Am I on the right track with this?
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode Order Execution?

Post by Knight Captain »

On a related note, how does the Banes_Released flag do so much? I've seen that some of the things only take place when the Avatar is near.
Locked