Page 1 of 1

Help: Can we edit carve/cook amount algorithm?

Posted: Tue Mar 14, 2006 4:12 pm
by stranf
Here is what I want to implement:

--When a fish is clicked on with a knife, the .js script carves ALL fish of that type (not just 1 for 4 steaks). The algorithm automatically checks the skill of the PC, and damages certain fish if appropriate.

--When cooking ribs or fish steaks the .js script will calculate the entire resource amount, cook all that can be cooked, and damage the ones that should be burnt.

--Appropriate skill gains are given just as if the PC cooked them one at a time.



Since my shard isn't intended for a compenative persistant world with thousands of PCs, it is kind of boring and redundant to have to click and cook each rib and fish individually. Fishing is fun, but carving 64 fish and then cooking 700+ steaks individually is boring and time consuming. If we could adjust the .JS scripts to handle each thing singularly that would be awesome!

Since there are 4 or 5 fish types, carving 4 or 5 fish, and then cooking all in one batch would still include the fun of UO's item-interaction but save the boredom of single cooking and/or setting up macros and waiting.

Thanks guys!

Posted: Tue Mar 14, 2006 4:24 pm
by Grimson
A simple change in the item creation part of the scripts should do this.

for example in rawfish.js change this:

Code: Select all

			targSerial.amount = targSerial.amount -1;
			if( targSerial.amount < 1 )
				targSerial.Delete();
			pUser.SoundEffect( 0x018E, true );
			var itemMade = CreateDFNItem( pUser.socket, pUser, "0x097a", 4, "ITEM", true ); // makes 4 raw fish steaks
to this:

Code: Select all

			var itemAmount = targSerial.amount * 4; // How many raw steaks to create
			targSerial.Delete(); // Delete the fish
			pUser.SoundEffect( 0x018E, true );
			var itemMade = CreateDFNItem( pUser.socket, pUser, "0x097a", itemAmount, "ITEM", true ); // makes raw fish steaks
			pUser.SysMessage( "You slice a fish to steaks." );
Edit:
For actions that take skill it might be better to wrap the code into a while loop:

Code: Select all

while( ressource > x )
{
    do it
}
for example on cookedfish the code would look like this:

Code: Select all

		// remove one raw fish steak
		var iMakeResource = pUser.ResourceCount( 0x097A );	// is there enough resources to use up to make it
		if( iMakeResource < 1 )
		{
			pUser.SysMessage( "You don't seem to have any fish steaks!" );
			return;
		}
		while( iMakeResource > 0 )
		{
			pUser.UseResource( 1, 0x097A ); // uses up a resource (amount, item ID, item colour)
			iMakeResource = iMakeResource - 1; // decrease the resource count for the while loop
			pUser.SoundEffect( 0x0021, true );
			// check the skill
			if( !pUser.CheckSkill( 13, 1, 300 ) )	// character to check, skill #, minimum skill, and maximum skill
			{
				pUser.SysMessage( "You burnt the fish to crisp." );
				return;
			}
			var itemMade = CreateDFNItem( pUser.socket, pUser, "0x097B", 1, "ITEM", true ); // makes a fish steak
		}
		pUser.SysMessage( "You cook fish steaks." );
Note: This will abort when CheckSkill fails.

Posted: Tue Mar 14, 2006 5:43 pm
by stranf
Thanks! I'll implement this as soon as I can.

Posted: Tue Mar 14, 2006 6:54 pm
by giwo
Just note that ResourceCount() finds everything in your possesion that matches the ID you pass. This means that with that while loop, even fish steaks that are not part of the stack you clicked on and deep inside other packs will get cooked. :)

Posted: Tue Mar 14, 2006 9:17 pm
by stranf
Interesting. That's probably not so much of an issue. I might just make the loop to cook a maximum of 20 at a time or something like that.


So are all fish with the same ID? Since there are 4 or so different fish stacks when you fish, if I carve one, will it loop and chop up all 4 different stacks?

Posted: Tue Mar 14, 2006 9:27 pm
by giwo
Will only find things of the same ID, so if they look exactly the same in-game (facing the same way, etc) then they likely have the same ID. Notably anything stackable should stack on other items of the same ID and Color (usually automatically when they are created with cooking, etc).

Posted: Wed Mar 15, 2006 1:09 am
by Xuri
You could just change the script to cut up the stack all at once, and only run checkskill 20 times (or however many fish steaks there are).

Code: Select all

var i = 0;
while( i > item.amount )
{
    checkskill stuff;
    next i;
}
(or whatever the while loop will look like)

Posted: Wed Mar 15, 2006 1:15 am
by Grimson
Xuri wrote:You could just change the script to cut up the stack all at once, and only run checkskill 20 times (or however many fish steaks there are).

Code: Select all

var i = 0;
while( i > item.amount )
{
    checkskill stuff;
    next i;
}
(or whatever the while loop will look like)
This way he will also get steaks when checkskill actually failed ;).

Posted: Wed Mar 15, 2006 1:55 am
by Xuri
Oops, that's right. Didn't think of that :) Heh

Code: Select all

var i = 0; 
var successAmount = 0;
while( i > item.amount ) 
{ 
    if( checkskill stuff is true )
    successAmount++; 
    next i; 
}
CreateDFNItem( fishsteak, successAmount )
;P

Posted: Thu Mar 16, 2006 2:36 pm
by jr
Xuri wrote:

Code: Select all

var i = 0; 
var successAmount = 0;
while( i > item.amount ) 
{ 
    if( checkskill stuff is true )
    successAmount++; 
    next i; 
}
CreateDFNItem( fishsteak, successAmount )
Actually I think it would be a good idea to encapsulate this loop into a new CheckSkill method (available to C++ and JS) that takes an additional count parameter and returns the number of successes.

Posted: Thu Mar 16, 2006 3:02 pm
by Maarc
Shunting out a function like this to JS/C++ wouldn't be very hard, I just wonder about the pay off. Would there really be that many instances where this needs to occur? If it will be used fairly frequently, I could understand, but I don't know how often it would be. If you think it'll be frequent, feel free to sing out, I rarely code in JS myself :)

Posted: Thu Mar 16, 2006 3:36 pm
by jr
Maarc wrote:Shunting out a function like this to JS/C++ wouldn't be very hard, I just wonder about the pay off. Would there really be that many instances where this needs to occur? If it will be used fairly frequently, I could understand, but I don't know how often it would be. If you think it'll be frequent, feel free to sing out, I rarely code in JS myself :)
I'm not doing that much skill coding either, but while I was playing around with mining I was stumbling about smelting which currently smelts the complete pile, but only does a single skill check (and destroys half the ore if the skill check fails). Therefore I was already thinking about this problem of repeated skill checks when I saw this topic. The pay off would be that all mass producing actions would use the same skill check semantics that could be centrally changed. Actually I think that mass producing is different enough from 'lovingly' manipulating single items that it would be a good idea to have the possibility to introduce a bonus (powergaming shard) or penalty (roleplaying shard) globally to mass producing.