SA-MP Forums Archive
Urgent help with bombing system. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Urgent help with bombing system. (/showthread.php?tid=615872)



Urgent help with bombing system. - DeeadPool - 28.08.2016

Hello all, I created a bombing system ( which works fine.) but, the problem is that when the player dies(the one who is planting the bomb) while planting the bomb, the bomb shall not get planted, but it does not happen like that and still the bomb get planted.

Here is my code:-
PHP код:
if(PRESSED(KEY_WALK))
   {
      if(
IsPlayerInRangeOfPoint(playerid1.5276.76434050.377928.5322))
         {
            if(
HUnderBomb[CASTLE] == && gTeam[playerid] == TEAM_DEFENDERS) return SendClientMessage(playeridCOLOR_RED"There is no bomb planted yet!");
            if(
HBombed[CASTLE] == && gTeam[playerid] == TEAM_ATTACKERS) return SendClientMessage(playeridCOLOR_RED"This area has already been bombed by someone!");
            if(
HUnderBomb[CASTLE] == && gTeam[playerid] == TEAM_ATTACKERS) return SendClientMessage(playeridCOLOR_RED"The area is already underbomb!");
            if(
IsPlayerInAnyVehicle(playerid) && gTeam[playerid] == TEAM_DEFENDERS) return SendClientMessage(playeridCOLOR_RED"You can not defuse the bomb while you are in a vehicle");
            if(
IsPlayerInAnyVehicle(playerid) && gTeam[playerid] == TEAM_ATTACKERS) return SendClientMessage(playeridCOLOR_RED"You can not plant a bomb while you are in a vehicle!");
            if(
gTeam[playerid] == TEAM_ATTACKERS && HBombed[CASTLE] == 0)
               {
                  
HIsPlayerBombing[playerid][CASTLE] = 1;
                  
HBombed[CASTLE] = 0;
                  
HUnderBomb[CASTLE] = 0;
                  
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Planting...");
                  
Timer[castle1] = SetTimerEx("castlebomb"1000false"i"playerid);
                  
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
               }
            if(
gTeam[playerid] == TEAM_DEFENDERS && HUnderBomb[CASTLE] == 1)
               {
                  
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Defusing...");
                  
HIsPlayerBombing[playerid][CASTLE] = 1;
                  
HUnderBomb[CASTLE] = 1;
                  
Timer[castled1] = SetTimerEx("castledefusebomb"1000false"i"playerid);
                  
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
               }
         }
    } 
The timer:-
PHP код:
forward castlebomb(playerid);
public 
castlebomb(playerid)
{
   
KillTimer(Timer[castle1]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Planting...");
   
Timer[castle2] = SetTimerEx("castlebomb2"1000false"i"playerid);
   
HBombed[CASTLE] = 0;
   
HIsPlayerBombing[playerid][CASTLE] = 1;
   
HUnderBomb[CASTLE] = 1;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   return 
1;
}
forward castlebomb2(playerid);
public 
castlebomb2(playerid)
{
   
KillTimer(Timer[castle2]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Planting...");
   
Timer[castle3] = SetTimerEx("castlebomb3"1000false"i"playerid);
   
HBombed[CASTLE] = 0;
   
HIsPlayerBombing[playerid][CASTLE] = 1;
   
HUnderBomb[CASTLE] = 1;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   return 
1;
}
forward castlebomb3(playerid);
public 
castlebomb3(playerid)
{
   
KillTimer(Timer[castle3]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Planting...");
   
Timer[castle4] = SetTimerEx("castlebomb4"1000false"i"playerid);
   
HBombed[CASTLE] = 0;
   
HIsPlayerBombing[playerid][CASTLE] = 1;
   
HUnderBomb[CASTLE] = 1;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   return 
1;
}
forward castlebomb4(playerid);
public 
castlebomb4(playerid)
{
   
KillTimer(Timer[castle4]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Planting...");
   
SendClientMessage(playeridCOLOR_WHITE"Bomb plant successful!");
   
HTimer[CASTLE] = SetTimerEx("explodecastle"120000false"i"playerid);
   
HBombed[CASTLE] = 0;
   
HIsPlayerBombing[playerid][CASTLE] = 0;
   
HUnderBomb[CASTLE] = 1;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   
SendClientMessageToAll(COLOR_ORANGE"[BOMB]: {FFFFFF}Bomb has been planted at {FF0000}'The Castle'{FFFFFF}. Defenders go defuse it before it's to late!");
   for(new 
0MAX_PLAYERSi++)
   {
     
PlayAudioStreamForPlayer(i"http://k003.kiwi6.com/hotlink/eg5ozskbs1/10*******.com_Bomb-Has-Been-Planted-Sound-Effect-CSGO_llCmtgvIqcY.mp3");
   }
   return 
1;
}
forward explodecastle(playerid);
public 
explodecastle(playerid)
{
   
KillTimer(HTimer[CASTLE]);
   
HBombed[CASTLE] = 1;
   
HtCB[CASTLE] = gTeam[playerid];
   
HUnderBomb[CASTLE] = 0;
   
CreateExplosion(276.76434050.377928.5322040.0);
   
SendClientMessage(playeridCOLOR_YELLOW"You have earned +10 score and $20000 from successfully detonating the bomb!");
   
SendClientMessageToAll(COLOR_ORANGE"[BOMB]:{FFFFFF} The bomb successfully exploded at {FF0000}'The Castle'{FFFFFF}. Good Job Attackers!");
   
GivePlayerMoney(playerid20000);
   
SetPlayerScore(playeridGetPlayerScore(playerid)+10);
   return 
1;
}
forward castledefusebomb(playerid);
public 
castledefusebomb(playerid)
{
   if(
HBombed[CASTLE] == 1) return SendClientMessage(playeridCOLOR_GREY"You failed to defuse the bomb.");
   
KillTimer(Timer[castled1]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Defusing...");
   
Timer[castled2] = SetTimerEx("castledefusebomb2"1000false"i"playerid);
   
HIsPlayerBombing[playerid][CASTLE] = 1;
   
HUnderBomb[CASTLE] = 1;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   return 
1;
}
forward castledefusebomb2(playerid);
public 
castledefusebomb2(playerid)
{
   if(
HBombed[CASTLE] == 1) return SendClientMessage(playeridCOLOR_GREY"You failed to defuse the bomb.");
   
KillTimer(Timer[castled2]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Defusing...");
   
Timer[castled3] = SetTimerEx("castledefusebomb3"1000false"i"playerid);
   
HIsPlayerBombing[playerid][CASTLE] = 1;
   
HUnderBomb[CASTLE] = 1;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   return 
1;
}
forward castledefusebomb3(playerid);
public 
castledefusebomb3(playerid)
{
   if(
HBombed[CASTLE] == 1) return SendClientMessage(playeridCOLOR_GREY"You failed to defuse the bomb.");
   
KillTimer(Timer[castled3]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Defusing...");
   
Timer[castled4] = SetTimerEx("castledefusebomb4"1000false"i"playerid);
   
HIsPlayerBombing[playerid][CASTLE] = 1;
   
HUnderBomb[CASTLE] = 1;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   return 
1;
}
forward castledefusebomb4(playerid);
public 
castledefusebomb4(playerid)
{
   if(
HBombed[CASTLE] == 1) return SendClientMessage(playeridCOLOR_GREY"You failed to defuse the bomb.");
   new 
String[256];
   
KillTimer(Timer[castled4]);
   
KillTimer(HTimer[CASTLE]);
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Defusing...");
   
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Bomb defusion successful!");
   
format(Stringsizeof(String), "%s has earned {FF0000}+5 score{FFFFFF} and {FF0000}$10000{FFFFFF} for defusing{FFFFFF} the bomb!"PlayerName(playerid));
   
SendClientMessageToAll(-1String);
   
SendClientMessage(playerid, -1"You have earned +5 score and $10000 for defusing the bomb.");
   
HIsPlayerBombing[playerid][CASTLE] = 0;
   
HUnderBomb[CASTLE] = 0;
   
HBombed[CASTLE] = 0;
   
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
   return 
1;
}
stock DBombCanceled(playerid)
{
KillTimer(HTimer[CASTLE]);
KillTimer(Timer[castled1]);
KillTimer(Timer[castled2]);
KillTimer(Timer[castled3]);
KillTimer(Timer[castled4]);
HIsPlayerBombing[playerid][CASTLE] = 0;
SendClientMessage(playeridCOLOR_GREY"You have failed to defuse this zone!");

OnPlayerDeath:-
PHP код:
if(HIsPlayerBombing[playerid][CASTLE] == && gTeam[playerid] == TEAM_ATTACKERS)
{
KillTimer(HTimer[CASTLE]);
KillTimer(Timer[castle1]);
KillTimer(Timer[castle2]);
KillTimer(Timer[castle3]);
KillTimer(Timer[castle4]);
HBombed[CASTLE] = 0;
HIsPlayerBombing[playerid][CASTLE] = 0;
HUnderBomb[CASTLE] = 0;
SendClientMessage(playeridCOLOR_GREY"You have failed to bomb this zone!");
}
if(
HIsPlayerBombing[playerid][CASTLE] == && gTeam[playerid] == TEAM_DEFENDERS)
{
   
DBombCanceled(playerid);




Re: Urgent help with bombing system. - Shinja - 28.08.2016

what you meaning with castle? shouldn't be MAX_PLAYERS?


Re: Urgent help with bombing system. - DeeadPool - 28.08.2016

Castle is my bomb site. I have defined it.


Re: Urgent help with bombing system. - Shinja - 28.08.2016

You must have a player that hold playerid
PHP код:
pTimer[playerid] = SetTimerEx("castlebomb"1000false"i"playerid); 
And kill it OnPlayerDeath/Disconnect..


Re: Urgent help with bombing system. - DeeadPool - 28.08.2016

Quote:
Originally Posted by Shinja
Посмотреть сообщение
You must have a player that hold playerid
PHP код:
pTimer[playerid] = SetTimerEx("castlebomb"1000false"i"playerid); 
And kill it OnPlayerDeath/Disconnect..
I did it once, but there was a lot of problem in defusing it, cause it should even kill the timer but as the timer is not a global variable, the bomb does not go off.


Re: Urgent help with bombing system. - Shinja - 28.08.2016

It MUST be global then


Re: Urgent help with bombing system. - DeeadPool - 28.08.2016

Can you tell how can I do it globally?


Re: Urgent help with bombing system. - HidroDF - 28.08.2016

Код:
// Outside all functions
new pTimer[playerid];

// OnPlayerDeath/Disconnect
KillTimer (pTimer[playerid]);



Re: Urgent help with bombing system. - Shinja - 28.08.2016

PHP код:
//TOP OF SCRIPT
new PlantTimer[MAX_PLAYERS];
new 
DefuseTimer[MAX_PLAYERS]; 
PHP код:
if(gTeam[playerid] == TEAM_ATTACKERS && HBombed[CASTLE] == 0
               { 
                  
HIsPlayerBombing[playerid][CASTLE] = 1
                  
HBombed[CASTLE] = 0
                  
HUnderBomb[CASTLE] = 0
                  
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Planting..."); 
                  
PlantTimer[playerid] = SetTimerEx("castlebomb"1000false"i"playerid); 
                  
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000); 
               } 
            if(
gTeam[playerid] == TEAM_DEFENDERS && HUnderBomb[CASTLE] == 1
               { 
                  
SendClientMessage(playeridCOLOR_LIGHTERBLUE"Defusing..."); 
                  
HIsPlayerBombing[playerid][CASTLE] = 1
                  
HUnderBomb[CASTLE] = 1
                  
DefuseTimer[playerid] = SetTimerEx("castledefusebomb"1000false"i"playerid); 
                  
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000); 
               } 
PHP код:
//OnPlayerDeath
KillTimer(PlantTimer[playerid]); 



Re: Urgent help with bombing system. - DeeadPool - 28.08.2016

So it will work globally? I mean it will not be bugged, as i explained? because what you did above is what i did exactly.