Bedroll v2

Want to contribute to the Ultima Offline eXperiment? Submit your JS/DFN/Code fixes and/or other UOX3 improvements here!
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Bedroll v2

Post by dragon slayer »

Update v2
It now checks if your near a campfire before you can use it.


I didnt see we had any scripted so i went ahead put together this bedroll.

What it does. when double clicked it will unroll a bed at your feet location and send you a logout gump.

if you click cancel nothing happens
if you click CONTINUE you will be automatic disconnected.
This bedroll also checks your camping skill and you will gain camping skill when used.

Known problems;
After log out bed roll stays on ground and decays and is moveable.
Not sure how to move it back to your backpack yet.
if you hit cancel you have to wait the 60 seconds to get your bedroll.
Still not sure how to fix this problem either

bedroll item

Code: Select all

function onUseChecked( pUser, iUsed ) 
{ 
    // get users socket 
    var srcSock = pUser.socket; 
    targX = srcSock.GetWord( 11 );
    targY = srcSock.GetWord( 13 ); 
    targZ = srcSock.GetSByte( 16 ) + GetTileHeight( srcSock.GetWord( 17 ) ); 

    var CampingAttempt = pUser.skills.camping / 10;
    var Success = RandomNumber( 0, 100 );	
    var itemFound = FindItem( targX, targY, targZ, pUser.worldnumber, 0x0de3 ); 
    if( itemFound && itemFound.x == targX && itemFound.y == targY ) 
    {
	if( pUser.CheckSkill( 10, 0, 1000 ))
	{
	   	if( iUsed.container != null && iUsed.container.serial == pUser.pack.serial ) 
	   	{
			iUsed.container = null;
			iUsed.Teleport( pUser.x, pUser.y, pUser.z, pUser.worldnumber );
		}
		else
		{
			if( !iUsed.InRange( pUser, 2 ) )
			{
				pUser.SysMessage( GetDictionaryEntry( 482, pSock.Language )); //You need to be closer to use that.
				return false;
			}
		}
		iUsed.movable = 2;
		iUsed.id = 0x0A55;
		pUser.SysMessage( "You Unroll the bedroll" );
		iUsed.StartTimer( 60000, 1, true ); //bedroll lasts for 60 seconds
                // this Creates our gump 
                var ret=displaygump(srcSock, pUser);
                return false;
	}
	else
		pUser.SysMessage("You Fail to Unroll the bed to logout.");
	return false;
    }
    else
        pUser.SysMessage( "You Have no campfire so this area isnt secure" );
     return false;
}

function displaygump(srcSock, pUser) 
{
  var myGump = new Gump;

  myGump.AddPage(0);
  myGump.AddBackground( 0, 0, 400, 350, 0xA28 );
  myGump.AddText( 65, 10, 0, "Logging out via camping" );                        
  myGump.AddButton( 26, 300, 0xfa5, 1, 0, 1);
  myGump.AddButton( 280, 300, 0xfa5, 1, 0, 0);
  myGump.AddText( 60, 300, 0, "CONTINUE" );
  myGump.AddText( 315, 300, 0, "CANCEL" );
  myGump.AddText( 45, 36, 0, "Using a bedroll in the safety of a camp will" );
  myGump.AddText( 45, 53, 0, "log you out of the game safely. If this is" );
  myGump.AddText( 45, 70, 0, "what you wish to do choose CONTINUE and" );
  myGump.AddText( 45, 90, 0, "you will be logged out. Otherwise select the" );
  myGump.AddText( 45, 110, 0, "CANCEL button to avoid logging out this" );
  myGump.AddText( 45, 130, 0, "time. The camp will remain secure till the" );
  myGump.AddText( 45, 150, 0, "campfire is out." );
  myGump.Send( srcSock );
  myGump.Free();

}

function onGumpPress(srcSock, myButtonID) 
{ 
  var srcChar = srcSock.currentChar;
   switch( myButtonID ) 
   { 
      case 0: // cancel
         srcSock.SysMessage("You Cancel the logout");
      break; 
      case 1: // go on
         srcSock.SysMessage("You been Disconnected"); 
         srcSock.Disconnect();
      break;
    }
}

function onTimer( bedroll, timerID )
{
	if( timerID == 1 )
	{
                bedroll.movable = 1;
		bedroll.id = 0x0A57; // turn bedroll back into rolled bedroll
		bedroll.decayable = true;
	}
}
Post Reply