PDA

View Full Version : moneybag global variable issue


div
23/06/2018, 02:37 AM
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..

div
23/06/2018, 03:13 AM
like?

div
23/06/2018, 03:18 AM
Defined, but not the on/off system, i'll do, when i work on SUPA SAVE commands..



Do i need to do it before?

div
23/06/2018, 03:22 AM
But it will be defined as 1 then, globally defined as one, means everyone has MoneyBag when they connect or rob..

Verc
23/06/2018, 04:09 AM
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.

div
23/06/2018, 04:18 AM
Changed it to bool


bool:pMoneyBag[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..

Verc
23/06/2018, 04:21 AM
Try debugging the code,add prints everywhere.

div
23/06/2018, 04:44 AM
I tried, when i removed this If, Else code, it worked fine.. when i added it back, it again began to create problems..

JasonRiggs
23/06/2018, 07:37 AM
The problem is very clear, that you can't detect small details..

You said if(pMoney == 1) then go ahead giving money and sending client message..

and 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..