Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------*
- | Explosion System |
- |========================|
- | Author: Miguel C. |
- | Version: 0.1 |
- | Released: 26/11/2010 |
- *------------------------*/
- #define FILTERSCRIPT
- #include <a_samp>
- #include <zcmd>
- #include <foreach>
- #undef MAX_PLAYERS
- #define MAX_PLAYERS (500) // Change this to your server's max slots.
- #define MAX_PLAYER_CHARGES (32) // Change this to the player's max bombs.
- #define DEFAULT_TYPE (7) // Default explosion type.
- #define DEFAULT_RADIUS (25) // Default explosion radius.
- #define COLOR_INFO 0xFFFFFFFF
- #define COLOR_YELLOW 0xFFFF00FF
- #define COLOR_SUCCESS 0x008A00FF
- #define COLOR_WARNING 0xF07800FF
- #define COLOR_ERROR 0xCE0000FF
- enum
- PlayerInfo
- {
- bool:planting,
- bool:detonating,
- bool:settingup,
- used_charges,
- first_charge,
- explosion_type,
- Float:explosion_radius
- }
- enum
- ChargeInfo
- {
- user,
- Float:x,
- Float:y,
- Float:z
- }
- new
- Player[MAX_PLAYERS][PlayerInfo],
- Charge[MAX_PLAYERS * MAX_PLAYER_CHARGES][ChargeInfo];
- forward OnPlayerPlantBomb(playerid);
- main(){}
- public OnFilterScriptInit()
- {
- printf(" Explosion System v0.1 by Miguel loaded.");
- ResetChargesInfo();
- foreach(Player, i) ResetPlayerChargesInfo(i);
- return 1;
- }
- public OnFilterScriptExit()
- {
- printf(" Explosion System v0.1 by Miguel unloaded.");
- return 1;
- }
- public OnGameModeInit()
- {
- ResetChargesInfo();
- return 1;
- }
- public OnGameModeExit()
- {
- ResetChargesInfo();
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- ResetPlayerChargesInfo(playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- ResetPlayerChargesInfo(playerid);
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & KEY_FIRE)
- {
- if((Player[playerid][detonating] == true) && (IsPlayerInAnyVehicle(playerid)) && (Player[playerid][settingup] == false))
- {
- for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
- {
- CreateExplosion(Charge[i][x], Charge[i][y], Charge[i][z], Player[playerid][explosion_type], Player[playerid][explosion_radius]);
- Charge[i][x] = 0.0;
- Charge[i][y] = 0.0;
- Charge[i][z] = 0.0;
- Charge[i][user] = -1;
- }
- Player[playerid][detonating] = false;
- Player[playerid][used_charges] = 0;
- Player[playerid][first_charge] = -1;
- SendClientMessage(playerid, COLOR_SUCCESS, "* The bombs have been detonated!");
- }
- }
- if(newkeys & KEY_WALK)
- {
- if((Player[playerid][planting] == true) && (Player[playerid][settingup] == false))
- {
- if(Player[playerid][used_charges] < (MAX_PLAYER_CHARGES - 1))
- {
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][user] = playerid;
- GetPlayerPos(playerid,
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][x],
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][y],
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][z]);
- Player[playerid][settingup] = true;
- ApplyAnimation(playerid, "BOMBER", " ", 2.5, 0, 1, 1, 0, 0, 1);
- ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 2.5, 0, 1, 1, 0, 0, 1);
- SetTimerEx("OnPlayerPlantBomb", 2400, false, "ii", playerid, Player[playerid][first_charge] + Player[playerid][used_charges]);
- }
- else
- {
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][user] = playerid;
- GetPlayerPos(playerid,
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][x],
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][y],
- Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][z]);
- Player[playerid][planting] = false;
- Player[playerid][detonating] = true;
- Player[playerid][settingup] = true;
- ApplyAnimation(playerid, "BOMBER", " ", 2.5, 0, 1, 1, 0, 0, 1);
- ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 2.5, 0, 1, 1, 0, 0, 1);
- SetTimerEx("OnPlayerPlantBomb", 2400, false, "ii", playerid, Player[playerid][first_charge] + Player[playerid][used_charges]);
- }
- }
- else if((Player[playerid][detonating] == true) && (Player[playerid][settingup] == false))
- {
- for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
- {
- CreateExplosion(Charge[i][x], Charge[i][y], Charge[i][z], Player[playerid][explosion_type], Player[playerid][explosion_radius]);
- Charge[i][x] = 0.0;
- Charge[i][y] = 0.0;
- Charge[i][z] = 0.0;
- Charge[i][user] = -1;
- }
- Player[playerid][detonating] = false;
- Player[playerid][used_charges] = 0;
- Player[playerid][first_charge] = -1;
- SendClientMessage(playerid, COLOR_SUCCESS, "* The bombs have been detonated!");
- }
- }
- if(newkeys & KEY_SUBMISSION)
- {
- if((Player[playerid][detonating] == true) && (Player[playerid][settingup] == false))
- {
- for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
- {
- CreateExplosion(Charge[i][x], Charge[i][y], Charge[i][z], Player[playerid][explosion_type], Player[playerid][explosion_radius]);
- Charge[i][x] = 0.0;
- Charge[i][y] = 0.0;
- Charge[i][z] = 0.0;
- Charge[i][user] = -1;
- }
- Player[playerid][detonating] = false;
- Player[playerid][used_charges] = 0;
- Player[playerid][first_charge] = -1;
- SendClientMessage(playerid, COLOR_SUCCESS, "* The bombs have been detonated!");
- }
- }
- return 1;
- }
- public OnPlayerPlantBomb(playerid)
- {
- Player[playerid][used_charges] ++;
- SendClientMessage(playerid, COLOR_YELLOW, "* You have planted a bomb.");
- Player[playerid][settingup] = false;
- if(Player[playerid][used_charges] >= (MAX_PLAYER_CHARGES))
- {
- SendClientMessage(playerid, COLOR_SUCCESS, "* You are now detonating the bombs!");
- SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to detonate the bombs.");
- SendClientMessage(playerid, COLOR_INFO, "* If you are in a vehicle, you can alternatively use the sub-mission key.");
- }
- return 1;
- }
- CMD:e_help(playerid, params[])
- {
- SendClientMessage(playerid, COLOR_YELLOW, "* Explosion commands:");
- SendClientMessage(playerid, COLOR_INFO, " /plant, /detonate, /cancel, /radius, /type.");
- SendClientMessage(playerid, COLOR_ERROR, "* Usage:");
- SendClientMessage(playerid, COLOR_INFO, " Use /plant and press the walk key to plant a bomb. After you plant all the bombs you wanted,");
- SendClientMessage(playerid, COLOR_INFO, " type /detonate and press the walk key to activate the bombs. If you don't want to continue,");
- SendClientMessage(playerid, COLOR_INFO, " type /cancel, it will remove all the explosives and it will quit the detonation.");
- SendClientMessage(playerid, COLOR_INFO, " Use /radius to change your explosions radius and /type to change your explosions type.");
- return 1;
- }
- CMD:radius(playerid, params[])
- {
- if(isnull(params)) return SendClientMessage(playerid, COLOR_ERROR, "* Usage: /radius [value]");
- new
- string[47],
- Float:radius = floatstr(params);
- if((radius < 0.1) || (radius > 10000.0)) return SendClientMessage(playerid, COLOR_ERROR, "* The explosion radius has to be between 0.1 and 10000!");
- Player[playerid][explosion_radius] = radius;
- format(string, sizeof(string), "* You have set your explosions radius to %.01f", radius);
- SendClientMessage(playerid, COLOR_SUCCESS, string);
- return 1;
- }
- CMD:type(playerid, params[])
- {
- if(isnull(params)) return SendClientMessage(playerid, COLOR_ERROR, "* Usage: /type [value]");
- new
- string[42],
- type = strval(params);
- if((type < 0) || (type > 13)) return SendClientMessage(playerid, COLOR_ERROR, "* The explosion type has to be between 0 and 13!");
- Player[playerid][explosion_type] = type;
- format(string, sizeof(string), "* You have set your explosions type to %i", type);
- SendClientMessage(playerid, COLOR_SUCCESS, string);
- return 1;
- }
- CMD:plant(playerid, params[])
- {
- if(Player[playerid][planting] == true)
- {
- SendClientMessage(playerid, COLOR_ERROR, "* You are already planting the bombs!");
- SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to plant bombs.");
- }
- else if(Player[playerid][used_charges] >= (MAX_PLAYER_CHARGES))
- {
- SendClientMessage(playerid, COLOR_ERROR, "* You have already used all your bombs, now you have to detonate them!");
- SendClientMessage(playerid, COLOR_INFO, "* If you don't want to detonate them, type /cancel.");
- }
- else if(Player[playerid][detonating] == true)
- {
- Player[playerid][planting] = true;
- Player[playerid][detonating] = false;
- SendClientMessage(playerid, COLOR_SUCCESS, "* You are now planting more bombs.");
- }
- else
- {
- for(new i = 0; i < (MAX_PLAYERS * MAX_PLAYER_CHARGES); i += 32)
- {
- if(Charge[i][user] == -1)
- {
- Charge[i][user] = playerid;
- Player[playerid][first_charge] = i;
- break;
- }
- }
- Player[playerid][planting] = true;
- Player[playerid][detonating] = false;
- SendClientMessage(playerid, COLOR_SUCCESS, "* You are now planting bombs!");
- SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to plant bombs.");
- }
- return 1;
- }
- CMD:detonate(playerid, params[])
- {
- if(Player[playerid][detonating] == true) return SendClientMessage(playerid, COLOR_ERROR, "* You are already detonating the bombs!");
- else if(Player[playerid][used_charges] < 1)
- {
- SendClientMessage(playerid, COLOR_ERROR, "* You have not planted any bomb!");
- if(Player[playerid][planting] == false) return SendClientMessage(playerid, COLOR_INFO, "* If you want to start planting bombs, type /plant.");
- else return SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to plant bombs.");
- }
- else
- {
- Player[playerid][detonating] = true;
- Player[playerid][planting] = false;
- SendClientMessage(playerid, COLOR_SUCCESS, "* You are now detonating the bombs!");
- SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to detonate the bombs.");
- SendClientMessage(playerid, COLOR_INFO, "* If you are in a vehicle, you can alternatively use the sub-mission key.");
- }
- return 1;
- }
- CMD:cancel(playerid, params[])
- {
- if(Player[playerid][detonating] == false)
- {
- if(Player[playerid][planting] == false) return SendClientMessage(playerid, COLOR_ERROR, "* You are not even planting or detonating any bomb!");
- else
- {
- for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
- {
- Charge[i][x] = 0.0;
- Charge[i][y] = 0.0;
- Charge[i][z] = 0.0;
- Charge[i][user] = -1;
- }
- Player[playerid][first_charge] = -1;
- Player[playerid][used_charges] = 0;
- Player[playerid][planting] = false;
- SendClientMessage(playerid, COLOR_WARNING, "* You have cancelled the bombs planting!");
- }
- }
- else
- {
- for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
- {
- Charge[i][x] = 0.0;
- Charge[i][y] = 0.0;
- Charge[i][z] = 0.0;
- Charge[i][user] = -1;
- }
- Player[playerid][first_charge] = -1;
- Player[playerid][used_charges] = 0;
- Player[playerid][detonating] = false;
- SendClientMessage(playerid, COLOR_WARNING, "* You have cancelled the bombs detonation!");
- }
- return 1;
- }
- stock ResetPlayerChargesInfo(playerid)
- {
- for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
- {
- Charge[i][x] = 0.0;
- Charge[i][y] = 0.0;
- Charge[i][z] = 0.0;
- Charge[i][user] = -1;
- }
- Player[playerid][planting] = false;
- Player[playerid][detonating] = false;
- Player[playerid][settingup] = false;
- Player[playerid][used_charges] = 0;
- Player[playerid][first_charge] = -1;
- Player[playerid][explosion_type] = DEFAULT_TYPE;
- Player[playerid][explosion_radius] = DEFAULT_RADIUS;
- }
- stock ResetChargesInfo()
- {
- for(new i = 0; i < (MAX_PLAYERS * MAX_PLAYER_CHARGES); i ++)
- {
- Charge[i][x] = 0.0;
- Charge[i][y] = 0.0;
- Charge[i][z] = 0.0;
- Charge[i][user] = -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement