First just encase anything I say here sounds iff. I dont own NWN2 Im a NWN1 player. So I may be wrong on some of your function calls.
Here is my Cut dow version of you script that I tested.
void main()
{
SendMessageToPC(GetFirstPC( ), "Uncontrolled Cycling");
object oSelf = OBJECT_SELF;
location lSelf = GetLocation(oSelf);
int nEnemyCount = 0;
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, lSelf, TRUE, OBJECT_TYPE_CREATURE);
while(GetIsObjectValid(oTarget))
{
if(GetIsInCombat() && GetIsEnemy(oTarget, oSelf))
{
SendMessageToPC(oSelf, "In Combat/Is Enemy");
nEnemyCount ++;
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, lSelf, TRUE, OBJECT_TYPE_CREATURE);
[/list]}//while
SendMessageToPC(oSelf, "nEnemyCount = " + IntToString(nEnemyCount));
[/list]}//main
now I was running it on the PC. hence I canged oSelf to object oSelf = OBJECT_SELF;
This makes the GetInCombat() functiom get wether or not the PC (being the object it is running on) is in combat.
Now in your version if our functions work the same way you may need to enter in the peramater for the function. If not you are checking to see if the AOE is in combat or not.
Now if this is running on a HB. and it is the oSelf that we are checking to see if they are in combat. We may want to limit the number of times it is checking down to once. and move the check for the limited reached back into the loop and break out of it once it is meet. This will hopefully make the loop a little more efficent. The only other real processor intensive calculation going on is in the GetNextObjectInShape with the line of sight peramerter being set to TRUE.
The slightly more efficent script would look like this.
void main()
{
SendMessageToPC(GetFirstPC( ), "Uncontrolled Cycling");
object oSelf = OBJECT_SELF;
location lSelf = GetLocation(oSelf);
int nEnemyCount = 0;
int nBonus;
// If oSelf Is not in comabt bail out no reason to go on.
// Or if His HP's are greater then half. He will not change so no reason to check futher.
if(!GetIsInCombat(oSelf)|| (GetCurrentHitPoints(oSelf) > GetMaxHitPoints(oSelf)/2) ) return;
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, lSelf, TRUE, OBJECT_TYPE_CREATURE);
while(GetIsObjectValid(oTarget))
{
if(GetIsEnemy(oTarget, oSelf))
{
SendMessageToPC(oSelf, "In Combat/Is Enemy");
//add one to the count and break out of while loop if quota
if (nEnemyCount > nBonus )break ;
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, lSelf, TRUE, OBJECT_TYPE_CREATURE);
[/list] }//while
SendMessageToPC(oSelf, "nEnemyCount = " + IntToString(nEnemyCount));
//in combat and HP already checked befor loop
if (nEnemyCount++ > nBonus )
{
// Apply your effects here.
}
[/list] }//main
Of course it is still my cut down version.
on building your Effects It also would not hurt to build them just befor useing them instead of at the begining of the script. No reason to wast the time every HB if they are not needed..
The other thing i see in this and have not placed a fix for. Is that it will apply the effects again to oSelf even if he is has already changed. You will need to add a check or control to exit the script if oself is already changed.
Modifié par Lightfoot8, 19 juillet 2010 - 05:31 .