How do i givecashtoall?
#1

i am making it so on my server every half second every player gets $2 but whats the script to give all players money?

i have checked wiki too, it is not there.
Reply
#2

Use a loop:

//OnGameModeInit()
Код:
SetTimer("GiveAllCash", 500, 1);
//Elsewhere:
Код:
forward GiveAllCash();
public GiveAllCash()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    GivePlayerMoney(i, 2);
  }
}
Reply
#3

oh i see!!! MAX PLAYERS = all players huh?? thanks!

and yeah i am using a loop. =P

i just didnt know how to use max players. thanks a lot!!!! =)
Reply
#4

Yes,

MAX_PLAYERS is defined in a_samp.inc as 200:
Quote:

#define MAX_PLAYERS (200)

so MAX_PLAYERS is equal to 200
and you can replace the loop with:

Код:
for(new i; i<200; i++)
Reply
#5

if u want to give a specific amount of money do this:

Код:
forward GiveAllCash(amount);

public GiveAllCash(amount)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    GivePlayerMoney(i, amount);
  }
}
Reply
#6

Check if they are connected first, Try to give cash to 200 non existant players mightcause a problem
Reply
#7

Quote:
Originally Posted by Drift_04
oh i see!!! MAX PLAYERS = all players huh?? thanks!

and yeah i am using a loop. =P

i just didnt know how to use max players. thanks a lot!!!! =)
Wow...
"MAX_PLAYERS = ALL PLAYERS HUH?? Thanks!
then
"and yeah I am using a loop!"

You're strange.
Reply
#8

Drift, please start searching.

This is everywhere.

Loops are used in like 65% of scripts.
Reply
#9

Quote:
Originally Posted by =>Sandra<=
Use a loop:

//OnGameModeInit()
Код:
SetTimer("GiveAllCash", 500, 1);
//Elsewhere:
Код:
forward GiveAllCash();
public GiveAllCash()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    GivePlayerMoney(i, 2);
  }
}
Код:
SetTimer("GiveAllCash", 2000, 1);
would be better cuz he wants it every 2 secs

2000 = 2000milliseconds = 2secs
Reply
#10

Quote:
Originally Posted by saiberfun
Код:
SetTimer("GiveAllCash", 2000, 1);
would be better cuz he wants it every 2 secs
2000 = 2000milliseconds = 2secs
No, he want's:
Quote:

every half second every player gets $2


Quote:
Originally Posted by JeNkStAX
Check if they are connected first, Try to give cash to 200 non existant players mightcause a problem
No, GivePlayerMoney has some sort of 'build in' IsPlayerConnected-function". If you run GivePlayerMoney on a non-connected player, it will simply return 0;
I remembered that for the Code Optimisations-topic by ******:

Quote:
Originally Posted by ******
Kick, and in fact all player functions, has an internal IsPlayerConnected check, so if you're only running one function in a loop it's more efficient to NOT call IsPlayerConnected and just call the function direct. If the player is connected you've saved a function call, if they're not connected you've not lost anything as the only code that's been executed is the same as if you called IsPlayerConnected.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)