Page 1 of 1

Item destruct after use

Posted: Wed Jul 09, 2003 6:18 pm
by Neve
I can't seem to create a script for this, though it should be something really easy :?

I put the following in the OnActivateItem of the module :

Code: Select all

void main()
{
    object oItem = GetItemActivated();

      if(GetName(oItem) == "Berry")
        DestroyObject(oItem);
}
But that doesn't work...

After that I put this in the OnRest, but that won't work either and is just plain inefficient...

Code: Select all

    while (GetIsObjectValid(oItem) == TRUE){
        if((GetName(oItem) == "Berry") && (GetItemCharges(oItem) == 0)){
            SendMessageToPC(oPC, GetName(oItem));
            SendMessageToPC(oPC, IntToString(GetItemCharges(oItem)));
            DestroyObject(oItem);
        }
        oItem = GetNextItemInInventory(oPC);
    }
I noticed that after using the item, which has 5 charges, the GetItemCharges(oItem) function still returns a 5 instead of a 0. Help with this would be greatly appreciated :)

Posted: Wed Jul 09, 2003 9:13 pm
by maxinion
How about a local int that tracks how many times you used it? Start it at five, and lower it each time. Check before to see where its at, and if it reaches 1, get a function to destroy it at the end of it purpose.

Re: Item destruct after use

Posted: Thu Jul 10, 2003 2:37 am
by Myk D'vor
Neve wrote:I can't seem to create a script for this, though it should be something really easy :?

I put the following in the OnActivateItem of the module :

Code: Select all

void main()
{
    object oItem = GetItemActivated();

      if(GetName(oItem) == "Berry")
        DestroyObject(oItem);
}
But that doesn't work...
You're better off comparing to the Tag than the name, IMO, but it shouldn't matter that much. The thing you need to do in order to get this to be CALLED is to give the item the "unique power self only" spell ability. Thing is, why would someone use it if it gets destroyed the first time? You need to have it do something useful the first 5 times, and get destroyed only after the fifth, it seems.
Neve wrote:After that I put this in the OnRest, but that won't work either and is just plain inefficient...

Code: Select all

    while (GetIsObjectValid(oItem) == TRUE){
        if((GetName(oItem) == "Berry") && (GetItemCharges(oItem) == 0)){
            SendMessageToPC(oPC, GetName(oItem));
            SendMessageToPC(oPC, IntToString(GetItemCharges(oItem)));
            DestroyObject(oItem);
        }
        oItem = GetNextItemInInventory(oPC);
    }
I noticed that after using the item, which has 5 charges, the GetItemCharges(oItem) function still returns a 5 instead of a 0. Help with this would be greatly appreciated :)
Let's back up a step. What do you want the Berry to do exactly? Is it a necessary component to a player being able to Rest? If so, all you need to do is use your prior code block, with a couple additions.

Code: Select all

    while (GetIsObjectValid(oItem) == TRUE){
        if(GetName(oItem) == "Berry"){
            if(GetItemCharges(oItem) <= 1)){ // if it's the last charge remaining, use it, and destroy it
                SendMessageToPC(oPC, GetName(oItem));
                SendMessageToPC(oPC, IntToString(GetItemCharges(oItem)));
                DestroyObject(oItem);
            } else { // decrement remaining charges
                SetItemCharges(oItem,GetItemCharges(oItem)-1);
            }
        }
        oItem = GetNextItemInInventory(oPC);
    }
It seems that the reason it always had 5 charges is because none were getting used up? Does it have more than one power that has charges? I need more information to be more helpful.

Myk D'Vor

Posted: Thu Jul 10, 2003 8:21 am
by Neve
That is actually quite helpful, it wasn't the unique power I gave it, but a cure minor wounds. (It's a curative berry which PC's can 'eat').

It's basically the same as the Bloodfury crystals or the Mellowsmoke weed on Avlis, only the Berry will heal players. The fact that I was going to remove them onRest was just a desperate attempt at trying to get rid of them anyway. So, all it should do is disappear after it has been used once :)

[Edit]

It works now, thanks alot !