Problem with for(new
#1

Hey guys,
I`ve a Problem.
I use for(new.... in my PayDay-Script buut,
I get the message 2x because me and my bot are connected.
Can anyone help me?

Код:
public PayDay()
{
	new
	    iMoney,
		string[100],
		stringd[100],
		BMoney,
		JMoney;
	SendClientMessageToAll(COLOR_ORANGE,"______________________Payday______________________");
	for(new i;i<MAX_PLAYERS;i++)
	{
		if(!IsPlayerConnected(i)) continue;
		iMoney = 0;
		BMoney = 0;
		JMoney = 0;
		for(new g; g < sizeof(Gebiete); g++)
		{
			if(gTeam[i] == Gebiete[g][gOwner])
			{
				iMoney += 300;
				Player[i][Bank] += 300;
			}
		}
   		if(Org[i][Member] == 4)
		{
			JMoney += 425;
		}
		if(Org[i][Member] == 5)
		{
			JMoney += 350;
		}
		if(Org[i][Member] == 6)
		{
			JMoney += 500;
		}
		if(Org[i][Member] == 7)
		{
			JMoney += 550;
		}
		Player[i][Bank] += JMoney;
		if(GetPVarInt(i, "Businessearnings") != 0)
		{
		  	BMoney = GetPVarInt(i, "Businessearnings");
	      	Player[i][Bank] += GetPVarInt(i, "Businessearnings");
		}
		if( iMoney > 0 || BMoney > 0 || JMoney > 0 ) {
			format(string,sizeof(string),"Properties: $%d      Zone/s: $%d (%d zone/s)      Job: $%d",BMoney,iMoney, ( iMoney / 300 ) , JMoney ) ;
			format(stringd,sizeof(stringd),"Unternehmen: $%d      Gebiet/e: $%d (%d Gebiet/e)      Job: $%d",BMoney,iMoney, ( iMoney / 300 ) , JMoney);
			ClientLanguageText(i,COLOR_ORANGE,stringd,string);
		}
	}
	SendClientMessageToAll(COLOR_ORANGE,"__________________________________________________");
	return 1;
}
Reply
#2

I already see the problem here..

for(new i;i<MAX_PLAYERS;i++) is a loop for each player, means this peace of code will be executed 500 times (because MAX_PLAYERS ammount of SA-MP is 500).
And if there are only 2 out of 500 players are connected..
Код:
if(!IsPlayerConnected(i)) continue; //Copied from your code
Then the code will be executed only 2 times, and if you look further down to the codes. You will find "SendClientMessageToAll".
As I already said this peace of code will be executed 2 times and if your using the function SendClientMessageToAll, then the message will be sent 2 Times To All players. Means the players will recieve 2 messages instead of 1.

You can fix this by modifing the SendClientMessageToAll code into SendClientMessage.
Example of how it works correctly:
Код:
SendClientMessageToAll(COLOR_ORANGE,"__________________________________________________");
Код:
SendClientMessage(i, COLOR_ORANGE,"__________________________________________________");

NOTE: Make sure you will also modify your SendClientMessageToAll code into SendClientMessage of
Код:
ClientLanguageText(i, COLOR_ORANGE, stringd, string);
This whole post is a bit messy but I hope this explains everything for you.

Kind Regards,
Improvement™
Reply
#3

I would recommend that you use foreach. It will end up being more efficient and if I'm not mistaken, it's a lot quicker.
Reply
#4

I used both solutions but i`ve still this problem.
I get the message ones and after 20-30 seconds i got it again.
The timer was set to 60000 for this test.
Reply
#5

Where do you set this timer?
Reply
#6

Quote:
Originally Posted by Zcelo12
Посмотреть сообщение
I used both solutions but i`ve still this problem.
I get the message ones and after 20-30 seconds i got it again.
The timer was set to 60000 for this test.
If its in milisecond, which is 60 seconds youll get message every minute
Reply
#7

Yes that's right.
But i get one message and after 30 seconds again instead after 60 seconds.
And than after 30 seconds again because the timer is set to 60 seconds.
The timer starts at OnGameModeInit() .
Reply
#8

Nobody?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)