Np, and thanks for the definition. I wonder why sometimes I get a script that will TMI, it's a spawn script, but not always. I'd say about 1 out of 5 times it fires it TMI's. Well here it is:
#include "NW_I0_GENERIC"
#include "x3_inc_string"
void main()
{
int nCreature, nNumber;
string sCreature = "";
string sMessage = (StringToRGBString("\\n AMBUSH !! \\n",STRING_COLOR_RED));
object oPC = GetEnteringObject();
object oArea = GetArea(oPC);
if (!GetIsPC(oPC))
return;
if (GetLocalInt(oPC,"Safe") == 1)
return;
if (GetLocalInt(oPC,"Ran") > 2 +d4(1))
return;//script will only run 3 times,plus d4 default would be 4
int iHd = GetHitDice(oPC);
if (d100() < 60 + (iHd))//set between 50-75. Lower means fewer spawns.
return;
//if (GetDetectMode(oPC) == DETECT_MODE_PASSIVE)//not actively searching.
//return;
object oTarget = oPC;
float fDistance = 2.0 + (iHd/2);//higher level notice things futher away
location lWP = GetRandomLocation(oArea,oTarget,fDistance);
location lTarget = GetLocation(oTarget);
//Cycle through PCs in area
object oPChp = GetFirstPC();
while (GetIsObjectValid(oPChp)||(oArea == GetArea(oPChp)))
{
if (oArea != GetArea(oPChp))
{
oPChp = GetNextPC();
}
iHd++;
iHd += GetHitDice(oPChp); //trying to add the pc's in the area hp
oPChp = GetNextPC();
}
if (iHd < 10)
SetLocalInt(oPC,"Spawn",1);
else if (iHd < 20)
SetLocalInt(oPC,"Spawn",2);
else if (iHd < 30)
SetLocalInt(oPC,"Spawn",3);
else
SetLocalInt(oPC,"Spawn",4);
if (GetIsNight())
{
SetLocalInt(oPC,"Spawn", GetLocalInt(oPC,"Spawn")+1);
}
if ( GetStealthMode( oPC ) == STEALTH_MODE_ACTIVATED )
{
SetLocalInt(oPC,"Spawn", GetLocalInt(oPC,"Spawn")-1);
}
if ((GetLocalInt(oPC,"Spawn")== 1) && (GetIsSkillSuccessful(oPC, SKILL_LISTEN, 5)))//easy
{
SendMessageToPC(oPC, "You Hear Something!");
GiveXPToCreature(oPC, 25);
switch (d4())
{
case 1: sCreature = "thugcn"; break;//resref of creature
case 2: sCreature = "madcrow"; break;
case 3: sCreature = "townperson"; break;
case 4: sCreature = "monkbd"; break;
}
for (nNumber = 0; nNumber < d3(); nNumber++)
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lWP, FALSE);
object oCreature = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE, lWP);
float fDistance1 = GetDistanceBetweenLocations(lWP, lTarget);
string sDistance = FloatToString(fDistance1, 2,0);
DelayCommand (3.0,SendMessageToPC(oPC, " Some noise, over there! " + sDistance + " metres away."));
DelayCommand (6.0, TurnToFaceObject(oCreature, oPC));
}
if ((GetLocalInt(oPC,"Spawn")== 2) && (GetIsSkillSuccessful(oPC, SKILL_SPOT, 15)))//harder
{
SendMessageToPC(oPC, "You Spot Something!");
GiveXPToCreature(oPC, 50);
switch (d4())//should be tougher creatures below
{
case 1: sCreature = "thugcn"; break;//resref of creature
case 2: sCreature = "monkbd"; break;
case 3: sCreature = "townperson"; break;
case 4: sCreature = "rioter003"; break;
}
//Randomly generate the number of monsters//
for (nNumber = 0; nNumber < d4(); nNumber++)//change d4 for more
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lWP, FALSE);
object oCreature = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE, lWP);
float fDistance1 = GetDistanceBetweenLocations(lWP, lTarget);
string sDistance = FloatToString(fDistance1, 2,0);
DelayCommand (2.5,SendMessageToPC(oPC, " Something, over there! " + sDistance + " meters away."));
DelayCommand (5.0, TurnToFaceObject(oCreature, oPC));
}
else if ((GetStealthMode(oPC) == STEALTH_MODE_DISABLED) && (GetIsNight ()) && (GetLocalInt(oPC,"Ran") < 3))
{
CreateObject(OBJECT_TYPE_CREATURE, "robber", lWP, FALSE);
DelayCommand (2.0, FloatingTextStringOnCreature(sMessage, oPC, FALSE));
}
if ((GetLocalInt(oPC,"Spawn")==3) && (GetIsSkillSuccessful(oPC, SKILL_LISTEN, 20)))
{
SendMessageToPC(oPC, "A faint sound reaches you!");
GiveXPToCreature(oPC, 100);
switch (d6())
{
case 1: sCreature = "thugcn"; break;//resref of creature
case 2: sCreature = "rioter003"; break;
case 3: sCreature = "townperson"; break;
case 4: sCreature = "youth01"; break;
case 5: sCreature = "maddog"; break;
case 6: sCreature = "monkbd"; break;
}
for (nNumber = 0; nNumber < d6(); nNumber++)
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lWP, FALSE);
object oCreature = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE, lWP);
float fDistance1 = GetDistanceBetweenLocations(lWP, lTarget);
string sDistance = FloatToString(fDistance1, 2,0);
DelayCommand (1.5,SendMessageToPC(oPC, " Something is moving, over there! " + sDistance + " metres away."));
DelayCommand (4.0, TurnToFaceObject(oCreature, oPC));
}
if ((GetLocalInt(oPC,"Spawn") == 4) && (GetIsSkillSuccessful(oPC, SKILL_SPOT, 25)))//etc...
{
SendMessageToPC(oPC, "Your highly attuned senses are alerted!");
GiveXPToCreature(oPC, 150);
switch (d6())//should be tougher creatures
{
case 1: sCreature = "harpy"; break;//resref of creature
case 2: sCreature = "robber"; break;
case 3: sCreature = "townperson"; break;
case 4: sCreature = "skeletondart"; break;
case 5: sCreature = "maddog"; break;
case 6: sCreature = "skeletonrapier"; break;
}
for (nNumber = 0; nNumber < d4(); nNumber++)
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lWP, FALSE);
object oCreature = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE, lWP);
float fDistance1 = GetDistanceBetweenLocations(lWP, lTarget);
string sDistance = FloatToString(fDistance1, 2,0);
DelayCommand (1.0,SendMessageToPC(oPC, " Some movement, over there! " + sDistance + " metres away."));
DelayCommand (4.0, TurnToFaceObject(oCreature, oPC));
}
else if ((GetStealthMode(oPC) == STEALTH_MODE_DISABLED) && (GetIsNight ()) && (GetLocalInt(oPC,"Ran") < 3))
{
CreateObject(OBJECT_TYPE_CREATURE, "robber", lWP, FALSE);
DelayCommand (2.0, FloatingTextStringOnCreature(sMessage, oPC, FALSE));
}
else if ((GetStealthMode(oPC) == STEALTH_MODE_DISABLED) && (GetIsNight ()) && (GetLocalInt(oPC,"Ran") < 3))
{
CreateObject(OBJECT_TYPE_CREATURE, "harpy", lWP, FALSE);
DelayCommand (2.0, FloatingTextStringOnCreature(sMessage, oPC, FALSE));
}
SetLocalInt(oArea,"Ran", GetLocalInt(oArea,"Ran")+1);
DelayCommand (400.0/ d4(2), ExecuteScript("ranspslistenslum",oArea));
DelayCommand (300.0, DeleteLocalInt(oArea,"Ran"));
}
I have many similar scripts that work fine but this one seems to be cranky. Maybe I just have a bracket in the wrong place. Now that I look at it maybe these lines have an uneeded bracket:
{
if (oArea != GetArea(oPChp))
//{maybe no bracket needed here.
oPChp = GetNextPC();
}
Modifié par ffbj, 07 février 2013 - 06:24 .