Jump to content

Home

Populate Function


TimBob12

Recommended Posts

Populate Function

 

2.81 - STABLE AND WORKING

 

Available from same download link

 

This Populate function allows you to get four co-ordinates and randomly spawn any number of NPCs. It was designed to ease the process of creating modules. All information is included in the README.

 

This saves you having to create individual entries in the .git file. I think this should save a lot of time in Total Conversion Mods as people do not have to spend a lot of time populating areas. A few versions of this function spawning different NPCs and its done.

 

The screenshots are from SOTE posted with permission from HarIII

 

Thank you to everyone that helped but especially:

 

Bead-V

Darth Insidious

Varsity Puppet

 

Installation and Use

 

You need to place the "populate.nss" script in your K2 Override. (This will probably work with K1 but I cannot confirm that). To use the function add the line

#include "populate"

at the beginning of your script.

 

Then you will need to lay an imaginary square over the area where you want to spawn in. Then find the co-ordinates of the four corners using D3's Whereami armband. Write down what you get and work out the smallest X value and the largest X Value and then do the same with the Y Co-ordinates. Then include this in the main function of your script.

 

Populate(Amount, xMin, xMax, yMin, yMax, Tag);

 

Amount = The number of NPCs of the specified tag to spawn.

xMin = The smallest X value

xMax = The largest X Value

yMin = The smallest Y Value

yMax = The largest Y Value

Tag = The tag of the NPC you want to spawn.

 

 

 

Screenshots

 

Show spoiler
(hidden content - requires Javascript to show)

populate1.png

 

Show spoiler
(hidden content - requires Javascript to show)

populate2.png

 

Show spoiler
(hidden content - requires Javascript to show)

populate3.png

 

Show spoiler
(hidden content - requires Javascript to show)

populate4.png

 

 

 

Download Link - http://deadlystream.com/forum/files/file/45-populate-function/

Link to comment
Share on other sites

Awesome! pure awesome!

 

 

Edit: Oh with you want it to work for kotor1, i believe you have to compile the script in kotor1 option in kotortools.

If it does then it should then be ready for kotor1 use.

 

Thanks again for building this.

Link to comment
Share on other sites

OK I followed the example script to create my own but every time I try to compile it kotor tool finds probelms with the populate.nss script.

 

(17) error: syntax error at "bool"

(23) error: syntax error at "while"

(38) error: syntax error at "if"

 

Also here is a copy of my script if you see anything ovisouly wrong please point it out.

 

#include "populate"

 

void main() {

Tag = "n_com1 ;

Populate(10, 32.88562, 53.56025, -39.01687, 22.53749,Tag , TRUE);

 

}

Link to comment
Share on other sites

There are a couple of things wrong with your script. One isn't your fault.

 

#include "populate"

void main() {
Tag = "n_com1" ;  //YOU FORGOT THE SECOND QUOTATION HERE
Populate(10, 33, 54, -39, 23,Tag , TRUE);

}

 

For the random number generation to work the numbers you put in have to be integers ie no decimals. I forgot to mention that.

 

also you can use the

code tags for declaring code.

Link to comment
Share on other sites

My script:

 

#include "populate"

 

void main() {

Tag = "n_com1" ;

Populate(10, 32, 53, -39, 22,Tag , TRUE);

 

}

 

 

Your Script:

 

//Feel free to use this script in any mod

//Feel free to modify this script but please ask me before / if you distribute it.

 

#include "k_inc_generic"

#include "k_inc_utility"

 

 

int RandomInt(int iMax=1, int iMin=0) //Created by bead-v. Thank You

{

int Malo = iMin;

if(iMin>iMax) Malo=iMax;

int iRandom = Malo + Random(abs(iMax-iMin));

return iRandom;

}

 

 

void Populate(int Amount, int xMin, int xMax, int yMin, int yMax, string Tag, bool Walk)

{

 

 

int AutoInc = 0;

 

while(AutoInc<Amount)

{

AutoInc++;

 

int x = RandomInt(xMax, xMin);

int y = RandomInt(yMax, yMin);

float z = 0.0;

int Orient = Random(360);

 

float x1 = IntToFloat(x);

float y1 = IntToFloat(y);

float Orient1 = IntToFloat(Orient);

 

object NPC = CreateObject(OBJECT_TYPE_CREATURE, Tag, Location(Vector(x1,y1,z), Orient1));

 

if(Walk == TRUE)

{

 

AssignCommand(NPC, ActionRandomWalk());

}

}

}

 

//Created by TimBob12

Link to comment
Share on other sites

I have uploaded a new version without the choice of walking as it was causing issues. NPcs will now walk as DEFAULT. This can be changed by commenting out

 

AssignCommand(NPC, ActionRandomWalk());

 

with a // before the line.

 

Waiting for new version to be reviewed at deadly stream. Will be on same download link.

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

TB -

 

How do I modify your example script

 

void main() { 

  string Tag = "ch_guard_1"; //Declare the tag of the NPC you want to spawn

  Populate(20, -28, 21, 69, 121, Tag, TRUE); //This is the bit that does all the spawning

 

For multiple npc tags? I want to spawn 4-5 different npc's on the onenter script. I'm a scripting idiot and don't know the correct syntax.

Link to comment
Share on other sites

I will have to modify the script but I have a pretty good idea of how to do it and will have a look asap. I might be able to use random numbers. How many NPCs at a time do you think? 5? You'd be able to have 5 or less then.

 

Sorry for the late reply by the way. I have been away for the weekend and had no access to a computer other than my phone and I felt that I would not be able to give an adequate reply.

Link to comment
Share on other sites

Here is how I did my script. I was able to fill an entire module of 7 different charcter types(I think 7).

 

#include "populate"

 

void main() {

Populate(2, 32, 53, -39, 22, "n_com1");

Populate(2, 32, 53, -39, 22, "n_com");

Populate(3, 32, 53, -39, 22, "n_com2");

Populate(2, 32, 53, -39, 22, "n_com7");

Populate(1, 32, 53, -39, 22, "n_com3");

Populate(3, 32, 53, -39, 22, "n_com4");

Populate(3, 32, 53, -39, 22, "n_com5");

Populate(3, 32, 53, -39, 22, "n_com6");

 

}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...