Advertisement
ZiGGi

Untitled

May 13th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.85 KB | None | 0 0
  1. forward attack();
  2. public attack()
  3. {
  4.     new Float:min_dist,
  5.         Float:curr_dist;
  6.  
  7.     for (new npcid = 0; npcid < sizeof(npc); npcid++) {
  8.         GetNPCPos(npc[npcid][npc_ID], ftmp[0], ftmp[1], ftmp[2]);
  9.         npc[npcid][npc_TargetID] = -1;
  10.         min_dist = 99999.0;
  11.  
  12.         // get closest player
  13.         for (new playerid = 0; playerid < maxplayers; playerid++) {
  14.             if (!IsPlayerConnected(playerid) || IsPlayerNPC(playerid)) {
  15.                 continue;
  16.             }
  17.  
  18.             curr_dist = GetPlayerDistanceFromPoint(playerid, ftmp[0], ftmp[1], ftmp[2]);
  19.             if (min_dist > curr_dist && curr_dist < npc[npcid][npc_TargetDist]) {
  20.                 min_dist = curr_dist;
  21.                 npc[npcid][npc_TargetID] = playerid;
  22.             }
  23.         }
  24.  
  25.         // shoot in closest player
  26.         if (npc[npcid][npc_TargetID] != -1) {
  27.             pNPC_ShootAt(npc[npcid][npc_ID], npc[npcid][npc_TargetID]);
  28.         } else {
  29.             StopNPC(npc[npcid][npc_ID]);
  30.         }
  31.     }
  32.     return 1;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement