problems with js equiping a item to player

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

problems with js equiping a item to player

Post by dragon slayer »

Okay so I'm trying to figure how to make this item be equiped to a player

Code: Select all

   FindItemLayer=tChar.FindItemLayer(0x02);
   if (tChar.FindItemLayer(0x02))
   { 
      var itemMade = CreateDFNItem( tChar.socket, tChar, "0x13e4", 1, "ITEM", false );
      itemMade.FindItemLayer(0x02);
   } 
Tom
UOX3 Neophyte
Posts: 31
Joined: Tue Dec 20, 2011 9:36 pm
Location: Berkeley
Has thanked: 0
Been thanked: 0

Post by Tom »

Code: Select all

itemMade.SetCont(tChar);
tommyhawk is back!
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

na doesn't work. i don't think we have a function for equiping items to players yet though js.. maybe some one could add it :)
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 »

Ye of little faith, dragon slayer ;)
//Check if player currently has item equipped in layer 2
var tempObj = tChar.FindItemLayer( 2 );

//If he has, unequip it
if( tempObj != null )
    tempObj.container = tChar.pack;
else
{
    //If there is no item equipped in layer 2, create one and equip it on character
    var itemMade = CreateDFNItem( tChar.socket, tChar, "0x13e4", 1, "ITEM", true );
    if( itemMade )
    {
        itemMade.container = tChar;
        itemMade.layer = 2;
    }
    else
        tChar.SysMessage( "Failed to create item." );
}
-= Ho Eyo He Hum =-
Tom
UOX3 Neophyte
Posts: 31
Joined: Tue Dec 20, 2011 9:36 pm
Location: Berkeley
Has thanked: 0
Been thanked: 0

Post by Tom »

I saw an example on the jsdocs page like what I had, sorry, I knew it was container, just didn't know the syntax.
tommyhawk is back!
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

haha i didnt even think about it all that way.

maybe because i was trying easy way out LOL
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 »

Parts of the JS docs are in dire need of an update. :/
-= Ho Eyo He Hum =-
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

Your right about all that lol. so many functions i don't understand because just says the function name no a example how to use it.
Tom
UOX3 Neophyte
Posts: 31
Joined: Tue Dec 20, 2011 9:36 pm
Location: Berkeley
Has thanked: 0
Been thanked: 0

Post by Tom »

This may just be a good side project for me to be involved in.
Think making them in html is a good idea?
tommyhawk is back!
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 »

Link to current JS Docs

I suppose a Wiki-type thing would be the most ideal - though we tried that before, hosted on sourceforge. Only a few people contributed, and eventually the wiki was overrun by spammers. It is no longer operational.
These users thanked the author Xuri for the post:
Humility
-= Ho Eyo He Hum =-
Humility
UOX3 Neophyte
Posts: 28
Joined: Mon Nov 21, 2016 7:51 am
Has thanked: 4 times
Been thanked: 5 times

Post by Humility »

Hey Xuri, your above code is awesome, I modified it slightly to actually make a self equipping item. thx!
This was something I was trying to figure out too.

Code: Select all

function onUseUnChecked(objPlayer,objItem)
{
//Check if player currently has item equipped in layer 10
var tempObj = objPlayer.FindItemLayer( 10 );

//If he has, unequip it
if( tempObj != null )
   tempObj.container = objPlayer.pack;
else
{
   //If there is no item equipped in layer 10, equip me on character
   var itemMade = objItem //     Xuri's create line --> CreateDFNItem( objPlayer.socket, objPlayer, objItem.id, 1, "ITEM", true );
   if( itemMade )
   {
      itemMade.container = objPlayer;
      itemMade.layer = 10; 
   }
   else
      objPlayer.SysMessage( "Failed to hook item." );
}
}
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 »

Np, good stuff :)
-= Ho Eyo He Hum =-
Post Reply