SA-MP Forums Archive
Timer i all players to one player? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Timer i all players to one player? (/showthread.php?tid=370217)



Timer i all players to one player? - Admigo - 19.08.2012

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


Re: Timer i all players to one player? - Shetch - 19.08.2012

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

Код:
GivePlayerMoney(playerid, 5000);



Re: Timer i all players to one player? - Admigo - 25.08.2012

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?


Re: Timer i all players to one player? - Admigo - 25.08.2012

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.


Re: Timer i all players to one player? - Admigo - 25.08.2012

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;
}



Re: Timer i all players to one player? - Admigo - 25.08.2012

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.


Re: Timer i all players to one player? - leonardo1434 - 25.08.2012

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


Re: Timer i all players to one player? - Babul - 25.08.2012

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