[APPROVED] Turning kindling into campfires

Want to contribute to the Ultima Offline eXperiment? Submit your JS/DFN/Code fixes and/or other UOX3 improvements here!
Locked
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Turning kindling into campfires

Post by Grimson »

After seeing that the current UOX version comes with a not used script for kindling to turn it into a campfire I decided to give it a try, and this is the result:

Open the js/item/kindling.js and change the the onUse function so that it looks like this:

Code: Select all

function onUseChecked( pUser, iUsed )
{
	var pSock = pUser.socket;
	// is it on the ground
	var iCont = 0;
   	if( iUsed.container != null ) 
   	{
		pUser.SysMessage( GetDictionaryEntry( 1763, pSock.Language ));
		return false;
 	}
	
	var CampingAttempt = pUser.skills.camping / 10;
	var Success = RandomNumber( 0, 100 );	
	if( pUser.CheckSkill( 10, 0, 1000 ))
	{
		iUsed.movable = 2;
		iUsed.id = 0x0de3;
		iUsed.dir = 29; //Set light radius to 29
		pUser.SysMessage( GetDictionaryEntry( 1765, pSock.Language ));
		iUsed.StartTimer( 60000, 1, true ); //Campfire burns for 60 seconds
	}
	else
		pUser.SysMessage( GetDictionaryEntry( 1764, pSock.Language ));
	return false;
}
Then create a campfire.js and put this in:

Code: Select all

function onUseChecked( pUser, iUsed )
{
	iUsed.id = 0x0de9; // turn campfire into embers
	iUsed.dir = 2; //Set light radius to 2
	iUsed.StartTimer( 15000, 1, true ); //Embers last for 15 seconds
	return false;
}

function onTimer( campfire, timerID )
{
	if( timerID == 1 )
	{
		campfire.id = 0x0dea; // turn embers into burnt wood
		campfire.decayable = true;
	}
}
Now add these lines:

Code: Select all

5008=item/kindling.js
5009=item/campfire.js
after:

Code: Select all

5007=item/archerybutte.js
in js/jse_fileassociations.scp.

And these lines:

Code: Select all

//Kindling
0x0DE1=5008
//Campfire
0x0de3=5009
after:

Code: Select all

//Pickpocket Dips
0x1EC0=5006
0x1EC3=5006
in js/jse_objectassociations.scp.

Finally add these lines into the dictionarys:

Code: Select all

1763=You have to place the kindling on the ground.
1764=Your skill is to low to use this.
1765=You have started a campfire.
Restart the server and now you can place kindling on the ground and create a campfire, which can be used for cooking. The fire eighter burns out after 60 secs or when you use it again.

It still has some things that need to get worked out:
  • Skill increase on succesfull and failed attempts.
  • If the user logs out while the fire is burning the timers seem to stop, so the only way to stop the fire is by using it again.(Maybe a bug in the script engine?)
  • The fire doesn't secure the area (I don't know how to do this).
  • The onCollide doesn't seem to work, so you can't burn yourself when running through the fire.
  • Making shure only the one who started it can stop it, just in case.
  • And probably more things I forgot.
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 »

Doh! I knew there was something I forgot to do before packaging up 0.98-3.0: Adding the kindling-lines to jse_objectassociations.scp, and including the updated DICTIONARY files! Doh O_o

The already included kindling script works fine here, just need to actually assign it to the kindling =)

The pUser.CheckSkill( 10, 0, 1000 ) handles skillgain as well, btw. As for the other things you noted; The fire doesn't secure the area, no - don't think there's a way of doing that through the JS Engine just yet. onCollide works with me. (In the default script)
-= 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:Doh! I knew there was something I forgot to do before packaging up 0.98-3.0: Adding the kindling-lines to jse_objectassociations.scp, and including the updated DICTIONARY files! Doh O_o
Greets from Murphy ;).
Xuri wrote: The already included kindling script works fine here, just need to actually assign it to the kindling =)
I only changed the default script because with it you need to have the kindling in your backpack to start the fire, and the fire would then appear right below your feet (ouch ;)). I'd rather have the user to place it on the ground by himself for this. So it's just a matter of personal taste.
Xuri wrote: The pUser.CheckSkill( 10, 0, 1000 ) handles skillgain as well, btw.
Nice, maybe this should be mentioned in the docs ;).
Xuri wrote:As for the other things you noted; The fire doesn't secure the area, no - don't think there's a way of doing that through the JS Engine just yet.
Hmmm, ok.
Xuri wrote:onCollide works with me. (In the default script)
Strange, I didn't change anything to that part of the script.
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: Greets from Murphy ;)
Hehe yeah...damn him and his laws. Would never had happened if it weren't for him.
Grimson wrote:I only changed the default script because with it you need to have the kindling in your backpack to start the fire, and the fire would then appear right below your feet (ouch ). I'd rather have the user to place it on the ground by himself for this. So it's just a matter of personal taste.
From certain perspectives (including mine) it does make more sense to have the user place it on the ground for himself instead of automatically lighting it up underneath him/her, though I went with the OSI way on this one - or thought I did. Just logged on there now and tested, and it seems it's possible to do both from backpack and from the ground. So I'm changing the default script to allow for both of those simply by commenting out the following lines:

Code: Select all

/*	// is it in users pack 
	var iCont = 0;
   	if( iUsed.container == null || iUsed.container.serial != pUser.pack.serial ) 
   	{
		pUser.SysMessage( GetDictionaryEntry( 1763, pSock.Language ));
		return false;
 	}*/
Grimson wrote:Nice, maybe this should be mentioned in the docs .
Oops sorry, what I meant to say is that when CheckSkill is used, UOX3 sees it as a normal skilluse attempt, and thus uses the hardcoded code for calculating skillgain. Also note that admin/GM characters do not gain skill, so if you tested with a character like that - try again with a normal player account/character :) And yeah, it should be mentioned in the docs :P

And by the way, you are right - onCollide worked in 2.8h, but does not work in 3.0 :(
-= 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: From certain perspectives (including mine) it does make more sense to have the user place it on the ground for himself instead of automatically lighting it up underneath him/her, though I went with the OSI way on this one - or thought I did.
Well, the last time I really played UO was somewhere around 1998, so my memory of those things is a bit rusty...
Xuri wrote:Just logged on there now and tested, and it seems it's possible to do both from backpack and from the ground. So I'm changing the default script to allow for both of those simply by commenting out the following lines:

Code: Select all

/*	// is it in users pack 
	var iCont = 0;
   	if( iUsed.container == null || iUsed.container.serial != pUser.pack.serial ) 
   	{
		pUser.SysMessage( GetDictionaryEntry( 1763, pSock.Language ));
		return false;
 	}*/
Don't forget to make the item teleport depending on wheter it is in a container or not. ;)
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 »

Eeewp! Thanks for the reminder :) Actually forgot about that hehe.

So now I've changed the checkSkill "function" to the following:

Code: Select all

	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 = 0x0de3;
		iUsed.dir = 29; //Set light radius to 29
		pUser.SysMessage( GetDictionaryEntry( 1765, pSock.Language ));
		iUsed.StartTimer( 60000, 1, true ); //Campfire burns for 60 seconds
	}
Btw, I check to see if iUsed.container != null first, because if it's null and you try to do anything with iUsed.container, UOX3 will crash O_o.

Edit: Bugger, just remembered - since it allows on ground as well, need rangecheck. Coming soon ;P

Edit 2: Rangecheck implemented ;P
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Well, nothing changed in the onCollide function, and thus it should still work as it did.

Having said that, I took a look at it, and did notice an oddity, but one that should have only made it malfunction for Characters colliding with Characters.

I fixed that issue, and we'll have to see how it works now.
Scott
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

giwo wrote:Well, nothing changed in the onCollide function, and thus it should still work as it did.
I have just added a simply console output into the onCollide function in cScript.cpp to see wheter it is called. And it seems like it isn't called at all. But I couldn't see any obvious bugs in the code. Maybe this helps a bit.
Locked