View previous topic :: View next topic |
Author |
Message |
Sir Vendel
Joined: 19 Dec 2015 Posts: 7
|
Posted: Sat Jan 23, 2016 23:06 Post subject: suggested function to test NWNX is used |
|
|
Hi, all. I am pretty new to NWNX, but I love it increasingly. One function I missed turned out to be rather easy to make, so I post it here, if somone has not thought of it. Enjoy:
//--- prGetUseNWNX -------------------------------------------------------------
//Returns TRUE if NWNX is running, otherwise returns FALSE
int prGetUseNWNX() {
return (NWNXFuncs_GetAreaCount()>0); //All modules have at least 1 area.
} //--- end prGetUseNWNX ------------------------------------------------------- |
|
Back to top |
|
|
Valgav
Joined: 28 Aug 2010 Posts: 53
|
Posted: Sun Mar 13, 2016 3:04 Post subject: |
|
|
Where exactly you call that? I use some external call to nwn? There won't be any bridge open if module is not running. |
|
Back to top |
|
|
Baaleos
Joined: 02 Sep 2007 Posts: 830
|
Posted: Tue Mar 15, 2016 18:24 Post subject: |
|
|
Correct me if im wrong.
NWNXFuncs_GetAreaCount() is a member of nwnx_funcs
Surely that only detects if the server has nwnx_funcs available.
Arguably, GetAreaCount is a bad one to use, since in the background it counts the total areas - which could theoretically be hundreds of areas.
Surely
GetFirstArea() would be a better choice (if you are going with a nwnx_funcs) since it relies upon a single area.
It would theoretically run faster than GetAreaCount.
Code: |
int IsRunningNWNXFuncs()
{
return NWNXFuncs_GetFirstArea() != OBJECT_INVALID;
}
|
If nwnx_funcs is not installed, the method will return OBJECT_INVALID, so by checking it does not equal OBJECT_INVALID, we will know if nwnx_funcs is installed. |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Wed Mar 16, 2016 19:54 Post subject: |
|
|
Baaleos wrote: | Surely that only detects if the server has nwnx_funcs available.
Arguably, GetAreaCount is a bad one to use, since in the background it counts the total areas - which could theoretically be hundreds of areas |
no, area count is stored in memory and the plugin only read that number, it does not loop anything and even if it would, nwnx-code is way efficient than anything in nwscript anyway
but you are right this only checks whether nwnx_funcs is in use, however if you are using nwnx_funcs and nwnx_funcs is running then you can assume nwnx is running. _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
|