Jump to content

Timed Item Scripting Help


Sparrow

Recommended Posts

Hi, I'm trying to make a small mod of Hydrocraft to make farming/ranching a little more challenging.

 

My idea is to make it a little more realistic and immersive, with more item sprites, more time between animals aging up, getting sick, etc.

 

The trouble is I'm a scripting noob, so if anyone could give me some help I would really appreciate it.

 

For example, here is one of the scripts I'm trying to mod:

 

ItemTimeTrackerMod["HCSheepfemale"] = {};

ItemTimeTrackerMod["HCSheepfemale"]["Life"] = 120.0;

ItemTimeTrackerMod["HCSheepfemale"]["TurnInto"] = "Hydrocraft.HCSheepfemalehungry";

 

I'd like it so that when the sheep changes states from normal to hungry, it makes a "baa" sound. I liked the idea of, like a real farm, you are woken in the morning by the animals calling for their food. Or a rooster crowing in the morning, you know. Farm stuff.

 

How would I add a sound into the above script? How would I code it? I've looked up multiple scripting help guides but I can't find an answer.

 

Problem #2, I'd like to alter the breeding recipes so that there is a random chance to get a male or female baby animal, or none at all. Here is the breeding recipe for pigs:

 

recipe Breed Pigs
    {
     HCPigmale,
     HCPigfemale,
 Apple/Carrots/Cabbage/Corn/Lettuce/HCGrass/HCStraw/HCChinesecabbage/HCCornred/HCCornblue/HCCornwhite/HCCabbagered/HCCabbagewhite,
 Water,
     CanBeDoneFromFloor:true,
     Result:HCPigmalebaby=3,
     OnCreate:recipe_hcpigbreeding,
     Time:2000.0,
        NeedToBeLearn:true,
     Sound:oink,
     Category:Ranching,
    }

recipe Breed Pigs
    {
     HCPigmale,
     HCPigfemale,
 Apple/Carrots/Cabbage/Corn/Lettuce/HCGrass/HCStraw/HCChinesecabbage/HCCornred/HCCornblue/HCCornwhite/HCCabbagered/HCCabbagewhite,
 Water,
     CanBeDoneFromFloor:true,
     Result:HCPigfemalebaby=3,
     OnCreate:recipe_hcpigbreeding,
     Time:2000.0,
        NeedToBeLearn:true,
     Sound:oink,
     Category:Ranching,
    }

 

These are two different recipes. How would I alter it so it's one recipe with multiple possible results?

 

Thank you very much for your attention and any help you could havefer would be greatly appreciated! <3

 

 

Link to comment
Share on other sites

  • 5 weeks later...
On 11/9/2017 at 5:08 PM, Sparrow said:

>stuff<

These are two different recipes. How would I alter it so it's one recipe with multiple possible results?

 

Thank you very much for your attention and any help you could havefer would be greatly appreciated! <3

Yo man, I would need to see exactly how the stuff from your first question works in order to be able to try to answer that. HC is too big for me to go digging around in there to find out what function changes the animal to hungry, but you would need to alter that function. If you have Notepad++ you could do a search for "TurnInto" in all of the file contents and see what that's about, and that would help out.

 

As for the second question, the way PZ is coded limits what is made by recipes to one item, or multiple of one item. TIS included a function that works around this:

 

OnCreate:randomPiggies,

 

So you'd need to write a function that fires whenever that recipe is ran, and give it a random value for the piggies.

Something like this:

 

function randomPiggies(item, resultItem, player)
	local player = getPlayer();
	local pInv = player:getInventory();
	local numPiggies = ZombRand(4); --random number between 0 and 3
	local malePiggies = ZombRand(numPiggies); --random number between 0 and numPiggies
	
	if numPiggies > 0 then
		if malePiggies > 0 then
			pInv:AddItems("HydroCraft.MalePig", malePiggies);
      		pInv:AddItems("HydroCraft.FemalePig", malePiggies - numPiggies);
		else
      		pInv:AddItems("HydroCraft.FemalePig", numPiggies);
		end
	end
end

Now, before this code will work, you need to change the "HydroCraft.MalePig" and "...FemalePig" to whatever it actually is in his script. Those are just place holders. Another thing that might fuck this up is trying to AddItems("HC.Pig", 0). I don't know if AddItems will return an error if there are zero items to be added. If you do encounter this I could do a quick rewrite to fix it. 

 

Also, the issue with vanilla recipes is that SOMETHING has to be created. So I suggest making a dummy item like "HydroCraft.AfterBirth" that has no value, aside from weight and ickiness, that will be added so you can get around the problem of having to have a pig born every time.

 

So the new recipe would look like this:

recipe Breed Pigs
    {
     HCPigmale,
     HCPigfemale,
 Apple/Carrots/Cabbage/Corn/Lettuce/HCGrass/HCStraw/HCChinesecabbage/HCCornred/HCCornblue/HCCornwhite/HCCabbagered/HCCabbagewhite,
 Water,
     CanBeDoneFromFloor:true,
     Result:HCAfterBirth,
     OnCreate:recipe_hcpigbreeding,
	 OnCreate:RandomPiggies,
     Time:2000.0,
     NeedToBeLearn:true,
     Sound:oink,
     Category:Ranching,
    }

I just noticed that there is already an OnCreate in that recipe. I don't know if there's going to be an issue using that function twice, however there is a workaround for that, too, if there is a problem.

 

Please let me know if there are any issues with this, or if you don't understand something.

Edited by tommysticks
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...