Acquirement script - I must be missing something [SOLVED]

I have an acquirement script based on the Item Acquire template script under Templates in the Script Assist.
However, it doesn’t seem to be working so I must be doing something wrong. I have an item with the same tag that you pick up from 6 different creatures, and when you’ve picked up them all there should be a journal entry happening. Maybe you can’t have 6 items with the exact same tag and make it work this way? Here’s the script:

// i_temp_aq
/*
   Template for an Acquire item script.
   This script will run each time the item is acquired.
   
   How to use this script:
   Replace the word "temp" (in line 1) with the tag of the item.  Rename the script with this name.  
    
   Additional Info:
   In general, all the item "tag-based" scripts will be named as follows:
   - a prefix ("i_" by defualt)
   - the tag of the item
   - a postfix indicating the item event.
   
   This script will be called automatically (by defualt) whether it exists or not.  If if does not exist, nothing happens.
   "_aq" was used for the Acquire postfix because "_ac" was already taken by Activate.  
   
   Note: this script runs on the module object, an important consideration for assigning actions.
   -ChazM
*/
// Name_Date


#include "ginc_item_script"

void main()
{
    object oPC      = GetModuleItemAcquiredBy();
    object oItem    = GetModuleItemAcquired();
    int iStackSize  = GetModuleItemAcquiredStackSize();
    object oFrom    = GetModuleItemAcquiredFrom();


	// Once marked complete, never run this script again.
	//if (IsItemMarkedAsDone(oItem, SCRIPT_MODULE_ON_ACQUIRE_ITEM))
	//	return;
	
	// 	Don't run this script unless it's aqcuired by a player or party member
	// (This event runs at the start of the game	
	//if (!IsItemAcquiredByPartyMember())
	//	return;

				
 	// Update the journal
	
	int i = GetGlobalInt("nBoarItemsCollected") + 1;
	SetGlobalInt("nBoarItemsCollected", i);
	
	object oPC1 = GetFirstPC();
	if(GetGlobalInt("Boaritemsfound")) return;
		
    if (i == 6)
		{
 
		SetGlobalInt("Boaritemsfound",1);
		AddJournalQuestEntry("q_boars",11,oPC1);
		MarkItemAsDone(oItem, SCRIPT_MODULE_ON_ACQUIRE_ITEM);
		
		}
		
	// Permanently mark item as complete so script will never run again (even if the character is exported to another game)		
	//MarkItemAsDone(oItem, SCRIPT_MODULE_ON_ACQUIRE_ITEM);

}

I tested the script - It works.
Is the script name i_<itemtag>_aq? It must be in this format or it won’t execute.
If the script name is in the proper format, then once you collect all 6 items do you get a blank journal entry?

1 Like

Oh crap. I misspelled it! :man_facepalming:

The name of the script should have been “i_boarh_it_aq” and I had wrote “i_boardh_it_aq”. Urrgh! Such a simple mistake. Thanks travus!

2 Likes

Hmmm, it doesn’t quite work still. Odd. When I picked up 3 of these items I got a journal entry instead of when I had picked up 6.

i notice some anomalies in that script (unused variables, a redundant global, and no check for ItemDone)

here’s another way of it…

// 'i_boarh_it_aq'

void main()
{
    object oLeader = GetFactionLeader(GetModuleItemAcquiredBy());
    if (GetIsObjectValid(oLeader)) // is acquired by party
    {
        int iCollected = GetGlobalInt("nBoarItemsCollected");
        if (iCollected < 6)
        {
            SetGlobalInt("nBoarItemsCollected", ++iCollected);

            if (iCollected == 6)
                AddJournalQuestEntry("q_boars", 11, GetFirstPC());
        }
    }
}

not quite… editing… ok

1 Like

Ok, reading your script a few times I think I see the logic in your code, although I would never be able to come up with a code like that, I think.

So, what was wrong with my script? I guess the first things like the oPC and oFrom I don’t use (but I just copied that from the template and didn’t bother erasing it) but other than that, why didn’t my version work?

And I see that you don’t use the MarkItemAsDone. Maybe there’s a reason for that?

idk. Maybe the global “nBoarItemsCollected” had already been incremented to 3 somehow?

MarkItemAsDone() just sets a variable… we already have a variable that can be checked : “nBoarItemsCollected”. Why not use it?

2 Likes

Ah, ok, that makes sense, I guess. I just thought, since it is written that:

//This script will run each time the item is acquired.

then this script would be run unnecessarily if the player were to aquire another item of these, even though nothing would happen since the number would then be 7…or maybe I’m just stupid now… :confused:

I’m thinking about this:

// Permanently mark item as complete so script will never run again (even if the character is exported to another game)		
	//MarkItemAsDone(oItem, SCRIPT_MODULE_ON_ACQUIRE_ITEM);

Anyhow, I will test your version of the script and see if it works.

this is not exactly correct:

// Permanently mark item as complete so script will never run again (even if the character is exported to another game)

The script will run again… but it will be aborted quickly. So there’s still the overhead of the event firing …

however ! I notice that if it is not set, player can exploit my script by dropping and picking up the item repeatedly.

so here’s another take

// 'i_boarh_it_aq'

#include "ginc_item_script"

void main()
{
    object oIt = GetModuleItemAcquiredBy();

    if (!IsItemMarkedAsDone(oIt, SCRIPT_MODULE_ON_ACQUIRE_ITEM))
    {
        object oLeader = GetFactionLeader(oIt);
        if (GetIsObjectValid(oLeader)) // is acquired by party
        {
            MarkItemAsDone(oIt, SCRIPT_MODULE_ON_ACQUIRE_ITEM);

            int iCollected = GetGlobalInt("nBoarItemsCollected");
            if (iCollected < 6)
            {
                SetGlobalInt("nBoarItemsCollected", ++iCollected);

                if (iCollected == 6)
                    AddJournalQuestEntry("q_boars", 11, GetFirstPC());
            }
        }
    }
}
2 Likes

I tried your first version and it seemed to work. However, I have a question about your new version.

Since the MarkItemAsDone is run when the first item is picked up can the player really pick up 6 items of the same tag?

Or does the game treat each item as its own, although they have the same tag?

i believe the done flag is set on each item individually… so any of your items that haven’t been flagged would run through the script correctly. Only items that have already been flagged done ought abort fast

yeh :)

2 Likes

Thanks a lot, kevL_s! I will use your second script then!

I still find it odd that I got a journal entry after three items on my original script though. I see no reason for that. And travus reported that it worked on his end…odd…

1 Like

the only reason i can see for that atm, is the global was already at “3” … you could send the value to the chatbox to be sure ( ie. debug )

/shrug

Hmmm, I just tested your second version of your script, and it didn’t work, actually. I guess it must have something to do with the MarkItemIsDone then.

I think I’ll use the first version then, since that worked for me. Hopefully the player won’t exploit your script by dropping and picking up the items, but I don’t know…

Maybe one could do it like this instead?

// 'i_boarh_it_aq'

#include "ginc_item_script"

void main()
{
    object oIt = GetModuleItemAcquiredBy();

    if (!IsItemMarkedAsDone(oIt, SCRIPT_MODULE_ON_ACQUIRE_ITEM))
    {
        object oLeader = GetFactionLeader(oIt);
        if (GetIsObjectValid(oLeader)) // is acquired by party
        {
            

            int iCollected = GetGlobalInt("nBoarItemsCollected");
            if (iCollected < 6)
            {
                SetGlobalInt("nBoarItemsCollected", ++iCollected);

                if (iCollected == 6)
                    AddJournalQuestEntry("q_boars", 11, GetFirstPC());
                    MarkItemAsDone(oIt, SCRIPT_MODULE_ON_ACQUIRE_ITEM);
            }
        }
    }
}

Hmmm, maybe that doesn’t help in this case…

Edit: No, this variation didn’t work either. Really strange. And what’s more, when trying to dropping the items and picking them up, when looking at the character names of the PC and the companions, all of a sudden there was this weird text after them…I’ll have to do further testing, I think.

Edit2: Tested again. After picking up the first item it said “Charactername,DoOnce7=1” when using the script above that is.

@andgalf,

Take care with acquired counts, especially if there is a possibility that the variable state may be set another time.

I would be inclined to recount said item upon each acquisition to be sure of correct count. That would also allow for dropping of the item too. (Although checks would then also need to test for item ownership within the party or on the ground.)

I am also assuming this is only checking item being picked up by the same PC and ignoring that other party members are not doing the acquiring.

If it is not possible to drop the item again, then a single variable check (as already discussed) is the safest way to go.

1 Like

This sounds complicated. I don’t know if I could write such a code.
As it is now it is possible to drop the item again or give it to a companion.

I think I’ll test kevL_s first script again.

I guess one would have to use a lot of GetItemPossessedBy or something and while loops and all that, and I’m terrible with while-loops.

@andgalf,

It’s not too bad, but would involve a loop check. I can only offer advise at moment, but hope to give more help in coming weeks.

Although, I am confident others like @kevL_s or @travus may consider demonstrating such code if they have the time … But I also recognise this may be more than you need.

Edit: It also makes a difference if there are only six possible acquisitions of the item or if there are more available to collect.

Lance

1 Like

Ok. I’m looking at one of my brother’s scripts now with GetItemPossessedBy but that doesn’t involve counting of the item with the same tag so…as I said, I don’t think I’ll be able to code this on my own.
Maybe, as you say, these two gentlemen can help out with this, otherwise I might just run with kevL_s first version of his code.

As I’ve done it now, there are only six possible acquisitions.