Advertisement
ulfricmalcom

Random explosion generator

Nov 16th, 2012
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.42 KB | None | 0 0
  1. /* Known Issue: two points can't be too close. (At least 5 unit apart, or else why do you even use this lol?)*/
  2.  
  3. #define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6.  
  7. #define cYellow 0xFFFF00AA
  8. #define cWhite 0xFFFFFFAA
  9.  
  10. new explosionTimer = -1;
  11. enum pPos
  12. {
  13.     Float: pX,
  14.     Float: pY,
  15.     Float: pZ
  16. }
  17. new planePos[2][pPos];
  18. new explosionSize;
  19.  
  20. public OnFilterScriptInit()
  21. {
  22.     print("\n--------------------------------------");
  23.     print(" Random explosion generator by Nordic");
  24.     print("--------------------------------------\n");
  25.     return 1;
  26. }
  27.  
  28. public OnFilterScriptExit()
  29. {
  30.     KillTimer(explosionTimer);
  31.     return 1;
  32. }
  33.  
  34. public OnPlayerCommandText(playerid, cmdtext[])
  35. {
  36.     new cmd[128], index, string[128];
  37.     cmd = strtok(cmdtext, index);
  38.     if (strcmp("/setpos", cmd, true) == 0)
  39.     {
  40.         new tmp[128];
  41.         tmp = strtok(cmdtext, index);
  42.         if(!strlen(tmp)) return SendClientMessage(playerid, cYellow, "/setpos [pos number] 1 or 2");
  43.         new pos = strval(tmp);
  44.         new Float: x, Float: y, Float: z;
  45.         GetPlayerPos(playerid, x, y, z);
  46.         if(pos == 1)
  47.         {
  48.             planePos[0][pX] = x;
  49.             planePos[0][pY] = y;
  50.             planePos[0][pZ] = z;
  51.             format(string, sizeof(string), "Point 1 has been set to X: %f Y: %f", planePos[0][pX], planePos[0][pY]);
  52.         }
  53.         else
  54.         {
  55.             planePos[1][pX] = x;
  56.             planePos[1][pY] = y;
  57.             planePos[1][pZ] = z;
  58.             format(string, sizeof(string), "Point 2 has been set to X: %f Y: %f", planePos[1][pX], planePos[1][pY]);
  59.         }
  60.         SendClientMessage(playerid, cWhite, string);
  61.         evaluateHeight(playerid);
  62.         explosionSize = evaluateSize();
  63.         if(explosionSize == 7) SendClientMessage(playerid, cYellow, "Area might be too big!");
  64.         return 1;
  65.     }
  66.     if(strcmp("/explode", cmd, true) == 0)
  67.     {
  68.         if(explosionTimer == -1)
  69.         {
  70.             new tmp[128], interval;
  71.             tmp = strtok(cmdtext, index);
  72.             if(!strlen(tmp)) return SendClientMessage(playerid, cYellow, "/explode [interval] (Millisecond)");
  73.             interval = strval(tmp);
  74.             new Float: passZ;
  75.             passZ = floatabs(floatdiv( (planePos[0][pZ] + planePos[1][pZ]) , 2.0));
  76.             explosionTimer = SetTimerEx("generateExplosion", interval, true, "f", passZ);
  77.         }
  78.         else
  79.         {
  80.             KillTimer(explosionTimer);
  81.             explosionTimer = -1;
  82.             SendClientMessage(playerid, cYellow, "Explosions stopped.");
  83.         }
  84.         return 1;
  85.     }
  86.     return 0;
  87. }
  88.  
  89. forward generateExplosion(Float: valZ);
  90. public generateExplosion(Float: valZ)
  91. {
  92.     new Float: genX, Float: genY, string[128], negDebug;
  93.    
  94.     negDebug = floatround(   floatsub(planePos[1][pX], planePos[0][pX]), floatround_round);
  95.     if(negDebug < 0)
  96.     {
  97.         new newRand;
  98.         negDebug = negDebug * -1;
  99.         newRand = random(negDebug);
  100.         newRand = newRand * -1;
  101.         genX = float( newRand + floatround(planePos[0][pX], floatround_round));
  102.     }
  103.     else genX = float( random(negDebug) + floatround(planePos[0][pX], floatround_round));
  104.    
  105.     negDebug = floatround(   floatsub(planePos[1][pY], planePos[0][pY]), floatround_round);
  106.     if(negDebug < 0)
  107.     {
  108.         new newRand;
  109.         negDebug = negDebug * -1;
  110.         newRand = random(negDebug);
  111.         newRand = newRand * -1;
  112.         genY = float( newRand + floatround(planePos[0][pY], floatround_round));
  113.     }
  114.     else genY = float( random(negDebug) + floatround(planePos[0][pY], floatround_round));
  115.  
  116.     CreateExplosion(genX, genY, valZ, 10, 1.0);
  117.     format(string, sizeof(string), "X : %f Y: %f Z: %f", genX, genY, valZ);
  118.     SendClientMessageToAll(cWhite, string);
  119. }
  120. evaluateSize()
  121. {
  122.     new Float: distance;
  123.     distance = floatsqroot(floatpower( (planePos[1][pX] - planePos[0][pX]) , 2.0) + floatpower( (planePos[1][pY] - planePos[0][pY]) , 2.0 ));
  124.     if(distance < 50.0) return 11;
  125.     else if(distance < 100.0) return 10;
  126.     else if(distance < 150.0) return 6;
  127.     else return 7;
  128. }
  129. evaluateHeight(playerid)
  130. {
  131.     new Float: diff, string[128];
  132.     diff = planePos[0][pZ] - planePos[1][pZ];
  133.     if(floatabs(diff) > 20)
  134.     {
  135.         format(string, sizeof(string), "To get the best effect, the difference in height should be 0, current diffrence: %f", floatabs(diff));
  136.         SendClientMessage(playerid, cYellow, string);
  137.     }
  138. }
  139.  
  140. // credit to DracoBlue
  141. strtok(const string[], &index)
  142. {
  143.     new length = strlen(string);
  144.     while ((index < length) && (string[index] <= ' '))
  145.     {
  146.         index++;
  147.     }
  148.  
  149.     new offset = index;
  150.     new result[20];
  151.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  152.     {
  153.         result[index - offset] = string[index];
  154.         index++;
  155.     }
  156.     result[index - offset] = EOS;
  157.     return result;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement