Server Totals
Visimontium - (3)
Mikona - (1)
M'Chek - (1)
Underdark - (0)
Elysia - (0)
Ferrell - (0)
Le'Or - (0)
Wilderness - (0)
Deglos - (0)
Total players: 5
Gallery
  • gilbert
    Album name: DM Events
    Uploaded by: Ronan
    Uploaded: Tue Mar 10, 2015 12:55 am

Links Menu

Item destruct after use

Moderators: Nighthawk4, Dungeon Masters

Item destruct after use

PostAuthor: Neve » Wed Jul 09, 2003 6:18 pm

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 :)
- As you gaze unknowingly into the seemingly infinite depths of the optics of this altogether passionate embodiment of insatiability, you experience a gradual realisation that the heavily-embellished vocabulary scattered lavishly throughout the sentence you are currently reading is indisputably nothing greater than a generous ration of masculine bovine faeces.
User avatar
Neve
Prince of Bloated Discourse
 
Posts: 192
Joined: Mon Apr 14, 2003 4:09 pm
Location: The Netherlands

PostAuthor: maxinion » Wed Jul 09, 2003 9:13 pm

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.
User avatar
maxinion
Team Member; Retired with Honors
 
Posts: 2780
Joined: Mon Mar 17, 2003 7:44 pm
Location: Bay Area, CA
DM Avatar: Andrinor

Re: Item destruct after use

PostAuthor: Myk D'vor » Thu Jul 10, 2003 2:37 am

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

Myk D'vor
Lord of Blithering Idiots
 
Posts: 111
Joined: Mon Feb 24, 2003 9:05 am

PostAuthor: Neve » Thu Jul 10, 2003 8:21 am

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 !
- As you gaze unknowingly into the seemingly infinite depths of the optics of this altogether passionate embodiment of insatiability, you experience a gradual realisation that the heavily-embellished vocabulary scattered lavishly throughout the sentence you are currently reading is indisputably nothing greater than a generous ration of masculine bovine faeces.
User avatar
Neve
Prince of Bloated Discourse
 
Posts: 192
Joined: Mon Apr 14, 2003 4:09 pm
Location: The Netherlands


Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Fellock Dust Talon, Google [Bot]