I was found this yesterday and thought to try it out:
https://neverwintervault.org/project/nwn2/other/gui/lockpicking-trap-disarming-uis
It’s a really nice mini game with a custom GUI when picking locks and disarming traps. It works really well when using the testing module that this is shipped with. However, when trying to implement this into my own module, at first I thought it didn’t work, but then I realized that it did, but only if the PC is a rogue. I looked at the script and trying to make sense of things but I can’t get it to work with a companion being the rogue. If you use a companion, it just directly says the trap is disarmed although the GUI shows up. Can anyone of you masters of scripting take a look at this and help me perhaps? It’s a really nice system that I would have liked to use. Here’s the script that is used on a Trigger Trap:
// script_name: gui_open_trappicking
/*
Description:
*/
// LittleBaron 10/08
#include "x0_i0_position"
void main()
{
object opc = GetLastUsedBy();
if (!GetIsObjectValid(opc))
opc = GetEnteringObject();
int abd = GetLocalInt(OBJECT_SELF,"abd");
//SpeakString("script fired"+IntToString(abd));
if (abd == 2)//trap is jammed or disabled already.
{
if (GetObjectType(OBJECT_SELF)==OBJECT_TYPE_TRIGGER)
DestroyObject(OBJECT_SELF);
return;
}
// get trap DC from Object, if DC = 0, assign it.
int pclvl =GetTotalLevels(opc,FALSE);
int DC = GetTrapDisarmDC(OBJECT_SELF);
if (DC==0)
{
DC = 14+(pclvl+Random(pclvl/2));
SetTrapDisarmDC(OBJECT_SELF,DC);//if you no like, you fix.
}
// get trap detect DC from object, ""
int DDC = GetTrapDetectDC(OBJECT_SELF);
if (DDC == 0)
{
DDC = (DC/2)+Random(DC/2);
SetTrapDetectDC(OBJECT_SELF,DDC);
// again, you no like... you fix.
}
int traptype = GetLocalInt(OBJECT_SELF,"traptype");
if (traptype == 0)
{
traptype = GetTrapBaseType(OBJECT_SELF);
}
// because minor spike = 0 (grr) we must use a local int instead of getting base type, and add 1 and then always subtract it later
if (traptype == 0&&abd==0)//0 is actually a minor spike trap, but we'll roll a random one anyway =(
{
int level = (pclvl/5);
if (level < 1)
level = 1;
if (level > 4)
level = 4;
level=level-1;
traptype = Random(11);
traptype = traptype*4;
traptype = traptype + level;
}
//if this is a trigger, make the real trap now!
if (GetObjectType(OBJECT_SELF)==OBJECT_TYPE_TRIGGER)
{
location loc = GetAheadLocation(opc,2.0);
object ntrap = CreateTrapAtLocation(traptype,loc,2.5,"",STANDARD_FACTION_HOSTILE);
SetLocalObject(OBJECT_SELF,"ntrap",ntrap);
SetTrapRecoverable(ntrap, FALSE);
SetTrapActive(ntrap,TRUE);
SetTrapDetectable(ntrap,TRUE);
SetTrapDisarmable(ntrap,FALSE);
}
//see if the PC notices the trap!
int spot = GetSkillRank(SKILL_SPOT,opc,FALSE);
int srch = GetSkillRank(SKILL_SEARCH,opc,FALSE);
int droll;
int roll;
int x;
while (x < 3)//3 chances to more closely emulate the approach
{
droll = (Random(20)+1)+spot;
if (roll < droll)
roll = droll;
x++;
}
x=0;
//and if the PC is in active search mode he/she can try three times against search skill also
while (x<3&&GetDetectMode(opc)==DETECT_MODE_ACTIVE)
{
droll = (Random(20)+1)+srch;
if (roll < droll)
roll = droll;
x++;
}
droll = roll;//this will be the highest roll made.
object trap = OBJECT_SELF;
if (droll<DDC&&abd==0)//PC did NOT notice there was a trap...
{
if (GetLocalInt(OBJECT_SELF,"lockedalso")==0)
{
SetLocked(OBJECT_SELF,FALSE);
SetLockKeyRequired(OBJECT_SELF,FALSE);
}
if (GetObjectType(OBJECT_SELF)==OBJECT_TYPE_TRIGGER)
{
DestroyObject(OBJECT_SELF,2.0);
}
else
{
CreateTrapOnObject(traptype,OBJECT_SELF,STANDARD_FACTION_HOSTILE,"","");
SetTrapRecoverable(OBJECT_SELF, FALSE);
SetTrapActive(OBJECT_SELF,TRUE);
SetTrapDisarmable(OBJECT_SELF,FALSE);
SetTrapDetectable(OBJECT_SELF,TRUE);
}
SetLocalInt(OBJECT_SELF,"abd",2);
AssignCommand(opc,ClearAllActions());
AssignCommand(opc,ActionInteractObject(trap));
AssignCommand(opc,SpeakString("I should really pay more attention..."));
return;
}
else
{
AssignCommand(opc,ClearAllActions());
AssignCommand(opc,SpeakString("TRAP!"));
PlayCustomAnimation(OBJECT_SELF,"search",TRUE,3.0);
}
SetLocalInt(OBJECT_SELF,"traptype",traptype);
SetLocalObject(opc,"oTrap",OBJECT_SELF);
SetLocalInt(OBJECT_SELF,"abd",1);
if (GetObjectType(OBJECT_SELF)==OBJECT_TYPE_TRIGGER)
SetLocalInt(OBJECT_SELF,"abd",2);//b/c if it's a trigger there is no second chance
DisplayGuiScreen(opc,"SCREEN_TRAPPICKER",FALSE,"trappicker.xml");
SetGUIObjectText(OBJECT_SELF,"SCREEN_TRAPPICKER","RecoveryButton",-1,"");
int bonus;
//
// this is geared toward general use
//
object pickexists;
object pick = GetItemPossessedBy(opc,"NW_IT_PICKS001");
if(GetIsObjectValid(pick))
{
bonus = 1;
pickexists = pick;
}
pick = GetItemPossessedBy(opc,"NW_IT_PICKS002");
if(GetIsObjectValid(pick))
{
bonus = 3;
pickexists = pick;
}
pick = GetItemPossessedBy(opc,"NW_IT_PICKS003");
if(GetIsObjectValid(pick))
{
bonus = 6;
pickexists = pick;
}
pick = GetItemPossessedBy(opc,"NW_IT_PICKS004");
if(GetIsObjectValid(pick))
{
bonus = 10;
pickexists = pick;
}
if(GetIsObjectValid(pickexists))
DestroyObject(pickexists);
//
SetLocalInt(opc,"tdbonus",bonus);
//
//deactivate all buttons & Trap Pic to begin with
SetGUITexture(opc,"SCREEN_TRAPPICKER","TRAP_TOP","temp0.tga");
x=0;
string button;
while (x<14)
{
button="PICK_"+IntToString(x);
SetGUIObjectDisabled(opc,"SCREEN_TRAPPICKER",button,TRUE);
SetGUITexture(opc,"SCREEN_TRAPPICKER",button,"sigil_slot.tga");
x++;
}
if (abd==0)
SetTrapRecoverable(OBJECT_SELF,FALSE);
if (GetTrapRecoverable(OBJECT_SELF)==FALSE)
SetGUIObjectDisabled(opc,"SCREEN_TRAPPICKER","RecoveryButton",TRUE);
//show buttons, if this is not the first opening and there was another session with this object
string buttonv;
string trapname=GetLocalString(OBJECT_SELF,"trapname");
SetGUIObjectText(opc,"SCREEN_TRAPPICKER","TRAP_FEEDBACK",-1,GetLocalString(OBJECT_SELF,"trapname"));
//and the progress bars
SetGUIProgressBarPosition(opc,"SCREEN_TRAPPICKER","TRAP_PROG_GOOD",0.0);
SetGUIProgressBarPosition(opc,"SCREEN_TRAPPICKER","TRAP_PROG_BAD",0.0);
if (abd == 1)//show the buttons that were discovered, etc.
{
//progress bar functions
int x;
int y;
while (x < 14)
{
if ((GetLocalInt(OBJECT_SELF,"PICK_"+IntToString(x)+"T")>0)&&(GetLocalInt(trap,"PICK_"+IntToString(x)+"I")<2))
y++;
x++;
}
float ndvc = IntToFloat(GetLocalInt(OBJECT_SELF,"ndevices"));
float disarmed = ndvc-IntToFloat(y);
float percent = disarmed/ndvc;
SetGUIProgressBarPosition(opc,"SCREEN_TRAPPICKER","TRAP_PROG_GOOD",percent);
float failure = GetLocalFloat(OBJECT_SELF,"failure");
SetGUIProgressBarPosition(opc,"SCREEN_TRAPPICKER","TRAP_PROG_GOOD",failure);
//
if (GetTrapRecoverable(OBJECT_SELF))
{
SetGUIObjectDisabled(opc,"SCREEN_TRAPPICKER","RecoveryButton",FALSE);
//SetGUIObjectText(OBJECT_SELF,"SCREEN_TRAPPICKER","RecoveryButton",-1,"Recover");
}
if (!(trapname == ""||trapname == "Trap Type Unkown"))
SetGUITexture(opc,"SCREEN_TRAPPICKER","TRAP_TOP",GetLocalString(OBJECT_SELF,"trapimage"));
x =0;
while (x < 15)
{
button = "PICK_"+IntToString(x);
x++;
if (GetLocalInt(OBJECT_SELF,button+"I")>0)//button identified
{
SetGUIObjectDisabled(opc,"SCREEN_TRAPPICKER",button,FALSE);
buttonv = "DD";
buttonv = buttonv+(IntToString(GetLocalInt(OBJECT_SELF,button+"T")-1));
if (buttonv == "DD4")
{
buttonv = buttonv+GetLocalString(OBJECT_SELF,"addon");
}
if (GetLocalInt(OBJECT_SELF,button+"I")==1)
{
SetGUITexture(opc,"SCREEN_TRAPPICKER",button,buttonv+"_idle.tga");
}
if (GetLocalInt(OBJECT_SELF,button+"I")==2)
SetGUITexture(opc,"SCREEN_TRAPPICKER",button,buttonv+"_press.tga");
}
}
return;
}
//since this is the first opening everything must be set up.
int initialc;
string initialimg;
string trapimg;
string addon;
int buttontype;
if (traptype>11&&traptype<16)//acid trap
{
trapname = "Acid Blob";
trapimg = "it_kit_acidblobtrap";
initialimg = "DD4G_";
addon = "G";
buttontype = 5;
}
if (traptype>39&&traptype<44)//acid splash trap
{
trapname = "Acid Splash";
trapimg = "it_kit_acidsplashtrap";
initialimg = "DD4G_";
addon = "G";
buttontype = 5;
}
if ((traptype>19&&traptype<24)||traptype==44)//electrical trap
{
trapname = "Electric";
trapimg = "it_kit_electricaltrap";
initialimg = "DD0_";
buttontype = 1;
}
if ((traptype>15&&traptype<20)||traptype==45)//fire trap
{
trapname = "Fire";
trapimg = "it_kit_firetrap";
initialimg = "DD1_";
buttontype = 2;
}
if ((traptype>27&&traptype<32)||traptype==46)//frost trap
{
trapname = "Frost";
trapimg = "it_kit_frosttrap";
initialimg = "DD2_";
buttontype = 3;
}
if ((traptype>23&&traptype<28))//gas trap
{
trapname = "Gas";
trapimg = "it_kit_gastrap";
initialimg = "DD1_";
buttontype = 4;
}
if ((traptype>3&&traptype<7))//holy trap
{
trapname = "Holy Energy";
trapimg = "it_kit_holytrap";
initialimg = "DD4Y_";
addon = "Y";
buttontype = 5;
}
if ((traptype>31&&traptype<36))//Neg trap
{
trapname = "Negative Energy";
trapimg = "it_kit_negativetrap";
initialimg = "DD4R_";
addon = "R";
buttontype = 5;
}
if ((traptype>35&&traptype<40)||traptype==47)//Sonic trap
{
trapname = "Sonic";
trapimg = "it_kit_sonictrap";
initialimg = "DD2_";
buttontype = 3;
}
if ((traptype>-1&&traptype<4))//spike trap
{
trapname = "Spike";
trapimg = "it_kit_spiketrap";
initialimg = "DD3_";
buttontype = 17;
}
if ((traptype>7&&traptype<11))//tangle trap
{
trapname = "Tangle";
trapimg = "it_kit_tangletrap";
initialimg = "DD3_";
buttontype = 18;
}
trapname = trapname + " Trap";
string idtrapname = trapname;
SetLocalString(OBJECT_SELF,"idtrapname",idtrapname);
trapimg = trapimg+".tga";
SetLocalString(OBJECT_SELF,"trapimage",trapimg);
if (!(addon == ""))
SetLocalString(OBJECT_SELF,"addon",addon);
trapname = "Trap Type Unkown";
SetLocalString(OBJECT_SELF,"trapname",trapname);
SetGUIObjectText(opc,"SCREEN_TRAPPICKER","TRAP_FEEDBACK",-1,trapname);
initialc = Random(14);
button = "PICK_"+IntToString(initialc);
//string buttonv;
SetLocalInt(OBJECT_SELF,button+"T",buttontype);
//asign the dc to this button;
SetLocalInt(OBJECT_SELF,button+"DC",DC+5);//assign the difficulty
//The inital object counts for 10 DC points
//the DC here is simply for set-up purposes.
//
//Determine the remaining buttons
//Anything with a DC >14 will have at least one extra button.
if (abd==0)// set up the remaining buttons
{
x = (DC-10)/5;
int y;
x++;
if (x > 13)
x = 13;
SetLocalInt(OBJECT_SELF,"ndevices",x);
while (x > 0)
{
y = Random(14);
button = "PICK_"+IntToString(y);
if (GetLocalInt(OBJECT_SELF,button+"T")==0)//this button has not been chosen yet
{
x=x-1;
y =Random(11)+6;
if (y > 16)
y=16;
SetLocalInt(OBJECT_SELF,button+"T",y);
roll = Random(DC/2)-1;
roll = (DC/2)+roll;
SetLocalInt(OBJECT_SELF,button+"DC",roll);
}
}
}
}
What I did when trying to fix this was that I tried with changing opc
to GetFirstPC(FALSE);
but unfortunately that did nothing. I suspect it not working having something to do with that the companion automatically disarms the trap?
EDIT: I tried with changing the behaviour of the companion to not automatcally disarm traps but that still gave the same result: The trap was disarmed when the UI shows up.
EDIT 2: If noone has any answers or thoughts, I think I just have to give up on this. I’ve tried to think of everything, but I can’t see how to change anything in the script for it to work. I’ll take a look in the xml files too, but…xml coding is even harder to understand so I doubt I’ll have more luck there…
EDIT3: So, there’s no way to get this to work? Noone that could help?