Aller au contenu

Photo

A script that crashes half the time


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

#1
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
#include "x0_i0_position"
#include "tdebug"

object PlaceAhead(float fRange, int iType, string sTemplate, object oTarget, string sWhere="forward", string sTag="")
{
object oPC = GetFirstPC();
object oObj;
location locAhead = GetAheadLocation(oTarget, fRange);
location locAheadL = GetAheadLeftLocation(oTarget, fRange);
location locAheadR = GetAheadRightLocation(oTarget, fRange);


if (sWhere=="forward") oObj = CreateObject(iType, sTemplate, locAhead, FALSE, sTag);
if (sWhere=="right") oObj = CreateObject(iType, sTemplate, locAheadR, FALSE, sTag);
if (sWhere=="left") oObj = CreateObject(iType, sTemplate, locAheadL, FALSE, sTag);

AssignCommand(oObj, SetFacing(GetFacing(oPC)+180.0f) ); // adding 180 means it will be exactly opposite the PC facing
return oObj;
}

void PlayScene(string sScene)

{
object oPC = GetFirstPC();
DebugText("producing scene:: " + sScene);
if (sScene == "Scene1")
    {     
    object oAngel = PlaceAhead(5.0f, OBJECT_TYPE_CREATURE, "c_messenger", oPC, "forward", "angel");   
    AssignCommand(oAngel, ActionStartConversation(oPC, "", FALSE, FALSE, TRUE, FALSE) );
    }

if (sScene == "Scene2")
    {     
    //PlaceAhead(7.0f, OBJECT_TYPE_PLACEABLE, "dream_cabin", oPC, "forward", "dream_cabin");   
    PlaceAhead(4.0f, OBJECT_TYPE_PLACEABLE, "plc_ipspeaker", oPC, "forward", "IP_center");
    PlaceAhead(5.0, OBJECT_TYPE_CREATURE, "c_goblin_baby", oPC, "right", "dream_gob");
    PlaceAhead(4.7, OBJECT_TYPE_CREATURE, "c_goblin_baby", oPC, "right", "dream_gob");
    object oGob = PlaceAhead(4.4, OBJECT_TYPE_CREATURE, "c_goblin_baby", oPC, "right", "dream_gob");
    object oWidow = PlaceAhead(4.4, OBJECT_TYPE_CREATURE, "c_widow", oPC, "forward", "dream_widow");
    AssignCommand(oWidow, SetFacing(GetFacing(oGob)+180, TRUE));
    object oAngel = PlaceAhead(7.0f, OBJECT_TYPE_CREATURE, "c_messenger", oPC, "forward", "angel");   
    AssignCommand(oAngel, ActionStartConversation(oPC, "", FALSE, FALSE, TRUE, FALSE) );
    }

if (sScene == "Scene3")
    {     
    effect eHold = EffectCutsceneImmobilize();
    AssignCommand(oPC, ClearAllActions());
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eHold, oPC, 30.0f);

    object oAngel = PlaceAhead(8.0f, OBJECT_TYPE_CREATURE, "c_messenger", oPC, "forward", "angel");   
    object oWarA = PlaceAhead(5.0f, OBJECT_TYPE_CREATURE, "dream3wa", oPC, "left", "WarA");
    object oWarC = PlaceAhead(4.6f, OBJECT_TYPE_CREATURE, "dream3wa", oPC, "left", "WarC");   
    object oWarB = PlaceAhead(5.0f, OBJECT_TYPE_CREATURE, "dream3ev", oPC, "right", "WarB");
    object oWarD = PlaceAhead(4.6f, OBJECT_TYPE_CREATURE, "dream3ev", oPC, "right", "WarD");
    DelayCommand(1.0f, AssignCommand(oAngel, ActionStartConversation(oPC, "", FALSE, FALSE, TRUE, FALSE)
) );
   
    }
   
   
}


void main()
{

object oPC = GetFirstPC();
object oArea = GetArea(oPC);
if (GetTag(oArea)!="dream3") return;



int bIsBusy = IsInConversation(oPC);



int iScene = GetLocalInt(OBJECT_SELF, "iScene");
int iSteps = GetLocalInt(OBJECT_SELF, "iSteps");
DebugText("Step:" + IntToString(iSteps) + " Scene: " + IntToString(iScene) );

if (iSteps < 0 || iSteps > 3) {iSteps = 3; SetLocalInt(OBJECT_SELF, "iSteps", iSteps);}
if (bIsBusy) {SetLocalInt(OBJECT_SELF, "iSteps", 3); return;}

iSteps--;

if (iSteps==0) // place objects for dream sequence
    {   
    PlayScene("Scene" + IntToString(iScene));
    iScene++;
    SetLocalInt(OBJECT_SELF, "iScene", iScene);
    }
   
   
SetLocalInt(OBJECT_SELF, "iSteps", iSteps);

}


Inexplicably this script has been crashing for players about half to 1/3 the time since it was invented.
The trouble portion is in red; this is where it happens.  Previously I thought it happened when the player was in motion so I added the paralyze effect, but it can be removed or added, still get the same result. I'm out of guesses on this year old thing.

#2
MasterChanger

MasterChanger
  • Members
  • 686 messages

Eguintir Eligard wrote...

[b]if (sScene == "Scene3")
    {     
[/b][i]    effect eHold = EffectCutsceneImmobilize();
    AssignCommand(oPC, ClearAllActions());
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eHold, oPC, 30.0f);[/i][b]
    object oAngel = PlaceAhead(8.0f, OBJECT_TYPE_CREATURE, "c_messenger", oPC, "forward", "angel");    
    object oWarA = PlaceAhead(5.0f, OBJECT_TYPE_CREATURE, "dream3wa", oPC, "left", "WarA");
    object oWarC = PlaceAhead(4.6f, OBJECT_TYPE_CREATURE, "dream3wa", oPC, "left", "WarC");    
    object oWarB = PlaceAhead(5.0f, OBJECT_TYPE_CREATURE, "dream3ev", oPC, "right", "WarB");
    object oWarD = PlaceAhead(4.6f, OBJECT_TYPE_CREATURE, "dream3ev", oPC, "right", "WarD");
    DelayCommand(1.0f, AssignCommand(oAngel, ActionStartConversation(oPC, "", FALSE, FALSE, TRUE, FALSE) [/b]) );
   


Inexplicably this script has been crashing for players about half to 1/3 the time since it was invented.
The trouble portion is in red; this is where it happens.  Previously I thought it happened when the player was in motion so I added the paralyze effect, but it can be removed or added, still get the same result. I'm out of guesses on this year old thing.


The color didn't seem to show up in the code, so I'm assuming that the problem is somewhere in the italicized and/or bolded section above.

Two things that immediately spring to mind:

-First, you're applying an EffectToObject with DURATION_TYPE_PERMANENT, but you're supplying a duration nonetheless. I'd guess that the duration would just be ignored if you use anything but DURATION_TYPE_TEMPORARY, but better not to confuse things with unnecessary parameters.

-Second, you're creating a not-so-small number of objects right at the same time. Have you tried it with just one object being placed ahead? If that works, have you tried it with delays?

#3
SkywingvL

SkywingvL
  • Members
  • 351 messages
Could you clarify what you mean by 'crashes'? Is the script just not working properly, or is the server (or the client) actually crashing out or hanging?



If the client or server is crashing out, see if you can get the "nwn2_errorlog.txt" or "nwn2_servererrorlog.txt" (as appropriate) from your NWN2 game installation directory. Post or PM it to me, as that may contain valuable information useful to understand why the game might have been crashing.

#4
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
The first part wont matter because I added that recently and it does not change anything.



As for the second part... is 5 items really that much?

See in the first scene it creates 4, never crashses. Is that the limit lol?



I'll check I guess.

#5
Guest_ElfinMad_*

Guest_ElfinMad_*
  • Guests
I'll have a stab in the dark at it. Is it the SetFacing(GetFacing(oPC)+180.0f) in the function PlaceAhead()?

If the PC is facing 270.0f then this would pass a value of 450.0f to SetFacing() and as there is only 360 degrees in a circle the game freaks out.

It would explain the intermittent crashes as a PC who is facing <180.0f would have no problem. (Edit: Removed evidence of bad mathematical ability)

Could try:
if(GetFacing(oPC) > 180.0f) SetFacing(GetFacing(oPC) -180.0f);
else SetFacing(GetFacing(oPC)+180.0f);

Modifié par ElfinMad, 05 février 2011 - 11:02 .


#6
SkywingvL

SkywingvL
  • Members
  • 351 messages

ElfinMad wrote...

I'll have a stab in the dark at it. Is it the SetFacing(GetFacing(oPC)+180.0f) in the function PlaceAhead()?

If the PC is facing 270.0f then this would pass a value of 450.0f to SetFacing() and as there is only 360 degrees in a circle the game freaks out.

It would explain the intermittent crashes as a PC who is facing <180.0f would have no problem. (Edit: Removed evidence of bad mathematical ability)

Could try:
if(GetFacing(oPC) > 180.0f) SetFacing(GetFacing(oPC) -180.0f);
else SetFacing(GetFacing(oPC)+180.0f);

Values outside the domain of [0,360] should be treated as modulo 360 and should not crash the game.

If the game is actually crashing, an error log would be useful.

#7
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
I suspect its not a facing, but something dropping an object in an invalid location. Are you fully patched? Is this happening in a cramped area, or is it in a completely wide open area?



There is a function to get a safe location you can use to make sure the location is somewhere the player or placed object can go to. Generally you will have issues if the areas don't have enough room for the engine to drop things into the areas. I would comment out the lines where you place things and see what happens then.



This is just guessing, skywing really can see a lot more if you post a crash log.

#8
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
I never knew how to get logs or it would help a lot.



This is a wide open area therefore creatures are place on the fly. But even if I walk up to the zone boundary they seem to sometimes place fine its just it fails at random.

#9
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
I put the 4 warriors spawningin in its own function so it could delay. So far it might be working, 6 for 6 tries no crash. I'd like to test it like 50 but its a slow test.