Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Known Issue: two points can't be too close. (At least 5 unit apart, or else why do you even use this lol?)*/
- #define FILTERSCRIPT
- #include <a_samp>
- #define cYellow 0xFFFF00AA
- #define cWhite 0xFFFFFFAA
- new explosionTimer = -1;
- enum pPos
- {
- Float: pX,
- Float: pY,
- Float: pZ
- }
- new planePos[2][pPos];
- new explosionSize;
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" Random explosion generator by Nordic");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- KillTimer(explosionTimer);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[128], index, string[128];
- cmd = strtok(cmdtext, index);
- if (strcmp("/setpos", cmd, true) == 0)
- {
- new tmp[128];
- tmp = strtok(cmdtext, index);
- if(!strlen(tmp)) return SendClientMessage(playerid, cYellow, "/setpos [pos number] 1 or 2");
- new pos = strval(tmp);
- new Float: x, Float: y, Float: z;
- GetPlayerPos(playerid, x, y, z);
- if(pos == 1)
- {
- planePos[0][pX] = x;
- planePos[0][pY] = y;
- planePos[0][pZ] = z;
- format(string, sizeof(string), "Point 1 has been set to X: %f Y: %f", planePos[0][pX], planePos[0][pY]);
- }
- else
- {
- planePos[1][pX] = x;
- planePos[1][pY] = y;
- planePos[1][pZ] = z;
- format(string, sizeof(string), "Point 2 has been set to X: %f Y: %f", planePos[1][pX], planePos[1][pY]);
- }
- SendClientMessage(playerid, cWhite, string);
- evaluateHeight(playerid);
- explosionSize = evaluateSize();
- if(explosionSize == 7) SendClientMessage(playerid, cYellow, "Area might be too big!");
- return 1;
- }
- if(strcmp("/explode", cmd, true) == 0)
- {
- if(explosionTimer == -1)
- {
- new tmp[128], interval;
- tmp = strtok(cmdtext, index);
- if(!strlen(tmp)) return SendClientMessage(playerid, cYellow, "/explode [interval] (Millisecond)");
- interval = strval(tmp);
- new Float: passZ;
- passZ = floatabs(floatdiv( (planePos[0][pZ] + planePos[1][pZ]) , 2.0));
- explosionTimer = SetTimerEx("generateExplosion", interval, true, "f", passZ);
- }
- else
- {
- KillTimer(explosionTimer);
- explosionTimer = -1;
- SendClientMessage(playerid, cYellow, "Explosions stopped.");
- }
- return 1;
- }
- return 0;
- }
- forward generateExplosion(Float: valZ);
- public generateExplosion(Float: valZ)
- {
- new Float: genX, Float: genY, string[128], negDebug;
- negDebug = floatround( floatsub(planePos[1][pX], planePos[0][pX]), floatround_round);
- if(negDebug < 0)
- {
- new newRand;
- negDebug = negDebug * -1;
- newRand = random(negDebug);
- newRand = newRand * -1;
- genX = float( newRand + floatround(planePos[0][pX], floatround_round));
- }
- else genX = float( random(negDebug) + floatround(planePos[0][pX], floatround_round));
- negDebug = floatround( floatsub(planePos[1][pY], planePos[0][pY]), floatround_round);
- if(negDebug < 0)
- {
- new newRand;
- negDebug = negDebug * -1;
- newRand = random(negDebug);
- newRand = newRand * -1;
- genY = float( newRand + floatround(planePos[0][pY], floatround_round));
- }
- else genY = float( random(negDebug) + floatround(planePos[0][pY], floatround_round));
- CreateExplosion(genX, genY, valZ, 10, 1.0);
- format(string, sizeof(string), "X : %f Y: %f Z: %f", genX, genY, valZ);
- SendClientMessageToAll(cWhite, string);
- }
- evaluateSize()
- {
- new Float: distance;
- distance = floatsqroot(floatpower( (planePos[1][pX] - planePos[0][pX]) , 2.0) + floatpower( (planePos[1][pY] - planePos[0][pY]) , 2.0 ));
- if(distance < 50.0) return 11;
- else if(distance < 100.0) return 10;
- else if(distance < 150.0) return 6;
- else return 7;
- }
- evaluateHeight(playerid)
- {
- new Float: diff, string[128];
- diff = planePos[0][pZ] - planePos[1][pZ];
- if(floatabs(diff) > 20)
- {
- format(string, sizeof(string), "To get the best effect, the difference in height should be 0, current diffrence: %f", floatabs(diff));
- SendClientMessage(playerid, cYellow, string);
- }
- }
- // credit to DracoBlue
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement