How do i givecashtoall? -
Drift_04 - 10.03.2009
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.
Re: How do i givecashtoall? -
Sandra18[NL] - 10.03.2009
Use a loop:
//OnGameModeInit()
Код:
SetTimer("GiveAllCash", 500, 1);
//Elsewhere:
Код:
forward GiveAllCash();
public GiveAllCash()
{
for(new i; i<MAX_PLAYERS; i++)
{
GivePlayerMoney(i, 2);
}
}
Re: How do i givecashtoall? -
Drift_04 - 10.03.2009
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!!!! =)
Re: How do i givecashtoall? -
Sandra18[NL] - 10.03.2009
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++)
Re: How do i givecashtoall? -
VoX - 10.03.2009
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);
}
}
Re: How do i givecashtoall? -
ICECOLDKILLAK8 - 10.03.2009
Check if they are connected first, Try to give cash to 200 non existant players mightcause a problem
Re: How do i givecashtoall? -
MenaceX^ - 10.03.2009
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.
Re: How do i givecashtoall? -
Mikep - 10.03.2009
Drift, please start searching.
This is everywhere.
Loops are used in like 65% of scripts.
Re: How do i givecashtoall? -
saiberfun - 10.03.2009
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
Re: How do i givecashtoall? -
Sandra18[NL] - 10.03.2009
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.
|