moneybag global variable issue -
div - 23.06.2018
Hello, I'm facing a problem as usual XD, I've declared a global variable for Money bag as the enum was causing problem with value 0 or 1..
Here's the code
Код:
// if(pMoneyBag == 1)
// {
new RandMoney = random(2669);
GivePlayerMoney(playerid, RandMoney);
new msg[128], sName[24];
GetPlayerName(playerid, sName, 24);
format(msg, 128, "%s(%d) has robbed $%d.", sName, playerid, RandMoney);
SendClientMessageToAll(-1, msg);
// }
/* else if(pMoneyBag == 1)
{
new RandMoney = random(4969);
GivePlayerMoney(playerid, RandMoney + 4969);
new msg[128], sName[24];
GetPlayerName(playerid, sName, 24);
format(msg, 128, "%s(%d) has robbed $%d.", sName, playerid, RandMoney);
SendClientMessageToAll(-1, msg);
}
*/
When I add these commented lines, neither does it give me money, nor does it sends a client message.
But when they are again COMMENTED, it works smooth..
Also, about the random money, in the first case, i want it to be 1600 - 2500.. I did use RandomEx, but it gave some errors.. so i switched back to this..
Re: moneybag global variable issue -
div - 23.06.2018
like?
Re: moneybag global variable issue -
div - 23.06.2018
Defined, but not the on/off system, i'll do, when i work on SUPA SAVE commands..
Do i need to do it before?
Re: moneybag global variable issue -
div - 23.06.2018
But it will be defined as 1 then, globally defined as one, means everyone has MoneyBag when they connect or rob..
Re: moneybag global variable issue -
Verc - 23.06.2018
It means that pMoneybag variable is 0.
the second if(else if) should be zero,but you put 1. And there's no point using else if,just use else.
Re: moneybag global variable issue -
div - 23.06.2018
Changed it to bool
bool
MoneyBag[MAX_PLAYERS]
Код:
{
if(pMoneyBag[playerid] == false)
{
new RandMoney = random(2669);
GivePlayerMoney(playerid, RandMoney);
new msg[128], sName[24];
GetPlayerName(playerid, sName, 24);
format(msg, 128, "%s(%d) has robbed $%d.", sName, playerid, RandMoney);
SendClientMessageToAll(-1, msg);
SafeRecentlyRobbed[playerid] = 1;
SetTimer("SafeRobberyReset", 260000, false);
}
else if(pMoneyBag[playerid] == true)
{
new RandMoney = random(4969);
GivePlayerMoney(playerid, RandMoney + 4969);
new msg[128], sName[24];
GetPlayerName(playerid, sName, 24);
format(msg, 128, "%s(%d) has robbed $%d.", sName, playerid, RandMoney);
SendClientMessageToAll(-1, msg);
SafeRecentlyRobbed[playerid] = 1;
SetTimer("SafeRobberyReset", 260000, false);
}
return 1;
}
If i remove IF and ELSE statement, it will work fine, else it will not give me MONEY of robbery or SendClientMessage..
Re: moneybag global variable issue -
Verc - 23.06.2018
Try debugging the code,add prints everywhere.
Re: moneybag global variable issue -
div - 23.06.2018
I tried, when i removed this If, Else code, it worked fine.. when i added it back, it again began to create problems..
Re: moneybag global variable issue -
JasonRiggs - 23.06.2018
The problem is very clear, that you can't detect small details..
You said
then go ahead giving money and sending client message..
and
PHP код:
else if(pMoney == 1)
then go ahead giving the money and sending client message..
And that doesn't make sense.. You are making 2 cases for the same case, pMoney ==1 and pMoney == 1 also!
And this won't work for sure, only the first case will work..