logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Question about NWNX
Goto page Previous  1, 2
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
etched_in_blood



Joined: 28 Apr 2009
Posts: 13

PostPosted: Thu Apr 30, 2009 12:31    Post subject: Reply with quote

As nice as those options sound, the whole night/day spawn, things like that, the complexity would quickly become overwhelming if I started to dictate every portion of the spawns like that. All I want is this:

The script fires off, and first things first, it checks the area to make sure it's ready to be respawned/spawned by checking for a local int that's reset on a timer. If we're not good to go on respawn, it simply returns, if so, then we continue, and we set that int and timer now.

Then it starts by reading a local int on the area. This local int simply tells me what the Average CR of the area should be.

Then the script reads a second local int, and it tells me what the Terrain Type of the area is.

Then the script reads a final, third local int, and it tells me what the Maximum Spawn number should be for this area.

The script then randomizes a number between 1 and the Maximum Spawn number, and enters a while statement, which causes it to loop and spawn until it has spawned the proper number of creatures.

While it is looping and spawning, it rolls a d100 for percentile for each creature it's going to spawn. This percentile tells me what CR that creature will spawn as based on the Average CR of the area. For instance:

If the Average CR of the area is 4, the chances that an individual spawn will be of a specific CR is....

7% chance it will be 3 less than average Spawns a CR 1
12% chance it will be 2 less than average Spawns a CR 2
22% chance it will be 1 less than average Spawns a CR 3
30% chance it will be average Spawns a CR 4
18% chance it will be 1 more than average Spawns a CR 5
8% chance it will be 2 more than average Spawns a CR 6
3% chance it will be 3 more than average Spawns a CR 7

The minimum CR the script recognizes is 1, and any creature entered with a CR of less than one is treated as having a CR of 1. As you can see, this adds for a lot of possible flexibility in the actual spawns of any given area. That flexibility adds to a lot of the unpredictable nature of the world, without letting it get TOO out of hand.

So. Now the script knows what the Average CR of the area is. It knows what the Terrain Type of the area is. And it knows how many spawns it's going to create, because it randomizes a number between 1 and the Maximum Spawn. Now that it knows all of that, it starts spawning creatures. It grabs the actual CR to spawn by combining a percentage roll with the Average CR information as shown above for each creature it's going to spawn. This then tells the script all the information it needs to know in order to spawn the creature. It knows the CR to spawn, and it knows the Terrain Type that spawn is associated with.

In my CURRENT system, that's where the base script ends, and the LONG function comes in. It sorts by those specific groups, for instance CR 1's of Terrain Type 4, and it randomly chooses one of those creatures ResRefs. Then it simply spits back the ResRef of a randomly selected creature from the proper group. The code then generates a random location in the area, and spawns the randomly selected creature there.

Its a lot of randomization, but it guarantees that no area, and no dungeon will ever spawn the same way twice, and will never become predictable. There's chances for tougher, meaner creatures than usual, or weaker creatures than usual, while still primarily spawning creatures very close to a specific CR. If there ever comes an area that I don't want randomized like that, I simply don't have to use it in that area, so my options remain open.

For example, if I wanted a cave that spawned just orcs, I could simply use NWN standard spawning in that specific cave. If I have a specific boss I want to spawn in a specific dungeon, I can spawn him manually with a trigger or so forth. So now that I've explained exactly what the system does, you can obviously see what it is that I'm wanting out of it.

Now, beyond this, I'm lost. I'm not sure how to set up or update the database, or how exactly the script will change, so on and so forth. So with all that, I'll need some help. As I said, if it helps, I would be willing to post the home script and even the long function if need be to give a perfect representation of how it is supposed to function.
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Thu Apr 30, 2009 16:29    Post subject: Reply with quote

etched_in_blood wrote:
"Developer Machine"
"Multifunction Database"
"Online Transaction Processing"
NO to "Enable TCP/IP Networking"
YES to "Enable Strict Mode"
"Standard Character Set"

You do need to enable TCP/IP networking.

I'm also curious why you picked Online Transaction Processing. Assuming you're only using the database server for NWN, you'll only ever have one concurrent connection, plus maybe another one or two when you're actively doing stuff with the database yourself. I don't actually know the practical difference between the options, but in terms of the descriptions in the configuration wizard, DSS/OLAP seems like the better choice in this case.

As far as a GUI, I'm a fan of SQLyog, but it's by no means a requirement.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Thu Apr 30, 2009 19:13    Post subject: Reply with quote

etched_in_blood wrote:

Now, beyond this, I'm lost. I'm not sure how to set up or update the database, or how exactly the script will change, so on and so forth. So with all that, I'll need some help. As I said, if it helps, I would be willing to post the home script and even the long function if need be to give a perfect representation of how it is supposed to function.

No need, I know exactly what you need now - something that searches for a resref given a CR and a terrain type. You will need columns for resref, cr, and terrain. Normally I'd suggest a bit for terrain, so that creatures could have multiple terrain types as they do in sourcebooks, but that'd require almost no changes to the scripts I'm giving you, so you can change to that later if you want.

Before we being, I'm assuming you've set up your mod to use nwnx with the instructions that come with it - that includes having aps_include in your scripts, and having added code where it tells you to. If you have questions about that process, ask away.

First, you'll need to create the table we'll be using. Start up the mysql command line client, and switch to the database you set up for your server by typing 'use <name>;'. You'll see 'database changed'. Then input the following command to create the table for the script:

CREATE TABLE spawns (id int auto_increment primary key,resref varchar(16) not null,cr tinyint unsigned default 0,terrain int unsigned default 0,index(cr,terrain));

You can also input commands like that via nwscript using nwnx, but for now, you might as well get accustomed to the client.

To see what you've accomplished, enter:
show tables;

That displays the tables in your database. You should see one named 'spawns'. To see the characteristics of a table, enter:
describe <name>;

in this case, describe spawns;

You should see this:

mysql> describe spawns;
+---------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| resref | varchar(16) | | | | |
| cr | tinyint(3) unsigned | YES | MUL | 0 | |
| terrain | int(10) unsigned | YES | | 0 | |
+---------+---------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

You're done with the client for now. Enter 'exit' to close it.

Step 2 is the nwscript side. To pull up a random resref from this table (you'll be entering them in step 3), use this function:



Code:

#include "aps_include"
string GetResrefByTerrainAndCR(int nTerrain, int nCR) {
    string SQL = "SELECT resref FROM spawns WHERE terrain = " + IntToString(nTerrain)
                 + " AND cr = " + IntToString(nCR) + " ORDER BY RANDOM() LIMIT 1";
    SQLExecDirect(SQL);
    if (SQLFetch() != SQL_ERROR)
        return SQLGetData(1);
    return "";
}


You can actually do the same select in the mysql command line client, you just have to add a semicolon to the end. Here are a few sample selects to help you in viewing your data, once you enter it. You can find more information on syntax in this MySQL manual (make sure you check the site for the version you downloaded):
http://dev.mysql.com/doc/refman/5.0/en/index.html

SELECT * from spawns where cr = 5;

would pull up all the columns with cr of 5.

SELECT resref from spawns where terrain = 6;

would select all the resrefs from rows where terrain is 6 (you can use whatever ints you like for terrain).

SELECT resref from spawns where terrain = 3 and cr = 10;

would select all the resrefs from rows where terrain is 3 and cr is 10.

Anyway, on to step 3 - entering the data into the table. Again, from the command client, 'use' the proper database to open the database you're using for this. First, the syntax.

To insert the resref goblin1, with cr of 1, and terrain type 16, you would do this:

INSERT INTO spawns (id,resref,cr,terrain) VALUES (NULL,'goblin1',1,16);

You can insert multiple rows at once, as well:

INSERT INTO spawns (id,resref,cr,terrain) VALUES (NULL,'goblin1',1,16),(NULL,'goblin2',1,16),(NULL,'goblinarcher',2,16),(NULL,'goblincheif',5,16);

And that's all you need to know. Before I offer a few tips on fast entry, though, I'll explain the id field. It's a utility field to guarantee all the rows are unique. You input NULL for it when you add a new entry, and it automatically selects a new number (this is what the autoincrement means).

Now, for fast entry, I like to line up my columns in excel (or googledocs, or whatever spreadsheet program you like), in this case it'd be resref, cr, and terrain, and then add blank columns around them to paste in the connector text (the single quotes around the resref, the commas, the parens, etc). You can also use CONCATENATE to do the lifting for you. It's then child's play to dump them in a text file, replace the double tabs indicateing line breaks with "", and voila, you have your data entry string. I entered about 4000 rows in our augments database in just a day or so using this method, inputting from 250-500 at a go. If you need an easy way to access resref and cr information, I'd suggest Moneo, from the leto sourceforge site (you want version 24, NOT the beta):
http://sourceforge.net/project/showfiles.php?group_id=92983&package_id=98504

You can use that to print up separated lists of resrefs and crs (and names, if you want, or whatever), which you can then dump into excel and convert into entries. That's a bit beyond the scope of this post, but feel free to ask about it if you want to try it out.

Funky
Back to top
View user's profile Send private message
etched_in_blood



Joined: 28 Apr 2009
Posts: 13

PostPosted: Sun May 03, 2009 9:29    Post subject: Reply with quote

Well holy crap.... that seems fairly freaking simple. I just copied and pasted that so I would never ever lose it. Now how do I configure NWNx to use that database? Or will it just.... work? lol
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Sun May 03, 2009 18:37    Post subject: Reply with quote

You tell nwnx which database to use in the NWNX.ini, in the "; Use these five settings for MySQL connections" section:

Code:
; NWNX2 configuration file
; These are the default values for NWNX2. Values specified on the command
; line take precedence.

[NWNX]
ServerPort = 5121
;ModuleName = "Z-Dialog Sample"
;ModuleName = "aps_demo"
;ModuleName = "ChatTest"
ModuleName = "SIMTools_Test"
;ModuleName = "Higher Ground Legendary Levels"
;ModuleName = "Path of Ascension CEP Legends"
;ModuleName = "Elysium"
;ModuleName = "skybox"
;ModuleName = "HGPOA_PoM_Mjolnin_v01"
;ModuleName = "HGPOA_PoM_Mjolnin_v02"
;ModuleName = "HGPOA_Pit of Moliation"
;ModuleName = "speedtest"


WatchdogProcess = yes
UpdateIntervalProcess = 5
WatchdogGamespy = no
UpdateIntervalGamespy = 20
GamespyRetries = 5
OldGamespyProtocol = no
RestartDelay = 5

[ODBC2]
; Log file
MaxLogSize = 512 ; in KByte
LogLevel = 2 ; 0=nothing, 1=only errors, 2=everything

; Use these two settings for the SQLite internal database
;source = sqlite
;file   = sqlite.db

; Use these two settings for ODBC connections
;source = odbc
;dsn    = nwn

; Use these five settings for MySQL connections
source = mysql
server = localhost
user   = root
pwd    = myrealpassis12345likemyluggage
db     = higherground

; Set hookscorco to false if you want to disable hooking of
; StoreCampaignObject and RetrieveCampaignObject entirely
hookscorco = true

[PROFILER]
MaxLogSize = 512 ; in KByte
LogLevel = 1 ; 1=overall statistics, 2=full script callstack

[CHAT]
;chat_script=mod_speech
;server_script=mod_speech_srv
chat_script=fky_chat
server_script=fky_chat_srv
;processnpc=1


Funky
Back to top
View user's profile Send private message
etched_in_blood



Joined: 28 Apr 2009
Posts: 13

PostPosted: Thu May 14, 2009 8:43    Post subject: Reply with quote

Problem.

It is saying in the log that it connects to the database correctly, but it doesn't recognize the table "spawns". Thing is, I downloaded the GUI that someone talked about in this post, and looked it up. The table is right there. Don't know what's going on. The spelling is the same and all that, so I don't know what's happening.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group