PDA

View Full Version : need some help from you


STONEGOLD
13/06/2015, 10:02 PM
Guyz, I'm using this. I want to add if player get arrested or get killed while robbing so robbery should be canceled. I tried but didn't get something cool. Can you help me? Thanks!

CMD:robbank(playerid,params[])
{
if(gTeam[playerid] == CIVILIANS)
{
if(IsPlayerInDynamicCP(playerid, BankRobbery)) // Checking if player is in the checkpoint
{
if(bankrobbedrecently1 == 0) //checking if tatoo shop has been robbed recently
{
new chances = random(500);
if(chances >= 0 && chances <= 400)
{
new string[250];
ROBBING_BANK1[playerid] = 30; // setting the robbery timer
bankrobbedrecently1 =200; // Time the players needs to wait for starting an another robbery in the same place
SetPlayerWantedLevel(playerid,4);
format(string, sizeof(string), "Committed A Crime: Bank Robbery - Wanted Level 4 - Arrestable");
SendClientMessage(playerid, ROJO, string);
return true;
}
else if(chances >= 401 && chances <= 500)
{
new copmsg[250], name;
SendClientMessage(playerid, COLOR_RED, "You failed to rob store.");
SetPlayerWantedLevel(playerid,4);
format(copmsg, sizeof(copmsg), "Suspected: %s attemped to rob National Bank in Downtown San Fierro (SF).", name);
SendRadioMessageToCops(copmsg);
return true;
}
}
else if(bankrobbedrecently1 > 0) return SendClientMessage(playerid, ROJO, "Please wait before robbing this store again.");
}

if(ROBBING_BANK1[i] == 1) // IF the timer reached 1
{
new string[256], pName[MAX_PLAYER_NAME];// getting player name
GetPlayerName(i,pName,MAX_PLAYER_NAME);
ROBBING_BANK1[i] =0; // RESET timer
new earning =random(95000);
format(string,sizeof(string),"%s (%d) has stolen $%d from National Bank in Downtown San Fierro (SF)!",pName,i,earning);
SendClientMessageToAll(COLOR_CYAN,string);
format(string,sizeof(string),"ROBBERY COMPLETED");
GameTextForPlayer(i,string, 1000, 3);
format(string,sizeof(string),"Gread Job! You completed the robbery, profit: $%d", earning); //sending message to the player that robbery was complete
SendClientMessage(i,GREEN,string);
GivePlayerCashEx(i, earning);
SetPlayerWantedLevel(i, GetPlayerWantedLevel(i) + 1); //giving player 1 wanted level
GivePlayerScore(i,1);
pInfo[i][pStoreRobbed] ++;
pInfo[i][pStoreRobbedMoney] = pInfo[i][pStoreRobbedMoney] +earning;
}
if(ROBBING_BANK2[i] > 1 // Checking if robbery time is above 1
{
ROBBING_BANK2[i] --; // Decreasing time
new time[256]; //adding time variable
format(time,sizeof(time),"~y~Robbery Time: %d~n~~r~DO NOT MOVE UNTIL THE~n~ROBBERY IS COMPLETED",ROBBING_BANK2[i]);
GameTextForPlayer(i,time,3000,3); //shows gametext showing the time remaining for the robbery
}
if(ROBBING_BANK2[i] == 1) // IF the timer reached 1
{
new string[256], pName[MAX_PLAYER_NAME];// getting player name
GetPlayerName(i,pName,MAX_PLAYER_NAME);
ROBBING_BANK2[i] =0; // RESET timer
new earning =random(95000);
format(string,sizeof(string),"%s (%d) has stolen $%d from National Bank in EL Quebrados (BC)!",pName,i,earning);
SendClientMessageToAll(COLOR_CYAN,string);
format(string,sizeof(string),"ROBBERY COMPLETED");
GameTextForPlayer(i,string, 1000, 3);
format(string,sizeof(string),"Gread Job! You completed the robbery, profit: $%d", earning); //sending message to the player that robbery was complete
SendClientMessage(i,GREEN,string);
GivePlayerCashEx(i, earning);
SetPlayerWantedLevel(i, GetPlayerWantedLevel(i) + 1); //giving player 1 wanted level
GivePlayerScore(i,1);
pInfo[i][pStoreRobbed] ++;
pInfo[i][pStoreRobbedMoney] = pInfo[i][pStoreRobbedMoney] +earning;
}

Onleavecheckpoint

if(checkpointid == BankRobbery)
{
TextDrawHideForPlayer(playerid, banktd);
TextDrawHideForPlayer(playerid, banktdbox);
if(ROBBING_BANK1[playerid] >= 1) //checking if the person was robbing and his robbery timer was above 1
{
SendClientMessage(playerid, ROJO, "You have left checkpoint. Robbery Failed"); //Error message that he failed
GameTextForPlayer(playerid,"~r~Robbery Failed", 3000, 5);
ROBBING_BANK1[playerid] =0; // Setting Robbing_tatoo to 0. to stop the counter
HasDied{playerid} = true;
return 1;
}
}
if(checkpointid == BankRobbery2)
{
TextDrawHideForPlayer(playerid, banktd);
TextDrawHideForPlayer(playerid, banktdbox);
if(ROBBING_BANK2[playerid] >= 1) //checking if the person was robbing and his robbery timer was above 1
{
SendClientMessage(playerid, ROJO, "You have left checkpoint. Robbery Failed");
GameTextForPlayer(playerid,"~r~Robbery Failed", 3000, 5); //Error message that he failed
ROBBING_BANK2[playerid] =0; // Setting Robbing_tatoo to 0. to stop the counter
HasDied{playerid} = true;
return 1;
}
}

STONEGOLD
14/06/2015, 01:10 AM
Is someone help me? It has been few hours.

WilliamOordt
14/06/2015, 02:09 AM
Your code is a bit hard for me to understand so I just have a few things and I hope it helps.


First you would need to add a variable once a player starts a robbery, like so:


new RobberyInProgress[MAX_PLAYERS]


Change the variable once they start the robbery like this:


if(chances >= 0 && chances <= 400)
{
new string[250];
RobberyInProgress[playerid] = 1;
ROBBING_BANK1[playerid] = 30; // setting the robbery timer
bankrobbedrecently1 =200; // Time the players needs to wait for starting an another robbery in the same place
SetPlayerWantedLevel(playerid,4);
format(string, sizeof(string), "Committed A Crime: Bank Robbery - Wanted Level 4 - Arrestable");
SendClientMessage(playerid, ROJO, string);
return true;
}


Then we add an if statement under OnPlayerDeath:


public OnPlayerDeath(playerid, killerid, reason)
{
if(RobberyInProgress[playerid] == 1)
{
bankrobbedrecently1 = 200;
ROBBING_BANK2[i] =0;

}



}


BTW, it's 'great' instead of 'gread'