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?
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?
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…
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.
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
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…
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…
// '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.
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.
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.
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.