Advertisement
DraKiNs

[FS] Detectar tiro ao Objeto

Jul 31st, 2011
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.44 KB | None | 0 0
  1. #include a_samp
  2.  
  3. // ============ [ Posição do Objeto ] =========
  4.  
  5. new Float:X_OBJETO  =       128.7418;
  6. new Float:Y_OBJETO  =       -85.9495;
  7. #define TAMANHO_OBJETO      0.4
  8.  
  9. // =========== [ Criar Objeto para teste ] ========
  10.  
  11. main()
  12. {
  13.     CreateObject(2587, 128.7418,-85.9495,1.4297, 0.0, 0.0, 96.0);
  14.     return true;
  15. }
  16.  
  17. // =========== [ Dar Arma para Teste ] ========
  18.  
  19. public OnPlayerSpawn(playerid)
  20. {
  21.     GivePlayerWeapon(playerid, 32, 400);
  22.     return true;
  23. }
  24.  
  25. // =========== [ Detectar Tiro ] ================
  26.  
  27. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  28. {
  29.     if((newkeys & KEY_FIRE || oldkeys & KEY_FIRE ) &&  IsPlayerInRangeOfPoint(playerid, 200.0 , X_OBJETO , Y_OBJETO , 0.0))
  30.     {
  31.        
  32.         static
  33.             Float:xPos,
  34.             Float:yPos,
  35.             Float:zPos,
  36.             Float:distancia,
  37.             Float:aPos;
  38.  
  39.         GetPlayerPos(playerid, xPos, yPos, zPos);
  40.         GetPlayerFacingAngle(playerid, aPos);
  41.  
  42.         distancia = floatsqroot(floatpower(floatabs(xPos-X_OBJETO), 2) + floatpower(floatabs(yPos-Y_OBJETO), 2));
  43.         if(distancia <  100.0)
  44.         {
  45.             xPos += (distancia * floatsin(-aPos, degrees)),
  46.             yPos += (distancia * floatcos(-aPos, degrees));
  47.             distancia = floatsqroot(floatpower(floatabs(xPos-X_OBJETO), 2) + floatpower(floatabs(yPos-Y_OBJETO), 2));
  48.         }
  49.        
  50.         if(TAMANHO_OBJETO > distancia)
  51.         {
  52.             printf("Jogador %d acertou em um objeto (Pontuação: %f)", playerid, distancia);
  53.         }
  54.     }
  55.     return true;
  56. }
  57.  
  58. // Criado por Bruno da Silva
  59. // www.ips-team.blogspot.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement