[IMPLEMENTED] Item related JS functions
-
Grimson
- Developer
- Posts: 802
- Joined: Sat Jun 04, 2005 1:52 am
- Location: Germany
- Has thanked: 0
- Been thanked: 0
Item related JS functions
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.
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:
There's a function that doesn't specifically do that, but you can use to do it.
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
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.
Code: Select all
AreaItemFunction( functionName, srcObject, radius )
AreaCharacterFunction( functionName, srcObject, 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!" );
}
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
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.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.
- Xuri
- Site Admin
- Posts: 3704
- Joined: Mon Jun 02, 2003 9:11 am
- Location: Norway
- Has thanked: 48 times
- Been thanked: 8 times
- Contact:
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
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
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.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
Well, I'm going to sleep now. It has been enough coding for today