CMD:robbery(playerid, params[])
{
if(!IsPlayerInDynamicCP(playerid, CP_Warehouse)) return SendClientMessage(playerid, COLOR_RED,"You are not in a Warehouse Checkpoint!!");
{
if(Warehouserobbedrecently >=1) //checking if WArehouse has been robbed recently
{
SendClientMessage(playerid, COLOR_RED, "[ROBBERY]: Warehouse has been robbed recently"); // sending error message
}
ROBBING_Warehouse[playerid] = 60; // setting the robbery timer
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +5);
Warehouserobbedrecently =200; // Time the players needs to wait for starting an another robbery in the same place
}
return 1;
}
forward ServerRobbery();
public ServerRobbery()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i)) // checking if player connected
{
//ROBBERIES
if(ROBBING_Warehouse[i] > 1) // Checking if robbery time is above 1
{
ROBBING_Warehouse[i] --; // Decreasing time
new time[20]; //adding time variable
format(time,sizeof(time),"~b~Robbery Time:%d",ROBBING_Warehouse[i]);
SetPlayerWantedLevel(i, GetPlayerWantedLevel(i) + 4); //giving player 4 wanted level
GameTextForPlayer(i,time,500,3); //shows gametext showing the time remaining for the robbery
}
if(ROBBING_Warehouse[i] == 1) // IF the timer reached 1
{
new string[64], pName[MAX_PLAYER_NAME];// getting player name
GetPlayerName(i,pName,MAX_PLAYER_NAME);
SendClientMessage(i, COLOR_GREEN, "Robbery Complete"); //sending message to the player that robbery was complete
ROBBING_Warehouse[i] =0; // RESET timer
new mrand =random(200000);
format(string,sizeof(string),"[ROBBERY] %s(%d) has robbed a total of $%d from Warehouse!",pName,i,mrand);
SendClientMessageToAll(COLOR_RED,string);
GivePlayerMoney(i, mrand);
}
}
}
return 1;
}
new
value
;
value = random( 100 ); // will random create a number between 0 - 99
switch( value )
{
case 0 .. 49: // Rob Successful
{}
case 50 .. 99: // Rob Failed
{}
}
|
I'm sorry you lost me?
This is the easiest way to do it? You can modify the 'random' parameter to be less, and also edit the switch cases, to match the min and max of the value of 'value'. There really isn't an 'easier' way to do it. |
CMD:robbery(playerid, params[])
{
if(!IsPlayerInDynamicCP(playerid, CP_Warehouse)) return SendClientMessage(playerid, COLOR_RED,"You are not in a Warehouse Checkpoint!!");
{
if(Warehouserobbedrecently >=1) //checking if WArehouse has been robbed recently
{
SendClientMessage(playerid, COLOR_RED, "[ROBBERY]: Warehouse has been robbed recently"); // sending error message
}
new
can_rob
;
can_rob = random( 100 );
switch( can_rob )
{
case 0 .. 49: // successful robbery
{
ROBBING_Warehouse[playerid] = 60; // setting the robbery timer
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +5);
Warehouserobbedrecently = 200; // Time the players needs to wait for starting an another robbery in the same place
return 1;
}
default:
{
// send error message
}
}
}
return 1;
}
|
Here is your code finished, though in future most people won't be as nice to do it for you. I hope you learn from what I have done, and actually apply it in the future.
Код:
CMD:robbery(playerid, params[])
{
if(!IsPlayerInDynamicCP(playerid, CP_Warehouse)) return SendClientMessage(playerid, COLOR_RED,"You are not in a Warehouse Checkpoint!!");
{
if(Warehouserobbedrecently >=1) //checking if WArehouse has been robbed recently
{
SendClientMessage(playerid, COLOR_RED, "[ROBBERY]: Warehouse has been robbed recently"); // sending error message
}
new
can_rob
;
can_rob = random( 100 );
switch( can_rob )
{
case 0 .. 49: // successful robbery
{
ROBBING_Warehouse[playerid] = 60; // setting the robbery timer
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +5);
Warehouserobbedrecently = 200; // Time the players needs to wait for starting an another robbery in the same place
return 1;
}
default:
{
// send error message
}
}
}
return 1;
}
|
CMD:robnvpd(playerid, params[])
{
if(GetTeam{playerid} != CLASS_CIV) return SendClientMessage(playerid, RED, "Only civilians can rob places.");
if(IsRobbingNVPD{playerid} == true) return SendClientMessage(playerid, RED, "Your already robbing the joint.");
if(IsPlayerHoldingAGun(playerid) == 0 || HasBeenCuffed{playerid} == true) return SendClientMessage(playerid, RED, "You must be holding a gun to rob places.");
if((gettime() - 120) < TimerInfo[playerid][CMD_timer21]) return SendClientMessage(playerid, RED, "Please wait before using this command again.");
TimerInfo[playerid][CMD_timer21] = gettime();
new chance = random(3);
if(chance == 0)
{
format(fstr, sizeof(fstr), "[DISPATCH]: Suspect %s [%d] has attempted to rob the NVPD at New Vegas Square.", GetName(playerid), playerid);
CopRadio(BLUE, fstr);
SendClientMessage(playerid, RED, "You have failed to rob the NVPD.");
GameTextForPlayer(playerid, "~w~Robbery ~r~Failed", 5000, 5);
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 4);
}
else if(IsPlayerInRangeOfPoint(playerid,1.0,230.0261,165.0891,1003.0234))
{
if((gettime() - 120) < nvpdrobbed) return SendClientMessage(playerid, RED, "This place has been robbed recently, try again later.");
format(fstr, sizeof(fstr), "[DISPATCH]: Suspect %s [%d] is now robbing the NVPD at New Vegas Square.", GetName(playerid), playerid);
CopRadio(BLUE, fstr);
SendClientMessage(playerid, LIGHTGREEN, "Your robbing the NVPD, DON'T LEAVE THE CHECKPOINT!");
GameTextForPlayer(playerid, "~r~Holdup ~w~In ~g~Progress...~n~~r~Dont Leave ~w~The ~r~Checkpoint.", 25000, 5);
SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+6);
IsRobbingNVPD{playerid} = true;
nvpdtimer{playerid} = SetTimerEx("NVPDRob", 25000, false, "d", playerid);
ApplyAnimation(playerid,"ped","ARRESTgun",4.1,0,1,1,1,1);
nvpdrobbed = gettime();
}
else
{
SendClientMessage(playerid, RED, "Your not at the robbery checkpoint.");
}
new astring[100],pName[24];
GetPlayerName(playerid,(pName),sizeof(pName));
format(astring,sizeof(astring),"%s [%d] typed: /robnvpd",pName,playerid);
SendAdminMessage(GREY,astring);
return true;
}