Little script help please

Post » Mon Mar 15, 2010 6:42 am

I have a refinery that takes ingredients and turns them into Animal Feed.

With plants, I want 5 ingredients to be worth 1 Animal Feed portion.

How do I script this to happen without wastage?

For example...

     set numApples to Player.GetItemCount Apple     ;(numApples = how many apples player has)     set numAnimalFeed to numApples / 5     ;(numAnimalFeed = how many apples player has divided by 5.  So 1 AnimalFeed per 5 Apples)     if Player.GetItemCount Apple >= 5     ;(Player has atleast 5 apples)          Player.RemoveItem numApples     ;(Remove all apples player has in inventory)          Player.AddItem AnimalFeed numAnimalFeed      ;(Player gets AnimalFeed at one fifth of the amount of apples.)    endif


This code gives me 1 Animal Feed per 5 apples.

But the problem is that all the Apples a player has are removed. So if player has 12 apples, he loses all 12 and gets 2 Animal Feed. Thats a wastage of 2 apples.

How can I script it to only take apples that make up a whole animal feed and leave any remainders?
User avatar
Curveballs On Phoenix
 
Posts: 3365
Joined: Sun Jul 01, 2007 4:43 am

Post » Sun Mar 14, 2010 10:40 pm

I'm not sure whether a short is a rounded or unrounded integer. If it is unrounded you could use something like this:

short numapplesset numapples to player.getitemcount apple / 5player.additem AnimalFeed numapplesset numapples to numapples * 5player.removeitem apple numapples

User avatar
Daniel Holgate
 
Posts: 3538
Joined: Tue May 29, 2007 1:02 am

Post » Sun Mar 14, 2010 3:25 pm

I'm not sure whether a short is a rounded or unrounded integer. If it is unrounded you could use something like this:

short numapplesset numapples to player.getitemcount apple / 5player.additem AnimalFeed numapplesset numapples to numapples * 5player.removeitem apple numapples



I think shorts are rounded, floats are the ones that use decimal.

Issue is, I will then get an inaccurate amount of AnimalFeed because if the player has 9 apples, the short will round it to 10 correct?

So instead of having apple wastage, I'll get 1 more AnimalFeed than I should.
User avatar
Adriana Lenzo
 
Posts: 3446
Joined: Tue Apr 03, 2007 1:32 am

Post » Mon Mar 15, 2010 5:12 am

Ah, it's ok I've figured it out now.

I need a loop where it takes only 5 apples and gives only 1 animal feed, then checks the statement again and again until it returns false.
User avatar
Kari Depp
 
Posts: 3427
Joined: Wed Aug 23, 2006 3:19 pm

Post » Mon Mar 15, 2010 2:02 am

I think shorts are rounded, floats are the ones that use decimal.

Issue is, I will then get an inaccurate amount of AnimalFeed because if the player has 9 apples, the short will round it to 10 correct?

So instead of having apple wastage, I'll get 1 more AnimalFeed than I should.


Just tested in game (you could have done as well :)). Shorts are not rounded so the the script should work like it is.

EDIT: The method you described above works, but it causes message spam. Like 5 apples removed, 1 animal feed added, 5 apples removed, 1 animal feed added etc.
User avatar
MatthewJontully
 
Posts: 3517
Joined: Thu Mar 08, 2007 9:33 am

Post » Mon Mar 15, 2010 2:13 am

Just tested in game (you could have done as well :)). Shorts are not rounded so the the script should work like it is.

EDIT: The method you described above works, but it causes message spam. Like 5 apples removed, 1 animal feed added, 5 apples removed, 1 animal feed added etc.

Oh thanks.

How about if I put the ingredients into a container and have the ingredients removed from and added to the container, there should be no message spam then right?
User avatar
stephanie eastwood
 
Posts: 3526
Joined: Thu Jun 08, 2006 1:25 pm

Post » Mon Mar 15, 2010 1:03 am

Oh thanks.

How about if I put the ingredients into a container and have the ingredients removed from and added to the container, there should be no message spam then right?


You could also spawn a horde of Daedra carrying animal feed. They give it to the player, take the apples from him, open an Oblivion gate and exit through that gate. Or you could use the script I posted above, which would remove the correct amount of apples from the player and give the correct amount of animal feed to him and show the correct total amount of removed apples and added animal feed with just the two needed messages.
User avatar
Damned_Queen
 
Posts: 3425
Joined: Fri Apr 20, 2007 5:18 pm

Post » Mon Mar 15, 2010 2:14 am

You could also spawn a horde of Daedra carrying animal feed. They give it to the player, take the apples from him, open an Oblivion gate and exit through that gate.

Now thats just plain silly :)

I'm just thinking about the maths here.

player has 9 apples.

9 / 5 = 1.8

short rounds the 1.8, so it is now 2 correct? Or does it round only down?

So 9 apples will give player 2 animal feed instead of 1 with 4 remainding.

I'll go and try it later, can't right now as I'm not at my modding machine.
User avatar
DAVId MArtInez
 
Posts: 3410
Joined: Fri Aug 10, 2007 1:16 am

Post » Mon Mar 15, 2010 1:01 am

Just tested in game. Shorts are not rounded so the script should work like it is.


That means: 1.9 apples will become 1 apple. 1.2 apples will become 1 apple. Decimal places are not rounded, they are ignored. That was the whole idea behind the script I posted. To clarify even more I'll do the example with 12 apples:

short numapples ; this is a short variable, an unrounded integerset numapples to player.getitemcount apple / 5 ; 12 / 5 = 2.4 player.additem AnimalFeed numapples ; since numapples is a short 2.4 will become 2 so 2 Animal Feed are addedset numapples to numapples * 5 ; 2 * 5 = 10player.removeitem apple numapples ; 10 apples are removed from the player

User avatar
Prisca Lacour
 
Posts: 3375
Joined: Thu Mar 15, 2007 9:25 am

Post » Mon Mar 15, 2010 1:05 am

That means: 1.9 apples will become 1 apple. 1.2 apples will become 1 apple. Decimal places are not rounded, they are ignored. That was the whole idea behind the script I posted. To clarify even more I'll do the example with 12 apples:

short numapples ; this is a short variable, an unrounded integerset numapples to player.getitemcount apple / 5 ; 12 / 5 = 2.4 player.additem AnimalFeed numapples ; since numapples is a short 2.4 will become 2 so 2 Animal Feed are addedset numapples to numapples * 5 ; 2 * 5 = 10player.removeitem apple numapples ; 10 apples are removed from the player


Ah I see, that clears it up then. I didn't realise decimals were ignored completely.

Thanks.
User avatar
Joanne
 
Posts: 3357
Joined: Fri Oct 27, 2006 1:25 pm


Return to IV - Oblivion