Author Topic: Probem with scripting a function commanding a PC  (Read 560 times)

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Probem with scripting a function commanding a PC
« on: January 22, 2011, 10:25:54 pm »


               Well following the subject of cursed items I want to make a sword that can render its wielder berserk here's the function I use but I ran into one issue...Once in "berserk" state the PC never leave cutscene mode anymore even when there's no more creature around!
Here's the function:

void SetBerserk(object oPC, int nChance = 20, float fDelay = 6.0)
{
if (!GetIsCursed(oPC))
 {
 SetCutsceneMode(oPC, FALSE);
 return;
 }
SetCommandable(TRUE, oPC);
object oCrea = GetFirstObjectInShape(SHAPE_SPHERE, 15.0, GetLocation(oPC), TRUE, OBJECT_TYPE_CREATURE);
int nRand = d100();
if ((nRand <= nChance || GetLocalInt(oPC, "berserk") == 1) && GetIsObjectValid(oCrea))
 {
 SetCutsceneMode(oPC, TRUE);
 SetPlotFlag(oPC, FALSE);
 SetLocalInt(oPC, "berserk", 1);
 DelayCommand(0.0, AssignCommand(oPC, ClearAllActions()));
 DelayCommand(0.5, AssignCommand(oPC, ActionAttack(oCrea)));
 DelayCommand(fDelay, SetBerserk(oPC, nChance, fDelay));
 }
else
 {
 SetCutsceneMode(oPC, FALSE);
 DeleteLocalInt(oPC, "berserk");
 DelayCommand(fDelay, SetBerserk(oPC, nChance, fDelay));
 }
}

I tried the same function without using the cutscene mode (with setcommandable(TRUE/FALSE)) in that case the issue is the same the PC ends up in SetCommandable(FALSE) even when there's no more creature around...
What am I missing here? Thanks!
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Probem with scripting a function commanding a PC
« Reply #1 on: January 22, 2011, 10:47:51 pm »


               There will be every time at least one creature, you. Better would be to use GetNearestCreature and check for perception. Otherwise you can find another issue and thats enemy behind the wall.



Btw: Cutscene is quite unfriendly way to do, commandable is enough, but PC can still cancel an attack (the same problem have confused PC and I have not found any workaround yet).

               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Probem with scripting a function commanding a PC
« Reply #2 on: January 22, 2011, 11:19:56 pm »


               Just added a test if (oCrea == oPC) oCrea = GetNextObjectInShape and it now works perfectly in the SetCommandable form!! Should be no issue with an ennemy behind a wall because nLineofSight is set to TRUE in the getFirst/GetNextObjectInShape (but i have not tested yet...)

Thanks for your quick answer ShaDoOow!!!
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Probem with scripting a function commanding a PC
« Reply #3 on: January 23, 2011, 12:18:00 am »


               

Krevett wrote...

nLineofSight is set to TRUE in the getFirst/GetNextObjectInShape!

Oh, right, i forget on this paramater, then its fine.