SA-MP Forums Archive
ScoreTimer Only works for PlayerID 0 - 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: ScoreTimer Only works for PlayerID 0 (/showthread.php?tid=371534)



ScoreTimer Only works for PlayerID 0 - kbalor - 23.08.2012

pawn Код:
#define SCORE_TIME          3 * 60  // = 3Minutes

dcmd_CMD_REGISTER(playerid,params[])
{
       {
           //Somecodes related to register
           SetTimerEx("ScoreTimer", 1000, 0, "d", playerid);
           return 1;
    }
    return 1;
}

LoginPlayer(playerid)
{
    SetTimerEx("ScoreTimer", 1000, 0, "i", playerid);
    //Some other codes related...
}

forward ScoreTimer(playerid);
public ScoreTimer(playerid)
{
    if(!IsPlayerConnected(playerid)) return 1;
    AccInfo[playerid][pSecondScore] += 1;
    if(AccInfo[playerid][pSecondScore] >= SCORE_TIME)
    {
        SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
        AccInfo[playerid][pSecondScore] = 0;
    }
    SetTimerEx("ScoreTimer", 1000, 0, "d", playerid);
    return 1;
}



Re: ScoreTimer Only works for PlayerID 0 - clarencecuzz - 23.08.2012

pawn Код:
SetTimerEx("ScoreTimer", 1000, 0, "d", playerid);
Should Be:
pawn Код:
SetTimerEx("ScoreTimer", 1000, 0, "i", playerid);



Re : ScoreTimer Only works for PlayerID 0 - [M.A]Angel[M.A] - 23.08.2012

You can create new one,
Код:
UnderOnGameModeInit
	//SCORE
	SetTimer("scoretimer", 1000, true);
Anywhere
forward scoretimer();
public scoretimer()
{
    for(new i; i<MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        seconds[i] ++;
        if(seconds[i] == 60)
        {
            SetPlayerScore(i, GetPlayerScore(i) + 1);
            seconds[i] = 0;
        }
    }
    return 1;
}



Re: Re : ScoreTimer Only works for PlayerID 0 - kbalor - 23.08.2012

Quote:
Originally Posted by [M.A]Angel[M.A]
Посмотреть сообщение
You can create new one,
Код:
UnderOnGameModeInit
	//SCORE
	SetTimer("scoretimer", 1000, true);
Anywhere
forward scoretimer();
public scoretimer()
{
    for(new i; i<MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        seconds[i] ++;
        if(seconds[i] == 60)
        {
            SetPlayerScore(i, GetPlayerScore(i) + 1);
            seconds[i] = 0;
        }
    }
    return 1;
}
I'm not sure with this. But I'm going to test it later. +rep


Re: ScoreTimer Only works for PlayerID 0 - clarencecuzz - 23.08.2012

That wouldn't work, because he only wants them to start the timer once they login or register... this would give them score just for connecting.


Re: ScoreTimer Only works for PlayerID 0 - kbalor - 23.08.2012

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
pawn Код:
SetTimerEx("ScoreTimer", 1000, 0, "d", playerid);
Should Be:
pawn Код:
SetTimerEx("ScoreTimer", 1000, 0, "i", playerid);
Okay thanks again for helping. I can't test it right now without a player I need 1-3 player's. +rep

Anyway, what is the better way to use ScoreTimer, this one or the other one that Angel posted?


Re : Re: ScoreTimer Only works for PlayerID 0 - [M.A]Angel[M.A] - 23.08.2012

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
That wouldn't work, because he only wants them to start the timer once they login or register... this would give them score just for connecting.
Why not?

Код:
LoginPlayer(playerid)
{
    SetTimer("scoretimer", 1000, true);
    //Some other codes related...
}



Re: ScoreTimer Only works for PlayerID 0 - clarencecuzz - 23.08.2012

The EASIEST way to do it is with foreach. You need to download the 'foreach' include first and add #include <foreach> in your script.

Then...

With foreach include:
pawn Код:
#include <foreach>
public OnFilterScriptInit() //Or OnGameModeInit()
{
    SetTimer("ScoreTimer", 1000, true);
    return 1;
}

forward ScoreTimer();
public ScoreTimer()
{
    foreach(Player, i) //If you're using foreach include. (RECOMMENDED)
    {
        if(PlayerInfo[i][LoggedIn] == 1) //Check if player is logged in. Remember use 'i' not 'playerid'
        {
            seconds[i]++;
            if(seconds[i] >= 60)
            {
                SetPlayerScore(i, GetPlayerScore(i) + 1);
                seconds[i] = 0;
            }
        }
    }
    return 1;
}
Without foreach include:
pawn Код:
public OnFilterScriptInit() //Or OnGameModeInit()
{
    SetTimer("ScoreTimer", 1000, true);
    return 1;
}

forward ScoreTimer();
public ScoreTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][LoggedIn] == 1)
            {
                seconds[i]++;
                if(seconds[i] >= 60)
                {
                    SetPlayerScore(i, GetPlayerScore(i) + 1);
                    seconds[i] = 0;
                }
            }
        }
    }
    return 1;
}



Re: ScoreTimer Only works for PlayerID 0 - kbalor - 23.08.2012

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
The EASIEST way to do it is with foreach. You need to download the 'foreach' include first and add #include <foreach> in your script.

Then...

With foreach include:
pawn Код:
#include <foreach>
public OnFilterScriptInit() //Or OnGameModeInit()
{
    SetTimer("ScoreTimer", 1000, true);
    return 1;
}

forward ScoreTimer();
public ScoreTimer()
{
    foreach(Player, i) //If you're using foreach include. (RECOMMENDED)
    {
        if(PlayerInfo[i][LoggedIn] == 1) //Check if player is logged in. Remember use 'i' not 'playerid'
        {
            seconds[i]++;
            if(seconds[i] >= 60)
            {
                SetPlayerScore(i, GetPlayerScore(i) + 1);
                seconds[i] = 0;
            }
        }
    }
    return 1;
}
Without foreach include:
pawn Код:
public OnFilterScriptInit() //Or OnGameModeInit()
{
    SetTimer("ScoreTimer", 1000, true);
    return 1;
}

forward ScoreTimer();
public ScoreTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][LoggedIn] == 1)
            {
                seconds[i]++;
                if(seconds[i] >= 60)
                {
                    SetPlayerScore(i, GetPlayerScore(i) + 1);
                    seconds[i] = 0;
                }
            }
        }
    }
    return 1;
}
I use foreach. And changed the PlayerInfo to AccInfo. Now my last warning is seconds[i]++;

Код:
(8541) : error 017: undefined symbol "seconds"
(8541) : warning 215: expression has no effect
(8541) : error 001: expected token: ";", but found "]"
(8541) : error 029: invalid expression, assumed zero
(8541) : fatal error 107: too many error messages on one line
pawn Код:
forward ScoreTimer();
public ScoreTimer()
{
    foreach(Player, i) //If you're using foreach include. (RECOMMENDED)
    {
        if(AccInfo[i][LoggedIn] == 1) //Check if player is logged in. Remember use 'i' not 'playerid'
        {
            seconds[i]++;
            if(seconds[i] >= 60)
            {
                SetPlayerScore(i, GetPlayerScore(i) + 1);
                seconds[i] = 0;
            }
        }
    }
    return 1;
}
Thanks for the time making script for me. Appreciate every effort you made!


Respuesta: ScoreTimer Only works for PlayerID 0 - HydraX - 24.08.2012

Remove ; on that line.