Aller au contenu

Photo

Waypoint Question plz lighten me


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
Corvittin

Corvittin
  • Members
  • 23 messages
Hello everyone;
i have a Forest Area and theres 12 Waypoints. I want to spawn rabbits from these WPs for Every Daytime
so i wrote this one. script is on area hb
void main()
{
int ServerTime=GetTimeHour();
int i;
string sWPName="wp_neutral";
if(ServerTime = 6)
{
    for(i=1;i<=12;i++)
    {
    string si=IntToString(i);
    object oWP=GetWaypointByTag(sWPName+si);
    location lNew=GetLocation(oWP);
    CreateObject(OBJECT_TYPE_CREATURE,"c_rabbit0",lNew);
    }
}
if(ServerTime = 18)
{
    for(i=1;i<=12;i++)
    {
    string si=IntToString(i);
    object oWP=GetWaypointByTag(sWPName+si);
    location lNew=GetLocation(oWP);
    CreateObject(OBJECT_TYPE_CREATURE,"c_rabbit0",lNew);
    }
}
}
i tryed to do that with ginc_wp but it was a fail... so is this code Spaghetti or fine? thanks

Modifié par Corvittin, 26 décembre 2013 - 04:15 .


#2
Darin

Darin
  • Members
  • 282 messages

Corvittin wrote...

void main()
{
int ServerTime=GetTimeHour();
int i;
string sWPName="wp_neutral";
string si; //initialize outside the loop
object oWP;
location lNew;

if(ServerTime == 6) //use "==" for logic equals
{
    for(i=1;i<=12;i++)
    {
    si=IntToString(i);
    oWP=GetWaypointByTag(sWPName+si);
    lNew=GetLocation(oWP);
    CreateObject(OBJECT_TYPE_CREATURE,"c_rabbit0",lNew);
    }
}
if(ServerTime == 18) //again, ==
{
    for(i=1;i<=12;i++)
    {
    si=IntToString(i);
    oWP=GetWaypointByTag(sWPName+si);
    lNew=GetLocation(oWP);
    CreateObject(OBJECT_TYPE_CREATURE,"c_rabbit0",lNew);
    }
}
}


If it's not compiling, that may help.  Could also be that you're IF statements are just setting ServerTime = to 6 then again to 18...which isn't helpful; "=" means the math = (set equal to) while "==" is the logical equal "is equal to"; so A = 3 will set int A to value 3
A == 3 will be TRUE if A = 3, FALSE if A is not 3.

Modifié par EpicFetus, 26 décembre 2013 - 05:27 .


#3
Corvittin

Corvittin
  • Members
  • 23 messages
hmm understand thank you.

#4
MarshallV

MarshallV
  • Members
  • 43 messages
Take a look at the Legends Spawn plugin. It can do what you're looking for and more.

http://www.nwn2legen...s-spawn-plugin/

Cheers,

M

#5
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
For the heck of it, my rabbit-spawning script (called from area-on-enter script):
[nwscript]
// spawn_sc_rabbits

// Name_Date
int iResupplyClock() {
int iLastHour = GetLocalInt(OBJECT_SELF, "iRabbitLastHour");
int iThisHour = GetTimeHour();
int iSupplyClock = iThisHour - iLastHour;
// if (iSupplyClock < 0) {iSupplyClock = iSupplyClock + 24;}

int iLastDay = GetLocalInt(OBJECT_SELF, "iRabbitLastDay");
int iThisDay = GetCalendarDay();
if (iLastDay != iThisDay) {
iSupplyClock = iSupplyClock + 24;
}

SetLocalInt(OBJECT_SELF, "iRabbitLastHour", iThisHour);
SetLocalInt(OBJECT_SELF, "iRabbitLastDay", iThisDay);

return iSupplyClock;
}

object oSpawnRabbit(int iSpawnNum) {
object oWP = GetObjectByTag("SPAWN_SCRabbit" + IntToString(iSpawnNum));
location lLoc = GetLocation(oWP);
object oRabbit = CreateObject(OBJECT_TYPE_CREATURE, "myrabbit", lLoc, FALSE, "SCRabbit" + IntToString(iSpawnNum));
return oRabbit;
}


int iCheckSpawnRabbit(int iSpawnNum) {
object oRabbit = GetObjectByTag("SCRabbit" + IntToString(iSpawnNum));
if (GetIsObjectValid(oRabbit) && !GetIsDead(oRabbit)) {
ForceRest(oRabbit);
return 1;
}
else {
oSpawnRabbit(iSpawnNum);
return -2;
}
}

void main()
{
object oPC = GetFirstPC();
//Do Plot restrictions

int iMaxRabbits = 9;//Constant
int iSupply = iResupplyClock();
// SendMessageToPC(oPC, "Supply: " + IntToString(iSupply));

int iTer = 1;
while ((iTer <= iMaxRabbits) && (iSupply > 0)) {
// SendMessageToPC(oPC, "While Loop: " + IntToString(iTer) + "/" + IntToString(iSupply));
iSupply = iSupply + iCheckSpawnRabbit(iTer);
iTer = iTer + 1;
}
}
[/nwscript]

It just works to make the rabbit population doesn't get too big, and gradually repopulates after the PC kills a few.

Modifié par Lugaid of the Red Stripes, 26 décembre 2013 - 06:29 .


#6
Corvittin

Corvittin
  • Members
  • 23 messages
oh you are right rabbit population might be a problem yes :(

#7
Corvittin

Corvittin
  • Members
  • 23 messages
your scripts rabbitnum check depends on iSpawnNum if i understand correctly. are there any chance to get total rabbit number in area? Becouse im using 12 different spawn location.

Modifié par Corvittin, 26 décembre 2013 - 09:42 .


#8
Tchos

Tchos
  • Members
  • 5 063 messages
I also endorse Marshall's Legends Spawn plugin. No coding necessary if you're not comfortable with coding. Just mark some boxes and have things spawn and despawn at certain times of day. See the videos.

#9
Corvittin

Corvittin
  • Members
  • 23 messages
yes i know it marshall is a genius but i like to learn it =)

#10
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I have the max number set to 9 here(int iMaxRabbits = 9;//Constant), you could just as easily set it to 12 with your waypoint base tag replacing "SPAWN_SCRabbit".

"SC" is my code for this particular area, I could imagine you using something like AANeuRabbit, with 'AA' being the code for your area.  I use the 'SPAWN' prefix here, to keep things clear, but a generic 'WP' works just as well.

Modifié par Lugaid of the Red Stripes, 27 décembre 2013 - 12:00 .