ZiGGi

npc attack

May 10th, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.14 KB | None | 0 0
  1. #include <a_samp>
  2. #include <cnpc>
  3. #include <cnpc_controller>
  4. #include <vip>
  5.  
  6.  
  7. enum npcInfo {
  8.     npc_Skin,
  9.     npc_Weapon,
  10.     Float:npc_TargetDist,
  11.     Float:npc_X,
  12.     Float:npc_Y,
  13.     Float:npc_Z,
  14.     Float:npc_A,
  15.     npc_ID,
  16.     npc_TargetID,
  17. }
  18. new npc[][npcInfo] = {
  19.     {105, 33, 45.0, 2494.3379, 2762.0728, 10.8203, 82.6969},
  20.     {106, 33, 45.0, 2494.3379, 2782.0728, 10.8203, 92.4103},
  21.     {107, 34, 350.0, 2503.8342, 2693.0327, 74.8277, 60.8794},
  22.     {108, 34, 350.0, 2629.5791, 2830.3835, 122.9219, 122.1029},
  23.     {109, 34, 350.0, 2629.2607, 2833.8516, 122.9219, 123.6696},
  24.     {110, 34, 350.0, 2632.1509, 2828.6719, 122.9219, 120.5362},
  25.     {110, 34, 350.0, 2632.1509, 2828.6719, 122.9219, 120.5362},
  26.     {110, 34, 350.0, 2509.7610, 2691.3679, 74.8281, 324.5181},
  27.     {110, 34, 350.0, 2507.0632, 2694.1550, 74.8281, 343.0050},
  28.     {110, 34, 350.0, 2566.1340, 2671.0398, 36.4252, 32.8254},
  29.     {110, 30, 350.0, 2572.6440, 2721.6748, 22.9507, 54.1323},
  30.     {110, 30, 350.0, 2582.9189, 2721.2813, 22.9507, 45.0455},
  31.     {110, 34, 350.0, 2595.3552, 2721.4360, 25.8222, 60.0856},
  32.     {110, 30, 350.0, 2594.8645, 2732.3953, 23.8222, 84.2125},
  33.     {110, 30, 350.0, 2594.8845, 2758.3169, 23.8222, 81.0791},
  34.     {110, 30, 350.0, 2595.4187, 2781.5964, 23.8222, 92.3592},
  35.     {110, 30, 350.0, 2539.7051, 2803.9167, 27.8203, 132.7797},
  36.     {110, 37, 70.0, 2559.0647, 2820.2732, 10.8203, 93.4537},
  37.     {110, 33, 70.0, 2556.9497, 2835.6948, 10.8203, 178.0544},
  38.     {110, 33, 70.0, 2568.3921, 2842.4070, 14.2559, 126.6673},
  39.     {110, 33, 70.0, 2589.8901, 2842.2651, 14.2559, 113.8205},
  40.     {110, 34, 70.0, 2594.8040, 2834.4480, 10.8203, 103.1671}
  41. };
  42. new Float:ftmp[3];
  43. new maxplayers = MAX_PLAYERS;
  44.  
  45. public OnFilterScriptInit()
  46. {
  47.     maxplayers = GetMaxPlayers();
  48.     zmap_Init("SAfull.hmap",ZMAP_MODE_CHACHE);
  49.     nodes_Init();
  50.     paths_Init();
  51.    
  52.     for (new npcid = 0; npcid < sizeof(npc); npcid++) {
  53.         npc[npcid][npc_ID] = FindLastFreeSlot();
  54.        
  55.         CreateNPC(npc[npcid][npc_ID], "Vagos");
  56.         SpawnNPC(npc[npcid][npc_ID]);
  57.        
  58.         SetNPCPos(npc[npcid][npc_ID], npc[npcid][npc_X], npc[npcid][npc_Y], npc[npcid][npc_Z]);
  59.         SetNPCFacingAngle(npc[npcid][npc_ID], npc[npcid][npc_A]);
  60.         SetNPCSkin(npc[npcid][npc_ID], npc[npcid][npc_Skin]);
  61.         SetNPCWeapon(npc[npcid][npc_ID], npc[npcid][npc_Weapon]);
  62.     }
  63.     SetTimer("attack", 500, 1);
  64. }
  65.  
  66.  
  67.  
  68. public OnFilterScriptExit()
  69. {
  70.     paths_Exit();
  71.     nodes_Exit();
  72.     zmap_Exit();
  73.     return 1;
  74. }
  75.  
  76. public OnPlayerConnect(playerid)
  77. {
  78.     return 1;
  79. }
  80.  
  81. public OnPlayerDisconnect(playerid, reason)
  82. {
  83.     return 1;
  84. }
  85.  
  86. public OnPlayerUpdate(playerid)
  87. {
  88.     controller_OnPlayerUpdate(playerid);
  89.     return 1;
  90. }
  91.  
  92. public OnNPCGetDamage(npcid, playerid, Float:health_loss)
  93. {
  94.     return 1;
  95. }
  96.  
  97. public OnNPCSpawn(npcid)
  98. {
  99.     controller_OnNPCSpawn(npcid);
  100. }
  101.  
  102. public OnNPCMovingComplete(npcid)
  103. {
  104.     controller_OnNPCMovingComplete(npcid);
  105. }
  106.  
  107. public OnNPCDeath(npcid,killerid,reason)
  108. {
  109.     StopNPC(npcid);
  110.     SetTimer("RespawnCitizen", 15000, 1);
  111.     controller_OnNPCDeath(npcid, killerid, reason);
  112. }
  113.  
  114. public OnPathCalculated(pathid)
  115. {
  116.     paths_OnPathCalculated(pathid);
  117. }
  118.  
  119. public OnCompleteCalcPathForNPC(npcid)
  120. {
  121.     controller_OnCompCalcPathForNPC(npcid);
  122. }
  123.  
  124. public OnStartCalcPathForNPC(npcid)
  125. {
  126.  
  127. }
  128.  
  129.  
  130. forward attack();
  131. public attack()
  132. {
  133.     new Float:min_dist,
  134.         Float:curr_dist;
  135.    
  136.     for (new npcid = 0; npcid < sizeof(npc); npcid++) {
  137.         GetNPCPos(npc[npcid][npc_ID], ftmp[0], ftmp[1], ftmp[2]);
  138.         npc[npcid][npc_TargetID] = -1;
  139.         min_dist = 99999.0;
  140.        
  141.         // get closest player
  142.         for (new playerid = 0; playerid < maxplayers; playerid++) {
  143.             if (!IsPlayerConnected(playerid) || IsPlayerNPC(playerid)) {
  144.                 continue;
  145.             }
  146.            
  147.             curr_dist = GetPlayerDistanceFromPoint(playerid, ftmp[0], ftmp[1], ftmp[2]);
  148.             if (min_dist > curr_dist && curr_dist < npc[npcid][npc_TargetDist]) {
  149.                 min_dist = curr_dist;
  150.                 npc[npcid][npc_TargetID] = playerid;
  151.             }
  152.         }
  153.        
  154.         // shoot in closest player
  155.         if (npc[npcid][npc_TargetID] != -1) {
  156.             GetPlayerPos(npc[npcid][npc_TargetID], ftmp[0], ftmp[1], ftmp[2]);
  157.             NPC_ShootAt(npc[npcid][npc_ID], ftmp[0], ftmp[1], ftmp[2]);
  158.         } else {
  159.             StopNPC(npc[npcid][npc_ID]);
  160.         }
  161.     }
  162.     return 1;
  163. }
  164.  
  165. forward RespawnCitizen(npcid);
  166. public RespawnCitizen(npcid)
  167. {
  168.     DestroyNPC(npcid);
  169. }
Advertisement
Add Comment
Please, Sign In to add comment