Advertisement
Guest User

Kurence

a guest
Jan 4th, 2010
3,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. #include <a_samp>
  2. new Firehold[MAX_PLAYERS];
  3. stock Float:GetDistanceBetweenPoints(Float:X, Float:Y, Float:Z, Float:PointX, Float:PointY, Float:PointZ)
  4. {
  5. new Float:Distance;
  6. Distance = floatabs(floatsub(X, PointX)) + floatabs(floatsub(Y, PointY)) + floatabs(floatsub(Z, PointZ));
  7. return Distance;
  8. }
  9. stock GetNearestVehicle(playerid, Float:Distance = 1000.0)
  10. {
  11. Distance = floatabs(Distance);
  12. if(Distance == 0.0) Distance = 1000.0;
  13. new Float:X[2], Float:Y[2], Float:Z[2];
  14. new Float:NearestPos = Distance;
  15. new NearestVehicle = INVALID_VEHICLE_ID;
  16. GetPlayerPos(playerid, X[0], Y[0], Z[0]);
  17. for(new i; i<MAX_VEHICLES; i++)
  18. {
  19. if(!IsVehicleStreamedIn(i, playerid) || i == GetPlayerVehicleID(playerid)) continue;
  20. GetVehiclePos(i, X[1], Y[1], Z[1]);
  21. if(NearestPos > GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1])) NearestPos = GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1]), NearestVehicle = i;
  22. }
  23. if(NearestPos < Distance) return NearestVehicle;
  24. return INVALID_VEHICLE_ID;
  25. }
  26. forward ResprayTimer(playerid,vehicleid);
  27. public OnPlayerKeyStateChange(playerid,newkeys,oldkeys){
  28. if(newkeys & KEY_FIRE &&(GetPlayerWeapon(playerid) == 41 && !IsPlayerInAnyVehicle(playerid))){
  29. new nearveh=GetNearestVehicle(playerid,5);
  30. if(IsPlayerFacingVehicle(playerid,nearveh)){
  31. SetTimerEx("ResprayTimer",3000,0,"ii",playerid,GetNearestVehicle(playerid,5));
  32. Firehold[playerid] = 1;
  33. }
  34. }
  35. if(oldkeys & KEY_FIRE && (Firehold[playerid] == 1)) Firehold[playerid] = 0;
  36. return 1;
  37. }
  38. public ResprayTimer(playerid,vehicleid){
  39. if(GetPlayerWeapon(playerid) == 41 && GetNearestVehicle(playerid,8) == vehicleid && Firehold[playerid] == 1){
  40. if(IsPlayerFacingVehicle(playerid,vehicleid)){
  41. ChangeVehicleColor(GetNearestVehicle(playerid,8),random(127),random(127));
  42. RepairVehicle(GetNearestVehicle(playerid,8));
  43. GameTextForPlayer(playerid,"~g~Respray sucessfull",3000,4);
  44. }
  45. }
  46. return 1;
  47. }
  48. public OnPlayerCommandText(playerid,cmdtext[]){
  49. if(strcmp("/spray",cmdtext,true) == 0){
  50. GivePlayerWeapon(playerid,41,50000);
  51. return 1;
  52. }
  53. return 0;
  54. }
  55. stock IsPlayerFacingVehicle(playerid,vehicleid)
  56. {
  57.  
  58.     new Float:pX,Float:pY,Float:pZ,Float:X,Float:Y,Float:Z,Float:ang;
  59.  
  60.     if(!IsPlayerConnected(playerid)) return 0;
  61.  
  62.     GetVehiclePos(vehicleid, X, Y, Z);
  63.     GetPlayerPos(playerid, pX, pY, pZ);
  64.  
  65.     if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  66.     else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
  67.     else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  68.  
  69.     if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
  70.     else ang = (floatabs(ang) - 180.0);
  71.     new Float:russia;
  72.     GetPlayerFacingAngle(playerid,russia);
  73.     if(ang-russia<-130 || ang-russia>130) return 0;
  74.     else return 1;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement