Timer i all players to one player?
#1

Heey all,

I made this timer:
Код:
for(new i=0; i<MAX_PLAYERS; i++)
	{
	    if(IsPlayerConnected(i))
	    {
                  GivePlayerMoney(i,5000);
            }
        }
But its gives all players money. How can i change it to one player?

Thanks Admigo
Reply
#2

Код:
for(new i=0; i<MAX_PLAYERS; i++)
	{
	    if(IsPlayerConnected(i))
	    {
                  GivePlayerMoney(i,5000);
                  break;
            }
        }
Or just use

Код:
GivePlayerMoney(playerid, 5000);
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
If you don't want to give all players money, remove the loop that goes through all players!
If i delete the loop how can i define the playerid then or i?
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Well you'll have to pass it like any other function.
I dont know how . I have on timer and i was thinking only with a variable with MAX_PLAYERS it can be stored for one player.
Reply
#5

Is it stable to use the settimerex at onplayerconnect or will the server be laggy?
pawn Код:
public OnPlayerConnect(playerid)
{
SetTimerEx("OneSecondPlayerTimer",1000,true,"d",playerid);
return 1;
}
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
I don't know, did you TEST it on YOUR hardware? I can tell you if that's laggy or not on MY PC, but that's completely useless information for you!
I am hosting a server on kingj so i dont know:P
You guys have experience in timers.
Reply
#7

oh dude, just go test by yourself. at least doesn't laggy me at all.
Reply
#8

just some suggestions:
pawn Код:
//at top
new GetsMoney[MAX_PLAYERS];

//your timer()
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(GetsMoney[i]>0)
    {
//      GivePlayerMoney(i,5000);
        GivePlayerMoney(i,GetsMoney[i]);
        GetsMoney[i]=0;//after a player recieved money once, set it to 0 to avoid getting cash each time
    }
}

CMD:recieve(playerid,params[]){
    new targetid,amount;
    if(sscanf(params,"uD(1000)",targetid,amount))
    {
        SendClientMessage(playerid,0xff5555ff,"/recieve <id> [amount]");
        return 1;
    }
    GetsMoney[i]=amount;//to be stored in the array + synced in the next timer loop
    SendClientMessage(playerid,0x55ff55ff,"Money sent.");
    return 1;
}

public OnPlayerConnect(playerid)
{
    GetsMoney[i]=1000;
    return 1;
}
as you can see, one timer handling the all-player-loop, will do fine.
if you want the player(s) having the money at each iteration, then remove the
pawn Код:
GetsMoney[i]=0;
the zcmd:recieve needs some enhancements like adminlevel etc, but you get the concept i assume heh
*not tested
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)