The question you are asking would deserve its own tutorial to answer it properly for someone who is not experienced with NWN1, database, NWNX and scripting.
And I wrote quite a wall of text on this subject in other thread (only to be ignored by the OP) - read this post: Help with an on enter script
If you want exact code the best I can offer is to look into my persistent starter module, open it in toolset, find the code for storing location and copy it into your own module: https://neverwintervault.org/project/nwn1/module/no-hak-persistent-exploit-free-starter-module