// pc_update_v1
// created by: GhostOfGod
// altered by: Greyfort
//
// pc_update_v2
// created by: GhostOfGod
// altered by: Greyfort
//
/*
this is one script with oput include file all functions needed are here for
script.
This code can be used by a DM item or placed in a triger in the very first
area a pc will enter mod. This will insure that a PC wont run around a
world with a +20 vorpal time stoping sword...
*/
//////////////[ Adjust only these variables ]//////////////////////
const int nDM_Therapy=FALSE;//DEFAULT FALSE;
const int nUPDate_Msgs=FALSE;//DEFAULT FALSE;
//===============================================================//
//////////////////////////////[ START OF FUNCTIONS ]////////////////////////////
//////////[ !!! Don not change functions unless quality scripter !!! ]//////////
// checks if location valid
int GetIsLocationValid(location lLocation);
int GetIsLocationValid(location lLocation)
{
// note you need to create a hidden creature wuth resref "Loctstr"
object oLoctstr = CreateObject (OBJECT_TYPE_CREATURE,"Loctstr",lLocation);
if (GetIsObjectValid(oLoctstr)==TRUE){DestroyObject(oLoctstr);return TRUE;}
return FALSE;
}
// destroys all items with var invalid
void Destory_InValidItems(object oPC=OBJECT_SELF);
void Destory_InValidItems(object oPC=OBJECT_SELF)
{
int iSlot;
object oItem = GetFirstItemInInventory(oPC);
while ( GetIsObjectValid(oItem)==TRUE )
{ //SetLocalString(oItem,"Destroy","InValid");
if( GetLocalString(oItem,"Destroy")=="InValid" ){DestroyObject(oItem);}
oItem = GetNextItemInInventory(oPC);
}
for (iSlot=0; iSlot< 13; iSlot++)
{
oItem = GetItemInSlot(iSlot, oPC);
if (GetIsObjectValid(oItem))
{
if( GetLocalString(oItem,"Destroy")=="InValid" ){DestroyObject(oItem);}
}
}
}
// will destory items set for destruction by local variable
// if( GetLocalString(oItem,"Destroy")=="VALID" ){DestroyObject(oItem);}
// SetLocalString(oItem,"Destroy","VALID");
void Destory_Items(object oPC=OBJECT_SELF);
void Destory_Items(object oPC=OBJECT_SELF)
{
object oItem = GetFirstItemInInventory(oPC);
while ( GetIsObjectValid(oItem)==TRUE )
{
if( GetLocalString(oItem,"Destroy")=="TRUE" ){DestroyObject(oItem);}
oItem = GetNextItemInInventory(oPC);
}
}
// find resref matched weapon
void ResRefMatchReplace(object oItem, object oTarget);
void ResRefMatchReplace(object oItem, object oTarget)
{
string sResRef = GetResRef(oItem);
if ( GetLocalString(oItem,"Updated")!="Updated")
{
// debug
if( nUPDate_Msgs==TRUE){SendMessageToPC( oTarget,"@@@...Item name & ResRef="+GetName(oItem)+" & "+sResRef +"...@@@");}
object oReplacement = CreateItemOnObject(sResRef, oTarget,1);
if (GetIsObjectValid(oReplacement)==FALSE)
{
//do stuff if there is no item with matching res ref.
// if item doesn't have resref dont destroy, flag PC for DM intervention
// debug
if( nUPDate_Msgs==TRUE){SendMessageToPC( oTarget,"!!!...InValid Item...!!!");}
SetLocalString(oItem,"Destroy","InValid");
if ( nDM_Therapy==TRUE){
SetLocalInt(oTarget,"DM_intrvn",TRUE);}
}
else if (GetIsObjectValid(oReplacement)==TRUE)
{
// debug
if( nUPDate_Msgs==TRUE){SendMessageToPC( oTarget,"***...Valid Item...UPDATED***");}
//SetLocalInt(oTarget,"DM_intrvn",FALSE);
SetLocalString(oReplacement,"Updated","Updated");
SetLocalString(oItem,"Updated","Updated");
SetLocalString(oItem,"Destroy","TRUE");
}
}
}
//////////////////////////////[ END OF FUNCTIONS ]////////////////////////////
#include "x2_inc_switches"
void main()
{
// NOTE: this is code for a tool by GhostOfGod
/*
int iEvent = GetUserDefinedItemEventNumber();
if (iEvent != X2_ITEM_EVENT_ACTIVATE) return;
object oActivator = GetItemActivator();
if (!GetIsDM(oActivator)) return;
object oTarget = GetItemActivatedTarget();
object oItem = GetFirstItemInInventory(oTarget);
*/
// NOTE: this is code for trigger, trigers work better at clearing equiped gear.
// so I have found, then area event/scripts Greyfort
// here you will have to decide what DB you are using nwn_db or nwnx_db
// example useing nwn_db
// !!! CHANGE VARIABLES HERE !!!
// TO your DB var, your waypoints Tags, Save_loc var
string sDM_Name = "Help_Script_MOD";
object oDflt_Start = GetObjectByTag("WP_oDflt_Start");
object oDM_Thrpy = GetObjectByTag( "WP_oDM_Thrpy" );
object oTarget = GetEnteringObject();
location lSave_Loc = GetCampaignLocation( sDM_Name,"Save_Loc",oTarget );
// resets vars for testing other wise uncoment // it out
//SetCampaignInt(sDM_Name,"Gear_updtd",0,oTarget);
int iSlot;
//------------------------------------------------------------------------------
// added check for update variable if false update if true jump to loc
// if update false update
if( GetCampaignInt(sDM_Name,"Gear_updtd",oTarget)==0 )
{
//Get items in inventory and replace if needed
// debug
if( nUPDate_Msgs==TRUE){SendMessageToPC( oTarget,"1)...Inventory check...");}
object oItem = GetFirstItemInInventory(oTarget);
while (GetIsObjectValid(oItem)==TRUE )
{
//if item is a container, loop through items inside
if (GetHasInventory(oItem)==TRUE)
{
// debug
if( nUPDate_Msgs==TRUE){SendMessageToPC( oTarget,"2)...Container check...");}
object oConItem = GetFirstItemInInventory(oItem);
while (GetIsObjectValid(oConItem)==TRUE)
{
ResRefMatchReplace(oConItem, oTarget);
oConItem = GetNextItemInInventory(oItem);
}
}
else
{
ResRefMatchReplace(oItem, oTarget);
}
oItem = GetNextItemInInventory(oTarget);
}
//Get equipped items and replace if necessary
// debug
if( nUPDate_Msgs==TRUE){SendMessageToPC( oTarget,"equipped items check...");}
for (iSlot=0; iSlot< 13; iSlot++)
{
oItem = GetItemInSlot(iSlot, oTarget);
if (GetIsObjectValid(oItem))
{
ResRefMatchReplace(oItem, oTarget);
}
}
//-----------------------[jump player to apropriate loc]----------------
// now if player flagged for DM intervention jump play to DM Therepy...
if ( nDM_Therapy==TRUE)
{
if ( GetLocalInt(oTarget,"DM_intrvn")==TRUE)
{
// flag player not updated here:
SetCampaignInt(sDM_Name,"Gear_updtd",0,oTarget);
// jump to DM_area
AssignCommand(oTarget,ClearAllActions(TRUE));
AssignCommand(oTarget,ActionJumpToObject( oDM_Thrpy ));
}
// now if player not flagged for DM intervention jump player to default start,
// or saved loc
if ( GetLocalInt(oTarget,"DM_intrvn")==FALSE)
{
//jump to save loc if valid else jump to default start
if (GetIsLocationValid(lSave_Loc)==TRUE)
{
// flag player updated here:
SetCampaignInt(sDM_Name,"Gear_updtd",1,oTarget);
// jump to save_lov
//AssignCommand(oTarget,ClearAllActions(TRUE));
AssignCommand(oTarget,JumpToLocation( lSave_Loc ));
}
else
{
// flag player updated here:
SetCampaignInt(sDM_Name,"Gear_updtd",1,oTarget);
// jump to default start
//AssignCommand(oTarget,ClearAllActions(TRUE));
AssignCommand(oTarget,ActionJumpToObject( oDflt_Start ));
}
}
}//END OF if ( nDM_Therapy=TRUE)
//////////////////////////////////
// not use dm_option
if ( nDM_Therapy==FALSE)
{
//jump to save loc if valid else jump to default start
if (GetIsLocationValid(lSave_Loc)==TRUE)
{
// flag player updated here:
SetCampaignInt(sDM_Name,"Gear_updtd",1,oTarget);
// jump to save_lov
//AssignCommand(oTarget,ClearAllActions(TRUE));
AssignCommand(oTarget,JumpToLocation( lSave_Loc ));
}
else
{
// flag player updated here:
SetCampaignInt(sDM_Name,"Gear_updtd",1,oTarget);
// jump to default start
//AssignCommand(oTarget,ClearAllActions(TRUE));
AssignCommand(oTarget,ActionJumpToObject( oDflt_Start ));
}
}//END OF if ( nDM_Therapy=FALSE)
}//END OF if( SetCampaignInt(sDM_Name,"Gear_updtd")==FALSE )
//------------------------------------------------------------------------------
// if update TRUE DONT update this is dependant on data base
if( GetCampaignInt(sDM_Name,"Gear_updtd",oTarget)==1 )
{
//jump to save loc if valid else jump to default start
if (GetIsLocationValid(lSave_Loc)==TRUE)
{
// flag player updated here:
SetCampaignInt(sDM_Name,"Gear_updtd",1,oTarget);
// jump to save_lov
//AssignCommand(oTarget,ClearAllActions(TRUE));
AssignCommand(oTarget,JumpToLocation( lSave_Loc ));
}
else
{
// flag player updated here:
SetCampaignInt(sDM_Name,"Gear_updtd",1,oTarget);
// jump to default start
//AssignCommand(oTarget,ClearAllActions(TRUE));
AssignCommand(oTarget,ActionJumpToObject( oDflt_Start ));
}
}//END if( SetCampaignInt(sDM_Name,"Gear_updtd")==TRUE )
//---!!!!!!!!!!--
// destroy items
//
// debug
if( nUPDate_Msgs==TRUE){SendMessageToPC( oTarget,"3)...DESTORYING Updated ITEMS...");}
Destory_Items(oTarget);
if ( nDM_Therapy==FALSE){Destory_InValidItems(oTarget);}
//[END OF SCRIPT//]
}
Forgive me I posted the wrong script, this is the correct script. You can place it on areas/triggers “on enter†event/script. I can also send you a Module as an example if you like.
This script is adjustable use dm_therapy option True/false , show Update messaging
Modifié par Greyfort, 20 juin 2011 - 01:21 .