Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Populate Function

Page: 1 of 1
 TimBob12
04-02-2011, 4:18 PM
#1
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


http://img402.imageshack.us/img402/1087/populate1.png)



http://img51.imageshack.us/img51/2898/populate2.png)



http://img859.imageshack.us/img859/6995/populate3.png)



http://img24.imageshack.us/img24/5936/populate4.png)




Download Link - http://deadlystream.com/forum/files/file/45-populate-function/)
 newbiemodder
04-02-2011, 4:34 PM
#2
Great jobe TB....you put a lot of effort into creating this...thanks to all his helpers too.
 logan23
04-02-2011, 4:57 PM
#3
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.
 harark1
04-02-2011, 6:06 PM
#4
Thanks will help so much.
 JediExile
04-02-2011, 6:35 PM
#5
VERY cool idea, TB! Thank you for sharing, this will help so much. :D
 Viado Onasi
04-02-2011, 7:13 PM
#6
very cool!
 Canderis
04-04-2011, 8:04 PM
#7
THANK YOU. This is going to be so helpful!
 Lord of Hunger
04-04-2011, 10:59 PM
#8
This is going to be one of the best modding tools ever made. Thank you TimBob for revolutionizing KOTOR modding!
 harark1
04-06-2011, 5:29 PM
#9
AHHH! Script won't work. Need help.
 TimBob12
04-06-2011, 5:34 PM
#10
What doesnt work?
 harark1
04-06-2011, 5:44 PM
#11
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);

}
 TimBob12
04-07-2011, 2:30 AM
#12
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.
 harark1
04-08-2011, 9:00 PM
#13
Ah that explains it. trying again.



Edit: Yeah it is still reading the probelms with your populate script. My script works now but that still isn't.
 TimBob12
04-09-2011, 2:45 AM
#14
Can you post your new script again and the populate script that you downloaded in case I distributed the wrong one(That would be imbarrasing)
 harark1
04-10-2011, 9:07 AM
#15
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
 TimBob12
04-11-2011, 3:50 AM
#16
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.
 TimBob12
04-13-2011, 8:43 AM
#17
Version 2.81 available to download now from the same download link. It is a stable and working version.
 Nick Vader
05-03-2011, 6:12 PM
#18
This really is top notch. Now modules seem to fly past as they're done superfast. A major "thank you" for this utility man.:band1
 TimBob12
05-04-2011, 11:44 AM
#19
Im just glad people can make use of it :)
 newbiemodder
05-13-2011, 11:37 PM
#20
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.
 harark1
05-14-2011, 1:05 PM
#21
I just copied the line multiple times and input a different npc tag in each line.
 newbiemodder
05-14-2011, 2:08 PM
#22
I tried that but I get errors..."tag" defined multiple times in the same scope.....

I even tried with a simpler one creature tag spawn in a smaller area...script compiles but nothing spawned.
 TimBob12
05-15-2011, 4:01 PM
#23
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.
 newbiemodder
05-15-2011, 5:19 PM
#24
yeah, 5 should do it I think....thanks....take your time
 harark1
05-16-2011, 4:35 PM
#25
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");

}
 TimBob12
05-16-2011, 5:03 PM
#26
That's how I thought it should work but I never got round to test it. I have the script ready I just need to test it which I'll do tomorrow as its getting late and I have an exam tomorrow. I will also test hararks method if I get round to it :)
 newbiemodder
05-16-2011, 5:03 PM
#27
I'll give it a try later...thx
 newbiemodder
05-16-2011, 8:53 PM
#28
This is my script

#include "populate"

void main() {

Populate(15, 8, 121, -10, 103, "522_man1");
Populate(15, 8, 121, -10, 103, "522_man2");
Populate(15, 8, 121, -10, 103, "522_man3");
Populate(15, 8, 121, -10, 103, "522_fem1");
Populate(15, 8, 121, -10, 103, "522_fem2");
Populate(15, 8, 121, -10, 103, "522_fem3");



}


Doesn't work. I even changed the coords above to a much smaller area and no go

Seems to compile fine....beginning to think that this some crazy glitch that sometimes happens when modding.

Edit, I used the debugging technique from the tutorials and the script is being read onenter...so...
 harark1
05-16-2011, 9:26 PM
#29
No idea but this populate function does seem to have a few glitches. I've noticed something but i wasn't sure if it was my doing until today. It seems not to obey the number of each charcter put in, i put 3 of a charcter that has an ithorian model in the script, in game I counted 5 ithorians and only one charcter type has the ithorian model. Little confused but its timbob's scripting hopefully he knows.
 harark1
05-19-2011, 6:42 PM
#30
Timbob we have a probelm!!!! Using the same script I posted earlier, note I had not changed it, suddenly this happened :ohdear:


http://www.lucasforums.com/picture.php?albumid=738&pictureid=8184)
 JebusJM
05-19-2011, 10:56 PM
#31
Just to clarify, you didn't put multiple copies of the script in the Override did you?
 harark1
05-20-2011, 5:16 PM
#32
Uh, hmm good question that is a stupid thing I would do. Let me check.

Edit: nope just once.
 TimBob12
05-21-2011, 4:33 AM
#33
I will be frankly honest... I haven't a clue why this is happening. Harak1 can you open up populate.nss in your overide and PM Me what it says please so I can make a few checks. Thanks.
 Canderis
06-14-2011, 4:00 PM
#34
Has this been confirmed working in k1?
 TimBob12
06-14-2011, 4:18 PM
#35
Hasn't but in theory it should work with no problems although some users have experienced problems that only some people seem to get. It works for like 80% of people. I just haven't had the time to confirm for K1. Should work fine though.
 harIII
06-15-2011, 8:06 PM
#36
OMG, why haven't I seen this!?! Timbob to put it clearly YOU ARE A GOD!!! Instant download
 Nick Vader
06-17-2011, 1:12 PM
#37
TimBob my characters seem to be spawning at random numbers, and I can't tell why! I used this script as my OnEnter script:

#include "populate"
void main() {
Populate( 3, -62, -26, -80, -76, "gmember");
Populate( 3, -62, -26, -80, -76, "gmember2");
Populate( 3, -62, -26, -80, -76, "gmember3");
ActionStartConversation(GetFirstPC(),"guardtalk"); //this line has nothing to do with your script, by the way...
}
 harark1
06-17-2011, 1:40 PM
#38
What do you mean by random numbers? Random numbers of charcters?
 UltimateHK47
12-04-2011, 3:58 PM
#39
//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"
#include "populate"


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)
{


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));



}
}


//Created by TimBob12

I really dont get it. So where do i replace my coordinates, xmin, ymin ect. Do i replace those with my coordinates. And for amount do i put the amount of people i want to spawn and copy it over amount? Where else do i have to put numbers :( im lost but i need this or ill be mapping nearly 100 people!!!!!!!
 darth-ackbar
01-07-2012, 4:08 AM
#40
I've tried doing this with multiple populate lines:
Populate(5, 6, 9, 12, 15, Tag1);
Populate(7, 5, 12, 14, 19, Tag2);

And put the script in the OnEnter function. Whenever I try to use it, the game crashes. I'm guessing that this is due to the amount of processing power it uses, so is there a better way to do this?
 Fallen Guardian
10-06-2012, 5:06 PM
#41
I tried using the populate function without success... but, looking at the populate.nss script, I figured out why. I was using an Obsidian UTC, which meant that the tag and template were different. So, when I specified the UTC's tag instead of its template the creature would never spawn, because the CreateObject function used within populate.nss' code requires the template of a creature to spawn it. So the example was a bit misleading, but, still an excellent function.
Page: 1 of 1