Home Forums Forum Index Neverwinter Nights NWN 1: Scripting Checking items on NPC corpse
NWN 1: Scripting
Mithrandir666
Game OwnerNWN NWN: SoU NWN: HotU NWN 2 Joined: 21 Jan 2003 From: UK
Posted: Wednesday, 04 November 2009 09:33AM
I've been trying to get a script to work that checks whether an NPC corpse has an item on it after it's been killed, but it doesn't seem to work. I'm wondering if anyone knows whether a corpse cannot be checked for items for some reason? This is the script: If I put this on the heartbeat of the creature, the item check works fine, but when called from an ondeath script it fails. The creature's corpse is destroyed however, which implies that oTarget is correct. Any thoughts appreciated _________________http://www.silver-spire.com
ChocoBlok
Game OwnerNWN NWN: SoU NWN 2 Joined: 27 Jun 2003 From: England
Posted: Thursday, 05 November 2009 12:33AM
Hi there, I did some testing on this, by doing the following: I attached the following script to the death event on several monsters, and tried killing a horde of them.Code:
void main()
{
object oItem = GetItemPossessedBy(OBJECT_SELF, "test");
if ( GetIsObjectValid(oItem))
{
SendMessageToAllDMs("FOUND.");
}
else
{
SendMessageToAllDMs("DIDN'T FIND.");
}
}
View Post/Code in separate window Since every time I got a "found", I decided to try something a little closer to your code:Code:
void main()
{
object oItem = GetItemPossessedBy(OBJECT_SELF, "test");
location lLoc = GetLocation(OBJECT_SELF);
if ( GetIsObjectValid(oItem))
{
CreateObject(OBJECT_TYPE_CREATURE, "death_tester", lLoc);
}
else
{
}
DestroyObject(OBJECT_SELF, 0.1f);
}
View Post/Code in separate window And this worked fine for me, although I didn't try killing more than one monster at a time. Hope it helps. ~S
Mithrandir666
Game OwnerNWN NWN: SoU NWN: HotU NWN 2 Joined: 21 Jan 2003 From: UK
Posted: Friday, 06 November 2009 01:47PM
Ok, that inspired me to have another look at this, and whereas previously our script was split into 2 scripts, having it as one script did help. However, have run into an issue (which is I believe related to my original issue). In summary, what I'm looking for is a creature that has a heart in its inventory. When it dies, the script should check whether this heart is present and if it is then it spawns a new creature, and destroys the corpse. However, there needs to be a delay in checking for the heart, so the PCs have time to get it off the corpse. So my issue is that this script:Code:
void ActionCreate(string sCreature, location lCreationPoint)
{
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lCreationPoint);
}
object oHeart = GetItemPossessedBy(oTarget,"tag_of_heart");
if ( GetIsObjectValid(oHeart) )
{
DelayCommand(8.0, ActionCreate("tag_of_creature", lSpn));
}
View Post/Code in separate window .. works fine in that it does create a new creature. However, because the heart check is done instantly, but the creation not for 8 seconds, there's no time for the PC to get the heart, and hence a new creature is created every time. But, this script:Code:
void ActionCreate(string sCreature, location lCreationPoint, object oTarget)
{
object oHeart = GetItemPossessedBy(oTarget,"tag_of_heart");
if ( GetIsObjectValid(oHeart) )
{
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lCreationPoint);
}
}
DelayCommand(8.0, ActionCreate("tag_of_creature", lSpn, oTarget));
View Post/Code in separate window ... never creates a new creature. Putting some debug messages into there shows that oTarget is valid, but oHeart is not. So, to me it looks like a lootable corpse can be queried directly in a script, but cannot if a subsequent script or function is called. Perhaps passing a parameter into a function or script passes in a copy of the item, but in this case without any inventory? Bit confused! Serves me right for thinking I was getting the hang of this!! _________________http://www.silver-spire.com Edited By Mithrandir666 on 11/06/09 13:51
Cereborn
Game OwnerNWN NWN: SoU NWN: HotU Joined: 06 Jun 2002
Posted: Friday, 06 November 2009 06:33PM
In the onDeath script, you're not querying the lootable corpse (which hasn't been created yet) you're querying the creature, which at that point still has it's inventory. After the onDeath script, the lootable corpse is created (a body bag placeable, actually) and the creature's inventory is moved to the placeable (because you can't open a creature's inventory). You can find the placeable by using GetNearestObjectByTag (nearest the creature) - the tag will be "BodyBag" iirc (or maybe "Body Bag". Try both...) _________________The NESS User's Guild:
Mithrandir666
Game OwnerNWN NWN: SoU NWN: HotU NWN 2 Joined: 21 Jan 2003 From: UK
Posted: Friday, 06 November 2009 08:18PM
I was heading towards the lootable corpse being a different object, but I never would have got the BodyBag thing - so many thanks for that! It now works pretty much flawlessly! For reference, here's the core bits of the script, placed in the onDeath of the creature:Code:
void ActionCreate(string sCreature, location lCreationPoint, object oTarget)
{
object oBodyBag = GetNearestObjectByTag("BodyBag", oTarget);
object oHeart = GetItemPossessedBy(oBodyBag,"tag_of_heart");
if ( GetIsObjectValid(oHeart) )
{
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lCreationPoint);
}
}
void main()
{
object oTarget = OBJECT_SELF;
location lSpn = GetLocation(oTarget);
float fRespawn_time = IntToFloat(d6(1)) + 14.0;
float fDeath_time = fRespawn_time + 0.1;
DelayCommand(fRespawn_time, ActionCreate("tag_of_creature", lSpn, oTarget));
DestroyObject(oTarget, fDeath_time);
}
View Post/Code in separate window This gives the PC 15-20 seconds to rip out the heart from the creature, else it "rises" again. Many thanks for the help - much appreciated! _________________http://www.silver-spire.com Edited By Mithrandir666 on 11/06/09 20:20
What do these icons mean?
Where can I learn how to use the forums?
Jump To:
Select A Forum
BioWare General
-- Web Site Help
-- BioWare News Discussion
-- BioWare Online Store Support
Premium Neverwinter Nights Modules
-- Premium Neverwinter Nights 1 Modules Tec...
-- Premium Neverwinter Nights 1 Modules Dis...
Neverwinter Nights
-- NWN 1: General Discussion (No Spoilers ...
-- NWN 1: Players - Official Campaign (Spo...
-- NWN 1: Players - SoU Official Campaign (...
-- NWN 1: Players - HotU Official Campaign ...
-- NWN 1: Modules Discussion
-- NWN 1: Community Expansion Pack (CEP)
-- NWN 1: Guilds and Registry - Ye Olde Tav...
-- NWN 1: Dungeon Master's Realm
-- NWN 1: Toolset
-- NWN 1: Scripting
-- NWN 1: Custom Content
-- NWN 1: For Developers
-- NWN 1/SoU/HotU Technical Support (Self-H...
-- NWN 1: Server Admin
-- NWN 1: Linux Version - General Discussio...
-- NWN 1: Macintosh Version - General Discu...
Off Topic
-- Off Topic
Old Dragon Age Forums
-- Dragon Age (Old)
-- Dragon Age: Origins General Discussion
Sonic Chronicles: The Dark Brotherhood
-- Sonic Chronicles: The Dark Brotherhood G...
-- Sonic Chronicles Storyline and Strategy ...
Baldur's Gate II Series
-- Baldur's Gate II: SoA and ToB General Di...
-- Baldur's Gate II Gameplay (Spoilers!)
-- Baldur's Gate II: SoA and ToB Technical ...
Baldur's Gate Series
-- Baldur's Gate and Tales of the Sword Coa...
-- Baldur's Gate Gameplay (Spoilers!)
-- Baldur's Gate and TotSC Technical Suppor...
MDK2
-- MDK2 General Discussion
-- MDK2 Gameplay (Spoilers!)
-- MDK2 Technical Support
Shattered Steel
-- Shattered Steel General Discussion
Star Wars: Knights of the Old Republic
-- Official Announcements - Star Wars: Knig...
-- Storyline Discussion (Spoilers Warning) ...
-- Xbox Version (Spoilers Will Be Moved) - ...
-- PC/Mac Version (Spoilers Will Be Moved) ...
-- Technical Support (Self-Help) - Star War...
Jade Empire Forums
-- Jade Empire PC General Discussion (Spoil...
-- Jade Empire Xbox General Discussion (Spo...
-- Jade Empire Storyline and Strategy Discu...
-- Jade Empire Technical Support (Self-Help...
Neverwinter Nights 2
-- NWN2: General discussion forums for NWN2...
-- NWN2: Players - NWN2 Official Campaign (...
-- NWN2: Players - Mask of The Betrayer Cam...
-- NWN2: Players - Storm of Zehir (Spoilers...
-- NwN2: Mysteries of Westgate Adventure Pa...
-- NWN2: Modules
-- NWN2: Guilds and Registry
-- NWN2: Builders - NWN2 Toolset
-- NWN2: Builders - NWN2 Scripting
-- NWN2: Custom Content
-- NWN2: Dungeon Masters Realm
-- NWN2: Persistent Worlds & Multiplayer
-- NWN2: For the Mac
-- NWN2: Tools and Plugin Developers
-- NWN2: Technical Support (Self-Help)
Mass Effect Forums
-- Mass Effect 2 General Discussion (No Spo...
-- Mass Effect 1 General Discussion (No spo...
-- Mass Effect PC Version General Discussio...
-- Mass Effect Storyline and Strategy Discu...
-- Mass Effect for PC Technical Support (Se...
-- Mass Effect for Xbox 360 Technical Suppo...
Archives: Neverwinter Nights
-- Archives: For Everyone - NWN General Di...
-- Archives: NWN HotU General Discussion
-- Archives: NWN SoU General Discussion
-- Archives: Players - NWN Official Campaig...
-- Archives: Witch's Wake Discussion
-- Archives - Players - NWN Modules
-- Archives: Players - Ye Olde Tavern
-- Archives: DMs - Dungeon Master's Realm
-- Archives: Builders - NWN Toolset
-- Archives: Builders - NWN Scripting
-- Archives: Builders - NWN Custom Content
-- Archives: NWN Technical Support (Self-He...
Pre-Release NWN Archives
-- Archives - NWN Official Announcements
-- Archives - General Discussion
-- Archives - Ye Olde Tavern
-- Archives - Dungeon Master's Realm
-- Archives - Models and Model Viewer
-- Archives - Beta Toolset General
-- Archives - Beta Toolset Technical Issues
-- Archives - Beta Toolset Bug Reporting
Forums Archives
-- Archives - Baldur's Gate II Gameplay (Sp...
-- Archives: Baldur's Gate II: SoA and ToB ...
-- Archives - Off Topic
Archives: Star Wars: Knights of the Old Republic
-- Archives: PC/Mac Version (Spoilers Will ...
-- Archives: Storyline Discussion (Spoilers...
-- Archives: Xbox Version (Spoilers Will Be...
Jade Empire Archives
-- Archives - Jade Empire General Discussio...
NwN2 - Pre-Release Archives
-- NWN 2 General Discussion
-- NWN 2 Gameplay and Rules
-- NWN 2 Art and Graphics Engine
-- NWN 2 Single Player Campaign
-- NWN 2 Toolset and Custom Content
Search Forums |
Forums FAQ |
Forum Archives