Day_Walker

Shooting problem

Nov 3rd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. #include <a_samp>
  2. #include <streamer>
  3.  
  4. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  5. {
  6. if(newkeys & KEY_FIRE)
  7. {
  8. if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  9. {
  10. new Float:pos[6], Float:m_pos[6], Float:v_pos[7], vehicleid = GetPlayerVehicleID(playerid), Float:distance = 120.0, Float:speed = distance + 30.0;
  11. GetVehiclePos(vehicleid, v_pos[0], v_pos[1], v_pos[2]);
  12. GetVehicleRotation(vehicleid, v_pos[3], v_pos[4], v_pos[5]);
  13. GetVehicleZAngle(vehicleid, v_pos[6]);
  14.  
  15. for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  16. {
  17. if(IsPlayerConnected(i))
  18. {
  19. if(i == playerid) continue;
  20. new Float:vel = GetVehicleSpeed(vehicleid);
  21. if(IsPlayerInRangeOfPoint(i, distance, v_pos[0], v_pos[1], v_pos[2]) && vel <= 5.0)
  22. {
  23. new Float:tmpx, Float:tmpy, Float:tmpz, Float:tmpang;
  24. GetPlayerPos(i, tmpx, tmpy, tmpz);
  25. tmpang = (90 - atan2(tmpy - v_pos[1], tmpx - v_pos[0]) );
  26. if(tmpang < 0) tmpang = 360.0 + tmpang;
  27. tmpang = 360.0 - tmpang;
  28. if(floatabs(tmpang - v_pos[6]) < 5.0)
  29. {
  30. distance = GetPlayerDistanceFromPoint(i, v_pos[0], v_pos[1], v_pos[2]);
  31. }
  32. }
  33. }
  34. }
  35.  
  36. conversion(v_pos[0], v_pos[1], v_pos[2], v_pos[3], v_pos[4], v_pos[5], 0.0, 3.5, -0.4, 0.0, 0.0, 0.0, pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
  37. conversion(pos[0], pos[1], pos[2], pos[3], pos[4], pos[5], 0.0, distance, 0.2, 0.0, 0.0, 0.0, m_pos[0], m_pos[1], m_pos[2], m_pos[3], m_pos[4], m_pos[5]);
  38. new id = CreateDynamicObject(345, pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
  39. new areaid = CreateDynamicSphere(0.0, 0.0, 0.0, 5.5);
  40. AttachDynamicAreaToObject(areaid, id);
  41.  
  42. new ob_info[2]; ob_info[0] = true; ob_info[1] = areaid;
  43. new area_info[3]; area_info[0] = true; area_info[1] = id; area_info[2] = playerid;
  44. Streamer_SetArrayData(STREAMER_TYPE_OBJECT, id, E_STREAMER_EXTRA_ID, ob_info, 2);
  45. Streamer_SetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, area_info, 3);
  46.  
  47. MoveDynamicObject(id, m_pos[0], m_pos[1], m_pos[2], speed);
  48. Streamer_Update(playerid);
  49. return 1;
  50. }}
  51. return true;
  52. }
  53.  
  54. public OnDynamicObjectMoved(objectid)
  55. {
  56. new ob_info[2];
  57. Streamer_GetArrayData(STREAMER_TYPE_OBJECT, objectid, E_STREAMER_EXTRA_ID, ob_info, 2);
  58. if(ob_info[0])
  59. {
  60. DestroyDynamicArea(ob_info[1]);
  61. new Float:pos[3];
  62. GetDynamicObjectPos(objectid, pos[0], pos[1], pos[2]);
  63. SHOOTER_CreateExplosion(pos[0], pos[1], pos[2], 0, 15.0);
  64. DestroyDynamicObject(objectid);
  65. }
  66. return 1;
  67. }
  68.  
  69. forward Float:GetVehicleSpeed(vehicleid);
  70. public Float:GetVehicleSpeed(vehicleid)
  71. {
  72. new Float:vx, Float:vy, Float:vz;
  73. GetVehicleVelocity(vehicleid, vx, vy, vz);
  74. new Float:vel = floatmul(floatsqroot(floatadd(floatadd(floatpower(vx, 2), floatpower(vy, 2)), floatpower(vz, 2))), 181.5);
  75. return vel;
  76. }
  77.  
  78. stock GetVehicleRotation(vehicleid,&Float:rx,&Float:ry,&Float:rz)
  79. {
  80. new Float:qw,Float:qx,Float:qy,Float:qz;
  81. GetVehicleRotationQuat(vehicleid,qw,qx,qy,qz);
  82. rx = asin(2*qy*qz-2*qx*qw);
  83. ry = -atan2(qx*qz+qy*qw,0.5-qx*qx-qy*qy);
  84. rz = -atan2(qx*qy+qz*qw,0.5-qx*qx-qz*qz);
  85. }
  86.  
  87. //-------------------------------------------------- STYLOCK --------------------------------------------------
  88. conversion(Float:or_pos_x, Float:or_pos_y, Float:or_pos_z, Float:or_rot_x, Float:or_rot_y, Float:or_rot_z, Float:off_x, Float:off_y, Float:off_z, Float:rot_x, Float:rot_y, Float:rot_z, &Float:X, &Float:Y, &Float:Z, &Float:RX, &Float:RY, &Float:RZ) // By Stylock - http://forum.sa-mp.com/member.php?u=114165
  89. {
  90. static
  91. Float:sin[3],
  92. Float:cos[3],
  93. Float:pos[3],
  94. Float:rot[3];
  95.  
  96. pos[0] = or_pos_x;
  97. pos[1] = or_pos_y;
  98. pos[2] = or_pos_z;
  99. rot[0] = or_rot_x;
  100. rot[1] = or_rot_y;
  101. rot[2] = or_rot_z;
  102.  
  103. EDIT_FloatEulerFix(rot[0], rot[1], rot[2]);
  104. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  105. pos[0] = pos[0] + off_x * cos[1] * cos[2] - off_x * sin[0] * sin[1] * sin[2] - off_y * cos[0] * sin[2] + off_z * sin[1] * cos[2] + off_z * sin[0] * cos[1] * sin[2];
  106. pos[1] = pos[1] + off_x * cos[1] * sin[2] + off_x * sin[0] * sin[1] * cos[2] + off_y * cos[0] * cos[2] + off_z * sin[1] * sin[2] - off_z * sin[0] * cos[1] * cos[2];
  107. pos[2] = pos[2] - off_x * cos[0] * sin[1] + off_y * sin[0] + off_z * cos[0] * cos[1];
  108. rot[0] = asin(cos[0] * cos[1]); rot[1] = atan2(sin[0], cos[0] * sin[1]) + rot_z; rot[2] = atan2(cos[1] * cos[2] * sin[0] - sin[1] * sin[2], cos[2] * sin[1] - cos[1] * sin[0] * -sin[2]);
  109. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  110. rot[0] = asin(cos[0] * sin[1]); rot[1] = atan2(cos[0] * cos[1], sin[0]); rot[2] = atan2(cos[2] * sin[0] * sin[1] - cos[1] * sin[2], cos[1] * cos[2] + sin[0] * sin[1] * sin[2]);
  111. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  112. rot[0] = atan2(sin[0], cos[0] * cos[1]) + rot_x; rot[1] = asin(cos[0] * sin[1]); rot[2] = atan2(cos[2] * sin[0] * sin[1] + cos[1] * sin[2], cos[1] * cos[2] - sin[0] * sin[1] * sin[2]);
  113. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  114. rot[0] = asin(cos[1] * sin[0]); rot[1] = atan2(sin[1], cos[0] * cos[1]) + rot_y; rot[2] = atan2(cos[0] * sin[2] - cos[2] * sin[0] * sin[1], cos[0] * cos[2] + sin[0] * sin[1] * sin[2]);
  115. X = pos[0];
  116. Y = pos[1];
  117. Z = pos[2];
  118. RX = rot[0];
  119. RY = rot[1];
  120. RZ = rot[2];
  121. }
  122.  
  123.  
  124. EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z)
  125. {
  126. EDIT_FloatGetRemainder(rot_x, rot_y, rot_z);
  127. if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0))
  128. && (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0)))
  129. {
  130. rot_y = 0.0000002;
  131. }
  132. return 1;
  133. }
  134.  
  135. EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z)
  136. {
  137. EDIT_FloatRemainder(rot_x, 360.0);
  138. EDIT_FloatRemainder(rot_y, 360.0);
  139. EDIT_FloatRemainder(rot_z, 360.0);
  140. return 1;
  141. }
  142.  
  143. SHOOTER_CreateExplosion(Float:x, Float:y, Float:z, type, Float:radius)
  144. {
  145. for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  146. {
  147. if(IsPlayerConnected(i))
  148. {
  149. CreateExplosionForPlayer(i, x, y, z, type, radius);
  150. }
  151. }
  152. return 1;
  153. }
  154.  
  155. EDIT_FloatRemainder(&Float:remainder, Float:value)
  156. {
  157. if(remainder >= value)
  158. {
  159. while(remainder >= value)
  160. {
  161. remainder = remainder - value;
  162. }
  163. }
  164. else if(remainder < 0.0)
  165. {
  166. while(remainder < 0.0)
  167. {
  168. remainder = remainder + value;
  169. }
  170. }
  171. return 1;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment