Jump to content

ItemContainer/IsoObject


badtrix

Recommended Posts

Since hours I'm trying to get something for my mod (Building Mod) to work, but still it isn't. So i hope maybe someone else can help me. The problem is the following:

 

The following code creates e.g. a gun locker, dresser etc:

 

 

(based on ISWoodenContainer.lua)

BMContainer = ISBuildingObject:derive("BMContainer");function BMContainer:create(x, y, z, north, sprite)	local cell = getWorld():getCell();	self.sq = cell:getGridSquare(x, y, z);        -- creates the object as a new instance of IsoThumpable	self.javaObject = IsoThumpable.new(cell, self.sq, sprite, north, self);		buildUtil.setInfo(self.javaObject, self);	buildUtil.consumeMaterial(self);	-- the wooden wall have 200 base health + 100 per carpentry lvl	self.javaObject:setMaxHealth(BMContainer:getHealth());	-- the sound that will be played when our door frame will be broken	self.javaObject:setBreakSound("breakdoor");	-- add the item to the ground        self.sq:AddSpecialObject(self.javaObject);	buildUtil.addWoodXp();		self.javaObject:transmitCompleteItemToServer();endfunction BMContainer:new(sprite, northSprite, containerType)	BMContainerHealth.amount = 0;	BMContainerHealth.perlvl = 0;		local o = {};	setmetatable(o, self);	self.__index = self;	o:init();	o:setSprite(sprite);	o:setNorthSprite(northSprite);	o.isContainer = true;	o.blockAllTheSquare = true;	o.dismantable = true;	o.canBeAlwaysPlaced = true;	if containerType == "Gun Locker" then 		o.name = "Gun Locker";		BMContainerHealth.amount = 800;		BMContainerHealth.perlvl = 1;	elseif containerType == "Beige Dresser" then 		o.name = "Beige Dresser";		BMContainerHealth.amount = 300;		BMContainerHealth.perlvl = 1;	elseif containerType == "Cellar" then 		o.name = "Cellar";		BMContainerHealth.amount = 10000;		BMContainerHealth.perlvl = 10;	else		o.name = "Wooden Crate";		BMContainerHealth.amount = 10000;		BMContainerHealth.perlvl = 10;	end	return o;end

 

the problem is that i need to set a parameter for that newly created object "self.javaObject" in the BMContainer:create() function, which i dont know how to do.

 

The parameter to be set belongs to the class

java.lang.Object

inherit.gifzombie.inventory.ItemContainer


more specific, i need to set the "type" parameter, which can be done with the setType() function offered by the ItemContainer class. However, i do not know how to properly call that function, because the object created (self.javaObject) in the BMContainer:create() function belongs to the class

java.lang.Object

inherit.gifzombie.iso.IsoObject
inherit.gifzombie.iso.objects.IsoThumpable


 

Further Explanation:

for my mod i want to implement the possibility to preserve food in a storage object. For that purpose i need to check if ItemContainer.type == "preserve" whenever an item is transfered into a container (happens in ISInventoryTransferAction:perform()). 

 

However, by default containers created by the code above  have the ItemContainer.type = "crate", which needs to be changed to "preserve" so that my mod will work.

 

It would be awesome if someone could tell me how i can call that setType() function so i can alter the type for the newly created item.

 

And i hope i could explain my problem in an understandable way :P

Link to comment
Share on other sites

I never really looked into the building object code so this is just a guess:

 

If I understood you correctly you want to declare your building object as a container (so that it works like a fridge or a cupboard in the game). Have you tried something like this:

 

    -- Create a new item container object:    self.container = ItemContainer.new('containerName', self.sq, self.javaObject, 100, 100);

 

As I said it is just a guess and I haven't got the time to test it, but mabye it's the push in the right direction you need ;)


Also look at the java source code and check how TIS makes new ItemContainers. Most of the stuff on the java side can be done on the lua side with a few changes.

Link to comment
Share on other sites

thanks RoboMat. Well, i already tried your suggestion for Windows objects last week (as they would need to be of the class IsoWindow instead of IsoThumpable to be functional). However, it did not work because it seems there is no IsoWindow.new() or ItemContainer.new() function.

 

Basically what the problem with the IsoThumpable class is, is that it was coded to work with the buildable objects implemented in the original build 25. Thus it offers only the functions needed to create those objects. however if you want to do new stuff and implement objects with functions which havent been implemented in original game yet it gets difficult.

 

To have alook at the java source code would be nice, but actually i do not know where to look (didnt had to do with java coding for the past 10 years i guess)? do i have to open all .jar files in the main game directory to find the IsoThumpable.new() function?

 

or to formulate my problem in easier words with less code, thats what i want to do (just wrote that code without testing, maybe this might work):

function BMContainer:create(x, y, z, north, sprite)-- get the tile we want to build our objectlocal cell = getWorld():getCell();self.sq = cell:getGridSquare(x, y, z);-- now create the objectself.javaObject = IsoThumpable.new(cell, self.sq, sprite, north, self);-- now get the ItemContainer on the same square x, y, z and setType()-- (IsoThumpable somehow creates the object as an ItemContainer)-- however, i do not know how to get the container on that square. -- thats my main problemend
Link to comment
Share on other sites

ok, i found the specific java classes and functions which is responsible for my problem:

 

from IsoThumpable.class

 public void setIsContainer(boolean pIsContainer)  {    this.isContainer = pIsContainer;    if (pIsContainer)    {      this.container = new ItemContainer("crate", this.square, this, 6, 6);      this.container.setExplored(true);    }  }

what i am wondering now, is it possible to do java modding, like to alter the original IsoThumpable.class and implement it into my mod?

 

else i do not see how i could change the type from "crate" to "preserve".

Link to comment
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
×
×
  • Create New...