I need to store many shops's names in a variable.
I'm making a shop robbery.
Here's the code:
On top:
PHP код:
new robberytimer[128];
new robbing[128]=0;
new PlayerBar:robberybar[128];
new Text:robberytext;
new robbingcount[128]=0;
new shopunrobbable[128]=0;
new shopname[128][128];
OnGameModeInit
PHP код:
lspizza=CreateDynamicCP(376.4199,-119.9786,1001.4995,3,310,5,-1,25);
OnPlayerEnterDynamicCP
PHP код:
if(checkpointid==lspizza)
{
SendClientMessage(playerid, COLOR_ORANGE, "Robbery: Type /robstore to rob this store.");
}
OnPlayerCommandText
PHP код:
if(strcmp(cmdtext, "/robstore", true, 20)==0)
{
new string[128], playername[128];
if(GetPlayerTeam(playerid)==TEAM_COPS || GetPlayerTeam(playerid)==TEAM_SWAT || GetPlayerTeam(playerid)==TEAM_ARMY || GetPlayerTeam(playerid)==TEAM_MEDICS) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: Your class cannot use this command.");
if(cuffed[playerid]==1 || swatcuffed[playerid]==1) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: You cannot use this command while cuffed.");
if(IsPlayerInDynamicCP(playerid, lspizza))
{
if(shopunrobbable[lspizza]==1) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: The Well Stacked Pizza Co has been robbed recently.");
SendClientMessage(playerid, COLOR_ORANGE, "Robbery: You have started to rob this shop. Do not leave the checkpoint until robbery is finished.");
SetTimerEx("ShopTimer", 100000, false, "i", lspizza);
shopunrobbable[lspizza]=1;
robbing[playerid]=1;
robberybar[playerid]=CreatePlayerProgressBar(playerid, 265.000000, 362.000000, 126.000000, 21.000000, 1189758719, 10, BAR_DIRECTION_RIGHT);
TextDrawShowForPlayer(playerid, robberytext);
format(shopname[lspizza], sizeof(shopname), "Well Stacked Pizza Co");
robbingcount[playerid]=0;
robberytimer[playerid]=SetTimerEx("Robbery", 1000, true, "iiii", playerid, 5000, 3500, 10, lspizza);
GetPlayerName(playerid, playername, sizeof(playername));
for(new i=0; i<MAX_PLAYERS; i++)
{
new iteam=GetPlayerTeam(i);
if(iteam==TEAM_COPS || iteam==TEAM_SWAT || iteam==TEAM_ARMY)
{
format(string, sizeof(string), "Robbery: %s is currently robbing the Well Stacked Pizza Co., Idlewood.", playername);
SendClientMessage(i, COLOR_CRIME, string);
SendClientMessage(i, COLOR_CRIME, "DISPATCH: All units in this area, please respond.");
}
}
wantedlevel[playerid]=wantedlevel[playerid]+5;
SetWanted(playerid, wantedlevel[playerid]);
format(string, sizeof(string), "{%06x}(Crime committed) Wantedlevel: %d. Robbing.", GetPlayerColor(playerid)>>>8, wantedlevel[playerid]);
SendClientMessage(playerid, COLOR_WHITE, string);
}
else
{
SendClientMessage(playerid, COLOR_ORANGE, "ERROR: You are not in any robbery checkpoint");
}
return 1;
}
Timer1:
PHP код:
forward Robbery (playerid, maxmoney, minmoney, maxvalue, shopid);
public Robbery (playerid, maxmoney, minmoney, maxvalue, shopid)
{
if(robbingcount[playerid]>maxvalue)
{
new playername[128], string[128], money;
TextDrawHideForPlayer(playerid, robberytext);
DestroyPlayerProgressBar(playerid, robberybar[playerid]);
KillTimer(robberytimer[playerid]);
money=random(maxmoney);
while(money<minmoney)
{
money=money+500;
}
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "%s has robbed $%d from the %s.", playername, money, shopname[shopid]);
SendClientMessageToAll(COLOR_ORANGE, string);
PlayerInfo[playerid][pRobberies]++;
format(string, sizeof(string), "You have robbed this store and your robskill has been increased to %d.", PlayerInfo[playerid][pRobberies]);
SendClientMessage(playerid, COLOR_PINK, string);
PlayerInfo[playerid][pCash]=PlayerInfo[playerid][pCash]+money;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
PlayerInfo[playerid][pScore]++;
robbing[playerid]=0;
return 1;
}
robbingcount[playerid]++;
SetPlayerProgressBarValue(playerid, robberybar[playerid], robbingcount[playerid]);
return 1;
}
Timer2:
PHP код:
forward ShopTimer(shopid);
public ShopTimer(shopid)
{
shopunrobbable[shopid]=0;
}
OnPlayerLeaveDynamicCP
PHP код:
if(checkpointid==lspizza)
{
if(robbing[playerid]==1)
{
robbing[playerid]=0;
SendClientMessage(playerid, COLOR_ORANGE, "You have left the checkpoint and hence the robbery has failed.");
KillTimer(robberytimer[playerid]);
TextDrawHideForPlayer(playerid, robberytext);
DestroyPlayerProgressBar(playerid, robberybar[playerid]);
}
}
This is my code. I need to store all shops's name to one variable so that I can add more shops easily within /robstore command.