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/)
Great jobe TB....you put a lot of effort into creating this...thanks to all his helpers too.
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.
Thanks will help so much.
VERY cool idea, TB! Thank you for sharing, this will help so much. :D
THANK YOU. This is going to be so helpful!
This is going to be one of the best modding tools ever made. Thank you TimBob for revolutionizing KOTOR modding!
AHHH! Script won't work. Need help.
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);
}
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.
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.
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)
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
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.
Version 2.81 available to download now from the same download link. It is a stable and working version.
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
Im just glad people can make use of it :)
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.
I just copied the line multiple times and input a different npc tag in each line.
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.
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.
yeah, 5 should do it I think....thanks....take your time
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");
}
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 :)
I'll give it a try later...thx
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...
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.
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)
Just to clarify, you didn't put multiple copies of the script in the Override did you?
Uh, hmm good question that is a stupid thing I would do. Let me check.
Edit: nope just once.
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.
Has this been confirmed working in k1?
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.
OMG, why haven't I seen this!?! Timbob to put it clearly YOU ARE A GOD!!! Instant download
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...
}
What do you mean by random numbers? Random numbers of charcters?
//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!!!!!!!
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?
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.