Larian Banner: Baldur's Gate Patch 9
Previous Thread
Next Thread
Print Thread
#714487 23/10/20 10:38 PM
Joined: Oct 2020
H
stranger
OP Offline
stranger
H
Joined: Oct 2020
TLDR: How do I reference object out of scope. how do I despawn/destroy npc

I am trying to spawn a hostile npc with CharacterCreateAtPosition() and that works fine however I cant figure out how to destroy/despawn the creature later on.

IF
something()
AND
CharacterCreateAtPosition(_x,_y,_z,"Harth_Field_Skeleton_weak_04588216-1307-4569-ae7d-1a34aa43f4c8",1,_Skeleton1)
THEN
something()

After this block I need another check that destroys the _Skeleton1 under certain conditions but the _Skeleton1 can't be referenced in other blocks because it is out of scope. I also don't know what functions to use to destroy or despawn a character. DB_CharacterDestroy is listed on the larian docs but doesn't show as a usable function when i tried testing on another npc.


Joined: Sep 2017
veteran
Offline
veteran
Joined: Sep 2017
You can achieve this by using databases. I've written an example to illustrate it for you.

Code
IF
// Event to start spawning hostiles
AND
CharacterCreateAtPosition(_x,_y,_z, "Harth_Field_Skeleton_weak_04588216-1307-4569-ae7d-1a34aa43f4c8", 1, _Skeleton1)
THEN
DB_MyModPrefix_TemporaryHostileSpawn(_Skeleton1); // Add _Skeleton1 to a database for future referencing

IF
// Event to kill off remaining spawned hostiles
AND
DB_MyModPrefix_TemporaryHostileSpawn(_SpawnedHostiles) // Refers to previously stored spawns
THEN
CharacterDieImmediate(_SpawnedHostiles); // Kills any living spawned creature immediately
SetOnStage(_SpawnedHostiles, 0); // Removes them from being visible



Joined: Oct 2020
H
stranger
OP Offline
stranger
H
Joined: Oct 2020
Ah my hero. So I was struggling to understand the usage of DB but this finally cleared it up for me. Thanks Composer, you rock.

Joined: Mar 2016
Location: Belgium
T
addict
Offline
addict
T
Joined: Mar 2016
Location: Belgium
Small nitpick: it's better to use https://docs.larian.game/Osiris/API/TemporaryCharacterCreateAtPosition in this case to avoid increasing the savegame size.


Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.5