moneybag global variable issue
#1

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..
Reply
#2

like?
Reply
#3

Defined, but not the on/off system, i'll do, when i work on SUPA SAVE commands..



Do i need to do it before?
Reply
#4

But it will be defined as 1 then, globally defined as one, means everyone has MoneyBag when they connect or rob..
Reply
#5

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.
Reply
#6

Changed it to bool


boolMoneyBag[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..
Reply
#7

Try debugging the code,add prints everywhere.
Reply
#8

I tried, when i removed this If, Else code, it worked fine.. when i added it back, it again began to create problems..
Reply
#9

The problem is very clear, that you can't detect small details..

You said
PHP код:
if(pMoney == 1
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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)