Sign in to follow this  
joedobo

[RELEASED] Make the fruit press bigger, script runner example.

Recommended Posts

Here is an example using the script runner mod loader tool to make the fruit press bigger. A press that holds 45kg is much better to use then one that only holds 2kg. This does make the press larger so it will fit inside less containers ( will usualy only go in containers larger then a small barrel for the default settings supplied).  

This WILL NOT resize already created items. Nor will items created when it's in use be reverted if it's removed.

 

To use this:

1. Copy the code in the white box.

2. Paste into a text editor program (notepad, wordpad, notepad++, ....).

3. Save as a something with .js extension.

4. Put that file in the appropriate folder. My path looks like: Wurm Unlimited Dedicated Server\mods\scriptrunner\scripts\ onItemTemplatesCreated. If onItemTemplatesCreated folder doesn't exists, create it.

5. specify the item you want changed with the "itemName" field. And change the x,y,z values to change its size.

 

Spoiler

// **************************************************************************************************
// Set size in the from: x, y, z. A small barrel is 30, 30, 50. ALWAYS! sort them in ascending order regardless.
var toSetX = 30;
var toSetY = 30;
var toSetZ = 50;

// This is an item's name exactly as it's seen in game and only for a single item. Do not included: rename text,
//		materials, rarities, or things inside square brackets[]. 
// For example: "fantastic pickaxe, steel" would be just "pickaxe". 
// For example: "rare small bucket, birchwood" would be just "small bucket".
var itemName = "fruit press";
// **************************************************************************************************

var ItemTemplateFactory = Packages.com.wurmonline.server.items.ItemTemplateFactory;
var ReflectionUtil = Packages.org.gotti.wurmunlimited.modloader.ReflectionUtil;
var Class = Packages.java.lang.Class;
var Integer = Packages.java.lang.Integer;
var Double = Packages.java.lang.Double;
var Logger = Packages.java.util.logging.Logger;
var logger = Logger.getLogger("com.joedobo27.scriptRunnerMods.resize-item");

// Java requires a int for the volume value. For some reason JS is making it into a double. This was the only way
// I could get it to be of correct type.
var toSetVolume = toSetX * toSetY * toSetZ;
var toSetVolume = Double.toString(toSetVolume);
var toSetVolume = toSetVolume.replace(".0", "");
var toSetVolume = Integer.parseInt(toSetVolume, 10);


function onItemTemplatesCreated() {
	var itemTemplates = ItemTemplateFactory.getInstance().getTemplates();
	var fieldCentimetersX = ReflectionUtil.getField(
	    Class.forName("com.wurmonline.server.items.ItemTemplate"), "centimetersX");
	var fieldCentimetersY = ReflectionUtil.getField(
	    Class.forName("com.wurmonline.server.items.ItemTemplate"), "centimetersY");
	var fieldCentimetersZ = ReflectionUtil.getField(
	    Class.forName("com.wurmonline.server.items.ItemTemplate"), "centimetersZ");
	var fieldVolume = ReflectionUtil.getField(
	    Class.forName("com.wurmonline.server.items.ItemTemplate"), "volume");
	var fieldSize = ReflectionUtil.getField(
	    Class.forName("com.wurmonline.server.items.ItemTemplate"), "size");

	for (i = 0; i < itemTemplates.length; i++) {
        var sizeNumber = ReflectionUtil.getPrivateField(itemTemplates[i], fieldSize);
        var name = getSizeString(sizeNumber) + itemTemplates[i].getName();
        if (name == itemName) {
            ReflectionUtil.setPrivateField(itemTemplates[i], fieldCentimetersX, toSetX);
            ReflectionUtil.setPrivateField(itemTemplates[i], fieldCentimetersY, toSetY);
            ReflectionUtil.setPrivateField(itemTemplates[i], fieldCentimetersZ, toSetZ);
            ReflectionUtil.setPrivateField(itemTemplates[i], fieldVolume, toSetVolume);

            var centimetersX = ReflectionUtil.getPrivateField(itemTemplates[i], fieldCentimetersX);
            var centimetersY = ReflectionUtil.getPrivateField(itemTemplates[i], fieldCentimetersY);
            var centimetersZ = ReflectionUtil.getPrivateField(itemTemplates[i], fieldCentimetersZ);
            var volume = ReflectionUtil.getPrivateField(itemTemplates[i], fieldVolume);
            logger.info("The " + name + " is now x, y, z, volume: " + Integer.toString(centimetersX) + ", " +
                Integer.toString(centimetersY) + ", " + Integer.toString(centimetersZ) + ", " +
                Integer.toString(volume) + ".");
        }
	}
}

function getSizeString(size) {
    if (size == 1)
        return "tiny ";
    else if (size == 2)
        return "small ";
    else if (size == 4)
        return "large ";
    else if (size == 5)
        return "huge ";
    return "";
}

 

 

Edited by joedobo
  • Like 2

Share this post


Link to post
Share on other sites

wow that's awesome, i'm going to do this, when I get time, programming is like an alien language to me, so i'm grateful to see guys and dolls like you doing stuff like this.

Share this post


Link to post
Share on other sites

+1 for this idea!

 

Or, how about making the huge tub into a larger type of fruit press? I see no need for a huge tub otherwise.

Share this post


Link to post
Share on other sites

@Nienoriif you want a fruit press as big as a huge tub then change the numbers to 100, 150, 150. Those are the size of a huge tub. If you do this the press will only fit in a wagon or large ship. Guess I didn't say the graphic doesn't change when folks resize it.  Anyway, there it is.

Share this post


Link to post
Share on other sites

Sorry about the necromance

 

but is it possible to use this script to create a larger bucket? 12litres is far toosmall, suggestions? Thanks mate

Share this post


Link to post
Share on other sites
19 hours ago, ozmods said:

Sorry about the necromance

 

but is it possible to use this script to create a larger bucket? 12litres is far toosmall, suggestions? Thanks mate

 

 

 

Cut the code out as it didn't work.

Edited by Enuf

Share this post


Link to post
Share on other sites

thanks dude, but no dice still the same as before.

cheers all the same

Share this post


Link to post
Share on other sites

@ozmodsI changed the first post's code so we can specify an item using the name we see in-game. 

  • Like 2

Share this post


Link to post
Share on other sites

thanks mate, for doing this, but it didnt work, that might be something this old fart just cant grasp, how much of the above code do i put into np++ and do i need to have the small bucket json file in a folder called "small b ucket" sorry lol b ut i'm not really that smart when it comes to things like this, i'm better with things in the real world, not on a computer as in programming stuff lol.

Share this post


Link to post
Share on other sites

You need to copy the entire code in the reveal box. Your bucket file should be in the same folder ( \mods\scriptrunner\scripts\onItemTemplateCreator\ )as the fruit press one just with a different name like smallbucket.js

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this