home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 April / Gamestar_83_2006-04_dvd.iso / Dema / demowot_english.exe / Script / Source / akcommon.inc < prev    next >
Text File  |  2005-03-11  |  72KB  |  2,498 lines

  1. #if defined _akcommon_inc
  2.     #endinput
  3. #endif
  4. #define _akcommon_inc
  5.  
  6. stock gPlayerTeam = -1;
  7.  
  8. // stock eDebugLevel:gSettingsIniDL = eDebugLevel:-1;        // Ha veletlenul nem olvasnank be kesobb, akkor FORBID
  9. // stock eDebugLevel:gDLOverwrite = eDebugLevel:9999;        // ezzel jelezzuk, hogy invalid
  10. // stock eDebugLevel:gDLOverwriteMin = eDebugLevel:10;
  11. // stock eDebugLevel:gDLOverwriteMax = eDebugLevel:15;
  12.  
  13. stock eDebugLevel:gDL;
  14. stock eDebugLevel:gDLMin = eDebugLevel:10;
  15. stock eDebugLevel:gDLMax = eDebugLevel:15;
  16.  
  17. stock gDebugMessageStyle[50] = "#d#";
  18.  
  19. stock gTigerVal=-1;
  20. stock gPZIIINVal=-1;
  21. stock gShermanVal=-1;
  22. stock gDaimlerIIVal=-1;
  23.  
  24. stock forbidden_grp_num;
  25. stock gForbiddenGroups[10][30];
  26.  
  27.  
  28. //======================================================================================================
  29. stock Abs( Value )
  30. {
  31.     if( Value < 0 )
  32.         return -Value;
  33.     
  34.     return Value;
  35. }
  36.  
  37.  
  38.  
  39.  
  40. //======================================================================================================
  41. stock AddAKEntityEvent( FunctionName[], const DrID:TargetObject, const Event[], Float:Delay = 0.0 )
  42. // A function, which maps the hard to remember ClassName-MessageID pair
  43. // to a simplier EventID. For event names see the macros.inc file.
  44. {
  45.  
  46.     new tmp[255];
  47.     ConcatString(tmp, 255, "", Event);
  48.  
  49.     new ClassName[CLASSNAME_MAXLENGTH];
  50.     new MessageID;
  51.     new Pos;
  52.     
  53.     for( Pos = 0; Event[Pos] != ','; Pos++ )
  54.         ClassName[Pos] = Event[Pos];
  55.  
  56.     MessageID = (Event[Pos+1]-'0')*10 + Event[Pos+2]-'0';
  57.     AddEntityEvent( FunctionName, TargetObject, ClassName, MessageID, Delay );
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. //======================================================================================================
  65. stock AddAKSelectorEvent( FunctionName[], Selector[], const Event[], Float:Delay = 0.0 )
  66. // A function, which maps the hard to remember ClassName-MessageID pair
  67. // to a simplier EventID. For event names see the macros.inc file.
  68. {
  69.     new ClassName[CLASSNAME_MAXLENGTH];
  70.     new MessageID;
  71.     new Pos;
  72.     
  73.     for( Pos = 0; Event[Pos] != ','; Pos++ )
  74.         ClassName[Pos] = Event[Pos];
  75.  
  76.     MessageID = (Event[Pos+1]-'0')*10 + Event[Pos+2]-'0';
  77.     AddSelectorEvent( FunctionName, Selector, ClassName, MessageID, Delay );
  78. }
  79.  
  80.  
  81. //======================================================================================================
  82. stock DrID:AddMapTickToEnt( DrID:Unit, Float:Time, spriteFileName[] = "", entityType[] = "" , toolTip[] = "", Float:heightOffset=0.0)
  83. {
  84.     if(Unit==DrID:0)
  85.     {
  86.         DebugMessage( "akcommon.inc:AddMapTickToEnt: INVALID ENTITY!!!", DL_ERROR );
  87.         return DrID:0;    
  88.     }
  89.     new Float:lTmpVec3[vec3];
  90.     GetPropertyVec3( Unit, "LogicalPos_", lTmpVec3);
  91.     return AddMapTick( lTmpVec3, Time, spriteFileName, entityType, toolTip, heightOffset );
  92. }
  93.  
  94. //======================================================================================================
  95. stock AddRGBA( Float:Vec1[rgba], Float:Vec2[rgba], Float:Sum[rgba] )
  96. {
  97.     Sum[quat:r] = Vec1[quat:r] + Vec2[quat:r];
  98.     Sum[quat:g] = Vec1[quat:g] + Vec2[quat:g];
  99.     Sum[quat:b] = Vec1[quat:b] + Vec2[quat:b];
  100.     Sum[quat:a] = Vec1[quat:a] + Vec2[quat:a];
  101. }
  102.  
  103.  
  104.  
  105.  
  106. //======================================================================================================
  107. stock AddVec2( Float:Vec1[vec2], Float:Vec2[vec2], Float:Sum[vec2] )
  108. {
  109.     Sum[vec3:x] = Vec1[vec3:x] + Vec2[vec3:x];
  110.     Sum[vec3:y] = Vec1[vec3:y] + Vec2[vec3:y];
  111. }
  112.  
  113.  
  114.  
  115.  
  116. //======================================================================================================
  117. stock AddVec3( Float:Vec1[vec3], Float:Vec2[vec3], Float:Sum[vec3] )
  118. {
  119.     Sum[vec3:x] = Vec1[vec3:x] + Vec2[vec3:x];
  120.     Sum[vec3:y] = Vec1[vec3:y] + Vec2[vec3:y];
  121.     Sum[vec3:z] = Vec1[vec3:z] + Vec2[vec3:z];
  122. }
  123.  
  124. stock SubVec3( Float:Vec1[vec3], Float:Vec2[vec3], Float:Diff[vec3] )
  125. {
  126.     Diff[vec3:x] = Vec1[vec3:x] - Vec2[vec3:x];
  127.     Diff[vec3:y] = Vec1[vec3:y] - Vec2[vec3:y];
  128.     Diff[vec3:z] = Vec1[vec3:z] - Vec2[vec3:z];
  129. }
  130.  
  131. stock Float:Vec3Length(Float:vec[vec3])
  132. {
  133.     return sqrt(vec[vec3:x] * vec[vec3:x] + vec[vec3:y] * vec[vec3:y] + vec[vec3:z] * vec[vec3:z]);
  134. }
  135.  
  136. stock NormalizeVec3(Float:vec[vec3])
  137. {
  138.     new Float:l = 1.0 / Vec3Length(vec);
  139.     vec[vec3:x] *= l;
  140.     vec[vec3:y] *= l;
  141.     vec[vec3:z] *= l;
  142. }
  143.  
  144.  
  145.  
  146. //======================================================================================================
  147. stock StopBurning(DrID:SB_Entity)
  148. {
  149.     if(SB_Entity==DrID:0)
  150.     {
  151.         DebugMessage( "StopBurning: DrID:0 asked ...", DL_ERROR );
  152.         return;
  153.     }
  154.     new DrID:FlamComp=GetComponent( SB_Entity, "cFlammability");
  155.     if(FlamComp==DrID:0)
  156.     {
  157.         DebugMessage( "StopBurning: The requested Entity has no Flammability Component", DL_ERROR )
  158.     }
  159.     SetPropertyFloat( FlamComp, "Temperature", 0.0 );
  160. }
  161.  
  162. stock BurnEntity(DrID:BE_Entity)
  163. {
  164.     if(BE_Entity==DrID:0)
  165.     {
  166.         DebugMessage( "BurnEntity: What do you want to burn? DrID:0?", DL_ERROR );
  167.         return;
  168.     }
  169.     new DrID:FireStarter=CreateEntity2Ent("sys_firestarter", BE_Entity);
  170.     SetPropertyInt( FireStarter, "Team", 7 );
  171.     DamageEntity( FireStarter, 100.0, 49 );
  172. }
  173.  
  174. //======================================================================================================
  175. #define CLEAR_HQ_INIT                0
  176. #define CLEAR_HQ_FIND_TARGET        1
  177. #define CLEAR_HQ_STOP                2
  178. stock ClearHQ( Group[], HQ[], TeamToKill, InnerMode = 0, OptParam = 0 ) // Egy idoben csak egy ClearHQ futhat!
  179. {
  180.     static mGroup[200];
  181.     static mHQ[200];
  182.     static mArea[200];
  183.     static mTeam;
  184.     
  185.     switch( InnerMode )
  186.     {
  187.         case CLEAR_HQ_INIT:
  188.         {
  189.             // Beallitjuk kezdoertekeket:
  190.             DebugMessage( "ClearHQ: Initializing.", DL_MESSAGE );
  191.             ConcatString( mGroup, 199, Group, "" );
  192.             ConcatString( mHQ, 199, HQ, "" );
  193.             mTeam = TeamToKill;
  194.  
  195.             // HQ-hoz csinalunk areat jol
  196.             new Float:Pos[vec3];
  197.             GetPropertyVec3( GetEntity( mHQ ), "LogicalPos_", Pos );
  198.             
  199.             new DrID:Area = CreateEntity( "sys_circlearea", Pos );
  200.             GetPropertyString( Area, "StringID", 199, mArea );
  201.             
  202.             SetPropertyFloat( Area, "Radius", GetPropertyFloat( GetEntity( mHQ ), "Radius" ));
  203.             SetPropertyInt( Area, "Team", mTeam );
  204.             SetPropertyBool( GetEntity( mArea ) , "IncludeBuildingMountedSoldiers", false );
  205.  
  206.             RefreshArea( Area );
  207.             if( IsDebugLevelOK( DL_MESSAGE ))
  208.                 Test_ListEntitiesInSelector( mArea );
  209.                         
  210.              ClearHQ( "", "", 0, CLEAR_HQ_FIND_TARGET );
  211.         }
  212.         case CLEAR_HQ_FIND_TARGET:
  213.         {
  214.             DebugMessage( "ClearHQ: Searching for target...", DL_MESSAGE );
  215.             RemoveEvent( "ClearHQ_QueueEmpty" );
  216.  
  217.             new DrID:Target = GetFirstLivingUnit( mArea );
  218.             if( Target ) // Ha van meg celpont.
  219.             {
  220.                 CmdGroupAttack( mGroup, Q_OVERRIDE, Target, AF_FORCE );
  221. //                AddAKEntityEvent( "ClearHQ_QueueEmpty", ANY_ENTITY, UNIT_DIED );
  222.                 AddAKSelectorEvent( "ClearHQ_QueueEmpty", mArea, UNIT_DIED );
  223.                 DebugMessage( "ClearHQ: Target Found.", DL_MESSAGE );
  224.             }
  225.             else // Mar nincs unit.
  226.             {
  227.                 DebugMessage( "ClearHQ: There are no unmounted units in the area.", DL_MESSAGE );
  228.                 if( GetPropertyBool( GetEntity( mArea ), "IncludeBuildingMountedSoldiers" )) // Ha mar epuleteket is neztunk, akkor vege
  229.                 {
  230.                     DebugMessage( "ClearHQ: Job's done.", DL_MESSAGE );
  231.                 }
  232.                 else // Nezzunk epuleteket is
  233.                 {
  234.                     DebugMessage( "ClearHQ: Let's see, who is hiding there...", DL_MESSAGE );
  235.                     SetPropertyBool( GetEntity( mArea ) , "IncludeBuildingMountedSoldiers", true );
  236.                     ClearHQ( "", "", 0, CLEAR_HQ_FIND_TARGET );
  237.                 }
  238.             }
  239.         } // Find target
  240.         case CLEAR_HQ_STOP:
  241.         {
  242.             RemoveEvent( "ClearHQ_QueueEmpty" );
  243.             
  244.             DebugMessage( "ClearHQ: Stopped.", DL_MESSAGE );
  245.  
  246.             DeActivateEntity( GetEntity( mArea ));
  247.  
  248.             if( OptParam )
  249.                 CmdGroupStop( mGroup, Q_OVERRIDE );
  250.         }
  251.     }
  252. }
  253.  
  254. public ClearHQ_QueueEmpty( DrID:Sender )
  255. {
  256.     DebugMessage( "ClearHQ_QueueEmpty: somebody died.", DL_MESSAGE );
  257.     ClearHQ( "", "", 0, CLEAR_HQ_FIND_TARGET );
  258. }
  259.     
  260. stock ClearHQ_Stop( bool:StopCommand = true )
  261. {
  262.     DebugMessage( "ClearHQ_Stop.", DL_MESSAGE );
  263.     ClearHQ( "", "", 0, CLEAR_HQ_STOP, _:StopCommand );
  264. }
  265.  
  266.  
  267.  
  268.  
  269. //======================================================================================================
  270. stock CmdMoveToEnt( DrID:Unit, DrID:TargetEntity, eQueuing:Queuing = Q_OVERRIDE, eMoveFlag:flags = MF_NONE, Float:Reach = 0.0)
  271. {
  272.     new Float:TmpVec3[vec3];
  273.  
  274.     GetPropertyVec3( TargetEntity, "LogicalPos_", TmpVec3 );
  275.     CmdMove( Unit, Queuing, TmpVec3, flags, Reach);
  276. }
  277.  
  278.  
  279.  
  280.  
  281.  
  282. //======================================================================================================
  283. stock CmdGroupMoveToEnt( Selector[], DrID:TargetEntity, eQueuing:Queuing = Q_OVERRIDE, eMoveFlag:flags = MF_NONE, Float:Distance=0.0)
  284. {
  285.     new Float:TmpVec3[vec3];
  286.  
  287.     GetPropertyVec3(  TargetEntity , "LogicalPos_", TmpVec3 );
  288.     CmdGroupMove( Selector, Queuing, TmpVec3, flags, Distance );
  289. }
  290.  
  291.  
  292.  
  293.  
  294. //======================================================================================================
  295. stock CmdGroupRandomWait( Group[], Float:RandomMax, eQueuing:Queuing )
  296. {
  297.     new Iterator:i = Iterate( Group ); 
  298.     
  299.     while( ItNext( i )) 
  300.         CmdWait( ItEntity( i ), Queuing, FloatRnd( 0.0, RandomMax )); 
  301.     
  302.     ItStop( i );
  303. }
  304.  
  305.  
  306.  
  307.  
  308.  
  309. //======================================================================================================
  310. stock CmdGroupTurnToEnt( Selector[], DrID:TargetEntity, eQueuing:Queuing = Q_OVERRIDE, flags = TF_NONE )
  311. {
  312.     new Float:TmpVec3[vec3];
  313.  
  314.     GetPropertyVec3(  TargetEntity , "LogicalPos_", TmpVec3 );
  315.     CmdGroupTurnToPos( Selector, Queuing, TmpVec3, flags );
  316. }
  317.  
  318.  
  319.  
  320.  
  321. //======================================================================================================
  322. stock CmdTurnToEnt( DrID:Unit, DrID:TargetEntity, eQueuing:Queuing = Q_OVERRIDE, flags = TF_NONE )
  323. {
  324.     new Float:TmpVec3[vec3];
  325.  
  326.     GetPropertyVec3(  TargetEntity , "LogicalPos_", TmpVec3 );
  327.     CmdTurnToPos( Unit, Queuing, TmpVec3, flags );
  328. }
  329.  
  330. stock CmdTurnWpToEnt( DrID:Unit, DrID:TargetEntity, eQueuing:Queuing = Q_OVERRIDE )
  331. {
  332.     new Float:TmpVec3[vec3];
  333.  
  334.     GetPropertyVec3(  TargetEntity , "LogicalPos_", TmpVec3 );
  335.     CmdTurnWpToPos( Unit, Queuing, TmpVec3);
  336. }
  337.  
  338.  
  339.  
  340. //======================================================================================================
  341. stock CommonAKMain() // Ide kerulnek olyan altalanos dolgok, amik jo esellyel minden palyara kellenek.
  342. {
  343. //    gSettingsIniDL = eDebugLevel:floatround( GetNumberSetting( "script", "debuglevel" ));
  344.     gDL = eDebugLevel:floatround( GetNumberSetting( "script", "debuglevel" ));
  345.     
  346.     DebugMessage( "CommonAKMain started...", DL_MESSAGE );
  347.  
  348.     // Common things executed after game start
  349.     AddAKEntityEvent( "PostGameStart", GetEntity( "World"), POSTGAMESTART );
  350.     DebugMessage( "    Event 'POSTGAMESTART' added -> function 'PostGameStart'.", DL_MESSAGE );
  351.     
  352.     
  353.     if( eDebugLevel:floatround( GetNumberSetting( "script", "debuglevel" )) != DL_FORBID ) {
  354.         AddAKEntityEvent( "IterateDebugLevels", ANY_ENTITY, DEBUG_EVENT );
  355.         DebugMessage( "    DebugLevel != -1 => Event 'DEBUG_EVENT' added -> funciton 'IterateDebugLevels'.", DL_MESSAGE );
  356.     }
  357.     DebugMessage( "CommonAKMain executed.", DL_MESSAGE );
  358. }
  359.  
  360.  
  361.  
  362. //======================================================================================================
  363. stock CommonAKInit()
  364. {
  365.     DebugMessage( "CommonAKInit started...", DL_MESSAGE );
  366.     gPlayerTeam = GetPropertyInt( GetWorld(), "PlayerTeam" );
  367.     gShermanVal=GetPropertyInt( GetBaseComponentBase( GetEntityBase( "al_M4 Sherman" ), "cManagementBase"), "Value" );
  368.     gTigerVal=GetPropertyInt( GetBaseComponentBase( GetEntityBase( "ax_Tiger" ), "cManagementBase"), "Value" );
  369.     gPZIIINVal=GetPropertyInt( GetBaseComponentBase( GetEntityBase( "ax_PzIIIN" ), "cManagementBase"), "Value" );
  370.     gDaimlerIIVal=GetPropertyInt( GetBaseComponentBase( GetEntityBase( "al_DaimlerII" ), "cManagementBase"), "Value" );
  371.     DebugMessage( "CommonAKInit executed.", DL_MESSAGE );
  372. }
  373.  
  374. //======================================================================================================
  375.  
  376. //======================================================================================================
  377. stock CopyRGBA( Float:Source[rgba], Float:Dest[rgba] )
  378. {
  379.     Dest[rgba:r] = Source[rgba:r];
  380.     Dest[rgba:g] = Source[rgba:g];
  381.     Dest[rgba:b] = Source[rgba:b];
  382.     Dest[rgba:a] = Source[rgba:a];
  383. }
  384.  
  385.  
  386.  
  387.  
  388. //======================================================================================================
  389. stock CopyVec2( Float:Source[vec2], Float:Dest[vec2] )
  390. {
  391.     Dest[vec2:x] = Source[vec2:x];
  392.     Dest[vec2:y] = Source[vec2:y];
  393. }
  394.  
  395.  
  396.  
  397.  
  398. //======================================================================================================
  399. stock CopyVec3( Float:Source[vec3], Float:Dest[vec3] )
  400. {
  401.     Dest[vec3:x] = Source[vec3:x];
  402.     Dest[vec3:y] = Source[vec3:y];
  403.     Dest[vec3:z] = Source[vec3:z];
  404. }
  405.  
  406.  
  407.  
  408.  
  409. //======================================================================================================    
  410. stock CountLiving( DrID:... ) // Megszamolja, hany el a felsorolt unitok kozul
  411. {
  412.     new Counter = 0;
  413.  
  414.     for( new i = 0; i < numargs(); i++ )
  415.         if( IsAlive(DrID:getarg(i)))
  416.             Counter++;
  417.         
  418.     return Counter;
  419. }
  420.  
  421.  
  422.  
  423.  
  424. //======================================================================================================
  425. stock CountEntitiesInSelector( Selector[] , const ClassType[] = "cAKEntity" ) // Megszamlalja, a szelektornak hany eleme van.
  426. {
  427.     new NoOfEntities = 0;
  428.     
  429.     new Iterator:i = Iterate( Selector , ClassType);
  430.     while( ItNext(i))
  431.         NoOfEntities++;
  432.  
  433.     ItStop(i);    
  434.  
  435.     return NoOfEntities;
  436. }
  437.  
  438.  
  439.  
  440.  
  441. //======================================================================================================
  442. stock CountInCircleArea( Selector[], DrID:CircleArea  , const ClassType[] = "cAKEntity")
  443. {
  444.     new Counter = 0;
  445.     new Float:Radius = GetPropertyFloat( CircleArea, "Radius" );
  446.     
  447.     new Iterator:i = Iterate( Selector , ClassType );
  448.     while( ItNext(i))
  449.         if( DistanceAKe2e( ItEntity(i), CircleArea ) < Radius )
  450.             Counter++;
  451.     
  452.     ItStop(i);
  453.     
  454.     return Counter;
  455. }
  456.  
  457.  
  458.  
  459.  
  460. //======================================================================================================
  461. stock CountLivingMatesCircle( Selector[], Team, DrID:CircleArea ) // Count living mates in circle area
  462. // Ha lehet, hasznalj helyette CountLivingInSelector-t, mert az gyorsabb
  463. {
  464.     new Counter = 0;
  465.     new DrID:Unit;
  466.     new Float:Radius = GetPropertyFloat( CircleArea, "Radius" );
  467.     
  468.     new Iterator:i = Iterate( Selector );
  469.     while( ItNext(i)) {
  470.         Unit = ItEntity(i);
  471.         if(    
  472.             IsAlive(Unit) &&
  473.             GetPropertyInt( Unit, "Team" ) == Team &&
  474.             IsEntityActive( Unit )
  475.         ) {
  476.             if( DistanceAKe2e( Unit, CircleArea ) < Radius )
  477.                 Counter++;
  478.         }
  479.     }
  480.     
  481.     ItStop(i);
  482.     
  483.     return Counter;
  484. }
  485.  
  486.  
  487.  
  488.  
  489. //======================================================================================================
  490. stock CountLivingInSelector( Selector[] ) // Counts living and active entities in selector
  491. {
  492.     new NoOfLivingActive = 0;
  493.     
  494.     new Iterator:i = Iterate( Selector );
  495.     while( ItNext(i))
  496.     {
  497.         new DrID:Entity = ItEntity(i)
  498.         if( IsAlive( Entity) && IsEntityActive( Entity))
  499.             NoOfLivingActive++;            
  500.     }
  501.     ItStop(i);
  502.     
  503.     return NoOfLivingActive;
  504. }
  505.  
  506. //======================================================================================================
  507. stock CountLivingIn2Selector( Selector1[], Selector2[] ) // Counts living and active entities in the intersection
  508. {
  509.     new NoOfLivingActive = 0;
  510.     
  511.     new Iterator:i = Iterate( Selector1 );
  512.     while( ItNext(i))
  513.     {    
  514.         new DrID:Entity = ItEntity(i);
  515.         if( IsAlive( Entity ) && IsEntityActive( Entity) && IsInSelector( Entity, Selector2 ))
  516.             NoOfLivingActive++;            
  517.     }
  518.     ItStop(i);
  519.     
  520.     return NoOfLivingActive;
  521. }
  522.  
  523.  
  524.  
  525. //======================================================================================================
  526. stock CountLivingMates( Selector[], Team )
  527. {
  528.     new Counter = 0;
  529.     new DrID:Unit;
  530.     
  531.     new Iterator:i = Iterate( Selector );
  532.     while( ItNext(i)) {
  533.         Unit = ItEntity(i);
  534.         if(    
  535.             IsAlive(Unit)&&
  536.             GetPropertyInt( Unit, "Team" ) == Team &&
  537.             IsEntityActive( Unit )
  538.         )
  539.             Counter++;
  540.     }
  541.  
  542.     ItStop(i);
  543.     
  544.     return Counter;
  545. }
  546.  
  547. //======================================================================================================
  548. stock DrID:CreateEntity2Ent(Base[], DrID:Entity, bool:UseDir=true, Float:ReqDir=90.0)
  549. {
  550. //native DrID:CreateEntity( const Base[], Float:Pos[vec3], Float:dir = 90.0 );
  551.     if(Entity==DrID:0)
  552.     {
  553.         DebugMessage( "CreateEntity2Ent: Invalid Entity requested!", DL_ERROR );
  554.         return DrID:0;        
  555.     }
  556.     new Float:Pos[vec3];
  557.     GetPropertyVec3( Entity, "LogicalPos_", Pos );
  558.     new Float:EntDir
  559.     if(UseDir)
  560.     {
  561.         EntDir=GetEntityDir( Entity, DB_X_AXIS );
  562.     }
  563.     else
  564.     {
  565.         EntDir=ReqDir;
  566.     }
  567.     new DrID:NewEntity=CreateEntity( Base, Pos, EntDir );
  568.     if(NewEntity==DrID:0)
  569.     {
  570.         DebugMessage( "CreateEntity2Ent: Entity creation FAILED!", DL_ERROR );
  571.     }
  572.     return NewEntity;
  573. }
  574.  
  575.  
  576. //======================================================================================================
  577. stock CropString(StringToCrop[],StartPos,EndPos)
  578. {
  579.     EndPos++;
  580.     if(StartPos > strlen(StringToCrop) || EndPos > strlen(StringToCrop) || StartPos < 0 || EndPos < 0)
  581.     {
  582.         DebugMessage( "akcommon.inc:CropString:One of the positions is out of String", DL_ERROR );
  583.         if(StartPos > strlen(StringToCrop))
  584.             StartPos = strlen(StringToCrop);
  585.         if(EndPos > strlen(StringToCrop))
  586.             EndPos = strlen(StringToCrop);
  587.         if(StartPos < 0)
  588.             StartPos = 0;
  589.         if(EndPos < 0)
  590.             EndPos = 0;
  591.         DebugMessage( "akcommon.inc:CropString:MODIFIED TO CORRECT VALUE!", DL_ERROR );        
  592.     }
  593.     if(StartPos >EndPos)
  594.     {
  595.         DebugMessage( "akcommon.inc:CropString:Starting Position is after End Position!", DL_ERROR );
  596.         return false;
  597.     }
  598.     StringToCrop[EndPos]=0;
  599.     ConcatString( StringToCrop, 100, StringToCrop[StartPos], "" );
  600.     return true;
  601. }
  602.  
  603. stock DiffVec3(Float:DV3Source[vec3],Float:DV3Target[vec3],Float:DV3Difference[vec3])
  604. {
  605.     DV3Difference[vec3:x]=DV3Target[vec3:x]-DV3Source[vec3:x];
  606.     DV3Difference[vec3:y]=DV3Target[vec3:y]-DV3Source[vec3:y];
  607.     DV3Difference[vec3:z]=DV3Target[vec3:z]-DV3Source[vec3:z];
  608. }
  609.  
  610. //======================================================================================================
  611. stock DebugMessage( Message[], eDebugLevel:Level = DL_MESSAGE  )
  612. {
  613.     if( IsDebugLevelOK( Level ) ) {
  614.         
  615.         // Determine if print to viewport is needed:
  616.         new PrintToViewport = false;
  617.     
  618.         if( gDL >= eDebugLevel:10 )
  619.             PrintToViewport = true;
  620.  
  621.         new tmpMessage[301];
  622.         ConcatString( tmpMessage, 300, gDebugMessageStyle, Message );
  623.         switch( Level ) {
  624.             case DL_CRITICAL:     ConcatString( tmpMessage, 300, "#cred#CRITICAL ERROR: ", tmpMessage );
  625.             case DL_ERROR:         ConcatString( tmpMessage, 300, "#cred#ERROR: ", tmpMessage );
  626.             case DL_WARNING:    ConcatString( tmpMessage, 300, "#cyellow#WARNING: ", tmpMessage );
  627.             case DL_MESSAGE:    ConcatString( tmpMessage, 300, "DEBUG INFO: ", tmpMessage );
  628.             case DL_BEHAVIOR:    ConcatString( tmpMessage, 300, "#cyellow#BEHAVIOR: ", tmpMessage );
  629.         }
  630.  
  631.         // Output the message:
  632.         Log( tmpMessage, "proglog\\scriptlog" );
  633.         if( PrintToViewport )
  634.             ShowShortMessage( tmpMessage );
  635.     }
  636. }
  637.  
  638.  
  639.  
  640.  
  641. //======================================================================================================    
  642. stock DebugMessageP1( Message[], Param, eDebugLevel:Level)
  643. {
  644.     if( IsDebugLevelOK( Level )) {
  645.         new tmpstr[301];
  646.         Int2Str( Param, tmpstr, 300 );
  647.         ConcatString( tmpstr, 300, Message, tmpstr );    
  648.         DebugMessage( tmpstr, Level );
  649.     }
  650. }
  651.  
  652.  
  653.  
  654.  
  655.  
  656. //======================================================================================================    
  657. stock Float:DegToRad( Float:Value )
  658.     return (Value * PI / 180);
  659.     
  660.  
  661.  
  662.  
  663. //======================================================================================================
  664. stock Float:DistanceAKe2e( DrID:Entity1, DrID:Entity2 )
  665. {
  666.     new Float:Pos1[vec3];
  667.     new Float:Pos2[vec3];
  668.     
  669.     GetPropertyVec3( Entity1, "LogicalPos_", Pos1 );
  670.     GetPropertyVec3( Entity2, "LogicalPos_", Pos2 );
  671.     Pos1[vec3:z] = Pos2[vec3:z] = 0.0;
  672.     
  673.     return Distance( Pos1, Pos2 );
  674. }
  675.  
  676.  
  677.  
  678.  
  679. //======================================================================================================
  680. stock Float:DistanceAKe2p( DrID:Entity, Float:Pos1[vec3] )
  681. {
  682.     new Float:Pos2[vec3];
  683.  
  684.     GetPropertyVec3( Entity, "LogicalPos_", Pos2 );
  685.     Pos1[vec3:z] = Pos2[vec3:z] = 0.0;
  686.  
  687.     return Distance( Pos1, Pos2 );
  688. }
  689.  
  690.  
  691.  
  692.  
  693. //======================================================================================================
  694. stock Float:DistanceAKp2p( Float:Pos1[vec3], Float:Pos2[vec3] ) // Int tavolsagot ad vissza, z koordinatat figyelmen kivul hagyja
  695. {
  696.     Pos1[vec3:z] = Pos2[vec3:z] = 0.0;
  697.     return Distance( Pos1, Pos2 );
  698. }
  699.  
  700. //======================================================================================================
  701. //returns true if the unit can phisically see an other unit from the queried selector
  702. stock bool:DoesSeeSelector(DrID:UndWho, UndSelector[])
  703. {
  704.     if(UndWho==DrID:0)
  705.     {
  706.         DebugMessage( "DoesSeeEnemy: Invalid DrID!", DL_ERROR )
  707.         return false;
  708.     }
  709.     if(!IsAlive(UndWho))
  710.     {
  711.         DebugMessage( "DoesSeeEnemy: Queried DrID is DEAD!", DL_ERROR )
  712.         return false;
  713.     }        
  714.     new Float:lTmpFloat=GetPropertyFloat( UndWho, "FOWRangeInnerRadius" );
  715.     new DrID:lTmpDrID=GetNearestEntity(UndWho,UndSelector, true, GetClassID( "cUnit" ), false);
  716.     if(lTmpDrID==DrID:0)
  717.     {
  718.         DebugMessage( "DoesSeeEnemy: No living unit in the queried selector!", DL_ERROR )
  719.         return false;
  720.     }        
  721.     //ha a tav a legkozelebbi enemy es kozte <= FOWRange belso kore akkor true
  722.      return(DistanceAKe2e( UndWho, lTmpDrID )<=lTmpFloat);
  723. }
  724.  
  725. stock DropPara2Ent(Team, setupID[], DrID:DP2E_Entity, flags)
  726. {
  727.     new Float:DP2E_Vec3[vec3];
  728.     if(DP2E_Entity!=DrID:0)
  729.     {
  730.         GetPropertyVec3( DP2E_Entity, "LogicalPos_", DP2E_Vec3 );
  731.     }
  732.     else
  733.     {
  734.         return;
  735.     }
  736.     DropParatroopers(Team, setupID, DP2E_Vec3, flags);    
  737. }
  738.  
  739. //======================================================================================================
  740. stock Float:FloatAbs( Float:Value )
  741. {
  742.     if( Value < 0.0 )
  743.         return -Value;
  744.     
  745.     return Value;
  746. }
  747.  
  748.  
  749.  
  750.  
  751. //======================================================================================================
  752. stock Float:FloatClamp( Float:Value, Float:Min, Float:Max )
  753. {
  754.     if( Max < Min )
  755.         DebugMessage( "Warning:akcommon.inc:FloatClamp: Max < Min!", DL_WARNING );
  756.         
  757.     if( Value < Min )
  758.         Value = Min;
  759.     else if( Value > Max )
  760.         Value = Max;
  761.     
  762.     return Value;
  763. }
  764.  
  765.  
  766.  
  767.  
  768. //======================================================================================================
  769. stock Float:FloatRnd( Float:Min, Float:Max )
  770. {
  771.     if( Max < Min )
  772.         DebugMessage( "Warning:akcommon.inc:FloatRnd: Max < Min!", DL_WARNING );
  773.  
  774.     return Min + ( Max - Min ) * float( Rnd( 0, 32768 )) / 32768;
  775. }
  776.  
  777. //======================================================================================================
  778. stock FillWithCrew(DrID:FWFC_Ent, FWFC_Team=1, FWFC_LeaveEmpty=0)
  779. {
  780. //     if(FWFC_Ent==DrID:0
  781. //     ||!(IsInstanceOf( FWFC_Ent, GetClassID( "cVehicle" ))
  782. //      || IsInstanceOf( FWFC_Ent, GetClassID( "cVehicle" ))))
  783. //     {
  784. //         return;    
  785. //     }
  786.     new DrID:FWFC_MPoint = GetComponent(FWFC_Ent, "cMountPoint");
  787.     if(FWFC_MPoint==DrID:0)
  788.     {
  789.         DebugMessage( "FillWithCrew: The requested Entity is not mountable!", DL_WARNING );
  790.         return;
  791.     }
  792.      new FWFC_ciklus;
  793.      new FWFC_MP_Max=GetPropArrayLength(FWFC_MPoint, "MountPositions");
  794.      FWFC_MP_Max-=FWFC_LeaveEmpty;
  795.      new FWFC_MP_Act=GetPropArrayLength(FWFC_MPoint, "Mounted");
  796.     new DrID:FWFC_2BMounted;
  797.     new FWFC_Soldat[66];
  798.     new Float:FWFC_Loc[vec3];
  799.     GetPropertyVec3( FWFC_Ent, "LogicalPos_", FWFC_Loc )
  800.     if(FWFC_MP_Act>=FWFC_MP_Max)
  801.     {
  802.         DebugMessage( "FillWithCrew: The requested Entity already full!", DL_WARNING );
  803.         return;
  804.     }
  805.     for (FWFC_ciklus=FWFC_MP_Act;FWFC_ciklus<FWFC_MP_Max;FWFC_ciklus++)
  806.     {
  807.         switch(FWFC_Team)
  808.         {
  809.             case 1:
  810.             {
  811.                 FWFC_Soldat="ax_rifleman";                
  812.             }
  813.             default:
  814.             {
  815.                 FWFC_Soldat="al_rifleman";            
  816.             }
  817.         }
  818.         FWFC_2BMounted=CreateEntity( FWFC_Soldat, FWFC_Loc );
  819.         SetPropertyInt( FWFC_2BMounted, "Team", FWFC_Team );
  820.         CmdMount( FWFC_2BMounted, Q_OVERRIDE, FWFC_Ent,MTF_TELEPORT );
  821.     }
  822. }
  823.  
  824.  
  825.  
  826. //======================================================================================================
  827. stock FillSelectorWithCrew( Selector[], FWFC_Team=1, FWFC_LeaveEmpty=0 )
  828. {
  829.     new Iterator:i = Iterate( Selector );
  830.     while( ItNext( i ))
  831.         FillWithCrew( ItEntity( i ), FWFC_Team, FWFC_LeaveEmpty );
  832.     ItStop( i );
  833. }
  834.  
  835.  
  836.  
  837.  
  838. //======================================================================================================
  839. stock FixZ( Group[] )
  840. {
  841.     new Iterator:i = Iterate( Group );
  842.     new DrID:Entity;
  843.     new Float:Coord[vec3];
  844.  
  845.     while( ItNext( i ))
  846.     {
  847.         Entity = ItEntity( i );
  848.         GetPropertyVec3( Entity, "LogicalPos_", Coord );
  849.  
  850.         Coord[vec3:z] = 0.0;
  851.  
  852.         SetPropertyVec3( Entity, "Pos", Coord );
  853.         SetPropertyFloat( Entity, "RelativeZ", 0.0 );
  854.         SetPropertyVec3( Entity, "Pos", Coord );
  855.         SetPropertyFloat( Entity, "RelativeZ", 0.0 );
  856.     }
  857. }
  858.  
  859.  
  860.  
  861.  
  862.  
  863. //======================================================================================================
  864. stock FormationMoveToEnt(DasGroup[],DrID:DasTarget,eQueuing:DasQju = Q_OVERRIDE, eMoveFlag:DasFlag = MF_NONE)
  865. {
  866. /*    //ha nem DIRECT MOVE-al kell neked akkor ezt hasznald:
  867.     CmdGroupMoveToEnt(DasGroup, DasTarget, DasQju, DasFlag | _:MF_KEEP_FORMATION);
  868. */    new Float:lTmpVec3[vec3];
  869.     GetPropertyVec3( DasTarget, "LogicalPos_", lTmpVec3 );
  870.     FormationMoveToPos(DasGroup,lTmpVec3,DasQju, DasFlag);
  871. }
  872.  
  873. stock FormationMoveToPos(DasGroup[],Float:DasPositzion[vec3],eQueuing:DasQju = Q_OVERRIDE, eMoveFlag:DasFlag = MF_NONE)
  874. {
  875. /*    ha nem DIRECT MOVE-al kell neked akkor ezt hasznald:
  876.         CmdGroupMove(DasGroup, DasQju, DasPositzion, DasFlag | _:MF_KEEP_FORMATION);
  877. */    
  878.     new Float:FMTPMiddle[vec3];
  879.     new Float:FMTPActPos[vec3];
  880.     new Float:FMTPDestPos[vec3];
  881.     new Float:FMTPDiff[vec3];
  882.     new Iterator:FMTPiti=Iterate(DasGroup);
  883.  
  884.     GetMiddleOfGroup(DasGroup, FMTPMiddle);
  885.     DiffVec3(FMTPMiddle,DasPositzion,FMTPDiff);
  886.     while(ItNext(FMTPiti))
  887.     {
  888.         if(IsInstanceOf( ItEntity(FMTPiti), GetClassID( "cUnit" )))
  889.         {
  890.             GetPropertyVec3( ItEntity(FMTPiti), "LogicalPos_", FMTPActPos );
  891.             AddVec3( FMTPActPos, FMTPDiff, FMTPDestPos );
  892.             if(!IsMounted( ItEntity(FMTPiti )))
  893.             {
  894.                 CmdMove( ItEntity(FMTPiti), DasQju, FMTPDestPos, DasFlag );    
  895.             }
  896.         }
  897.     }
  898.     ItStop(FMTPiti);
  899. }
  900.  
  901. stock DrID:GetBaseComponentBase(DrID:EntityBase, GeneKibaszottLusta[])
  902. {
  903.     new ComponentSzam=GetPropArrayLength(EntityBase, "ComponentBases");
  904.     new DrID:ImuleIsLusta;
  905.     new ciklus;
  906.     for(ciklus=0;ciklus<ComponentSzam;ciklus++)
  907.     {
  908.         ImuleIsLusta=GetArrayElement(EntityBase, "ComponentBases", ciklus);
  909.         if(IsInstanceOf(ImuleIsLusta, GetClassID( GeneKibaszottLusta )))
  910.         {
  911.             return ImuleIsLusta;
  912.         }    
  913.     }
  914.     return DrID:0;
  915. }
  916.  
  917.  
  918. //======================================================================================================
  919. stock DrID:GetFirstEntity( Selector[] )
  920. {    
  921.     new DrID:Entity = DrID:0;
  922.     
  923.     new Iterator:i = Iterate( Selector );
  924.     if( ItNext(i)) 
  925.         Entity = ItEntity(i);
  926.  
  927.     ItStop(i);
  928.     return Entity;
  929. }
  930.  
  931.     
  932.  
  933.  
  934.  
  935. //======================================================================================================
  936. stock DrID:GetFirstLivingUnit( Selector[] )
  937. {    
  938.     new DrID:Unit = DrID:0;
  939.     
  940.     new Iterator:i = Iterate( Selector );
  941.     while( ItNext(i)) {
  942.         if( IsAlive( ItEntity(i))) {
  943.             Unit = ItEntity(i);
  944.             ItStop(i);
  945.             break;
  946.         }
  947.     }
  948.  
  949.     return Unit;
  950. }
  951.  
  952.  
  953.  
  954.  
  955. //======================================================================================================
  956. stock GetIncrementFloat( Float:Value1, Float:Value2, Float:Duration, Float:TimeSlice )
  957.     return (Value2 - Value1) * TimeSlice / Duration;
  958.  
  959.  
  960.  
  961.  
  962. //======================================================================================================
  963. stock GetIncrementRGBA( Float:Color1[rgba], Float:Color2[rgba], Float:Result[rgba], Float:Duration, Float:TimeSlice )
  964. {
  965.     new Float:Ratio = TimeSlice / Duration;
  966.  
  967.     Result[rgba:r] = Ratio * ( Color2[rgba:r] - Color1[rgba:r] );
  968.     Result[rgba:g] = Ratio * ( Color2[rgba:g] - Color1[rgba:g] );
  969.     Result[rgba:b] = Ratio * ( Color2[rgba:b] - Color1[rgba:b] );
  970.     Result[rgba:a] = Ratio * ( Color2[rgba:a] - Color1[rgba:a] );
  971. }
  972.  
  973.  
  974.  
  975.  
  976. //======================================================================================================
  977. stock GetIncrementVec3( Float:Vec1[vec3], Float:Vec2[vec3], Float:Result[vec3], Float:Duration, Float:TimeSlice )
  978. {
  979.     new Float:Ratio = TimeSlice / Duration;
  980.  
  981.     Result[vec3:x] = Ratio * ( Vec2[vec3:x] - Vec1[vec3:x] );
  982.     Result[vec3:y] = Ratio * ( Vec2[vec3:y] - Vec1[vec3:y] );
  983.     Result[vec3:z] = Ratio * ( Vec2[vec3:z] - Vec1[vec3:z] );
  984. }
  985.  
  986.  
  987.  
  988.  
  989. //======================================================================================================
  990. // Ket float kozott ara'nnyal kiszamitott floatot ad vissza. Ratio: 0.0 - 1.0
  991. stock GetIntermediateFloat( Float:Value1, Float:Value2, Float:Ratio )
  992.     return ( Value1 + (Value2 - Value1) * Ratio );
  993.  
  994.  
  995.  
  996.  
  997. //======================================================================================================
  998. // Ket szin kozott ara'nnyal kiszamitott szint ad vissza: Ratio: 0.0 - 1.0
  999. stock GetIntermediateRGBA( Float:Color1[rgba], Float:Color2[rgba], Float:Result[rgba], Float:Ratio )
  1000. {
  1001.     Result[rgba:r] = Color1[rgba:r] + Ratio * ( Color2[rgba:r] - Color1[rgba:r] );
  1002.     Result[rgba:g] = Color1[rgba:g] + Ratio * ( Color2[rgba:g] - Color1[rgba:g] );
  1003.     Result[rgba:b] = Color1[rgba:b] + Ratio * ( Color2[rgba:b] - Color1[rgba:b] );
  1004.     Result[rgba:a] = Color1[rgba:a] + Ratio * ( Color2[rgba:a] - Color1[rgba:a] );
  1005. }
  1006.  
  1007.  
  1008.  
  1009.  
  1010. //======================================================================================================
  1011. // Ket vektor kozott ara'nnyal kiszamitott vektort ad vissza: Ratio: 0.0 - 1.0
  1012. stock GetIntermediateVec3( Float:Vec1[vec3], Float:Vec2[vec3], Float:Result[vec3], Float:Ratio )
  1013. {
  1014.     Result[vec3:x] = Vec1[vec3:x] + Ratio * ( Vec2[vec3:x] - Vec1[vec3:x] );
  1015.     Result[vec3:y] = Vec1[vec3:y] + Ratio * ( Vec2[vec3:y] - Vec1[vec3:y] );
  1016.     Result[vec3:z] = Vec1[vec3:z] + Ratio * ( Vec2[vec3:z] - Vec1[vec3:z] );
  1017. }
  1018.  
  1019.  
  1020.  
  1021.  
  1022. //======================================================================================================
  1023. stock Float:GetMaxSpeed( DrID:Unit, eMovementStyle:MovementStyle=MS_NONE ) // Untested
  1024. {
  1025.     new DrID:Comp = GetComponent( Unit, "cUnitController" );
  1026.     new DrID:BaseComp = GetComponent( GetBaseEntity( Unit ), "cUnitController" );
  1027.     
  1028.     switch( MovementStyle )
  1029.     {
  1030.         case MS_NONE:
  1031.         {
  1032.             // A kovekezo ket sor teszt celra szolgal:
  1033. //             new eMovementStyle:QueriedMS = eMovementStyle:GetPropertyInt( Comp, "MovementStyle" );
  1034. //             new iQueriedMS = GetPropertyInt( Comp, "MovementStyle" );
  1035.             switch( GetPropertyInt( Comp, "MovementStyle" )) 
  1036.             {
  1037.                 case MS_RUN:
  1038.                     return GetPropertyFloat( BaseComp, "MaxSpeedRun" );
  1039.                 case MS_WALK:
  1040.                     return GetPropertyFloat( BaseComp, "MaxSpeedWalk" );
  1041.                 case MS_CRAWL:
  1042.                     return GetPropertyFloat( BaseComp, "MaxSpeedCrawl" );
  1043.                 default:
  1044.                 { 
  1045.                     DebugMessage( "akcommon.inc:GetMaxSpeed: No movementstyle specified and invalid movementstyle queried!", DL_ERROR );
  1046.                     return -1.0;
  1047.                 }
  1048.             }
  1049.         }
  1050.         case MS_RUN:
  1051.             return GetPropertyFloat( BaseComp, "MaxSpeedRun" );
  1052.         case MS_WALK:
  1053.             return GetPropertyFloat( BaseComp, "MaxSpeedWalk" );
  1054.         case MS_CRAWL:
  1055.             return GetPropertyFloat( BaseComp, "MaxSpeedCrawl" );
  1056.     }
  1057.  
  1058.     // Egyebkent hiba:
  1059.     DebugMessage( "akcommon.inc:GetMaxSpeed:Invalid movementstyle queried!", DL_ERROR );
  1060.     return -1.0;
  1061. }
  1062.  
  1063. //======================================================================================================
  1064. stock DrID:GetNearestEntity(DrID:FromWho, FromSelector[], bool:Alive = true, UnitType[100] = "cAKEntity", bool:CanBeMounted = true,Float:GNEMinRange=0.0,Float:GNEMaxRange=6666.66)
  1065. {
  1066.     if(DrID:FromWho)
  1067.     {
  1068.         if(GetListLen(FromSelector)!=0)
  1069.         {
  1070.             new Float:LowestDistance = GNEMaxRange;
  1071.             new DrID:NearestEntity = DrID:0;
  1072.             new Iterator:i = Iterate(FromSelector, UnitType );
  1073.             new bool:AliveFlag = true;
  1074.             new Float:Dist;
  1075.             new DrID:ZieAktEntity
  1076.             while(ItNext(i))
  1077.             {
  1078.                 Dist=DistanceAKe2e( FromWho, ItEntity(i) );
  1079.                 ZieAktEntity=ItEntity(i);
  1080.                 if(Alive)
  1081.                     AliveFlag = IsAlive( ZieAktEntity ); 
  1082.                 if(
  1083.                    Dist< LowestDistance 
  1084.                 && IsMountedIn(FromWho)!= ZieAktEntity
  1085.                 && FromWho != ZieAktEntity
  1086.                 && AliveFlag 
  1087.                 && Dist > GNEMinRange
  1088.                   )
  1089.                 {
  1090.                     if(CanBeMounted) //if the entity could be mounted then we're done
  1091.                     {
  1092.                         NearestEntity = ZieAktEntity;
  1093.                         LowestDistance = Dist;
  1094.                     }
  1095.                     else //if can't be a mounted unit then we've to check this
  1096.                     {
  1097.                         if(IsMountedIn(ZieAktEntity) == DrID:0) //so this unit isn't mounted
  1098.                         {
  1099.                             NearestEntity = ZieAktEntity;
  1100.                             LowestDistance = Dist;                                    
  1101.                         }
  1102.                     }
  1103.                 }
  1104.             }
  1105.             ItStop(i);
  1106.             if(NearestEntity)
  1107.                 return NearestEntity;
  1108. //             else
  1109. //             {
  1110. //                 DebugMessage( "akcommon.inc:GetNearestEntity:Empty DrID is the query's result!!!!!", DL_ERROR );
  1111. //             }
  1112.         }
  1113. //         else
  1114. //         {
  1115. //             DebugMessage( "akcommon.inc:GetNearestEntity:Invalid Selector queried or no living member!!!!", DL_ERROR );
  1116. //         }
  1117.     }
  1118. //     else
  1119. //     {
  1120. //         DebugMessage( "akcommon.inc:GetNearestEntity:Invalid Entity queried!!!!", DL_ERROR );
  1121. //     }
  1122.  
  1123.     return DrID:0;
  1124. }
  1125.  
  1126. //======================================================================================================
  1127. stock GetMiddleOfGroup(GMOGGroup[],Float:GMOGMiddle[vec3])
  1128. {
  1129.     new Float:lSumVec3[vec3]={0.0,0.0,0.0};
  1130.     new Float:lActVec3[vec3];
  1131.     new lTotalMembs=0;
  1132.     new Iterator:iti=Iterate(GMOGGroup,"cAKEntity");
  1133.     
  1134.     new AkarmiString[255];
  1135.     new PozicioString[255];
  1136.     
  1137.     while(ItNext(iti))
  1138.     {
  1139.         if(ItEntity(iti)!=DrID:0)
  1140.         {
  1141.             GetPropertyString( ItEntity(iti), "StringID", 250, AkarmiString)
  1142.             GetPropertyVec3( ItEntity(iti), "LogicalPos_", lActVec3 );
  1143.             vec32str(PozicioString,lActVec3);
  1144.             lTotalMembs++;
  1145.             AddVec3( lSumVec3, lActVec3, lSumVec3 );
  1146.         }
  1147.     }
  1148.     ItStop(iti);
  1149.     if(lTotalMembs==0)
  1150.         lTotalMembs++;
  1151.     GMOGMiddle[vec3:x]=floatdiv(lSumVec3[vec3:x],float(lTotalMembs));
  1152.     GMOGMiddle[vec3:y]=floatdiv(lSumVec3[vec3:y],float(lTotalMembs));
  1153.     GMOGMiddle[vec3:z]=floatdiv(lSumVec3[vec3:z],float(lTotalMembs));
  1154. }
  1155.  
  1156. //======================================================================================================
  1157. stock DrID:GetSlowestUnitInSelector( Selector[], eMovementStyle:MovementStyle=MS_NONE ) // Untested
  1158. {    
  1159.     new DrID:SlowestUnit;
  1160.     new Float:SlowestSpeed = 10000.0;
  1161.     new Float:ActualSpeed;
  1162.     
  1163.     // Count Entities:
  1164.     new NoOfEntities = CountEntitiesInSelector( Selector );
  1165.  
  1166.     // Special Cases:
  1167.     if( NoOfEntities == 0)
  1168.         return DrID:0;
  1169.  
  1170.     // Iterations:        
  1171.     new Iterator:i = Iterate( Selector );
  1172.     while( ItNext( i )) {
  1173.         ActualSpeed = GetMaxSpeed( ItEntity( i ), MovementStyle );
  1174.         if( ActualSpeed < SlowestSpeed ) {
  1175.             SlowestUnit = ItEntity( i );
  1176.             SlowestSpeed = ActualSpeed;
  1177.         }
  1178.     }
  1179.     ItStop( i );
  1180.     
  1181.     return SlowestUnit;
  1182. }
  1183. //======================================================================================================
  1184. stock Float:GetSlowestSpeedInGroup( Group[])
  1185. {
  1186.     new Float:SpeedLimit = 10000.0;
  1187.     new Iterator:i = Iterate( Group );
  1188. //     new str[250];
  1189.         
  1190.     while( ItNext(i) )
  1191.     {
  1192.         new Float:ActMaxSpeed;
  1193.         
  1194.         ActMaxSpeed = GetPropertyFloat( GetComponent( ItEntity(i), "cUnitController"), "ActMaxSpeed" );
  1195.         if( ActMaxSpeed < SpeedLimit )
  1196.             SpeedLimit = ActMaxSpeed;
  1197.     }
  1198.     ItStop(i);
  1199.     
  1200.     if( SpeedLimit == 10000.0 ) 
  1201.     {
  1202.         if( IsDebugLevelOK( DL_WARNING ))
  1203.         {    
  1204.             new tmpStr[200];
  1205.             ConcatString( tmpStr, 199, "GetSlowestSpeedInGroup: Return value = 0.0, because group is empty: ", Group );
  1206.             DebugMessage( tmpStr, DL_WARNING );
  1207.         }
  1208.         return 0.0;
  1209.     }
  1210.  
  1211.     // else:
  1212.     return SpeedLimit;
  1213. }
  1214.  
  1215.  
  1216.  
  1217. //======================================================================================================
  1218. stock DrID:GetWorld()
  1219.     return GetEntity( "World" );
  1220.  
  1221.  
  1222.  
  1223.  
  1224. //======================================================================================================
  1225. stock bool:HasSelectorAnyAlive( Selector[], Limit = 1 ) // If selector has any OR! Limit piece of living entities
  1226. {
  1227.     new NoOfLivingActive = 0;
  1228.     
  1229.     new Iterator:i = Iterate( Selector );
  1230.     while( ItNext(i)) {
  1231.         if( IsAlive( ItEntity(i)) && IsEntityActive( ItEntity(i))) {
  1232.             NoOfLivingActive++;
  1233.             if( NoOfLivingActive >= Limit ) {
  1234.                 ItStop(i);
  1235.                 return true;
  1236.             }
  1237.         }
  1238.     }
  1239.  
  1240.     ItStop(i);
  1241.     return false;
  1242. }
  1243.  
  1244.  
  1245. //======================================================================================================
  1246. stock bool:IsEvenNum(LeNumero)
  1247. {
  1248.     return (((LeNumero/2)*2)==LeNumero);
  1249. }
  1250.  
  1251. //======================================================================================================
  1252. stock bool:IsAnyEntityMoving( Selector[] )
  1253. {
  1254.     new bool:IsSomebodyMoving = false;
  1255.     
  1256.     new Iterator:i = Iterate( Selector );
  1257.     while( ItNext(i)) {
  1258.         if( IsMoving( ItEntity(i))) {
  1259.             IsSomebodyMoving = true;
  1260.             ItStop(i);
  1261.             break;
  1262.         }
  1263.     }
  1264.  
  1265.     return IsSomebodyMoving;        
  1266. }
  1267.  
  1268. //======================================================================================================
  1269. stock bool:IsPlayer(DrID:UndWho)
  1270. {
  1271.     if(UndWho!=DrID:0)
  1272.         return (GetPropertyInt( UndWho, "Team" )==gPlayerTeam)
  1273.     return false;
  1274. }
  1275. //======================================================================================================
  1276. stock bool:IsEntityComp(DrID:Entity, Componentname[])
  1277. {
  1278.     if(Entity != DrID:0)
  1279.     {
  1280.         if(GetComponent( Entity, Componentname) != DrID:0)
  1281.             return true;
  1282.         else
  1283.             return false;
  1284.     }
  1285.  
  1286.     DebugMessage( "This DrID is not valid!", DL_ERROR );
  1287.     return false;
  1288. }
  1289. //======================================================================================================
  1290. stock Float:GetActualHealth( DrID:Unit )
  1291. {
  1292.     new DrID:DRComp = DrID:0;
  1293.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1294.         DRComp = GetComponent( Unit, "cDRVehicle");
  1295.     else
  1296.         if(IsInstanceOf( Unit, GetClassID( "cBuilding" )))
  1297.             DRComp = GetComponent( Unit, "cDRBuilding");
  1298.         else
  1299.             DRComp = GetComponent( Unit, "cDRSimple");
  1300.  
  1301.     if(DRComp == DrID:0)
  1302.     {
  1303.         DebugMessage( "akcommon.inc:GetActualHealth: The Unit doesn't have cDRVehicle/cDRBuilding/cDRSimple", DL_BEHAVIOR );
  1304.         return Float:-1.0;
  1305.     }    
  1306.  
  1307.     new DrID:BodyComp = GetPropertyObject( DRComp, "Body")    
  1308.  
  1309.     if(BodyComp == DrID:0)
  1310.     {
  1311.         DebugMessage( "akcommon.inc:IsAlive: The Unit doesn't have Body", DL_BEHAVIOR );
  1312.         return Float:-1.0;
  1313.     }    
  1314.     return Float:(GetPropertyFloat( BodyComp, "HP" ) );
  1315. }
  1316.  
  1317. //======================================================================================================
  1318. stock SetActualHealth( DrID:Unit, Float:Health )
  1319. {
  1320.     new DrID:DRComp = DrID:0;
  1321.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1322.         DRComp = GetComponent( Unit, "cDRVehicle");
  1323.     else
  1324.         if(IsInstanceOf( Unit, GetClassID( "cBuilding" )))
  1325.             DRComp = GetComponent( Unit, "cDRBuilding");
  1326.         else
  1327.             DRComp = GetComponent( Unit, "cDRSimple");
  1328.  
  1329.     if(DRComp == DrID:0)
  1330.     {
  1331.         DebugMessage( "akcommon.inc:GetActualHealth: The Unit doesn't have cDRVehicle/cDRBuilding/cDRSimple", DL_BEHAVIOR );
  1332.         return ;
  1333.     }    
  1334.  
  1335.     new DrID:BodyComp = GetPropertyObject( DRComp, "Body")    
  1336.  
  1337.     if(BodyComp == DrID:0)
  1338.     {
  1339.         DebugMessage( "akcommon.inc:IsAlive: The Unit doesn't have Body", DL_BEHAVIOR );
  1340.         return ;
  1341.     }    
  1342.     SetPropertyFloat( BodyComp, "HP", Health  );
  1343. }
  1344.  
  1345.  
  1346. stock bool:IsAttacking( DrID:Entity )
  1347. {
  1348.     new bool:IsHeAttacking=false;
  1349.     new DrID:WepMana=GetComponent( Entity, "cWeaponManager");
  1350.     if(WepMana==DrID:0)
  1351.     {
  1352.         DebugMessage( "akcommon.inc:IsAttacking: No Weapon Manager Detected.", DL_ERROR );
  1353.         return false;
  1354.     }
  1355.     else
  1356.     {
  1357.         DebugMessage( "akcommon.inc:IsAttacking: Weapon Manager Detected.", DL_BEHAVIOR );        
  1358.     }
  1359.  
  1360.     new WepArraySize= GetPropArrayLength( WepMana, "Weapons");
  1361.     if(WepArraySize==0)
  1362.     {
  1363.         DebugMessage( "akcommon.inc:IsAttacking: No Weapon under Weapon Manager!", DL_ERROR )
  1364.         return false;
  1365.     }
  1366.     else
  1367.     {
  1368.         DebugMessage( "akcommon.inc:IsAttacking: Got Weapon under Weapon Manager!", DL_BEHAVIOR )    
  1369.     }
  1370.     
  1371.     new DrID:AktElement;
  1372.     new Float:lTmpVec3[vec3];
  1373.     new ciklus;
  1374.     for(ciklus=0;ciklus<WepArraySize;ciklus++)
  1375.     {
  1376.         AktElement=GetArrayElement(WepMana, "Weapons", ciklus);
  1377.         if(AktElement!=DrID:0)
  1378.         {
  1379.             if(!(GetPropertyFloat( AktElement, "ReloadingCounter" )==0.0))
  1380.             {
  1381.                 DebugMessage( "IsAttacking: ReloadingCounter was higher than 0.0", DL_MESSAGE )
  1382.             }
  1383.             else
  1384.             {
  1385.                 DebugMessage( "IsAttacking: ReloadingCounter is 0.0", DL_BEHAVIOR )            
  1386.             }
  1387.             GetPropertyVec3( AktElement, "TargetPos", lTmpVec3 );
  1388.             if(!(CompareVec3(lTmpVec3,Float:{0.0,0.0,0.0})||CompareVec3(lTmpVec3,Float:{-1.0,-1.0,-1.0})))
  1389.             {
  1390.                 DebugMessage( "IsAttacking: TargetPos was differ from 0,0,0 or -1,-1,-1", DL_MESSAGE )
  1391.             }
  1392.             else
  1393.             {
  1394.                 DebugMessage( "IsAttacking: TargetPos is 0,0,0 or -1,-1,-1", DL_BEHAVIOR )            
  1395.             }
  1396.             
  1397.             if(!
  1398.                 (    
  1399.                     CompareVec3(lTmpVec3,Float:{0.0,0.0,0.0})
  1400.                     ||
  1401.                     CompareVec3(lTmpVec3,Float:{-1.0,-1.0,-1.0})
  1402.                 )
  1403.                 ||
  1404.                 !(
  1405.                     GetPropertyFloat( AktElement, "ReloadingCounter" )==0.0
  1406.                 )
  1407.               )
  1408.             {
  1409.                 IsHeAttacking=true;
  1410.             }
  1411. //             new lTmpStr[255]
  1412. //             vec32str(lTmpStr, lTmpVec3)
  1413. //             DebugMessage( lTmpStr, DL_MESSAGE );
  1414. //             Float2Str( GetPropertyFloat( AktElement, "ReloadingCounter" ), lTmpStr, 255, "%7.3f" );
  1415. //             DebugMessage( lTmpStr, DL_MESSAGE );
  1416.         }
  1417.     }
  1418.     return IsHeAttacking;
  1419. }
  1420.  
  1421.  
  1422. //======================================================================================================
  1423. stock bool:IsDebugLevelOK( eDebugLevel:DebugLevel )
  1424. {
  1425.     new eDebugLevel:tmpDL = gDL;
  1426.  
  1427.     if( tmpDL >= eDebugLevel:10 )
  1428.         tmpDL -= eDebugLevel:10;
  1429.     
  1430.     if( !DebugLevel || !tmpDL ) // If either of them is 0. For the sake of security.
  1431.         return false;
  1432.         
  1433.     if( DebugLevel <= tmpDL )
  1434.         return true;
  1435.     
  1436.     return false;
  1437. }
  1438.  
  1439.  
  1440.  
  1441. //======================================================================================================
  1442. public IterateDebugLevels( DrID:Sender )
  1443. {
  1444.     // A fuggveny erdekessege, hogy a palyan levo minden entitasban hozza kell adni az event handlert,
  1445.     // hogy meghivodjon. Viszont a valtast csak egyszer kell kiirni a kepernyore.
  1446.     
  1447.     // Leptetes:
  1448.     if( gDL != DL_FORBID ) // csak akkor leptetunk, ha nem tilos
  1449.     {
  1450.         gDL++;
  1451.         
  1452.         if( gDL < eDebugLevel:10 ) // mindenkeppen bekapcsoljuk a kepernyore irast
  1453.             gDL += eDebugLevel:10;
  1454.     }
  1455.         
  1456.     if( gDL > gDLMax )
  1457.         gDL = gDLMin;
  1458.         
  1459.     // Kiiras:
  1460.     new tmpMessage[200];
  1461.     Int2Str( gDL, tmpMessage, 10 );
  1462.     ConcatString( tmpMessage, 200, "#cred#>>>#d##cyellow#DebugLevel changed to ", tmpMessage );    
  1463.     switch( gDL - eDebugLevel:10 ) {
  1464.         case DL_OFF:        ConcatString( tmpMessage, 200, tmpMessage, " :     No debug messages." );
  1465.         case DL_CRITICAL:    ConcatString( tmpMessage, 200, tmpMessage, " : Critical Errors. (Press CTRL-W to disable)" );
  1466.         case DL_ERROR:        ConcatString( tmpMessage, 200, tmpMessage, " : Errors. (Press CTRL-W to disable)" );
  1467.         case DL_WARNING:    ConcatString( tmpMessage, 200, tmpMessage, " : Warnings. (Press CTRL-W to disable)" );
  1468.         case DL_MESSAGE:    ConcatString( tmpMessage, 200, tmpMessage, " : Messages. (Press CTRL-W to disable)" );
  1469.         case DL_BEHAVIOR:    ConcatString( tmpMessage, 200, tmpMessage, " : Behavior messages. (Lots of text! Press CTRL-W to disable)" );
  1470.         default:            ConcatString( tmpMessage, 200, tmpMessage, " : Error in akcommon.inc:IterateDebugLevels." );
  1471.     }
  1472.     
  1473.     if( GetEntity( "self" ) == GetWorld() ) { // Csak a palyascriptre irjuk ki
  1474.         ShowShortMessage( tmpMessage );
  1475.         Log( tmpMessage, "proglog\\scriptlog" );
  1476.     }
  1477. }
  1478.  
  1479.  
  1480.  
  1481.  
  1482. // Az alabbi beolvassa es visszaadja a local settingsbeli erteket, vagy visszaadja az overwrite-olt erteket
  1483. //======================================================================================================
  1484. stock eDebugLevel:GetDebugLevel()
  1485. {
  1486.     return gDL;
  1487. }
  1488.  
  1489.  
  1490. //======================================================================================================
  1491. stock HideEntity(DrID:Unit)
  1492. {
  1493.     if(Unit!=DrID:0)
  1494.     {
  1495.         SetPropertyBool( Unit, "Visible", false );
  1496.         SetPropertyBool( Unit, "Invisible", true );
  1497.     }
  1498. }
  1499.  
  1500. //======================================================================================================
  1501. stock bool:IsAlive( DrID:Unit, bool:CheckIfActive = false )
  1502. {
  1503.     new DrID:DRComp = DrID:0;
  1504.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1505.         DRComp = GetComponent( Unit, "cDRVehicle");
  1506.     else
  1507.         if(IsInstanceOf( Unit, GetClassID( "cBuilding" )))
  1508.             DRComp = GetComponent( Unit, "cDRBuilding");
  1509.         else
  1510.             DRComp = GetComponent( Unit, "cDRSimple");
  1511.  
  1512.     if(DRComp == DrID:0)
  1513.     {
  1514.         DebugMessage( "akcommon.inc:IsAlive: The Unit doesn't have cDRVehicle/cDRBuilding/cDRSimple", DL_BEHAVIOR );
  1515.         return false;
  1516.     }    
  1517.  
  1518.     new DrID:BodyComp = GetPropertyObject( DRComp, "Body" )    
  1519.  
  1520.     if(BodyComp == DrID:0)
  1521.     {
  1522.         DebugMessage( "akcommon.inc:IsAlive: The Unit doesn't have Body", DL_BEHAVIOR );
  1523.         return false;
  1524.     }
  1525.  
  1526.     // Check if active:    
  1527.     new bool:ActiveOK = true;
  1528.     
  1529.     if( CheckIfActive && !GetPropertyBool( Unit, "Active" ))
  1530.         ActiveOK = false;
  1531.         
  1532.     return bool:( GetPropertyFloat( BodyComp, "HP" ) > 0.0 && ActiveOK );
  1533. }    
  1534.  
  1535. //======================================================================================================
  1536. stock bool:IsAliveTurret( DrID:Unit )
  1537. {
  1538.     new DrID:DRComp = DrID:0;
  1539.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1540.     {
  1541.         DRComp = GetComponent( Unit, "cDRVehicle");
  1542.     }
  1543.     else
  1544.     {
  1545.         DebugMessage( "akcommon.inc:IsAliveTurret: The Unit is not a Vehicle", DL_BEHAVIOR );
  1546.         return false;
  1547.     }    
  1548.         
  1549.     if(DRComp == DrID:0)
  1550.     {
  1551.         DebugMessage( "akcommon.inc:IsAliveTurret: The Unit doesn't have cDRVehicle", DL_BEHAVIOR );
  1552.         return false;
  1553.     }    
  1554.  
  1555.     if(!GetPropertyBool( GetComponentBase(DRComp), "HasTurret" ))    
  1556.     {
  1557.         DebugMessage( "akcommon.inc:IsAliveTurret: The Unit doesn't have a Turret", DL_BEHAVIOR );
  1558.         return true; //returning true so repairing not necessary on this
  1559.     }        
  1560.     return (GetPropertyFloat( DRComp, "TurretPercent" ) > 0.0);
  1561. }    
  1562.  
  1563. //======================================================================================================
  1564. stock bool:IsAliveCaterpillar( DrID:Unit )
  1565. {
  1566.     new DrID:DRComp = DrID:0;
  1567.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1568.     {
  1569.         DRComp = GetComponent( Unit, "cDRVehicle");
  1570.     }
  1571.     else
  1572.     {
  1573.         DebugMessage( "akcommon.inc:IsAliveCaterpillar: The Unit is not a Vehicle", DL_BEHAVIOR );
  1574.         return false;
  1575.     }    
  1576.         
  1577.     if(DRComp == DrID:0)
  1578.     {
  1579.         DebugMessage( "akcommon.inc:IsAliveCaterpillar: The Unit doesn't have cDRVehicle", DL_BEHAVIOR );
  1580.         return false;
  1581.     }    
  1582.  
  1583.     if(!GetPropertyBool( GetComponentBase(DRComp), "HasCaterpillar" ))
  1584.     {
  1585.         DebugMessage( "akcommon.inc:IsAliveCaterpillar: The Unit doesn't have a Caterpillar", DL_BEHAVIOR );
  1586.         return true; //probably the unit is not immobilized then -> repairing not necessary
  1587.     }        
  1588.     return (GetPropertyFloat( DRComp, "CaterpillarPercent" ) > 0.0);
  1589. }    
  1590.  
  1591. //======================================================================================================
  1592. stock bool:IsWreck( DrID:Unit )
  1593. {
  1594.     new DrID:DRComp = DrID:0;
  1595.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1596.         DRComp = GetComponent( Unit, "cDRVehicle");
  1597.     else
  1598.         if(IsInstanceOf( Unit, GetClassID( "cBuilding" )))
  1599.             DRComp = GetComponent( Unit, "cDRBuilding");
  1600.         else
  1601.             DRComp = GetComponent( Unit, "cDRSimple");
  1602.  
  1603.     if(DRComp == DrID:0)
  1604.     {
  1605.         DebugMessage( "akcommon.inc:IsAlive: The Unit doesn't have cDRVehicle/cDRBuilding/cDRSimple", DL_BEHAVIOR );
  1606.         return false;
  1607.     }    
  1608.  
  1609.     new DrID:WreckComp = GetPropertyObject( DRComp, "ActWreck")    
  1610.  
  1611.     if(WreckComp == DrID:0)
  1612.     {
  1613.         DebugMessage( "akcommon.inc:IsAlive: The Unit doesn't have ActWreck", DL_BEHAVIOR );
  1614.         return false;
  1615.     }    
  1616.     return !(GetPropertyFloat( WreckComp, "HP" ) > 0.0);
  1617. }    
  1618.  
  1619. //======================================================================================================
  1620. stock bool:IsMounted( DrID:Unit, bool:returnMounting = false )
  1621. {
  1622.     return (IsMountedIn(Unit, returnMounting) != DrID:0);
  1623. }    
  1624.  
  1625. //======================================================================================================
  1626. stock DrID:IsMountedIn(DrID:Entity, bool:returnMounting = false)
  1627. {
  1628.     if( IsInstanceOf( Entity, GetClassID( "cSoldier" )))
  1629.     {
  1630.         new DrID:hc = GetComponent(Entity, "cHumanController");
  1631.         new bool:isMounted = GetPropertyBool(hc, "Mounted"); // Ez a prop mutatja, hogy be hova van tenylegesen bemountolva
  1632.         if (!isMounted && !returnMounting)
  1633.             return DrID:0;
  1634.         return GetPropertyObject( Entity, "Mount" ); // Ez a prop mutatja, hogy hova van mountolva, vagy hova mountol eppen
  1635.     }
  1636.     else
  1637.     {
  1638.         DebugMessage( "IsMountedIn: The requested Entity is not a soldier!", DL_BEHAVIOR )
  1639.     }
  1640.  
  1641.     return DrID:0;
  1642. }
  1643.  
  1644.  
  1645.  
  1646. //======================================================================================================
  1647. stock bool:IsRegularInstanceOf( DrID:Entity, DrID:ClassID )
  1648. {
  1649.     if( !IsInSelector( Entity, "Irregular" ))
  1650.         return IsInstanceOf( Entity, ClassID )
  1651.  
  1652.     return false;
  1653. }
  1654.  
  1655.  
  1656.  
  1657. //======================================================================================================
  1658. stock bool:IsTarget( DrID:Entity ) // Returns true, if param entity is the target of the event
  1659. {
  1660.     if( GetMsgParamObject() != Entity )
  1661.         return false;
  1662.         
  1663.     return true;
  1664. }
  1665.  
  1666.  
  1667.  
  1668.  
  1669. //======================================================================================================
  1670. stock Percent( Base, Percent ) // Int-ben visszaad egy szazalekkal modositott erteket
  1671.     return floatround( (Base*Percent)/100.0 );
  1672.  
  1673.  
  1674. //======================================================================================================
  1675. stock RndWeighted( ... )    // Sulyozott rnd-t szamol, visszateresi erteke, hogy hanyadik savba esik
  1676.                             // Visszateresi ertek 0..N-1, vagy -1 ha nem jott legalabb 2 parameter
  1677. {    // Check the number of arguments:
  1678.     new n = numargs();
  1679.     if( n < 2) {
  1680.         DebugMessage( "akcommon.inc:RndWeighted: At least 2 arguments needed!", DL_WARNING );
  1681.         return -1;
  1682.     }
  1683.  
  1684.     // Summarize values:
  1685.     new sum, i;
  1686.     for( i = 0; i < n; i++ )
  1687.         sum += getarg(i);
  1688.  
  1689.     // Randomize:
  1690.     new TmpInt = Rnd( 0, sum - 1 );
  1691.  
  1692.     // Select which zone is the number in:
  1693.     while( TmpInt <= sum - 1 )
  1694.         sum -= getarg( --i );
  1695.  
  1696.     return i;
  1697. }
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703. //======================================================================================================
  1704. stock Float:RadToDeg( Float:Value )
  1705.     return (Value * 180 / PI);
  1706.     
  1707.  
  1708.  
  1709. //======================================================================================================
  1710. stock Regroup( selector[], eQueuing:Queuing = Q_OVERRIDE, flags = MF_NONE )
  1711. {
  1712.     new Iterator:i = Iterate( selector );
  1713.  
  1714.     if ( CountLivingInSelector( selector ) < 2 )
  1715.     {
  1716.         ItStop( i );
  1717.         return;
  1718.     }
  1719.  
  1720.     ItNext(i);
  1721.     new DrID:Unit = ItEntity(i);
  1722.  
  1723.     new Float:TmpPos[vec3];
  1724.     GetPropertyVec3( Unit, "LogicalPos_", TmpPos );
  1725.  
  1726.     new Float:MinX = TmpPos[vec3:x];
  1727.     new Float:MaxX = TmpPos[vec3:x];
  1728.     new Float:MinY = TmpPos[vec3:y];
  1729.     new Float:MaxY = TmpPos[vec3:y];
  1730.  
  1731.     while( ItNext(i))
  1732.     {
  1733.         Unit = ItEntity(i);
  1734.         GetPropertyVec3( Unit, "LogicalPos_", TmpPos );
  1735.         if( TmpPos[vec3:x] < MinX )
  1736.         {
  1737.             MinX = TmpPos[vec3:x]
  1738.         }
  1739.         else if( TmpPos[vec3:x] > MaxX )
  1740.         {
  1741.             MaxX = TmpPos[vec3:x]
  1742.         } 
  1743.         if( TmpPos[vec3:y] < MinY )
  1744.         {
  1745.             MinY = TmpPos[vec3:y]
  1746.         }
  1747.         else if( TmpPos[vec3:y] > MaxY )
  1748.         {
  1749.             MaxY = TmpPos[vec3:y]
  1750.         } 
  1751.     }
  1752.     ItStop( i );
  1753.  
  1754.     TmpPos[vec3:x] = ( MinX + MaxX ) / 2.0;
  1755.     TmpPos[vec3:y] = ( MinY + MaxY ) / 2.0;
  1756.     TmpPos[vec3:z] = 0.0;
  1757.  
  1758.     CmdGroupMove( selector, Queuing, TmpPos, flags);
  1759. }
  1760.  
  1761. //======================================================================================================
  1762. //.hack\\sign!
  1763. stock RefreshArea(DrID:ZieArea)
  1764. {
  1765.     new Float:lTmpVec3[vec3];
  1766.     GetPropertyVec3( ZieArea, "LogicalPos_", lTmpVec3 );
  1767.     lTmpVec3[vec3:x]+=1.0;
  1768.     SetPropertyVec3( ZieArea, "Pos", lTmpVec3 );
  1769.     lTmpVec3[vec3:x]-=1.0;
  1770.     SetPropertyVec3( ZieArea, "Pos", lTmpVec3 );
  1771. }
  1772.  
  1773. //======================================================================================================
  1774. stock ShowEntity(DrID:HiddenEntity)
  1775. {
  1776.     if(HiddenEntity!=DrID:0)
  1777.     {
  1778.         SetPropertyBool( HiddenEntity, "Invisible", false );
  1779.         if(IsPlayer(HiddenEntity))
  1780.             SetPropertyBool( HiddenEntity, "Visible", true );
  1781.     }
  1782. }
  1783.  
  1784. //======================================================================================================
  1785. stock SetSpeedInSelector( Selector[], Float:Speed ) // Untested
  1786. {    
  1787.     new Iterator:i = Iterate( Selector );
  1788.     while( ItNext( i ))
  1789.         SetPropertyFloat( GetComponent( ItEntity( i ), "cUnitController" ), "SpeedOverride", Speed );
  1790.  
  1791.     ItStop( i );
  1792. }
  1793.  
  1794.  
  1795. //======================================================================================================
  1796. stock MakeUnSelectable(DrID:Entity)
  1797. {
  1798.     SetPropertyBool( Entity, "Selectable", false );
  1799. //    RemoveFromGroup( "Selection", Entity );
  1800.     if(IsInSelector( Entity, "Selection" ))
  1801.         RemoveFromSelector("Selection", Entity);
  1802. }
  1803.  
  1804. //======================================================================================================
  1805. stock MakeSelectable(DrID:Entity)
  1806. {
  1807.     SetPropertyBool( Entity, "Selectable", true );
  1808. }
  1809.  
  1810.  
  1811. stock MakeInvulnerable(DrID:Unit)
  1812. {
  1813.     new DrID:DRComp = DrID:0;
  1814.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1815.         DRComp = GetComponent( Unit, "cDRVehicle");
  1816.     else
  1817.         if(IsInstanceOf( Unit, GetClassID( "cBuilding" )))
  1818.             DRComp = GetComponent( Unit, "cDRBuilding");
  1819.         else
  1820.             DRComp = GetComponent( Unit, "cDRSimple");
  1821.  
  1822.     if(DRComp == DrID:0)
  1823.     {
  1824.         DebugMessage( "MakeInvulnerable: The Unit doesn't have cDRVehicle/cDRBuilding/cDRSimple", DL_BEHAVIOR );
  1825.         return false;
  1826.     }    
  1827.  
  1828.     SetPropertyBool( DRComp, "Invulnerable", true);
  1829.     return true;
  1830. }
  1831.  
  1832. stock MakeMountable(DrID:Who)
  1833. {
  1834.  
  1835.     new DrID:egy = GetComponent(Who, "cMountPoint");
  1836.     new DrID:ketto;
  1837.      new i=0;
  1838.      new j=GetPropArrayLength(egy, "MountPositions");
  1839.     for (i=0;i<j;i++)
  1840.     {
  1841.         ketto = GetArrayElement (egy,"MountPositions",i);
  1842.         SetPropertyBool( ketto, "Active", true );
  1843.     }
  1844. }
  1845.  
  1846. stock MakeNOTMountable(DrID:Who)
  1847. {
  1848.  
  1849.     new DrID:egy = GetComponent(Who, "cMountPoint");
  1850.     new DrID:ketto;
  1851.      new i=0;
  1852.      new j=GetPropArrayLength(egy, "MountPositions");
  1853.     for (i=0;i<j;i++)
  1854.     {
  1855.         ketto = GetArrayElement (egy,"MountPositions",i);
  1856.         SetPropertyBool( ketto, "Active", false );
  1857.     }
  1858. }
  1859.  
  1860. stock MakeVulnerable(DrID:Unit)
  1861. {
  1862.     new DrID:DRComp = DrID:0;
  1863.     if(IsInstanceOf( Unit, GetClassID( "cVehicle" )))
  1864.         DRComp = GetComponent( Unit, "cDRVehicle");
  1865.     else
  1866.         if(IsInstanceOf( Unit, GetClassID( "cBuilding" )))
  1867.             DRComp = GetComponent( Unit, "cDRBuilding");
  1868.         else
  1869.             DRComp = GetComponent( Unit, "cDRSimple");
  1870.  
  1871.     if(DRComp == DrID:0)
  1872.     {
  1873.         DebugMessage( "MakeVulnerable: The Unit doesn't have cDRVehicle/cDRBuilding/cDRSimple", DL_BEHAVIOR );
  1874.         return false;
  1875.     }    
  1876.  
  1877.     SetPropertyBool( DRComp, "Invulnerable", false);
  1878.     return true;
  1879. }
  1880.  
  1881. //======================================================================================================
  1882. stock MoveCameraToEnt( DrID:TargetEntity )
  1883. {
  1884.     new Float:TargetPos[vec3];
  1885.     
  1886.     GetPropertyVec3( TargetEntity , "LogicalPos_", TargetPos );
  1887.     SetCameraTargetPos( TargetPos );
  1888. }
  1889.  
  1890. //======================================================================================================
  1891. stock MoveForward(DrID:ZieEntity, Float:ZieDistance, eQueuing:queuing = Q_ENQUEUE,eMoveFlag:flags = MF_NONE)
  1892. {
  1893.     if(ZieEntity==DrID:0)
  1894.     {
  1895.         return;
  1896.     }
  1897.     new Float:MF_EntDir=GetEntityDir( ZieEntity ,DB_X_AXIS )-90.0;
  1898.     new Float:MF_NewPos[vec3];
  1899.     MF_NewPos[vec3:x]=0.0;
  1900.     MF_NewPos[vec3:y]=ZieDistance;
  1901.     MF_NewPos[vec3:z]=0.0;
  1902.     new Float:MF_OldPos[vec3];
  1903.     GetPropertyVec3(ZieEntity, "LogicalPos_", MF_OldPos );
  1904.     RotateVec2(MF_NewPos,MF_EntDir);
  1905.     AddVec3( MF_NewPos, MF_OldPos, MF_NewPos );
  1906.     CmdMove( ZieEntity, queuing, MF_NewPos, flags );
  1907. }
  1908.  
  1909. stock TurnCW(DrID:ZieEntity, Float:ZieAngle, eQueuing:queuing = Q_ENQUEUE, eTurnFlags:flags = TF_NONE)
  1910. {
  1911.     if(ZieEntity==DrID:0)
  1912.         return;
  1913.     new Float:TCW_Dir=GetEntityDir( ZieEntity,DB_X_AXIS )
  1914.     TCW_Dir-=ZieAngle;
  1915.     TCW_Dir=NormalizeDegree(TCW_Dir);
  1916.     CmdTurnToDir( ZieEntity, queuing, TCW_Dir, DB_X_AXIS, flags );
  1917. }
  1918.  
  1919. stock Float:NormalizeDegree(Float:ND_Angle)
  1920. {
  1921.     while(ND_Angle>180.0)
  1922.     {
  1923.         ND_Angle-=(360.0);
  1924.     }
  1925.     while(ND_Angle<-180.0)
  1926.     {
  1927.         ND_Angle+=(360.0);
  1928.     }
  1929.     return ND_Angle;
  1930. }
  1931.  
  1932. //======================================================================================================
  1933. stock RotateCameraToEnt( DrID:TargetEntity )
  1934. {
  1935.     SetCameraTargetRotate( GetEntityDir( TargetEntity ));
  1936. }
  1937.  
  1938.  
  1939.  
  1940.  
  1941. //======================================================================================================
  1942. stock StrCpy( StrSource[], StrDest[], MaxLength = STR_PROP_MAX_LENGTH ) // Untested
  1943. {
  1944.     new i;
  1945.     
  1946.     for( i = 0; ( Str1[i] ) && ( i <= MaxLength - 1 ); i++ )
  1947.         StrDest[i] = StrSource[i];
  1948.     
  1949.     StrDest[i+1] = 0;
  1950.  
  1951.     return true;
  1952. }
  1953.  
  1954.  
  1955.  
  1956.  
  1957. //======================================================================================================
  1958. stock Reinforcement( ID[], DrID:DeployAt, DrID:ArriveTo )
  1959. {
  1960.     new Float:PosDeployAt[vec3];
  1961.     new Float:PosArriveTo[vec3];
  1962.  
  1963.     GetPropertyVec3( DeployAt, "LogicalPos_", PosDeployAt );
  1964.     GetPropertyVec3( ArriveTo, "LogicalPos_", PosArriveTo );
  1965.         
  1966.     TriggerReinforce( ID, PosDeployAt, PosArriveTo );
  1967. }
  1968.  
  1969.  
  1970.  
  1971.  
  1972. //======================================================================================================
  1973. stock Vec2toVec3( Float:Source[vec2], Float:Destination[vec3] )
  1974. {
  1975.     Destination[vec3:x] = Source[vec2:x];
  1976.     Destination[vec3:y] = Source[vec2:y];
  1977.     Destination[vec3:z] = 0.0;
  1978.     
  1979.     return true;
  1980. }
  1981.  
  1982.  
  1983.  
  1984.  
  1985. //======================================================================================================
  1986. stock Vec3toVec2( Float:Source[vec3], Float:Destination[vec2] )
  1987. {
  1988.     Destination[vec2:x] = Source[vec3:x];
  1989.     Destination[vec2:y] = Source[vec3:y];
  1990.     
  1991.     return true;
  1992. }
  1993. //======================================================================================================
  1994. // usefull only to debug processes.
  1995. stock vec32str(DaString[255],Float:DaVec3[vec3])
  1996. {
  1997.     new lTmpStr[250];
  1998.     DaString="";
  1999.     Float2Str( DaVec3[vec3:x], lTmpStr, 255, "%7.3f" );
  2000.     ConcatString( DaString, 255, DaString, lTmpStr );
  2001.     ConcatString( DaString, 255, DaString, " | " );
  2002.     Float2Str( DaVec3[vec3:y], lTmpStr, 255, "%7.3f" );
  2003.     ConcatString( DaString, 255, DaString, lTmpStr );
  2004.     ConcatString( DaString, 255, DaString, " | " );
  2005.     Float2Str( DaVec3[vec3:z], lTmpStr, 255, "%7.3f" );
  2006.     ConcatString( DaString, 255, DaString, lTmpStr );
  2007.     ConcatString( DaString, 255, DaString, " | " );
  2008.     return true;
  2009. }
  2010.  
  2011. stock CmpVec3(Float:v1[vec3], Float:v2[vec3])
  2012. {
  2013.     if (v1[vec3:x] != v2[vec3:x])
  2014.         return false;
  2015.     if (v1[vec3:y] != v2[vec3:y])
  2016.         return false;
  2017.     if (v1[vec3:z] != v2[vec3:z])
  2018.         return false;
  2019.     return true;
  2020. }
  2021.  
  2022. stock ShowTheStats()
  2023. {
  2024.     static ShowTheStatsNum = 0;
  2025.     ShowTheStatsNum++;
  2026.  
  2027.     new lTmpStr[255];
  2028.     new Float:CamActPos[vec3];
  2029.     GetCameraActualPos( CamActPos );
  2030.     new Float:CamActRot=GetCameraActualRotate();
  2031.     new Float:CamActPit=GetCameraActualPitch();
  2032.     new Float:CamActDis=GetCameraActualDistance();
  2033.  
  2034.     Int2Str( ShowTheStatsNum, lTmpStr );
  2035.     ConcatString( lTmpStr, 100, "No: ", lTmpStr );
  2036.     DebugMessage( lTmpStr, DL_MESSAGE );
  2037.     ShowShortMessage( lTmpStr );    
  2038.  
  2039.     vec32str( lTmpStr, CamActPos);
  2040.     ConcatString( lTmpStr, 100, "Actual Position: ", lTmpStr );
  2041.     DebugMessage( lTmpStr, DL_MESSAGE );
  2042.     ShowShortMessage( lTmpStr );    
  2043.  
  2044.     Float2Str( CamActRot, lTmpStr, 10, "%7.3f" );
  2045.     ConcatString( lTmpStr, 100, "Actual Rotation: ", lTmpStr );
  2046.     DebugMessage( lTmpStr, DL_MESSAGE );
  2047.     ShowShortMessage( lTmpStr );    
  2048.     
  2049.     Float2Str( CamActPit, lTmpStr, 10, "%7.3f" );
  2050.     ConcatString( lTmpStr, 100, "Actual Pitch: ", lTmpStr );
  2051.     DebugMessage( lTmpStr, DL_MESSAGE );
  2052.     ShowShortMessage( lTmpStr );    
  2053.  
  2054.     Float2Str( CamActDis, lTmpStr, 10, "%7.3f" );
  2055.     ConcatString( lTmpStr, 100, "Actual Distance: ", lTmpStr );
  2056.     DebugMessage( lTmpStr, DL_MESSAGE );
  2057.     ShowShortMessage( lTmpStr );    
  2058. }
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064. //====================================================
  2065. //Recon stuffazz
  2066.  
  2067.  
  2068. stock DrID:GetSupportObj(DasTeam)
  2069. {
  2070.      new DrID:ReinfSys = GetPropertyObject( GetEntity( "World" ), "ReinforcementSystem" );
  2071.     new DrID:AktElement;
  2072.     new MaxElement = GetPropArrayLength( ReinfSys, "TeamDescriptors" );
  2073.     new ciklus;
  2074.     for(ciklus=0;ciklus<MaxElement;ciklus++)
  2075.     {
  2076.         AktElement=GetArrayElement(ReinfSys, "TeamDescriptors", ciklus);
  2077.         if(AktElement!=DrID:0)
  2078.         {
  2079.             if(GetPropertyObject(AktElement, "Support")!=DrID:0)
  2080.             {
  2081.                 if(GetPropertyInt( AktElement, "Team" )==DasTeam)
  2082.                 {
  2083.                     return GetPropertyObject(AktElement, "Support");
  2084.                 }
  2085.             }
  2086.             else
  2087.             {
  2088.                 DebugMessage( "akcommon.inc:GetSupportObj: Requested Team doesn't have Support!!!", DL_ERROR );            
  2089.                 return DrID:0;
  2090.             }
  2091.         }
  2092.     }    
  2093.     DebugMessage( "akcommon.inc:GetSupportObj: Requested Team doesn't have ReinforcementSystem!!!", DL_ERROR );
  2094.     return DrID:0;
  2095. }
  2096.  
  2097. stock GetNAirStrikes(DasTeam)
  2098. {
  2099.     new DrID:lTmpDrID=GetSupportObj(DasTeam);
  2100.     if(lTmpDrID)
  2101.         return GetPropertyInt( lTmpDrID, "NAirStrikes");
  2102.     return -1;
  2103. }
  2104.  
  2105. stock GetNAirRecons(DasTeam)
  2106. {
  2107.     new DrID:lTmpDrID=GetSupportObj(DasTeam);
  2108.     if(lTmpDrID)
  2109.         return GetPropertyInt( lTmpDrID, "NRecons");
  2110.     return -1;
  2111. }
  2112.  
  2113. stock GetNArtilleryAttack(DasTeam)
  2114. {
  2115.     new DrID:lTmpDrID=GetSupportObj(DasTeam);
  2116.     if(lTmpDrID)
  2117.         return GetPropertyInt( lTmpDrID, "NArtilleryAttacks");
  2118.     return -1;
  2119. }
  2120.  
  2121. stock GetNParatroopers(DasTeam)
  2122. {
  2123.     new DrID:lTmpDrID=GetSupportObj(DasTeam);
  2124.     if(lTmpDrID)
  2125.         return GetPropertyInt( lTmpDrID, "NParatroopers");
  2126.     return -1;
  2127. }
  2128.  
  2129. stock SetAirStrike(DasTeam,DasNum)
  2130. {
  2131.     if(GetNAirStrikes(DasTeam)!=-1)
  2132.         SetPropertyInt( GetSupportObj(DasTeam), "NAirStrikes",DasNum);
  2133. }
  2134.  
  2135. stock SetAirRecon(DasTeam,DasNum)
  2136. {
  2137.     if(GetNAirRecons(DasTeam)!=-1)
  2138.         SetPropertyInt( GetSupportObj(DasTeam), "NRecons",DasNum);
  2139. }
  2140.  
  2141. stock SetArtilleryAttack(DasTeam,DasNum)
  2142. {
  2143.     if(GetNArtilleryAttack(DasTeam)!=-1)
  2144.         SetPropertyInt( GetSupportObj(DasTeam), "NArtilleryAttacks",DasNum);
  2145. }
  2146.  
  2147. stock SetParatroopers(DasTeam,DasNum)
  2148. {
  2149.     if(GetNParatroopers(DasTeam)!=-1)
  2150.         SetPropertyInt( GetSupportObj(DasTeam), "NParatroopers",DasNum);
  2151. }
  2152.  
  2153. stock GiveAirStrike(DasTeam)
  2154. {
  2155.     if(GetNAirStrikes(DasTeam)!=-1)
  2156.         SetPropertyInt( GetSupportObj(DasTeam), "NAirStrikes",GetNAirStrikes(DasTeam)+1);
  2157. }
  2158.  
  2159. stock GiveAirRecon(DasTeam)
  2160. {
  2161.     if(GetNAirRecons(DasTeam)!=-1)
  2162.         SetPropertyInt( GetSupportObj(DasTeam), "NRecons",GetNAirRecons(DasTeam)+1);
  2163. }
  2164.  
  2165. stock GiveArtilleryAttack(DasTeam)
  2166. {
  2167.     if(GetNArtilleryAttack(DasTeam)!=-1)
  2168.         SetPropertyInt( GetSupportObj(DasTeam), "NArtilleryAttacks",GetNArtilleryAttack(DasTeam)+1);
  2169. }
  2170.  
  2171. stock GiveParaTroopers(DasTeam)
  2172. {
  2173.     if(GetNParatroopers(DasTeam)!=-1)
  2174.         SetPropertyInt( GetSupportObj(DasTeam), "NParatroopers",GetNParatroopers(DasTeam)+1);
  2175. }
  2176.  
  2177. stock CountMPInSelector(DasSelector[],bool:MustBeAlive=true, IsInTeam=-1)
  2178. {
  2179.     new lMPTotal=0;
  2180.     new Iterator:iti=Iterate(DasSelector);
  2181.     while(ItNext(iti))
  2182.     {
  2183.         if(!MustBeAlive||IsAlive(ItEntity(iti)))
  2184.         {
  2185.             if(IsInTeam==-1||GetPropertyInt( ItEntity(iti), "Team" )==IsInTeam)    
  2186.             {
  2187.                 lMPTotal+=GetPropertyInt(GetComponentBase(GetComponent(ItEntity(iti),"cManagement")), "Value" );
  2188.             }
  2189.         }
  2190.     }
  2191.     ItStop(iti);
  2192.     return lMPTotal;
  2193. }
  2194.  
  2195. stock DestructEntityFake(DrID:entity)
  2196. {
  2197.     SetPropertyBool( entity, "Survivor", false );
  2198.     SetPropertyInt( entity, "Team", 0 );
  2199.     HideEntity(entity);
  2200.     DeActivateEntity( entity );
  2201. }
  2202.  
  2203. //-----------ANTI GOD MODE HACK by TIMBER--------------
  2204. stock bool:CheatDetector()
  2205. {
  2206. // insert this code just before >>EndMission( MS_ACCOMPLISHED );<<
  2207. //--GOD MODE DETECTION-START--
  2208. //     if(CheatDetector())
  2209. //     {
  2210. //         return;
  2211. //     }
  2212. //--GOD MODE DETECTION-END--
  2213.     SetEnabledMessages(0);
  2214.     new DrID:MegDogleszGeco=CreateEntity( "al_rifleman", Float:{0.0,0.0,0.0} );
  2215.     SetPropertyInt( MegDogleszGeco, "Team", gPlayerTeam );
  2216.     DamageEntity( MegDogleszGeco, 666.666, 49 );
  2217.      if(IsAlive(MegDogleszGeco))
  2218.      {
  2219.          AddObjective( "Cheater", OT_PRIMARY, "Cheating is not payable!", "Cheating is bad! Don't do it", OS_IN_PROGRESS );
  2220.          SetObjectiveState( "Cheater", OS_FAILED );
  2221.          EndMission( MS_FAILED);
  2222.         SetEnabledMessages(255);
  2223.          return true;
  2224.      }
  2225.     SetEnabledMessages(255);
  2226.      return false;
  2227. }
  2228.  
  2229. stock bool:CompareVec3(Float:First[vec3],Float:Second[vec3])
  2230. {
  2231.     return bool:( (First[vec3:x]==Second[vec3:x]) && (First[vec3:y]==Second[vec3:y]) && (First[vec3:z]==Second[vec3:z]) );
  2232. }
  2233.  
  2234. stock SetBehav( Group[],
  2235.                 eMovementBehavior:SetMB     = MB_UNMODIFIED, 
  2236.                 eFiringBehavior:SetFB         = FB_UNMODIFIED,
  2237.                 eUnmountBehav:SetUB         = UB_UNMODIFIED,
  2238.                 eDestEmptyBehav:SetDB         = DB_UNMODIFIED,
  2239.                 eMountBehav:SetMoB             = MOB_UNMODIFIED,
  2240.                 eMountTargetPref:SetMTPB     = MTP_UNDEFINED)
  2241. {
  2242.     new Iterator:i = Iterate(Group);
  2243.     
  2244.     while(ItNext(i))
  2245.     {
  2246.         SetBehav2Ent( ItEntity(i), SetMB, SetFB, SetUB, SetDB, SetMoB, SetMTPB)
  2247.     }
  2248.     ItStop(i);
  2249. }
  2250.  
  2251. stock SetBehav2Ent( DrID:Unit,
  2252.                 eMovementBehavior:SetMB     = MB_UNMODIFIED, 
  2253.                 eFiringBehavior:SetFB         = FB_UNMODIFIED,
  2254.                 eUnmountBehav:SetUB         = UB_UNMODIFIED,
  2255.                 eDestEmptyBehav:SetDB         = DB_UNMODIFIED,
  2256.                 eMountBehav:SetMoB             = MOB_UNMODIFIED,
  2257.                 eMountTargetPref:SetMTPB     = MTP_UNDEFINED)
  2258. {
  2259.     if(IsAlive(Unit))
  2260.     {
  2261.         if(SetMB != MB_UNMODIFIED)
  2262.             CmdSetMB( Unit, Q_ENQUEUE, SetMB );
  2263.  
  2264.         if(SetFB != FB_UNMODIFIED)
  2265.             CmdSetFB( Unit, Q_ENQUEUE, SetFB );
  2266.         
  2267.         if(SetUB != UB_UNMODIFIED)
  2268.             SetPropertyInt( Unit, "UnmountBehavior", SetUB );
  2269.         
  2270.         if(SetDB != DB_UNMODIFIED)
  2271.             SetPropertyInt( Unit, "DestroyEmptyBehavior", SetDB );
  2272.         
  2273.         if(SetMoB != MOB_UNMODIFIED)
  2274.             SetPropertyInt( Unit, "MountBehavior", SetMoB );
  2275.  
  2276.         if(SetMTPB != MTP_UNDEFINED)
  2277.             SetPropertyInt( Unit, "MountTargetPreference", SetMTPB );
  2278.         
  2279.     }
  2280. }
  2281.  
  2282. stock WreckDestructor(DrID:Entity, CompositeID[])
  2283. {
  2284.     if(IsInSelector( Entity, CompositeID ))
  2285.         if(IsInstanceOf( Entity, GetClassID( "cVehicle" ) ))
  2286.             DamageEntity( Entity, 1000.0, 49 );
  2287. }
  2288. //============================================================================================================================
  2289. stock CamPosStore(bool:flag=true)
  2290. {
  2291.     static Float:Camactpos[vec3];
  2292.     static Float:Camactdist;
  2293.     static Float:Camactrot;
  2294.     static Float:Camactpitch;
  2295.     
  2296.     if(flag)
  2297.     {
  2298.         GetCameraActualPos( Camactpos );
  2299.         Camactdist = GetCameraActualDistance();
  2300.         Camactrot = GetCameraActualRotate();
  2301.         Camactpitch = GetCameraActualPitch();
  2302.     }
  2303.     else
  2304.     {
  2305.         ResetCameraSpeed();
  2306.         SetCameraTargetPos( Camactpos );
  2307.         SetCameraTargetDistance( Camactdist );
  2308.         SetCameraTargetPitch( Camactpitch );
  2309.         SetCameraTargetRotate( Camactrot );
  2310.     }
  2311. }
  2312. stock CamPosRestore()
  2313. {
  2314.     CamPosStore(false);
  2315. }
  2316. //============================================================================================================================
  2317. stock MountedPlaceNr(DrID:Entity = DrID:0)
  2318. {
  2319.     new    Establishment = 0
  2320.     if (IsEntityComp( Entity, "cMountPoint"))
  2321.         Establishment = GetPropArrayLength( GetComponent( Entity, "cMountPoint"), "Mounted")
  2322.     else
  2323.         Establishment = -1
  2324.     return Establishment
  2325. }
  2326. //======================================================================================================
  2327. stock UnitCallEvent(DrID:UndWho, UndWhat[], eQueuing:queuing = Q_ENQUEUE, flags = CF_NONE)
  2328. {
  2329.     CmdThrowEvent( UndWho, queuing, 666, flags );
  2330.     AddAKEntityEvent( UndWhat, UndWho, CMD_EVENT );
  2331. }
  2332.  
  2333. stock KillEntity(DrID:UndWho)
  2334. {
  2335.     DamageEntity( UndWho, Float:(GetActualHealth(UndWho)+1.0), 49 );
  2336. }
  2337. //======================================================================================================
  2338. stock DrID:CreateFOWBtoEntity( DrID:Entity, Base[]="fowbacon_180" )
  2339. {
  2340.     new Float:pos[vec3];
  2341.     GetPropertyVec3( Entity, "LogicalPos_", pos );
  2342.     new DrID:Fow = CreateEntity( Base, pos );
  2343.     SetPropertyInt( Fow, "Team", gPlayerTeam );
  2344.     SetPropertyBool( Fow, "GadgetsVisible", false );
  2345.     RefreshFOW();
  2346.     return Fow;
  2347. }
  2348.  
  2349.  
  2350. stock ShowWeapon(DrID:Soldier, bool:WPisApply = true)
  2351. {
  2352.     if(WPisApply == true)
  2353.     {
  2354.         if(IsInstanceOf( Soldier, GetClassID( "cSolider" )))
  2355.             SetPropertyInt(GetComponent( Soldier ,"cHumanController"), "TextureStatus",0);
  2356.         else
  2357.             DebugMessage( "This entity is not soldier or dont exist!!", DL_ERROR );
  2358.     }
  2359.     else
  2360.     {
  2361.         if(IsInstanceOf( Soldier, GetClassID( "cSolider" )))
  2362.             SetPropertyInt(GetComponent( Soldier ,"cHumanController"), "TextureStatus",1);
  2363.         else
  2364.             DebugMessage( "This entity is not soldier or dont exist!!", DL_ERROR );
  2365.     }
  2366. }
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372. //======================================================================================================
  2373. stock Test_ListEntitiesInSelector( Selector[] , const ClassType[] = "cAKEntity", bool:AliveOnly=false )
  2374. {
  2375.     if( !IsDebugLevelOK( DL_MESSAGE ))
  2376.         return;
  2377.  
  2378.     new NoOfEntities = 0;
  2379.     new tmpstr[200];    
  2380.  
  2381.     ConcatString( tmpstr, 199, "Listing the enitities in selector '", Selector );
  2382.     ConcatString( tmpstr, 199, tmpstr, "'." );
  2383.     DebugMessage( tmpstr, DL_MESSAGE );
  2384.  
  2385.     new Iterator:i = Iterate( Selector , ClassType );
  2386.     while( ItNext(i))
  2387.     {
  2388.         if(IsAlive(ItEntity(i))||!AliveOnly)
  2389.         {
  2390.             GetPropertyString( ItEntity( i ), "StringID", 199, tmpstr );
  2391.             if(!GetPropertyBool( ItEntity(i), "Active" ))
  2392.             {
  2393.                 ConcatString( tmpstr, 199, tmpstr, " (Inactive)" );
  2394.             }
  2395.             if(IsInSelector( ItEntity(i), "Irregular" ))
  2396.             {
  2397.                 ConcatString( tmpstr, 199, tmpstr, " (Irregular)" );
  2398.             }
  2399.             DebugMessage( tmpstr, DL_MESSAGE );
  2400.             NoOfEntities++;
  2401.         }
  2402.     }
  2403.     ItStop(i);    
  2404.  
  2405.     ConcatString( tmpstr, 199, "Number of entities in selector '", Selector );
  2406.     ConcatString( tmpstr, 199, tmpstr, "' = " );
  2407.  
  2408.     new tmpstr2[200];
  2409.     Int2Str( NoOfEntities, tmpstr2, 199 );
  2410.  
  2411.     ConcatString( tmpstr, 199, tmpstr, tmpstr2 );
  2412.  
  2413.     DebugMessage( tmpstr, DL_MESSAGE );
  2414. }
  2415. //============================================================================================================================
  2416. stock GroupRemover(DrID:Unit)
  2417. {
  2418.     if(GetPropertyInt( Unit, "Team" ) == gPlayerTeam)
  2419.     {
  2420.         new GroupStr[200] = "";
  2421.         new Char;
  2422.         new i = 0;
  2423.         new j = 0;
  2424.         new tmpstr[100];
  2425.         GetPropertyString( Unit, "Group", 198, GroupStr );
  2426.         
  2427.         Char = GroupStr{0};
  2428.         while(Char != '\0')
  2429.         {
  2430.             if(Char != ',')
  2431.             {
  2432.                 tmpstr[j] = Char;
  2433.                 j++;
  2434.             }
  2435.             else
  2436.             {
  2437.                 tmpstr[j] = '\0';
  2438.                 RemoveIfNotForbidden(tmpstr, Unit);
  2439.                 j = 0;
  2440.             }
  2441.             i++;
  2442.             Char = GroupStr{i};
  2443.         }
  2444.         tmpstr[j] = '\0';
  2445.         RemoveIfNotForbidden(tmpstr, Unit);
  2446.     }
  2447. }
  2448.  
  2449. stock RemoveIfNotForbidden(group[], DrID:Unit)
  2450. {
  2451.     new k;
  2452.     for(k = 0; k != forbidden_grp_num; k++ )
  2453.     {
  2454.         if(CompareString( group, gForbiddenGroups[k]) == 0)
  2455.             break;
  2456.     }
  2457.     if (k == forbidden_grp_num)
  2458.         RemoveFromGroup( group, Unit );
  2459. }
  2460.  
  2461. //============================================================================================================================
  2462. // Requires an entity named 'scenarioflag' which is available only in Scenario Mode.
  2463. stock bool:IsScenario()
  2464. {
  2465.     return (GetEntity( "scenarioflag" )!=DrID:0)
  2466. }
  2467.  
  2468.  
  2469. //============================================================================================================================
  2470. stock SetLvBehSentProp(ID, bool:Bool)
  2471. {
  2472.     new MaxLength = GetPropArrayLength(GetEntity("World"), "LevelBehaviours");
  2473.     new DrID:AktElement;
  2474.     new i;
  2475.     new tmpID;
  2476.     for(i = 0; i<MaxLength; i++)
  2477.     {
  2478.         AktElement = GetArrayElement(GetEntity("World"), "LevelBehaviours", i);
  2479.         if(AktElement != DrID:0)
  2480.         {
  2481.             tmpID = GetPropertyInt(AktElement, "Id" );
  2482.             if(ID == tmpID)
  2483.                  SetPropertyBool( AktElement, "Sent", Bool);
  2484.         }
  2485.     }
  2486. }
  2487.  
  2488. //============================================================================================================================
  2489. stock ShipMode(DrID:SM_Unit,bool:SM_Mode=true)
  2490. {
  2491.     if(SM_Unit==DrID:0)
  2492.         return;
  2493.     new DrID:SM_UnitComm = GetComponent( SM_Unit, "cUnitController" );
  2494.     if(SM_UnitComm==DrID:0)
  2495.         return;
  2496.     SetPropertyBool( SM_UnitComm, "ShipMode", SM_Mode );    
  2497. }
  2498.