adding multiple items to inventory at once? (and other stuff)

Started by Michigami, Mon 25/05/2009 07:09:17

Previous topic - Next topic

Michigami

yet another moment of stupidity here.  I've temporarily given up on this thing until i can get help on getting this to work.  (i'm using 3.0 of the editor prog.)

firstly, i need to know how to add multiple items into an inventory at once.  Every code bit i've used has either done nothing or made the program error.  I need one of my quests to give 3 empty vials to the player, and another needs to take 5 apples at once from the inventory and give a pie in return.

i also need some help figuring out using several things with each other.  i have bits and pieces of this one working, but i wanted to have it that in addition to actually having an empty basket to pick berries with, they also have to pick berries 3 times to fill one basket, or use 3 apples on a pie shell to fill it and change it into a useable "pie" item.


i also need help letting the player type in and store a character name, and using it later when they achieve a job class, ie the player's character "Bob" eventually becomes "Bob the Blacksmith" once he gets enough labor, merchant, and logic skill points to qualify and goes to the village job center and buys a specialized class title.  (I have the skill point system working pretty well with globals, it's just the name, and adding the title to the name later i needed)

Wonkyth

I'm not so good with real code, but I'll give it a try.

First, when you say "Give 3" or "take 5" I assume you mean of the same item. So if you have five of iApple, you can get iPie. If so, You'd probably do this with the InventoryQuantaty property.
Not sure exactly how, but it shouldn't be too tricky.

Second, do you have your apples as separate items, like iApple1, iApple2 and iApple3?
if so you could do something like this:
pseudo
Code: ags

int ApplesAdded;

function UseAppleOnPieshell(int AppleNumber) {
if (AppleNumber==1){
LoseInv(iApple1);
}
else if(AppleNumber==2){
LoseInv(iApple2);
}
else {
LoseInv(iApple3);
}
ApplesAdded = ApplesAdded + 1;
if (ApplesAdded==3) {
LoseInv(iEmptyPie);
GetInv(iPie);
}
}

or something like that.
If they are multiples of the same item, then do the same sort of thing, but using InventoryQuantaty.


Third, this could probably be achieved by simply getting the player to type in a name and storing it as a string.
when the time comes to affix a title, just do something like this:
pseudo
Code: ags


string PlayerName; //this should probably be a global variable, but I'm not sure

function AddTitle(eTitleType) {
if (TitleType==eBlacksmith){
PlayerName...//whatever string manipulation is required, I'm not sure about this, as I've never done it
}
else if (TitleType==Bureaucrat) {
//more of the same
} 
}

Again, I'm not sure about any of this, as this is the first time I've tried to get an idea across to someone.
Should probably be reviewed by one of the AGS Tutors.
Anyway, hope it helps.
"But with a ninja on your face, you live longer!"

Khris

To elaborate a bit:

To add an inv item multiple times, simply call the command multiple times, e.g. using a loop:
Code: ags
  int i;
  while (i < 5) {
    player.AddInventory(iApple);
    i++;
  }


In the general settings pane, under "Inventory", check out the first option "Display multiple icons for multiple items".
AGS stores the carried inventory items by keeping track of how many of each of the set up items the player has, using the Character.InventoryQuantity[] array.
So if the player, like above, has received five iApple, this means that player.InventoryQuantity[iApple.ID] has a value of 5.
If the mentioned setting is set to false (the default, iirc), only one apple is displayed. If it is set to true, the InvWindow will display five apples. Alternatively, you can display the count next to the item, check out my InvAmount module.

To implement a partly filled basket, you can either create four basket items (empty, 1/3 full, 2/3 full, full) or use a global variable to keep track of the amount of berries. I'd recommend the latter method.
Code: ags
// room script

function oBush_Interact() {
  if (basket_level == 3) player.Say("Nah, my basket is full.");
  else {
    basket_level++;
    iBasket.Graphic = basket_level + 32;   // assuming the four graphics for the basket are sprites 32-35
    Display("You pluck a good deal of berries from the bush and put them in your basket.");
  }
}


The name of the player can be stored by setting/changing player.Name.
To add a title, call
Code: ags
  player.Name = player.Name.Append(" the Blacksmith");

SMF spam blocked by CleanTalk