#include <a_samp>
new ObjectHP[MAX_OBJECTS];
//We've declared a variable called 'ObjectHP' for 1000 objects. (MAX_OBJECTS = 1000)
#define FILTERSCRIPT
#include <a_samp>
#define FILTERSCRIPT
#include <a_samp>
new ObjectHP[MAX_OBJECTS];
public OnFilterScriptInit()
{
//Let's loop through MAX_OBJECTS and reset their HP.
for(new i; i< MAX_OBJECTS; i++) ObjectHP[i] = 0;
/*What the above code does is, it loops till 1000 as MAX_OBJECT's value is 1000.
Basically it does:
ObjectHP[0] = 0;
ObjectHP[1] = 0;
ObjectHP[2] = 0;
...
ObjectHP[999] = 0; */
CreateObject(18848, 1450.59, -2446.57, 12.50, 0.00, 0.00, 0.00);
CreateObject(18848, 1442.11, -2444.87, 12.55, 0.00, 0.00, 0.00);
CreateObject(18848, 1461.18, -2446.89, 12.54, 0.00, 0.00, 0.00);
CreateObject(18848, 1457.31, -2430.67, 12.54, 0.00, 0.00, 0.00);
CreateObject(18848, 1449.48, -2430.51, 12.54, 0.00, 0.00, 0.00);
//I've created 5 objects which are S-A-M missile launchers (Unbreakable)
//Now, let me set their HP.
for(new i; i< MAX_OBJECTS; i++) { //Looping once again
if(!IsValidObject(i)) continue; /*If it's not a valid object, it skips that loop and jumps to next.
! being used before this function means if it returns a false statement.
*/
ObjectHP[i] = 100; //I'm setting every valid object's HP to 100 as this is a quicker way.
}
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
return 1;
#define BULLET_HIT_TYPE_NONE 0
#define BULLET_HIT_TYPE_PLAYER 1
#define BULLET_HIT_TYPE_VEHICLE 2
#define BULLET_HIT_TYPE_OBJECT 3
#define BULLET_HIT_TYPE_PLAYER_OBJECT 4
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
//We must know if the bullet hit type is related to object, so use an if statement and verify if it's hitting an object.
if(hittype == BULLET_HIT_TYPE_OBJECT) { //In case if player hits an object
if(IsValidObject(hitid)) { /*The callback may get called only if hitting valid objects, but still to verify much,
we can know if it's a valid object or not using 'IsValidObject'. Here, in case if it's a valid object, then:
We're gonna reduce it's HP. Reducing a custom value wouldn't seem to be good, so let's randomize the value.
Reducing also depends on the firerates, so if player got good firerates, reducing would go fastly.
*/
ObjectHP[hitid] -= random(10) + 1;
/*
Here, we're reducing the ObjectHP of the object ID which is called on this callback. It reduces from a
minimum of 1. random(max) means it will return any numbers starting from random to the max specified value.
I've added additional +1 to it because in case if 0 is the result, it sums up and doesn't result in 0.
Now, in case if object's HP goes at 0 or lower than that, we must destroy it. */
if(ObjectHP[hitid] <= 0) { //If objectHP of that object is either 0 or lower,:
DestroyObject(hitid);
}
}
}
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
//We must know if the bullet hit type is related to object, so use an if statement and verify if it's hitting an object.
if(hittype == BULLET_HIT_TYPE_OBJECT) { //In case if player hits an object
if(IsValidObject(hitid)) { /*The callback may get called only if hitting valid objects, but still to verify much,
we can know if it's a valid object or not using 'IsValidObject'. Here, in case if it's a valid object, then:
We're gonna reduce it's HP. Reducing a custom value wouldn't seem to be good, so let's randomize the value.
Reducing also depends on the firerates, so if player got good firerates, reducing would go fastly.
*/
ObjectHP[hitid] -= random(10) + 1;
/*
Here, we're reducing the ObjectHP of the object ID which is called on this callback. It reduces from a
minimum of 1. random(max) means it will return any numbers starting from random to the max specified value.
I've added additional +1 to it because in case if 0 is the result, it sums up and doesn't result in 0.
Now, in case if object's HP goes at 0 or lower than that, we must destroy it. */
if(ObjectHP[hitid] >= 0) { //If object's HP is either 0 or 1.
new str[128]; //We will need to declare a string to display the message.
//I'll be using GameTextForPlayer because if we're using SendClientMessage, it could always spam.
format(str, sizeof(str), "~G~OBJECT DAMAGED!~N~~Y~OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~ %d", hitid, ObjectHP[hitid]);
//I've formatted the string which includes the information of object id and it's HP left.
GameTextForPlayer(playerid, str, 1800, 3);
//I'm displaying the info to player. I'm using style '3' because it's the better one in case if this callback is being called at many times.
}
if(ObjectHP[hitid] <= 0) { //If objectHP of that object is either 0 or lower,:
DestroyObject(hitid);
}
}
}
return 1;
}
#define FILTERSCRIPT
#include <a_samp>
new ObjectHP[MAX_OBJECTS];
public OnFilterScriptInit()
{
//Let's loop through MAX_OBJECTS and reset their HP.
for(new i; i< MAX_OBJECTS; i++) ObjectHP[i] = 0;
/*What the above code does is, it loops till 1000 as MAX_OBJECT's value is 1000.
Basically it does:
ObjectHP[0] = 0;
ObjectHP[1] = 0;
ObjectHP[2] = 0;
...
ObjectHP[999] = 0; */
CreateObject(18848, 1450.59, -2446.57, 12.50, 0.00, 0.00, 0.00);
CreateObject(18848, 1442.11, -2444.87, 12.55, 0.00, 0.00, 0.00);
CreateObject(18848, 1461.18, -2446.89, 12.54, 0.00, 0.00, 0.00);
CreateObject(18848, 1457.31, -2430.67, 12.54, 0.00, 0.00, 0.00);
CreateObject(18848, 1449.48, -2430.51, 12.54, 0.00, 0.00, 0.00);
//I've created 5 objects which are S-A-M missile launchers (Unbreakable)
//Now, let me set their HP.
for(new i; i< MAX_OBJECTS; i++) { //Looping once again
if(!IsValidObject(i)) continue; /*If it's not a valid object, it skips that loop and jumps to next.
! being used before this function means if it returns a false statement.
*/
ObjectHP[i] = 100; //I'm setting every valid object's HP to 100 as this is a quicker way.
}
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
//We must know if the bullet hit type is related to object, so use an if statement and verify if it's hitting an object.
if(hittype == BULLET_HIT_TYPE_OBJECT) { //In case if player hits an object
if(IsValidObject(hitid)) { /*The callback may get called only if hitting valid objects, but still to verify much,
we can know if it's a valid object or not using 'IsValidObject'. Here, in case if it's a valid object, then:
We're gonna reduce it's HP. Reducing a custom value wouldn't seem to be good, so let's randomize the value.
Reducing also depends on the firerates, so if player got good firerates, reducing would go fastly.
*/
ObjectHP[hitid] -= random(10) + 1;
/*
Here, we're reducing the ObjectHP of the object ID which is called on this callback. It reduces from a
minimum of 1. random(max) means it will return any numbers starting from random to the max specified value.
I've added additional +1 to it because in case if 0 is the result, it sums up and doesn't result in 0.
Now, in case if object's HP goes at 0 or lower than that, we must destroy it. */
if(ObjectHP[hitid] >= 0) { //If object's HP is either 0 or 1.
new str[128]; //We will need to declare a string to display the message.
//I'll be using GameTextForPlayer because if we're using SendClientMessage, it could always spam.
format(str, sizeof(str), "~G~OBJECT DAMAGED!~N~~Y~OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~ %d", hitid, ObjectHP[hitid]);
//I've formatted the string which includes the information of object id and it's HP left.
GameTextForPlayer(playerid, str, 1800, 3);
//I'm displaying the info to player. I'm using style '3' because it's the better one in case if this callback is being called at many times.
}
if(ObjectHP[hitid] <= 0) { //If objectHP of that object is either 0 or lower,:
DestroyObject(hitid);
}
}
}
return 1;
}
#define FILTERSCRIPT
//This example is also a FS related example.
#include <a_samp>
new ObjectHP[MAX_OBJECTS];
new bool:ObjectDamage[MAX_OBJECTS]; //Let's create this as a boolean as there's only two statements to be declared.
//I'll be using it in a way as if the variable is true, it means the object is assigned to face damage, else not.
#define FILTERSCRIPT
#include <a_samp>
new ObjectHP[MAX_OBJECTS],
bool:ObjectDamage[MAX_OBJECTS];
public OnFilterScriptInit()
{
//Let's loop through MAX_OBJECTS and reset their HP.
for(new i; i< MAX_OBJECTS; i++) {
ObjectHP[i] = 0;
/*What the above code does is, it loops till 1000 as MAX_OBJECT's value is 1000.
Basically it does:
ObjectHP[0] = 0;
ObjectHP[1] = 0;
ObjectHP[2] = 0;
...
ObjectHP[999] = 0; */
//On the grouped method, I'm also resetting the assigned objects.
ObjectDamage[i] = false;
/* This performs in a loop in such a way that :
ObjectDamage[0] = false;
ObjectDamage[1] = false;
ObjectDamage[2] = false;
...
ObjectDamage[3] = false; */
}
/*
Now, these are the objects which requires to be assigned to face damage.
I'll retrieve the object IDs and assign those IDs to face damage.
I'm declaring an array to retrieve the object IDs.*/
new Object_ID[5]; //There's 5 objects, so size of 5.
Object_ID[0] = CreateObject(18848, 1450.59, -2446.57, 12.50, 0.00, 0.00, 0.00);
Object_ID[1] = CreateObject(18848, 1442.11, -2444.87, 12.55, 0.00, 0.00, 0.00);
Object_ID[2] = CreateObject(18848, 1461.18, -2446.89, 12.54, 0.00, 0.00, 0.00);
Object_ID[3] = CreateObject(18848, 1457.31, -2430.67, 12.54, 0.00, 0.00, 0.00);
Object_ID[4] = CreateObject(18848, 1449.48, -2430.51, 12.54, 0.00, 0.00, 0.00);
//I've created 5 objects which are S-A-M missile launchers (Unbreakable) and also grouped.
//Now, let me set their HP and assign them.
//This time, we'll set the HP only to the assigned ones.
//First of all, let me assign the ones.
for(new i; i< 5; i++) {
ObjectDamage[Object_ID[i]] = true; //The ObjectDamage boolean sets true to the object ids which have been retrieved.
/*Under loop, it does more faster and does in a way like this :
ObjectDamage[Object_ID[0]] = true;
ObjectDamage[Object_ID[1]] = true;
...
ObjectDamage[Object_ID[4]] = true; */
}
//Now just like I did before on the earlier method, I'm setting object's HP.
//But this time,I'm setting the HP of valid and assigned objects only.
for(new i; i< MAX_OBJECTS; i++) {
if(!IsValidObject(i)) continue; //Skips if it's not a valid object.
if(ObjectDamage[i] == false) continue; //If they're not assigned or not set to true, it will skip.
ObjectHP[i] = 100; //You can also change the HP rate according to the model ID of objects.
}
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
//We must know if the bullet hit type is related to object, so use an if statement and verify if it's hitting an object.
if(hittype == BULLET_HIT_TYPE_OBJECT) { //In case if player hits an object
if(IsValidObject(hitid)) { /*The callback may get called only if hitting valid objects, but still to verify much,
we can know if it's a valid object or not using 'IsValidObject'. Here, in case if it's a valid object, then:
We're gonna reduce it's HP. Reducing a custom value wouldn't seem to be good, so let's randomize the value.
Reducing also depends on the firerates, so if player got good firerates, reducing would go fastly.
*/
//This time, we're also looking if the object ID is assigned to true, else it won't get damaged!
if(ObjectDamage[hitid] == true) { //In case if it's assigned or true, it will damage.
ObjectHP[hitid] -= random(10) + 1;
/*
Here, we're reducing the ObjectHP of the object ID which is called on this callback. It reduces from a
minimum of 1. random(max) means it will return any numbers starting from random to the max specified value.
I've added additional +1 to it because in case if 0 is the result, it sums up and doesn't result in 0.
Now, in case if object's HP goes at 0 or lower than that, we must destroy it. */
if(ObjectHP[hitid] >= 0) { //If object's HP is either 0 or 1.
new str[128]; //We will need to declare a string to display the message.
//I'll be using GameTextForPlayer because if we're using SendClientMessage, it could always spam.
format(str, sizeof(str), "~G~OBJECT DAMAGED!~N~~Y~OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~ %d", hitid, ObjectHP[hitid]);
//I've formatted the string which includes the information of object id and it's HP left.
GameTextForPlayer(playerid, str, 1800, 3);
//I'm displaying the info to player. I'm using style '3' because it's the better one in case if this callback is being called at many times.
}
if(ObjectHP[hitid] <= 0) { //If objectHP of that object is either 0 or lower,:
DestroyObject(hitid);
}
}
}
}
return 1;
}
#define FILTERSCRIPT
#include <a_samp>
new ObjectHP[MAX_OBJECTS],
bool:ObjectDamage[MAX_OBJECTS];
public OnFilterScriptInit()
{
//Let's loop through MAX_OBJECTS and reset their HP.
for(new i; i< MAX_OBJECTS; i++) {
ObjectHP[i] = 0;
/*What the above code does is, it loops till 1000 as MAX_OBJECT's value is 1000.
Basically it does:
ObjectHP[0] = 0;
ObjectHP[1] = 0;
ObjectHP[2] = 0;
...
ObjectHP[999] = 0; */
//On the grouped method, I'm also resetting the assigned objects.
ObjectDamage[i] = false;
/* This performs in a loop in such a way that :
ObjectDamage[0] = false;
ObjectDamage[1] = false;
ObjectDamage[2] = false;
...
ObjectDamage[3] = false; */
}
/*
Now, these are the objects which requires to be assigned to face damage.
I'll retrieve the object IDs and assign those IDs to face damage.
I'm declaring an array to retrieve the object IDs.*/
new Object_ID[5]; //There's 5 objects, so size of 5.
Object_ID[0] = CreateObject(18848, 1450.59, -2446.57, 12.50, 0.00, 0.00, 0.00);
Object_ID[1] = CreateObject(18848, 1442.11, -2444.87, 12.55, 0.00, 0.00, 0.00);
Object_ID[2] = CreateObject(18848, 1461.18, -2446.89, 12.54, 0.00, 0.00, 0.00);
Object_ID[3] = CreateObject(18848, 1457.31, -2430.67, 12.54, 0.00, 0.00, 0.00);
Object_ID[4] = CreateObject(18848, 1449.48, -2430.51, 12.54, 0.00, 0.00, 0.00);
CreateObject(18848, 1486.46, -2439.21, 12.50, 0.00, 0.00, 0.00); //A normal object which isn't assigned to face damage.
//I've created 5 objects which are S-A-M missile launchers (Unbreakable) and also grouped.
//Now, let me set their HP and assign them.
//This time, we'll set the HP only to the assigned ones.
//First of all, let me assign the ones.
for(new i; i< 5; i++) {
ObjectDamage[Object_ID[i]] = true; //The ObjectDamage boolean sets true to the object ids which have been retrieved.
/*Under loop, it does more faster and does in a way like this :
ObjectDamage[Object_ID[0]] = true;
ObjectDamage[Object_ID[1]] = true;
...
ObjectDamage[Object_ID[4]] = true; */
}
//Now just like I did before on the earlier method, I'm setting object's HP.
//But this time,I'm setting the HP of valid and assigned objects only.
for(new i; i< MAX_OBJECTS; i++) {
if(!IsValidObject(i)) continue; //Skips if it's not a valid object.
if(ObjectDamage[i] == false) continue; //If they're not assigned or not set to true, it will skip.
ObjectHP[i] = 100; //You can also change the HP rate according to the model ID of objects.
}
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
//We must know if the bullet hit type is related to object, so use an if statement and verify if it's hitting an object.
if(hittype == BULLET_HIT_TYPE_OBJECT) { //In case if player hits an object
if(IsValidObject(hitid)) { /*The callback may get called only if hitting valid objects, but still to verify much,
we can know if it's a valid object or not using 'IsValidObject'. Here, in case if it's a valid object, then:
We're gonna reduce it's HP. Reducing a custom value wouldn't seem to be good, so let's randomize the value.
Reducing also depends on the firerates, so if player got good firerates, reducing would go fastly.
*/
//This time, we're also looking if the object ID is assigned to true, else it won't get damaged!
if(ObjectDamage[hitid] == true) { //In case if it's assigned or true, it will damage.
ObjectHP[hitid] -= random(10) + 1;
/*
Here, we're reducing the ObjectHP of the object ID which is called on this callback. It reduces from a
minimum of 1. random(max) means it will return any numbers starting from random to the max specified value.
I've added additional +1 to it because in case if 0 is the result, it sums up and doesn't result in 0.
Now, in case if object's HP goes at 0 or lower than that, we must destroy it. */
if(ObjectHP[hitid] >= 0) { //If object's HP is either 0 or 1.
new str[128]; //We will need to declare a string to display the message.
//I'll be using GameTextForPlayer because if we're using SendClientMessage, it could always spam.
format(str, sizeof(str), "~G~OBJECT DAMAGED!~N~~Y~OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~ %d", hitid, ObjectHP[hitid]);
//I've formatted the string which includes the information of object id and it's HP left.
GameTextForPlayer(playerid, str, 1800, 3);
//I'm displaying the info to player. I'm using style '3' because it's the better one in case if this callback is being called at many times.
}
if(ObjectHP[hitid] <= 0) { //If objectHP of that object is either 0 or lower,:
DestroyObject(hitid);
}
}
}
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/ls")) return SetPlayerPos(playerid,1450.59, -2446.57, 12.50+5.0);
return 0;
}
#define FILTERSCRIPT
#include <a_samp>
new PlayerObjectHP[MAX_PLAYERS][MAX_OBJECTS];
//It's a player object, so it needs an extra slot for storing player ID too. And hence, it's a 2D array.
new bool:PlayerObjectDamage[MAX_PLAYERS][MAX_OBJECTS];
//Just like I declared PlayerObjectHP, I'm declaring the group assigning variable too.
#define FILTERSCRIPT
#include <a_samp>
new PlayerObjectHP[MAX_PLAYERS][MAX_OBJECTS];
//It's a player object, so it needs an extra slot for storing player ID too. And hence, it's a 2D array.
new bool:PlayerObjectDamage[MAX_PLAYERS][MAX_OBJECTS];
//Just like I declared PlayerObjectHP, I'm declaring the group assigning variable too.
new p_OBJECTS[MAX_PLAYERS][5]; //Another 2D array to retrieve player's OBJECT ID. This is also used to destroy the object in case if it's alive when player disconnects.
new p_NODAMAGE[MAX_PLAYERS]; //This variable is to store the object which don't face damages. Why I'm declaring this is because I need to destroy this when player leaves.
public OnPlayerSpawn(playerid)
{
p_OBJECTS[playerid][0] = CreatePlayerObject(playerid, 18848, 1450.59, -2446.57, 12.50, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][1] = CreatePlayerObject(playerid, 18848, 1442.11, -2444.87, 12.55, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][2] = CreatePlayerObject(playerid, 18848, 1461.18, -2446.89, 12.54, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][3] = CreatePlayerObject(playerid, 18848, 1457.31, -2430.67, 12.54, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][4] = CreatePlayerObject(playerid, 18848, 1449.48, -2430.51, 12.54, 0.00, 0.00, 0.00);
p_NODAMAGE[playerid] = CreatePlayerObject(playerid, 18848, 1486.46, -2439.21, 12.50, 0.00, 0.00, 0.00);
//Now I've retrieved these created object's ID on these variables.
//The ones stored on p_OBJECTS are to be assigned to get damaged and the p_NODAMAGE won't get any damages.
//Just like I've done to global ones, here also I'm doing a loop and assigning these player objects to face damage.
for(new i; i< 5; i++) {
PlayerObjectDamage[playerid][p_OBJECTS[playerid][i]] = true; //It sets the assigned player object IDs to true so that it'll receive damages.
}
//Another loop in setting the player object's HP.
for(new i; i< MAX_OBJECTS; i++) {
if(!IsValidPlayerObject(playerid, i)) continue;
/* IsValidPlayerObject checks if it's a valid player-object for the specified player ID. I'm skipping the -
loop value in case if it's returning false.
*/
PlayerObjectHP[playerid][i] = 100; //Sets the player-object's HP to 100.
}
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(hittype == BULLET_HIT_TYPE_PLAYER_OBJECT) { //In case if player is shooting at a player object.
if(IsValidPlayerObject(playerid, hitid)) { //If the called player-object is valid for the player, then:
if(PlayerObjectDamage[playerid][hitid] == true) { //If the player's object ID is assigned to take damage, then:
//Now just like I've done to global objects, I'm once again reducing these object's HP randomly.
PlayerObjectHP[playerid][hitid] -= random(10) + 1;
if(PlayerObjectHP[playerid][hitid] >= 0) { //If the Player's Object's HP is either 0 or more;
new str[128]; //This concept isn't actually needed, however it's to show info of the damage.
//And yes, we're declaring a string variable to format it with the specifiers.
format(str, sizeof(str), "~G~DAMAGE DONE!~N~~Y~PLAYER OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~ %d", hitid, PlayerObjectHP[playerid][hitid]);
GameTextForPlayer(playerid, str, 1800, 3);
}
if(PlayerObjectHP[playerid][hitid] <= 0) { //If the HP goes to 0 or goes lesser than 0;
DestroyPlayerObject(playerid, hitid); //We're destroying the PLAYER's OBJECT then, not a global one.
}
}
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
//We'll loop through every objects at first.
for(new i; i< MAX_OBJECTS; i++) {
//Then, we'll see if it's a player object or not.
if(!IsValidPlayerObject(playerid, i)) continue; //If it's not a valid player object, it will skip that loop value.
DestroyPlayerObject(playerid, i); //In case if there's any player objects, it will be destroying them.
}
return 1;
}
#define FILTERSCRIPT
#include <a_samp>
new PlayerObjectHP[MAX_PLAYERS][MAX_OBJECTS];
//It's a player object, so it needs an extra slot for storing player ID too. And hence, it's a 2D array.
new bool:PlayerObjectDamage[MAX_PLAYERS][MAX_OBJECTS];
//Just like I declared PlayerObjectHP, I'm declaring the group assigning variable too.
new p_OBJECTS[MAX_PLAYERS][5]; //Another 2D array to retrieve player's OBJECT ID. This is also used to destroy the object in case if it's alive when player disconnects.
new p_NODAMAGE[MAX_PLAYERS]; //This variable is to store the object which don't face damages. Why I'm declaring this is because I need to destroy this when player leaves.
public OnPlayerSpawn(playerid)
{
p_OBJECTS[playerid][0] = CreatePlayerObject(playerid, 18848, 1450.59, -2446.57, 12.50, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][1] = CreatePlayerObject(playerid, 18848, 1442.11, -2444.87, 12.55, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][2] = CreatePlayerObject(playerid, 18848, 1461.18, -2446.89, 12.54, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][3] = CreatePlayerObject(playerid, 18848, 1457.31, -2430.67, 12.54, 0.00, 0.00, 0.00);
p_OBJECTS[playerid][4] = CreatePlayerObject(playerid, 18848, 1449.48, -2430.51, 12.54, 0.00, 0.00, 0.00);
p_NODAMAGE[playerid] = CreatePlayerObject(playerid, 18848, 1486.46, -2439.21, 12.50, 0.00, 0.00, 0.00);
//Now I've retrieved these created object's ID on these variables.
//The ones stored on p_OBJECTS are to be assigned to get damaged and the p_NODAMAGE won't get any damages.
//Just like I've done to global ones, here also I'm doing a loop and assigning these player objects to face damage.
for(new i; i< 5; i++) {
PlayerObjectDamage[playerid][p_OBJECTS[playerid][i]] = true; //It sets the assigned player object IDs to true so that it'll receive damages.
}
//Another loop in setting the player object's HP.
for(new i; i< MAX_OBJECTS; i++) {
if(!IsValidPlayerObject(playerid, i)) continue;
/* IsValidPlayerObject checks if it's a valid player-object for the specified player ID. I'm skipping the -
loop value in case if it's returning false.
*/
PlayerObjectHP[playerid][i] = 100; //Sets the player-object's HP to 100.
}
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(hittype == BULLET_HIT_TYPE_PLAYER_OBJECT) { //In case if player is shooting at a player object.
if(IsValidPlayerObject(playerid, hitid)) { //If the called player-object is valid for the player, then:
if(PlayerObjectDamage[playerid][hitid] == true) { //If the player's object ID is assigned to take damage, then:
//Now just like I've done to global objects, I'm once again reducing these object's HP randomly.
PlayerObjectHP[playerid][hitid] -= random(10) + 1;
if(PlayerObjectHP[playerid][hitid] >= 0) { //If the Player's Object's HP is either 0 or more;
new str[128]; //This concept isn't actually needed, however it's to show info of the damage.
//And yes, we're declaring a string variable to format it with the specifiers.
format(str, sizeof(str), "~G~DAMAGE DONE!~N~~Y~PLAYER OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~ %d", hitid, PlayerObjectHP[playerid][hitid]);
GameTextForPlayer(playerid, str, 1800, 3);
}
if(PlayerObjectHP[playerid][hitid] <= 0) { //If the HP goes to 0 or goes lesser than 0;
DestroyPlayerObject(playerid, hitid); //We're destroying the PLAYER's OBJECT then, not a global one.
}
}
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
//We'll loop through every objects at first.
for(new i; i< MAX_OBJECTS; i++) {
//Then, we'll see if it's a player object or not.
if(!IsValidPlayerObject(playerid, i)) continue; //If it's not a valid player object, it will skip that loop value.
DestroyPlayerObject(playerid, i); //In case if there's any player objects, it will be destroying them.
}
return 1;
}
public OnPlayerShootDynamicObject(playerid, weaponid, objectid, Float:x, Float:y, Float:z)
{
//objectid returns the object which has received shot!
if(IsValidDynamicObject(objectid)) { //Dynamic objects can be known by "IsValidDynamicObject", per-player objects too include these.
if(PlayerObjectDamage[playerid][objectid] == true) { //If the player's object ID is assigned to take damage, then:
//Now just like I've done to global objects, I'm once again reducing these object's HP randomly.
PlayerObjectHP[playerid][objectid] -= random(10) + 1;
if(PlayerObjectHP[playerid][objectid] >= 0) { //If the Player's Object's HP is either 0 or more;
new str[128]; //This concept isn't actually needed, however it's to show info of the damage.
//And yes, we're declaring a string variable to format it with the specifiers.
format(str, sizeof(str), "~G~DAMAGE DONE!~N~~Y~PLAYER OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~ %d", hitid, PlayerObjectHP[playerid][hitid]);
GameTextForPlayer(playerid, str, 1800, 3);
}
if(PlayerObjectHP[playerid][objectid] <= 0) { //If the HP goes to 0 or goes lesser than 0;
DestroyDynamicObject(objectid); //We're destroying the PLAYER's OBJECT then, not a global one.
}
}
}
}
return 1;
}
Thanks everyone.
@davve95, I've done the video and here's it. http://www.youtube.com/watch?v=Vu1hL24dFWc |
Thanks!, looks good.
You could create another object on it so it looks damaged. Or rotate the object so it looks like it felt down of damage. And/or also a applying texture that looks damaged like a black one so it looks it has been exploded or something etc.. Pretty hard to explain but I hope u get it. |
Could you add a part that you can destroy a certain object, not a whole map?
|
wow this is awesome this can be used to create training objects like in ammu nation in singleplayer!
Rep+ |
You should have read the whole tutorial, I've explained those on the part "Grouped Objects" which clearly shows that it doesn't destroy a whole map and allows damaging certain ones only.
@BlueSky_, I will be doing that soon, thank you for suggesting. |