[FIXED] Opened the Wrong Door

Found a bug in UOX3? Or experienced a server crash? Perhaps you've noticed a broken feature? Post the details here!
Post Reply
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Opened the Wrong Door

Post by Mindless Automaton »

I present you with the improper way to use UseDoor:

Code: Select all

function onAISliver( tChar )
{
			tChar.WalkTo( 1450, 1710, 20 ); //walk to door

			// open the door

				UseDoor( -1, 12 );

}
Visual Studio:

Code: Select all

>	UOX3.exe!JS_GetPrivate(JSContext * cx, JSObject * obj) Line 2294	C
 	UOX3.exe!SE_UseDoor(JSContext * cx, JSObject * obj, unsigned int argc, __int64 * argv, __int64 * rval) Line 1301	C++
 	UOX3.exe!js_Invoke(JSContext * cx, unsigned int argc, unsigned int flags) Line 1375	C
 	UOX3.exe!js_Interpret(JSContext * cx, unsigned char * pc, __int64 * result) Line 3947	C
 	UOX3.exe!js_Invoke(JSContext * cx, unsigned int argc, unsigned int flags) Line 1394	C
 	UOX3.exe!js_InternalInvoke(JSContext * cx, JSObject * obj, __int64 fval, unsigned int flags, unsigned int argc, __int64 * argv, __int64 * rval) Line 1469	C
 	UOX3.exe!JS_CallFunctionName(JSContext * cx, JSObject * obj, const char * name, unsigned int argc, __int64 * argv, __int64 * rval) Line 4340	C
 	UOX3.exe!cScript::OnAISliver(CChar * pSliver) Line 1390	C++
 	UOX3.exe!checkNPC(CChar & mChar, bool checkAI, bool doRestock, bool doPetOfflineCheck) Line 949	C++
 	UOX3.exe!CWorldMain::CheckAutoTimers() Line 1436	C++
 	UOX3.exe!main(int argc, char * * argv) Line 2809	C++
 	[External Code]	
Is it possible for NPCs to open doors/containers, etc? Thanks!
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Well, not really, no. The JS docs are a bit incorrect when they state that you can pass in -1 instead of a socket for the UseDoor function, because it will not work without it and the subsequent character derived from said socket. I should fix that discrepancy in the docs! What UseDoor does is actually to just call any onUseChecked events in scripts attached to the referenced item - but that function also requires a character to be passed in.

Two other points:
1) Your example of using UseDoor fails not only because it uses -1 instead of a valid socket, but also because you don't actually pass in the door to use/open (you pass in the number 12 instead). A working example in an onUseChecked( pUser, iUsed ) event would be ...

Code: Select all

UseDoor( pUser.socket, iUsed );
2) I'm going to change the UseDoor function in a couple of ways. First- I'm going to rename it to UseItem, because there's nothing door-specific about it! Second - I'm going to make the function accept a socket OR a character as the first argument. If you pass a player's socket, it will find the player's character automatically. If you pass a player's character - well, it will just use that character. If you pass an NPC character - that will also work.

Thus, it becomes a generic function that can allow a player or NPC to use any object with an onUseChecked() OR onUseUnChecked() event attached. You'll still need to reference the actual item to use though, so in your case you'd still need a way to detect the door. Maybe you could add an inRange event for either the character or the door, and trigger the UseItem from that if all the right conditions are met.

Example script I used to test the change:
var initialCheck = true;

function onAISliver( tChar )
{
    if( initialCheck )
    {
        initialCheck = false;
        tChar.StartTimer( 10000, 1, true );
    }
}

function onTimer( tChar, timerID )
{
    AreaItemFunction( "CheckNearbyItem", tChar, 3 );
}

function CheckNearbyItem( tChar, itemToCheck )
{
    if( itemToCheck.id == 0x0fa7 ) // Dice & Cup script
    {
        tChar.TextMessage( "My turn to roll the Dice & Cup!" );
        UseItem( tChar, itemToCheck );
    }
    else if( itemToCheck.type == 12 ) // Door
    {
        tChar.TextMessage( "Opening door..." );
        UseItem( tChar, itemToCheck );
    }
}
Result (after replacing item and reloading script, as it only triggers the timer ONCE):
npcUseDoor.gif
npcUseDoor.gif (112.27 KiB) Viewed 6816 times
npcUseDice.gif
npcUseDice.gif (81.97 KiB) Viewed 6816 times
-= Ho Eyo He Hum =-
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

I've committed the change I mentioned to the develop branch on GitHub, and updated the JS docs to reflect those changes.
-= Ho Eyo He Hum =-
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Mindless Automaton »

Xuri wrote: Thu Nov 12, 2020 7:01 pm

Code: Select all

UseDoor( pUser.socket, iUsed );
The next one I was going to try was:

Code: Select all

tChar.OpenDoor( iUsed, 1, 1484, 1709 )
The day destroys the night
Night divides the day
Tried to run
Tried to hide
Break on through to the other side..
I've committed the change I mentioned to the develop branch on GitHub, and updated the JS docs to reflect those changes.
Excellent!
Well, show me the way
To the next whisky bar
Oh, don't ask why
Oh, don't ask why
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
Post Reply