[IMPLEMENTED] Item related JS functions

If Wishes were UOX Coders, we'd be done by now ;P Post your wishes/suggestions for UOX3 changes/improvements here.
Post Reply
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Item related JS functions

Post by Grimson »

The following JS functions would be nice:

getItems( x, y, world, range)
To get a list of items that are within "range" (using a circle) of the given coordinates.

getItem( x, y, z, world)
To get the Item at the given coordinates.

findItem( x, y, z, world, itemType)
To find the item of "itemType" closest to the given coordinates.
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

There's a function that doesn't specifically do that, but you can use to do it.

Code: Select all

AreaItemFunction( functionName, srcObject, radius )
AreaCharacterFunction( functionName, srcObject, radius )
Basically, you call that (granted, I realise it's not a specific x/y/z/world), and it'll execute the function you specify on all the items in that radius.

eg

Code: Select all


function myTalker( srcObject, trgObject, mSocket )
{
   if( trgObject.type == 1 ) // a container
   {
            trgObject.TextMessage( "I'm a container!" );
            return true;
   }
   return false;
}

function onUse( cUser, iUsed )
{
    var itemsSpoken = AreaItemFunction( "myTalker", iUsed, 5 );
    cUser.TextMessage( "Wow, " + itemsSpoken + " containers talked to me!" );
}

This is written off the top of my head and a quick look at the code, but it looks right. Basically, if you double click on an item, it'll make all containers within 5 paces of it say something :)

There's no way (yet) to break out of the radial loop. I guess that should be an option to include, if people want to be able to break early. But it should let you get a few things done.

Hope that helps.
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Is someone working on this, if not I'll give it a try myself.
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Grimson wrote: getItem( x, y, z, world)
To get the Item at the given coordinates.

findItem( x, y, z, world, itemType)
To find the item of "itemType" closest to the given coordinates.
Those two are now on the CVS. As for the list of items, I simply don't know how to send such a list in a usable form to the JS engine.
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 »

What happens if there is more than one item at a given location?
-= Ho Eyo He Hum =-
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Xuri wrote:What happens if there is more than one item at a given location?
There shouldn't be more than one at the exact same location, but if it happens the first item at the given coordinates will be sent.
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 »

How do you tell what's the "first" item if there's a dynamic wooden floor tile as well as a piece of wall? :)
-= Ho Eyo He Hum =-
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Xuri wrote:How do you tell what's the "first" item if there's a dynamic wooden floor tile as well as a piece of wall? :)
It's the the item that comes first in the item list, that's stored in the map region, it is in.
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 »

Alrighty. Just trying to poke some holes =)

Btw, Maarc added some JS events a few versions ago similar to this, for static items, though I'm not sure if I ever got them working =P
UOX3 Changelog wrote: Added JS StaticAt function - takes 4 parameters - x, y, world, [tileID] (tileID is optional - if not specified, ANY static at that location will match)

Added JS StaticInRange function - takes 5 parameters - x, y, world, radius, tileID
-= Ho Eyo He Hum =-
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Xuri wrote:Btw, Maarc added some JS events a few versions ago similar to this, for static items, though I'm not sure if I ever got them working =P
UOX3 Changelog wrote: Added JS StaticAt function - takes 4 parameters - x, y, world, [tileID] (tileID is optional - if not specified, ANY static at that location will match)

Added JS StaticInRange function - takes 5 parameters - x, y, world, radius, tileID
They are not similar, they check if something is there an then return eighter true or false. While mine return an item or (hopefully) a list of items in range.

Well, I'm going to sleep now. It has been enough coding for today ;).
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Grimson, just so you know, we reverse-iterate our DataLists, thus when you call First(), it technically gives you the last entry in the list. :)
Scott
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 »

Grimson wrote:Well, I'm going to sleep now. It has been enough coding for today .
Whaat? But it's only 7 am! ;P hehe
-= Ho Eyo He Hum =-
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Grimson wrote:The following JS functions would be nice:

getItems( x, y, z, world, range)
To get a list of items that are within "range" of the given coordinates.
This is now on CVS.
Post Reply