Local int upon examine item (RESOLVED)

Maybe this can’t be done, but…Well, I want to run a script when the PC is examining an item. I know I could use the activate item for this, but I would so much like to set an integer when the PC is examining the item instead. Is this possible? So, something like this perhaps, but how to run the script…hmmm…

void main()
{

object oNote = GetObjectByTag("notewt");

object oPC = GetFirstPC();

object oPCExamine = GetPlayerCreatureExamineTarget(oPC);

SetLocalInt(oPC,"noteexamined",TRUE);

}

There doesn’t seem to be any event among the Module Properties that checks for when a PC examines an item, so maybe this just isn’t possible.

hm, fire your script by altering the XML that invokes the Examine screen?

i think that’s the only way to examine an item, or examine another item once the GUI is already open.

but GetPlayerCreatureExamineTarget() is for creatures only … so you might have to figure out a different way to get a reference to the item … iirc, i tend toward GetPlayerCurrentTarget(oPc)

 
@Lance_Botelle is the goto guy for stuff like this – but he’s on haitus for a couple wks.

1 Like

Yep, I know Lance said he would be gone for the whole of january.

I just re-read the thread where he helped me with XML coding for examining a placeable. I hardly understand what I have posted there myself, LOL. But it seems like maybe I have to do another alteration to the examine.xml file for this if I want it to work that way.

Maybe I should just be lazy and use the “activate item” thing for this. Thing is, if I do that, the player will suspect that there is something quite important with this item, whereas I would like to be a little more sneacky and not let the player know that this is important to examine…Ah, I don’t know. Maybe I’m making things more convoluted than they need to be.

well … u just want to add

OnAdd1='UIObject_Misc_ExecuteServerScript("gui_myscript")'

to the

<UIScene>

where gui_myscript is the name of your script (don’t forget the preface “gui_”)

note: I think oPc in such scripts is OBJECT_SELF (but should test that with some debug in the script)

And, uh, don’t mess up the OnAdd#

they go →

OnAdd=
OnAdd0=
OnAdd1=

and need to be in order (although OnAdd= can be skipped, starting at OnAdd0=)

1 Like

Alright, I’ll check with the gui script I have from Lance and see if I can do this.

@kevL_s - I managed to solve it! It works! Here’s an explanation for my future self and for others that want to attempt something similar on their own.

I used the custom examine.xml that @kevL_s or @Lance_Botelle (or both? I don’t remember) had made for me before, that I have in my override folder (could maybe have had it in my campain folder too, I don’t know). This XML examine script looks like this:

<?xml version="1.0" encoding="NWN2UI">

<UIScene name="SCREEN_EXAMINE" x=ALIGN_CENTER y=ALIGN_CENTER modal=false width=509 height=700 fadeout="0.3" fadein="0.3" draggable=true backoutkey=true scriptloadable=true
	OnAdd=UIScene_OnAdd_AddExamineScreen("EXAMINE_NAME_TEXT","EXAMINE_DESCRIPTION_TEXT","IDENTIFY_BUTTON")
	OnAdd0=UIObject_Misc_ExecuteServerScript("gui_effects")
	OnRemove=UIScene_OnRemove_RemoveExamineScreen() priority="SCENE_INGAME"/>

	<UIText name="EXAMINE_SCREEN_NAME" strref="549" uppercase=true x=60 y=12 width=208 height=20 align=left valign=middle fontfamily="Title_Font" style="1" />
	<UIIcon name="EXAMINE_DETAIL" img="ia_examine.tga" x=15 y=12 width=40 height=40 />

	<!-- Close Button -->
	<UIButton name="CloseButton" x=474 y=8 style="STYLE_CLOSE_BUTTON" 
		OnLeftClick=UIButton_Input_ScreenClose()>
	</UIButton>

	<UIButton name="IDENTIFY_BUTTON" x=ALIGN_CENTER y=45 width=140 height=29
	OnLeftClick=UIButton_Input_HandleIdentify() disabledcolor="white" >
		<UIText name="IDENTIFY_TEXT" width=PARENT_WIDTH height=PARENT_HEIGHT align=center valign=middle uppercase=truefontfamily="Default" style="bold" />
		<UIFrame state=up		fill="b_subtab_normal.tga" />
		<UIFrame state=down		fill="b_subtab_pressed.tga" />
		<UIFrame state=focused	fill="b_subtab_normal.tga" />
		<UIFrame state=hilited	fill="b_subtab_normal.tga" />
		<UIFrame state=hifocus	fill="b_subtab_pressed.tga" />
		<UIFrame state=disabled	fill="b_subtab_disabled.tga" />
	</UIButton>

	<!-- Item Name -->	
	<UIText name="EXAMINE_NAME_TEXT" x=ALIGN_CENTER y=87 width=474 height=55 align=center valign=middle fontfamily="Body_Font" style="bold" multiline=true maxlines=3 />

	<UIIcon name="HZ_BAR" img="grid_pixel.tga" x=10 y=138 width=490 height=1 />
	<UIListBox name="HEADER_LISTBOX" x=26 y=139 width=472 height=551 yPadding=0 xPadding=0 showpartialchild=true
	unequalcontrols=true scrollsegmentsize=30 hidescrollbarwhennotneeded=true >

		<UIText name="EXAMINE_DESCRIPTION_TEXT" width=PARENT_WIDTH height=DYNAMIC align=left valign=top color="3d3131" fontfamily="NWN1_Dialog" style="bold" />
		
		<UIScrollBar name="SB" style="STYLE_SB_THIN"></UIScrollBar>	
	</UIListBox>	

	<!-- Background Image -->
	<UIIcon name="EXAMINE_BACKGROUND_TOP" img="idesc_top_bg.tga" x=10 y=8 width=490 height=80 />
	<UIIcon name="EXAMINE_BACKGROUND" img="idesc_paper_bg.tga" x=10 y=88 width=490 height=603 />
	<UIFrame x=0 y=0 width=PARENT_WIDTH height=PARENT_HEIGHT topleft="frame1_tl.tga" topright="frame1_tr.tga" bottomleft="frame1_bl.tga"
		bottomright="frame1_BR.tga" top="frame1_t.tga" bottom="frame1_b.tga"
		left="frame1_l.tga" right="frame1_r.tga" border=32 />	

Then I checked my gui_effects script (must have been made by Lance originally and then edited by myself) and added some code to that:

///////////////////////////////////////////////////////////////////////////////////////////////////
// Get the nearest examined object to the PC (The game looks for object with the variable "LeftClickExamine").
// This is a way to workaround the fact that we cannot get the left click target any other way.
///////////////////////////////////////////////////////////////////////////////////////////////////

object GetToolsetExamined()
{
	object oPC = OBJECT_SELF;
	
	location lPC = GetLocation(oPC);

	object oPlace = GetFirstObjectInShape(SHAPE_SPHERE, 5.0, lPC, 0, OBJECT_TYPE_PLACEABLE);
	
	while(oPlace != OBJECT_INVALID)
	{		
		if(GetLocalInt(oPlace, "ClickExamine") && GetLocalInt(oPC,"ThePlaqueToExamine"))
		{			
			return oPlace;
		}
		
		oPlace = GetNextObjectInShape(SHAPE_SPHERE, 5.0, lPC, 0, OBJECT_TYPE_PLACEABLE);
	}	
	
	return OBJECT_INVALID;														
}

void main()
{

	object oPC = GetControlledCharacter(OBJECT_SELF);
	object oPC1 = GetFirstPC();

	// Current opened target
	object oTarget = GetPlayerCurrentTarget(oPC);	
	
	// If just a click examine via toolset setting
	if(oTarget == OBJECT_INVALID)
	{		
		oTarget = GetToolsetExamined();
	}
		
	string sScriptToRun = GetLocalString(oTarget, "OnExaminedScript");
		
	if(sScriptToRun == "s_tat_examineplaque" && !GetLocalInt(oPC1,"DoneExaminePlaque"))
	{
		AssignCommand(oPC, ClearAllActions(TRUE));	
		SetLocalObject(oPC, "ExaminedObject", oTarget);			
		DelayCommand(0.1, ExecuteScript(sScriptToRun, oPC));				
	}
	
	else if(sScriptToRun == "s_taf_examinenote" && !GetLocalInt(oPC1,"DoneExamineNote"))
	{
		AssignCommand(oPC, ClearAllActions(TRUE));	
		SetLocalObject(oPC, "ExaminedItem", oTarget);			
		DelayCommand(0.1, ExecuteScript(sScriptToRun, oPC));				
	}

}

The thing I added here was the “else if” part. In that “else if” part I mention my new script s_taf_examine script that looks like this:

void main()
{

	object oPC = OBJECT_SELF;
	//object oTarget = GetLocalObject(oPC, "ExaminedObject");
	//DeleteLocalObject(oPC, "ExaminedObject");	
	object oPC1 = GetFirstPC();

	if(GetLocalInt(oPC1,"DoneExamineNote")) return;
	
	SetLocalInt(oPC1,"DoneExamineNote",TRUE);
	SendMessageToPC(oPC1, "Examined note success!");		
		
}

I then went to the item in question, looked at properties and added this among the variables (I had made something similar with the placeable object):

Ingame I got the message “Examined note success!” so everything seems to be working!

3 Likes