Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Need help?

    Create a topic in the appropriate section
    Don't write everything in the chat!
  • Take a look at the marketplace

    There you can buy
    everything related to game servers
  • Don't want a ban?

    Please read our rules
    Don't disturb the order!
  • Sell or buy?

    Use services of the guarantor
    We will make your deal safe
  • 0
Sign in to follow this  
Loner

Определение количество объектов одного типа

Доброго времени суток!
У меня есть скрипт который определяет что в инвентаре предмета (например кастрюля), лежит один предмет

CargoBase cargo = MyObject.GetInventory().GetCargo();
            if(cargo.GetItemCount() == 1)
            { return True; } Else { return False; }

Как сделать подобный скрипт который определит сколько предметов одного типа лежит в инвентаре, например 4 яблока?

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Для подсчета количества предметов определенного типа в инвентаре:
 

int CountItemsOfType(string itemType) {
    int count = 0;
    for (int i = 0; i < GetInventory().AttachmentCount(); i++) {
        EntityAI item = GetInventory().GetAttachmentFromIndex(i);
        if (item && item.GetType() == itemType) {
            count++;
        }
    }
    return count;
}

Затем можно вызвать эту функцию для подсчета количества предметов определенного типа в инвентаре.Например, чтобы подсчитать количество яблок в инвентаре:
 

int appleCount = CountItemsOfType("Apple");

 

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  

×
×
  • Create New...

Important Information

By using this site, you automaticly agree to our Guidelines and Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.