Hi everyone,
I've run into a recent scripting roadblock that's probably pretty simple, but I haven't been able to find a documented solution. Basically, I'm trying to get a defined plot flag to return a value of 1 if the player has an item in his or her inventory, in order to allow for a conversation option to appear. The item in particular is Deathroot Extract. At the moment I have the following script included at the bottom of my existing plot script:
switch(nFlag)
{
case GANG_WAR_POISON_DRAKES_DEATHROOT_EXTRACT:
{
object oHero = GetHero();
string sDeathroot = "gen_im_qck_poison_102";
GetItemPossessedBy(oHero,sDeathroot);
if (sDeathroot=="gen_im_qck_poison_102")
{
nResult = 1;
}
else
{
nResult = 0;
}
}
}
Any help on getting this to work would be appreciated. I figure I'm pretty close to a solution but haven't been able to get anything to work properly.
Check for item in player's inventory
Débuté par
sea-
, mars 27 2011 01:48
#1
Posté 27 mars 2011 - 01:48
#2
Posté 27 mars 2011 - 04:09
I had a similar problem and I use something like this:
if(IsObjectValid(GetItemPossessedBy(oHero, "gen_im_qck_poison_102")))
Your script would always return 1 or true because you just check for the string not if the item is in the players inventory.
Could you post the whole script maybe there is a problem elsewhere in it.
if(IsObjectValid(GetItemPossessedBy(oHero, "gen_im_qck_poison_102")))
Your script would always return 1 or true because you just check for the string not if the item is in the players inventory.
Could you post the whole script maybe there is a problem elsewhere in it.
Modifié par Apolyon6k, 27 mars 2011 - 04:12 .
#3
Posté 27 mars 2011 - 05:42
Thanks for the help, but it didn't solve the immediate issue. Seems like the script isn't triggering properly at all, which is odd because I used the exact same format for another quest and it worked just fine.
The rest of the script isn't in use right now, but here it is, minus the includes and standard plot script template stuff:
if(nType == EVENT_TYPE_SET_PLOT) // actions -> normal flags only
{
int nValue = GetEventInteger(eParms, 2); // On SET call, the value about to be written (on a normal SET that should be '1', and on a 'clear' it should be '0')
int nOldValue = GetEventInteger(eParms, 3); // On SET call, the current flag value (can be either 1 or 0 regardless if it's a set or clear event)
// IMPORTANT: The flag value on a SET event is set only AFTER this script finishes running!
switch(nFlag)
{
case GANG_WAR_POISON_DRAKES:
{
if (nValue==1)
{
object oFish = GetObjectByTag("poison_fish");
SetObjectInteractive(oFish,1);
}
}
break;
case GANG_WAR_POISON_DRAKES_USED:
{
if (nValue==1)
{
object oHero = GetHero();
string sPoison = "gen_im_qck_poison_102";
resource rPoison = GetLocalResource(oHero, sPoison);
//SetObjectInteractive(oFish,1);
UT_RemoveItemFromInventory(rPoison,1,oHero,"gen_im_qck_poison_102");
}
}
break;
}
}
switch(nFlag)
{
case GANG_WAR_POISON_DRAKES_DEATHROOT_EXTRACT:
{
object oHero = GetHero();
string sDeathroot = "gen_im_qck_poison_102";
GetItemPossessedBy(oHero,sDeathroot);
if (IsObjectValid(GetItemPossessedBy(oHero, "gen_im_qck_poison_102")))
{
nResult = 1;
}
else
{
nResult = 0;
}
}
}
plot_OutputDefinedFlag(eParms, nResult);
return nResult;
}
Scripting isn't exactly like a second language to me, and it's less about elegance and more about bludgeoning things until they decide to work, so I apologise in advance for any and all stupid mistakes.
The rest of the script isn't in use right now, but here it is, minus the includes and standard plot script template stuff:
if(nType == EVENT_TYPE_SET_PLOT) // actions -> normal flags only
{
int nValue = GetEventInteger(eParms, 2); // On SET call, the value about to be written (on a normal SET that should be '1', and on a 'clear' it should be '0')
int nOldValue = GetEventInteger(eParms, 3); // On SET call, the current flag value (can be either 1 or 0 regardless if it's a set or clear event)
// IMPORTANT: The flag value on a SET event is set only AFTER this script finishes running!
switch(nFlag)
{
case GANG_WAR_POISON_DRAKES:
{
if (nValue==1)
{
object oFish = GetObjectByTag("poison_fish");
SetObjectInteractive(oFish,1);
}
}
break;
case GANG_WAR_POISON_DRAKES_USED:
{
if (nValue==1)
{
object oHero = GetHero();
string sPoison = "gen_im_qck_poison_102";
resource rPoison = GetLocalResource(oHero, sPoison);
//SetObjectInteractive(oFish,1);
UT_RemoveItemFromInventory(rPoison,1,oHero,"gen_im_qck_poison_102");
}
}
break;
}
}
switch(nFlag)
{
case GANG_WAR_POISON_DRAKES_DEATHROOT_EXTRACT:
{
object oHero = GetHero();
string sDeathroot = "gen_im_qck_poison_102";
GetItemPossessedBy(oHero,sDeathroot);
if (IsObjectValid(GetItemPossessedBy(oHero, "gen_im_qck_poison_102")))
{
nResult = 1;
}
else
{
nResult = 0;
}
}
}
plot_OutputDefinedFlag(eParms, nResult);
return nResult;
}
Scripting isn't exactly like a second language to me, and it's less about elegance and more about bludgeoning things until they decide to work, so I apologise in advance for any and all stupid mistakes.
Modifié par sea-, 27 mars 2011 - 05:48 .
#4
Posté 27 mars 2011 - 05:46
Interestingly, I'm also running into an issue where some custom placeables aren't displaying properly... my interactive fish crate is taking the appearance of a dead body (from another quest), and the body is invisible... however, when a plot flag somewhere changes, they show up correctly in the end. Very strange stuff. I have to wonder if it's another UID bug biting me in the ass for being lazy and copy-pasting stuff...
Modifié par sea-, 27 mars 2011 - 05:46 .
#5
Posté 27 mars 2011 - 06:05
Re the OP: try UT_CountItemInInventory
#6
Posté 27 mars 2011 - 06:43
There is something wrong with your script.
Defined flags cannot be set, you have to put the defined flag inside another if case.
if(nType == EVENT_TYPE_GET_PLOT)
Try out the sample projects of Sunjammer for more examples on defined flags and how to work with them. The one that helped me a lot was http://social.biowar.../project/2604/.
He has some draft articles on the wiki that might also help.
Defined flags cannot be set, you have to put the defined flag inside another if case.
if(nType == EVENT_TYPE_GET_PLOT)
Try out the sample projects of Sunjammer for more examples on defined flags and how to work with them. The one that helped me a lot was http://social.biowar.../project/2604/.
He has some draft articles on the wiki that might also help.
#7
Posté 27 mars 2011 - 06:47
Getting a bit late for me tonight, but I'll give it a look tomorrow. Thanks so much for the help, guys, I'm of a mind to even start crediting community members when (or if, I should say) this ever ends up being released.
#8
Posté 27 mars 2011 - 06:01
In keeping with Sunjammer's tutorial, I used a plot item, since it'd be a bit easier to work with (don't want to deal with a plot flag being set and the player then using the item). Unfortunately, I still can't get things working. I'm running the following in my module script, nearly copied directly from Sunjammer's own work.
Right underneath my character gen stuff:
case EVENT_TYPE_CAMPAIGN_ITEM_ACQUIRED:
{
string sItemTag = GetTag(GetEventObject(evCurrent, 0));
//check for Deathroot Extract during Gang War quest
if(sItemTag == "deathroot_garnish")
{
//plot flag set to notify player has Deathroot Garnish
WR_SetPlotFlag(PLT_GANG_WAR_POISON_DRAKES, GANG_WAR_POISON_DRAKES_ACQUIRED, TRUE);
bEventHandled = TRUE;
}
}
All includes and variables are defined properly so I'm really not sure what the issue is, considering my script is set up nearly identically.
Right underneath my character gen stuff:
case EVENT_TYPE_CAMPAIGN_ITEM_ACQUIRED:
{
string sItemTag = GetTag(GetEventObject(evCurrent, 0));
//check for Deathroot Extract during Gang War quest
if(sItemTag == "deathroot_garnish")
{
//plot flag set to notify player has Deathroot Garnish
WR_SetPlotFlag(PLT_GANG_WAR_POISON_DRAKES, GANG_WAR_POISON_DRAKES_ACQUIRED, TRUE);
bEventHandled = TRUE;
}
}
All includes and variables are defined properly so I'm really not sure what the issue is, considering my script is set up nearly identically.
Modifié par sea-, 27 mars 2011 - 06:02 .
#9
Posté 27 mars 2011 - 08:13
It is important that the item is really a plot item and has the variable "send acquired flag" set 1.
I forgot that for two items in my mod and wondered why the quest didn't finish properly.
Also double check your tags and plot flags.
It is also helpful to send a message on acquiring the item to check if it works.
try DisplayFloatyMessage(oUser, "Item Acquired", FLOATY_MESSAGE, 16777215, 1.5);
I forgot that for two items in my mod and wondered why the quest didn't finish properly.
Also double check your tags and plot flags.
It is also helpful to send a message on acquiring the item to check if it works.
try DisplayFloatyMessage(oUser, "Item Acquired", FLOATY_MESSAGE, 16777215, 1.5);
Modifié par Apolyon6k, 27 mars 2011 - 08:14 .
#10
Posté 27 mars 2011 - 09:44
D'oh, setting the item's plot variables worked. Thanks for the heads-up on those, that will actually be very useful in the future.
I'm still not sure if I'll be able to get things working with regular Deathroot Extract, but I might be able to do some sort of work-around for that problem. The intent was for the player to find the ingredients him/herself, or simply buy the stuff from a nearby merchant, but I suppose this works as well, and will still offer a unique outcome.
Now on to work on custom companions, and then perhaps some cutscenes... never truly finished with something, it seems, but at least I can close the books on this portion of my mod, for now. I appreciate the information everyone's contributed immensely.
I'm still not sure if I'll be able to get things working with regular Deathroot Extract, but I might be able to do some sort of work-around for that problem. The intent was for the player to find the ingredients him/herself, or simply buy the stuff from a nearby merchant, but I suppose this works as well, and will still offer a unique outcome.
Now on to work on custom companions, and then perhaps some cutscenes... never truly finished with something, it seems, but at least I can close the books on this portion of my mod, for now. I appreciate the information everyone's contributed immensely.
Modifié par sea-, 27 mars 2011 - 09:46 .





Retour en haut







