Don't like ads? PRO users don't see any ads ;-)
Guest

do_grenade

By: henesua on Jul 11th, 2012  |  syntax: C  |  size: 2.76 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //::///////////////////////////////////////////////
  2. //:: do_grenade
  3. //:://////////////////////////////////////////////
  4. /*
  5.     USE: player uses a grenade
  6.  
  7. */
  8. //:://////////////////////////////////////////////
  9. //:: Created By: The Magus (2012 july 10)
  10. //:: Modified:
  11. //:://////////////////////////////////////////////
  12.  
  13. #include "x2_inc_switches"
  14.  
  15. void DoThrowGrenade(object oGrenade, object oTarget, location lTarget, string sScript, int bSplash);
  16. void DoThrowGrenade(object oGrenade, object oTarget, location lTarget, string sScript, int bSplash)
  17. {
  18.     int nTargetType = GetObjectType(oTarget);
  19.     int bHit;
  20.     float fDist     = GetDistanceBetweenLocations(GetLocation(OBJECT_SELF),lTarget);
  21.     float fPrefDist = StringToFloat(Get2DAString("appearance", "PREFATCKDIST", GetAppearanceType(OBJECT_SELF)))*2.0;
  22.  
  23.     if(GetIsObjectValid(oTarget))
  24.     {
  25.         int nAttack;
  26.         if(fDist<=fPrefDist)
  27.             nAttack     = TouchAttackMelee(oTarget);
  28.         else
  29.             nAttack     = TouchAttackRanged(oTarget);
  30.         if(nAttack)
  31.         {
  32.             // direct hit
  33.             bHit    = TRUE;
  34.             ExecuteScript(sScript, oTarget);
  35.         }
  36.     }
  37.  
  38.     if(!bHit)
  39.     {
  40.         oTarget = GetAreaFromLocation(lTarget);
  41.         SetLocalInt(oTarget, "GRENADE_MISS", TRUE);
  42.         SetLocalLocation(oTarget, "GRENADE_LOCATION", lTarget);
  43.         ExecuteScript(sScript, oTarget);
  44.     }
  45.  
  46.     if(bSplash)
  47.     {
  48.         // potential splash
  49.         int nIt;
  50.         vector vPos         = GetPositionFromLocation(lTarget);
  51.         object oBystander   = GetFirstObjectInShape(SHAPE_SPHERE, 5.0, lTarget, TRUE, OBJECT_TYPE_CREATURE, vPos);
  52.         while(GetIsObjectValid(oBystander))
  53.         {
  54.             if(oBystander!=oTarget)
  55.             {
  56.                 SetLocalInt(oBystander,"GRENADE_SPLASH", ++nIt);
  57.                 DelayCommand(0.1, ExecuteScript(sScript, oBystander) );
  58.             }
  59.             oBystander  = GetNextObjectInShape(SHAPE_SPHERE, 5.0, lTarget, TRUE, OBJECT_TYPE_CREATURE, vPos);
  60.         }
  61.     }
  62. }
  63.  
  64.  
  65. //  MAIN ----------------------------------------------------------------------------
  66. void main()
  67. {
  68.     int nEvent              = GetUserDefinedItemEventNumber();
  69.  
  70.  // BEGIN Event Activate
  71.  if (nEvent==X2_ITEM_EVENT_ACTIVATE)
  72.  {
  73.     object oPC      = GetItemActivator();
  74.     object oGrenade = GetItemActivated();
  75.     if(!GetIsObjectValid(oPC)||!GetIsObjectValid(oGrenade))
  76.         return;
  77.     object oTarget  = GetItemActivatedTarget();
  78.     location lTarget= GetItemActivatedTargetLocation();
  79.     string sScript  = GetLocalString(oGrenade,"GRENADE_SCRIPT");
  80.     int bSplash     = GetLocalInt(oGrenade,"GRENADE_SPLASH");
  81.  
  82.     AssignCommand(oPC, DoThrowGrenade(oGrenade, oTarget, lTarget, sScript, bSplash ));
  83.   }
  84. }