Give money to all?
#1

Hey, I have a question.

How could I give money to all just like this?

Quote:

GivePlayerMoney(playerid, 1000);

Thanks.
Reply
#2

Quote:
Originally Posted by krawN
Hey, I have a question.

How could I give money to all just like this?

Quote:

GivePlayerMoney(playerid, 1000);

Thanks.
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
   if(IsPlayerConnected(i))
   {
     GivePlayerMoney(i,1000);
   }
}
^ that is your run-of-the-mill for-loop for all (connected) players. Study it...you will use it often.
Reply
#3

Quote:
Originally Posted by kaisersouse
Quote:
Originally Posted by krawN
Hey, I have a question.

How could I give money to all just like this?

Quote:

GivePlayerMoney(playerid, 1000);

Thanks.
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
   if(IsPlayerConnected(i))
   {
     GivePlayerMoney(i,1000);
   }
}
^ that is your run-of-the-mill for-loop for all (connected) players. Study it...you will use it often.
Ok.

Could you tell me what means "i++"? I don't know why it's there.

Thanks
Reply
#4

Quote:
Originally Posted by krawN
Quote:
Originally Posted by kaisersouse
Quote:
Originally Posted by krawN
Hey, I have a question.

How could I give money to all just like this?

Quote:

GivePlayerMoney(playerid, 1000);

Thanks.
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
   if(IsPlayerConnected(i))
   {
     GivePlayerMoney(i,1000);
   }
}
^ that is your run-of-the-mill for-loop for all (connected) players. Study it...you will use it often.
Ok.

Could you tell me what means "i++"? I don't know why it's there.

Thanks
"i++" is the same as "i +=1". "i" jus a variable, you can change it you anything you want: letter, or word.
Reply
#5

new i = 0; << creates a new variable named "i" and initializes it to 0

i < MAX_PLAYERS; << keep running through the loop while the value of i is less than the maximum number of players

i++ << increment the variable i by 1 each time the loop recycles. This is done until i equals the maximum number of players

Anything inside the first { and last } is executed each time the loop makes a pass. We added IsPlayerConnected to ensure that the server doesn't attempt to run code on a playerid that doesn't exist. At the least this will cause the loop to take longer than it should, and at the worst it will crash the server as it tries to run code on someone who isnt there.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)