Author Topic: How can you tell if something is doing two actions at the same time?  (Read 928 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0


               

I'd like to code an item to punish a player for run gunning with "ranged" weapons, IE arrow farting, but I don't really see a way to tell whether or not they're doing it .. I tried using "action_movetopoint", but it doesn't seem to register that the PC is moving while they're also attacking. Is there any way to definitively tell, and have the script act accordingly?


 


{

        if(GetCurrentAction(oSpellTarget) == ACTION_MOVETOPOINT)

        {

        nChance = GetCasterLevel(OBJECT_SELF) * 20;

        SpeakString("Stop that cheater!", TALKVOLUME_TALK);

        }

        else

        {

        nChance = GetCasterLevel(OBJECT_SELF) * 2;

        }



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
How can you tell if something is doing two actions at the same time?
« Reply #1 on: April 25, 2016, 10:43:35 pm »


               

I tried to code this on my boss creature and found out its not possible to do in NWScript. None of my attempts were accurate, either it detected the runshoot only in 20% cases, or it had falsepositives.


 


I don't think its doable.


 


And while nwnx fix for this exists, it creates lagginess so this is also not a way.



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
How can you tell if something is doing two actions at the same time?
« Reply #2 on: April 26, 2016, 12:42:38 am »


               

 if(GetCurrentAction(oSpellTarget) == ACTION_MOVETOPOINT ||

        GetFacing(oSpellTarget)  >= GetFacing(OBJECT_SELF) -90.0f  &&

        GetFacing(oSpellTarget)  <= GetFacing(OBJECT_SELF) +90.0f

       )

        {

        nChance = 100;

        SpeakString("My chance is..." + GetChance, TALKVOLUME_TALK);


        }

        else

        {

        nChance = GetCasterLevel(OBJECT_SELF) * 2;

        }

 


 


I tried to insert this into the chaos shield script I was modifying, basically what I think it's checking.. is to see if the character shooting arrows is facing them or not, if they're more than 90 degrees in either direction facing away from them then it should fire. But I'm not sure if I have the math right, because it fires every time it hits. D:



               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
How can you tell if something is doing two actions at the same time?
« Reply #3 on: April 26, 2016, 07:37:42 am »


               
int GetIsFacingTarget(object oSelf, object oTarget, int nViewArc)

{

 float AngleOffset = VectorToAngle( GetPosition(oTarget) - GetPosition(oSelf)) - GetFacing(oSelf) ;

 return (abs(FloatToInt(AngleOffset)) <  nViewArc/2);

}

 

Lightfoot8 wrote that for me, years back, for a function to check if something is in front of an object.  It's a handy function to have around.


               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
How can you tell if something is doing two actions at the same time?
« Reply #4 on: April 26, 2016, 03:53:02 pm »


               


 


int GetIsFacingTarget(object oSelf, object oTarget, int nViewArc)

{

 float AngleOffset = VectorToAngle( GetPosition(oTarget) - GetPosition(oSelf)) - GetFacing(oSelf) ;

 return (abs(FloatToInt(AngleOffset)) <  nViewArc/2);

}

 

Lightfoot8 wrote that for me, years back, for a function to check if something is in front of an object.  It's a handy function to have around.

 




 


I think that was one of the ones that he replaced later due to bugs.  AngleOffset has a range of -360<x<360 such that if I were facing East (reported as 0) and my target was 1 degree South of East (-1 is reported as 359) the AngleOffset would be 359 which would require a ViewArc to be greater than 718 in order to report true.


 


EDIT: Try this one:



int GetIsFacingTarget(object oSelf, object oTarget, float fViewArc)
{
 float AngleOffset = fabs(fabs(VectorToAngle(GetPosition(oSelf) - GetPosition(oTarget)) - GetFacing(oSelf)) - 180.0);
 return (AngleOffset <  fViewArc/2.0);
}


               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
How can you tell if something is doing two actions at the same time?
« Reply #5 on: April 27, 2016, 12:25:23 am »


               

This script will just check to see if they're in front of the object right, it wont get which direction they're facing?



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
How can you tell if something is doing two actions at the same time?
« Reply #6 on: April 27, 2016, 01:56:42 am »


               


This script will just check to see if they're in front of the object right, it wont get which direction they're facing?




 


It is in front of the object, with front being defined by the direction the object is facing.  The script does not check to see which way the target is facing.


               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
How can you tell if something is doing two actions at the same time?
« Reply #7 on: April 27, 2016, 03:03:50 am »


               


 


I think that was one of the ones that he replaced later due to bugs.  AngleOffset has a range of -360<x<360 such that if I were facing East (reported as 0) and my target was 1 degree South of East (-1 is reported as 359) the AngleOffset would be 359 which would require a ViewArc to be greater than 718 in order to report true.


 


EDIT: Try this one:



int GetIsFacingTarget(object oSelf, object oTarget, float fViewArc)
{
 float AngleOffset = fabs(fabs(VectorToAngle(GetPosition(oSelf) - GetPosition(oTarget)) - GetFacing(oSelf)) - 180.0);
 return (AngleOffset <  fViewArc/2.0);
}



You're right.  I've used that function quite a bit as well.  I'm surprised I never noticed it was doing that.