Aller au contenu

Photo

onInventoryDisturbed script


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

#1
TrekSL

TrekSL
  • Members
  • 32 messages
Got a problem - basically I have a script where all I want it to do is that when three books are acquired (all have same tag) an effect is played and a variable changed. I've gone through lilac soul's on acquire item method and made sure everything is set up so that the books are a tagged module item. My problem is i don't know how to convert the module item in the script so it is counted as a value of nbooks which will then fire the 'if' statement script.

void main()
{

object oPC = GetModuleItemAcquiredBy();

object oItem;
oItem = GetModuleItemAcquired();
if (!GetIsPC(oPC)) return;

//int nBooks = oItem;

//int nBooks = GetNumItems(oPC, "Conjugation");

if (nBooks == 3)
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_HEALING_L),oPC, 0.0);
    SetLocalString(oPC, "hasbooks", "TRUE");

    return;
}

#2
Baragg

Baragg
  • Members
  • 271 messages
Could try:

if( GetNumItems( oPC, "Conjugation" ) == 3)

#3
Baragg

Baragg
  • Members
  • 271 messages
You may want to make sure that the acquiring of anything else does not accidently fire that by enclosing that in another if.

IE:

if( GetTag( oItem ) == "Conjugation" )
{
if( GetNumItems( oPC, "Conjugation" ) == 3 )
{
// Do stuff here
}
}

#4
TrekSL

TrekSL
  • Members
  • 32 messages
trying that - it returns no right bracket on expression for the second if statement (if's and nested if's confuse the heck out of me)

EDIT - ahh missed out an include

Modifié par TrekSL, 21 juillet 2011 - 02:09 .


#5
CID-78

CID-78
  • Members
  • 1 124 messages
you shouldn't use a LocalString , you should use a LocalInt. it doesn't make sense to save a string "TRUE" you should set it to true. Baragg safty step isn't good enough. the player can drop a book and pick it up again and fire the effect part each time.

Use your Local Variable as protection instead.

#6
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Here's a script that I use to allow a player to take up to 3 items out of a chest. While there are more choices available, they can only pick/take 3. Written for NWN2 so may need some edits. Also, this destroys any remaining inventory in the chest and then destroys the chest itself (used as a "reward chest"):

void main()
{
object oSelf = OBJECT_SELF; // This is the chest that has this script OnInventoryDisturbed
object oMasterPC = GetFirstPC(TRUE);
object oPC = GetFirstPC(FALSE);

int nRewardValue = 3;
int nCurrentValue = 0;

// If we have not yet taken 3 items from chest
if(nCurrentValue != nRewardValue)
{
// Add +1 each time an item is taken
nCurrentValue += 1;
SetLocalInt(oSelf, "CurrentValue", nCurrentValue);

int nNewValue = GetLocalInt(oSelf, "CurrentValue");
// If we have taken 3 items, close the GUI screen, destroy inventory and destroy chest
if(nNewValue == nRewardValue)
{
CloseGUIScreen( oPC, "SCREEN_CONTAINER_DEFAULT");
object oInv = GetFirstItemInInventory(oSelf);
while(oInv != OBJECT_INVALID)
{
DestroyObject(oInv, 0.0, FALSE);

oInv = GetNextItemInInventory(oSelf);
}

if(oInv == OBJECT_INVALID)
{
DestroyObject(oSelf, 0.0f, FALSE);
}
}
}
}

#7
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Here's a tag based script for OnAcquire. Just give it the same name as the tag of your book. Should work:


#include "x2_inc_switches"
#include "nw_i0_plot"
void main()
{
    int iEvent = GetUserDefinedItemEventNumber();
    if (iEvent != X2_ITEM_EVENT_ACQUIRE) return;

    object oBook = GetModuleItemAcquired();
    object oPC = GetModuleItemAcquiredBy();

    if (GetNumItems(oPC, GetTag(oBook)) == 3)
    {
        ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_HEALING_L),oPC, 0.0);
        SetLocalString(oPC, "hasbooks", "TRUE");
    }
}

#8
Baragg

Baragg
  • Members
  • 271 messages

CID-78 wrote...

you shouldn't use a LocalString , you should use a LocalInt. it doesn't make sense to save a string "TRUE" you should set it to true. Baragg safty step isn't good enough. the player can drop a book and pick it up again and fire the effect part each time.

Use your Local Variable as protection instead.


Dag nab it, I forgot that they will be sneaky like that, lol.