Advertisement
Guest User

Ingame anti aircraft launcher maker by Kurence

a guest
Mar 14th, 2010
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.80 KB | None | 0 0
  1. #include <a_samp>
  2. #define COLOR 0x00FF00FF
  3. #define RED 0xFF0000FF
  4. #define DISTANCESHOT 300
  5. #define EXPORADIUS 7
  6. #define MOVESPEED 70
  7. #define TIMERTIME 300
  8. stock SetObjectFaceToPlayer(objectid,playerid)
  9. {
  10. new Float:X[2], Float:Y[2], Float:Z;
  11. new Float:Angle;
  12.  
  13. GetObjectPos(objectid, X[0], Y[0], Z);
  14. GetPlayerPos(playerid, X[1], Y[1], Z);
  15.  
  16. if(X[0] > X[1] && Y[0] > Y[1]) Angle = floatabs(atan2(floatsub(X[1], X[0]), floatsub(Y[1], Y[0])));
  17. if(X[0] > X[1] && Y[0] <= Y[1]) Angle = floatabs(atan2(floatsub(Y[0], Y[1]), floatsub(X[1], X[0]))) + 270.0;
  18. if(X[0] <= X[1] && Y[0] > Y[1]) Angle = floatabs(atan2(floatsub(Y[1], Y[0]), floatsub(X[0], X[1]))) + 90.0;
  19. if(X[0] <= X[1] && Y[0] <= Y[1]) Angle = floatabs(atan2(floatsub(X[0], X[1]), floatsub(Y[0], Y[1]))) + 180.0;
  20. SetObjectRot(objectid,0,0,Angle);
  21. return 1;
  22. }
  23. stock Float:GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  24. {
  25.     new Float:a;
  26.     GetPlayerPos(playerid, x, y, a);
  27.     if (IsPlayerInAnyVehicle(playerid))
  28.         GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  29.     else
  30.         GetPlayerFacingAngle(playerid, a);
  31.     x += (distance * floatsin(-a, degrees));
  32.     y += (distance * floatcos(-a, degrees));
  33.     return a;
  34. }
  35. new flare[MAX_PLAYERS];
  36. new launcher[MAX_OBJECTS];
  37. new placed[MAX_OBJECTS];
  38. new placinglnchr[MAX_PLAYERS];
  39. new timer[MAX_PLAYERS];
  40. forward launch(playerid);
  41. forward flarekill(flare2,playerid);
  42. public OnPlayerConnect(playerid){
  43. placinglnchr[playerid] = -1;
  44. timer[playerid] = SetTimerEx("launch",TIMERTIME,1,"i",playerid);
  45. return 1;
  46. }
  47. public OnPlayerDisconnect(playerid){
  48. KillTimer(timer[playerid]);
  49. return 1;
  50. }
  51. public OnPlayerDeath(playerid){
  52. DestroyObject(flare[playerid]);
  53. return 1;
  54. }
  55. public OnFilterScriptInit(){
  56. print("In-game launcher creator by Kurence loaded");
  57. for(new i;i<MAX_OBJECTS;i++) launcher[i] = -1;
  58. }
  59. public OnPlayerCommandText(playerid,cmdtext[]){
  60. if(strcmp("/addlauncher",cmdtext,true) == 0){
  61. if(placinglnchr[playerid] != -1){
  62. new string[100];
  63. format(string,sizeof(string),"Launcher created, his ID: %d",placinglnchr[playerid]);
  64. SendClientMessage(playerid,COLOR,string);
  65. DestroyObject(launcher[placinglnchr[playerid]]);
  66. new Float:X,Float:Y,Float:Z,Float:angle;
  67. GetPlayerPos(playerid,X,Y,Z);
  68. GetXYInFrontOfPlayer(playerid,X,Y,10);
  69. GetPlayerFacingAngle(playerid,angle);
  70. launcher[placinglnchr[playerid]] = CreateObject(3267,X,Y,Z,0,0,angle);
  71. placed[placinglnchr[playerid]] = 1;
  72. placinglnchr[playerid] = -1;
  73. return 1;
  74. }
  75. new Float:X,Float:Y,Float:Z;
  76. GetPlayerPos(playerid,X,Y,Z);
  77. GetXYInFrontOfPlayer(playerid,X,Y,10);
  78. for(new i;i<MAX_OBJECTS;i++){
  79. if(launcher[i] == -1){
  80. launcher[i] = CreateObject(3267,X,Y,Z,0,0,0);
  81. AttachObjectToPlayer(launcher[i],playerid,0,10,0,0,0,0);
  82. SendClientMessage(playerid,COLOR,"Place the launcher where you want it and use ''/addlauncher'' again");
  83. placinglnchr[playerid] = i;
  84. break;
  85. }
  86. }
  87. return 1;
  88. }
  89. if(strcmp("/dellauncher",cmdtext,true) == 0){
  90. if(placinglnchr[playerid] != -1) return SendClientMessage(playerid,RED,"Place that launcher first");
  91. for(new i;i<MAX_OBJECTS;i++){
  92. if(launcher[i] != -1){
  93. new Float:X,Float:Y,Float:Z;
  94. GetObjectPos(launcher[i],X,Y,Z);
  95. if(IsPlayerInRangeOfPoint(playerid,10,X,Y,Z)){
  96. DestroyObject(launcher[i]);
  97. launcher[i] = -1;
  98. }
  99. }
  100. }
  101. return 1;
  102. }
  103. return 0;
  104. }
  105. public launch(playerid){
  106. new Float:X,Float:Y,Float:Z;
  107. new Model = GetVehicleModel(GetPlayerVehicleID(playerid));
  108. if (Model == 548 || Model == 417 || Model == 557 || Model == 476 || Model == 520 || Model == 563 || Model == 553 || Model == 519 || Model == 592 || Model == 577 || Model == 497 || Model == 464 || Model == 465 || Model == 511 || Model == 512 || Model == 593 || Model == 460 ||  Model == 513 || Model == 425 || Model == 487 || Model == 488 || Model == 447 || Model == 469 || Model == 501){
  109. if(IsValidObject(flare[playerid])){
  110. GetObjectPos(flare[playerid],X,Y,Z);
  111. if(IsPlayerInRangeOfPoint(playerid,EXPORADIUS,X,Y,Z)){
  112. CreateExplosion(X,Y,Z,7,25);
  113. DestroyObject(flare[playerid]);
  114. }
  115. else{
  116. GetPlayerPos(playerid,X,Y,Z);
  117. MoveObject(flare[playerid],X,Y,Z,MOVESPEED);
  118. }
  119. return 1;
  120. }
  121. for(new i;i<MAX_OBJECTS;i++){
  122. if(placed[i] != 1) return 0;
  123. new Float:pX,Float:pY,Float:pZ;
  124. if(launcher[i] != -1){
  125. SetObjectFaceToPlayer(launcher[i],playerid);
  126. GetObjectPos(launcher[i],X,Y,Z);
  127. GetPlayerPos(playerid,pX,pY,pZ);
  128. if(IsPlayerInRangeOfPoint(playerid,DISTANCESHOT,X,Y,Z)){
  129. flare[playerid] = CreateObject(354,X,Y,Z,0,0,0);
  130. MoveObject(flare[playerid],pX,pY,pZ,MOVESPEED);
  131. SetTimerEx("flarekill",30000,0,"ii",flare[playerid],playerid);
  132. return 1;
  133. }
  134. }
  135. }
  136. }
  137. else{
  138. CreateExplosion(X,Y,Z,7,25);
  139. DestroyObject(flare[playerid]);
  140. }
  141. return 1;
  142. }
  143. public flarekill(flare2,playerid){
  144. new Float:X,Float:Y,Float:Z;
  145. GetObjectPos(flare2,X,Y,Z);
  146. CreateExplosion(X,Y,Z,7,25);
  147. DestroyObject(flare2);
  148. }
  149. public OnPlayerKeyStateChange(playerid) launch(playerid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement