Aller au contenu

Photo

Reset Cooldowns


  • Veuillez vous connecter pour répondre
15 réponses à ce sujet

#1
jsd313

jsd313
  • Members
  • 184 messages
Is it possible to set an area script to clear all active cooldowns when entering? I have it currently topping off health/mana/sta and removing injuries but I want to clear anything on cooldown from potions to abilities.

Thanks

#2
georage

georage
  • Members
  • 247 messages
sure ... check out this ... http://social.biowar...php/SetCooldown



That should help. You will likely have to loop through all spells and abilities and set them all to zero.

#3
jsd313

jsd313
  • Members
  • 184 messages
Sounds time consuming, right up my alley thanks I'll take a look. :)

#4
georage

georage
  • Members
  • 247 messages
a bioware worker posted this ...

Craig Graff wrote...



This might work:

[dascript]

object[] arParty = GetPartyList();

object oPartyMember;

int n, m;

int nPartySize = GetArraySize(arParty);



for (n = 0; n < nPartySize; n++)

{

oPartyMember = arParty[n];

for (m = 0; m < 50; m++)

{

Ability_SetCooldown(oPartyMember, GetQuickslot(oPartyMember, m));

}

}

[/dascript]



#5
jsd313

jsd313
  • Members
  • 184 messages
heh thanks georage, I had asked the question again in another topic. It works for abilities but not for quickuse items like potions. Hoping to figure that out soon.



Thank you for pointing that out though, very cool of ya.

#6
FanfanVilperdue

FanfanVilperdue
  • Members
  • 18 messages
Hi,

  I propose the following code: it's a bit heavy, but I tried and it looks like it works... Thanks to Anakin, whose message in another thread helped me.

void rna_remove_all_cooldowns_party()
{  
    object[] aParty = GetPartyList();
    int nPartySize = GetArraySize(aParty);
    int nCharacter;
    object oCharacter;
    int nTable;
    int nSize;
    int i;
    int nRow;
    int nID;
    object[] aItems;
    
    // Remove cooldowns on spells
    // We loop on abilities outside the character loop, in order to mimimize M2DA queries.
    nTable = TABLE_ABILITIES_SPELLS;
    nSize = GetM2DARows(nTable);
    for (i = 0; i < nSize; i++)
    {
        nRow = GetM2DARowIdFromRowIndex(nTable, i);
        nID = GetM2DAInt(nTable, "ID", nRow);
        for (nCharacter = 0; nCharacter < nPartySize; nCharacter++)
        {  
            oCharacter = aParty[nCharacter];
            if (HasAbility(oCharacter, nID))
            {  
                SetCooldown(oCharacter, nID, 0.0);
            }
        }
    }
                   
    // Remove cooldowns on talents
    // We loop on abilities outside the character loop, in order to mimimize M2DA queries.
    nTable = TABLE_ABILITIES_TALENTS;
    nSize = GetM2DARows(nTable);
    for (i = 0; i < nSize; i++)
    {
        nRow = GetM2DARowIdFromRowIndex(nTable, i);
        nID = GetM2DAInt(nTable, "ID", nRow);
        for (nCharacter = 0; nCharacter < nPartySize; nCharacter++)
        {  
            oCharacter = aParty[nCharacter];
            if (HasAbility(oCharacter, nID))
            {  
                SetCooldown(oCharacter, nID, 0.0);
            }
        }
    }
   
    // Remove cooldowns on items (health potions, etc.)
    for (nCharacter = 0; nCharacter < nPartySize; nCharacter++)
    {  
        oCharacter = aParty[nCharacter];
        aItems = GetItemsInInventory(oCharacter);
        nSize = GetArraySize(aItems);
        for (i = 0; i < nSize; i++)
        {   
            object oItem = aItems[i];
            SetCooldown(oCharacter, GetItemAbilityId(oItem), 0.0, GetTag(oItem));
        }
    }
}

Modifié par FanfanVilperdue, 06 avril 2010 - 09:11 .


#7
Sunjammer

Sunjammer
  • Members
  • 925 messages
Isn't this what we got GetAbilityList for?  It should allow you to replace the above with something more like:

void ResetPartyCooldown(object oCreature)
{  
    int nAbility, nPartyMember;
    int[] nAbilities;
    object oPartyMember;
    
    // for each member of the party ... 
    object[] oPartyMembers = GetPartyList(oCreature);
    for(nPartyMember = 0; nPartyMember < GetArraySize(oPartyMembers); nPartyMember++)
    { 
        oPartyMember = oPartyMembers[nPartyMember];
        
        // ... get their "hot" abilities ...
        nAbilities = GetAbilityList(oPartyMember, ABILITY_INVALID, TRUE);
        for(nAbility = 0; nAbility < GetArraySize(nAbilities); nAbility++)
        {
            // ... and cool them!
            SetCooldown(oPartyMember, nAbility, 0.0);
        }
    }
}

Please not the above is an example to illustrate the new function and which I haven't tested (yet). Also the items might need seperate treatment given the way SetCooldown works.

Modifié par Sunjammer, 06 avril 2010 - 09:49 .


#8
FanfanVilperdue

FanfanVilperdue
  • Members
  • 18 messages
Yes, Craig Graff mentionned also this "GetAbilityList" thing in http://social.biowar...1/index/1359533. But it looks like nobody found this one in the toolset (if you do, please tell us in which script). That's why Anakin5 suggested this kind of loop.

#9
Craig Graff

Craig Graff
  • Members
  • 608 messages
Um... it's been in since the last patch.

#10
FanfanVilperdue

FanfanVilperdue
  • Members
  • 18 messages
Thanks Craig for the piece of info. I think I should install it then... :-)

#11
Sunjammer

Sunjammer
  • Members
  • 925 messages
Sheesh ... the Devs get all the credit ... and all the girls!

The Lexicon never gets either despite the fact it has it listed as a v1.03 function. Perhaps I need to make the categories day-glow pink or something ...

Modifié par Sunjammer, 08 avril 2010 - 12:41 .


#12
TimelordDC

TimelordDC
  • Members
  • 923 messages
Nope, the Lex just needs more publicity :)

#13
FanfanVilperdue

FanfanVilperdue
  • Members
  • 18 messages
Hi,
See below my code as it is for the moment. This script works most of times, but
sometimes it doesn't terminate. I guess its execution is quite long and
that happens when the engine is a bit overloaded. As a consequence, the
parent script (in which I call reset_cooldowns on all party members,
amongst other things) doesn't terminate either.

Anybody has an idea about it? Thanks in advance.

void reset_cooldowns(object oCreature)
{
    // Non-item abilities
    int[] aCoolingDownAbilities = GetAbilityList(oCreature, ABILITY_INVALID, TRUE);
    int nSizeAbilities = GetArraySize(aCoolingDownAbilities);
    int i;
    int nIdAbility;
    for (i = 0; i < nSizeAbilities; i++)
    {
        nIdAbility = aCoolingDownAbilities[i];
        SetCooldown(oCreature, nIdAbility, 0.0);
    }

    // Remove cooldowns on items (health potions, etc.)
    object[] aItems = GetItemsInInventory(oCreature);
    int nSizeItems = GetArraySize(aItems);
    object oItem;
    for (i = 0; i < nSizeItems; i++)
    {
        oItem = aItems[i];
        nIdAbility = GetItemAbilityId(oItem);
        if (nIdAbility != ABILITY_INVALID)
            SetCooldown(oCreature, nIdAbility, 0.0, GetTag(oItem));
    }
}

Modifié par FanfanVilperdue, 14 avril 2010 - 08:59 .


#14
Magic

Magic
  • Members
  • 187 messages
The code looks fine. How much is nSizeAbilities + nSizeItems when you encounter problems?

#15
Sunjammer

Sunjammer
  • Members
  • 925 messages
Your item code is iterating over the shared inventory (backpack) for each creature in the party and attempting to reset the cooldown regardless of whether or not that creature has that ability.  This may or may not be causing you problems but it certainly not ideal. I suspect you'll want to add a HasAbility check.

That code is also resetting the cooldown regardless of whether or not it requires resetting. Again this may or may not be the cause but it should be addressed. This can be done by adding a GetRemainingCooldown check.

However the biggest issue as I see it is that you are not matching the ability to the item that provides it. The code is resetting the cooldown regardless of whether or the current item actually provided it, i.e. if you have multiple items that can provide abilities with the same ID. This issue is minimised by the previous check (assuming you include the item's tag) however if you have two items with the same tag then there does not seem to be a way to distinguish them.

Incidentally if you know your code doesn't work it is better to post it as a request for assistance rather than offer it up as a potential solution.

Modifié par Sunjammer, 13 avril 2010 - 06:19 .


#16
FanfanVilperdue

FanfanVilperdue
  • Members
  • 18 messages
Hi,

  Thank you for your help.

Magic wrote...

The code looks fine. How much is
nSizeAbilities + nSizeItems when you encounter problems?

nSizeAbilities is usually between 0-6, and nSizeItems between 100 et 120. But it is also the case when the script terminates.

Sunjammer wrote...

Your item code is iterating over the shared inventory (backpack) for each creature in the party

Nice idea. Now, for items abilities, I do the loop on items first and then on characters (see code below). According to my tests, it is more than twice faster this way (than the opposite). Theoretically, I guess it's possible that a equipped item has an "cooldownable" ability, so the script doesn't cover every possible cases, but the performance gain is worth it.

Sunjammer wrote...

I suspect you'll want to add a HasAbility check.

I had a look on this also... The only case where HasAbility returned FALSE was for nIdAbility = 200000, aka INVALID_ITEM_ABILITY. Dammit! As soon as I replaced ABILITY_INVALID with INVALID_ITEM_ABILITY, it terminated each time!

Sunjammer wrote...

That code is also resetting the cooldown regardless of whether or not it requires resetting. Again this may or may not be the cause but it should be addressed. This can be done by adding a GetRemainingCooldown check.

I tried to add a test with GetRemainingCooldown, but with no significally better performance.

Sunjammer wrote...

if you have two items with the same tag then there does not seem to be a way to distinguish them.

True, but linked to the syntax of SetCooldown for item abilities (reference by tag only). I don't think it's a problem in practice.

Sunjammer wrote...
Incidentally if you know your code doesn't work it is better to post it as a request for assistance rather than offer it up as a potential solution.

You're right, I edited my message.

By the way, TimelordDC was right, I didn't know the Lex but just the toolset wiki.

Finally, the code (which works for real, this time :))

void reset_cooldowns_party()
{
    object[] aParty = GetPartyList();
    int nPartySize = GetArraySize(aParty);
    int iCreature;
    object oCreature;
    int[] aCoolingDownAbilities;
    int nSizeAbilities;
    int iAbility;
    int nIdAbility;
    object[] aItems;
    int nSizeItems;
    int iItem;
    object oItem;

    // Non-item abilities
    for(iCreature = 0; iCreature < nPartySize; iCreature++)
    {
        oCreature = aParty[iCreature];
        aCoolingDownAbilities = GetAbilityList(oCreature, ABILITY_INVALID, TRUE);
        nSizeAbilities = GetArraySize(aCoolingDownAbilities);
        for (iAbility = 0; iAbility < nSizeAbilities; iAbility++)
        {
            nIdAbility = aCoolingDownAbilities[iAbility];
            SetCooldown(oCreature, nIdAbility, 0.0);
        }
    }                                                

    // Remove cooldowns on items (health potions, etc.)
    // According to tests, it's twice faster to loop on items then on creatures (than the opposite)
    aItems = GetItemsInInventory(GetHero(), GET_ITEMS_OPTION_BACKPACK);
    nSizeItems = GetArraySize(aItems);
    for (iItem = 0; iItem < nSizeItems; iItem++)
    {
        oItem = aItems[iItem];
        nIdAbility = GetItemAbilityId(oItem);
        if (nIdAbility != [color="#ff0000"]INVALID_ITEM_ABILITY[/color])
        {
            for(iCreature = 0; iCreature < nPartySize; iCreature++)
            {
                oCreature = aParty[iCreature];
                SetCooldown(oCreature, nIdAbility, 0.0, GetTag(oItem));
            }
        }
    }
}

Modifié par FanfanVilperdue, 15 avril 2010 - 07:59 .