ScoreTimer Only works for PlayerID 0
#1

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;
}
Reply
#2

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

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;
}
Reply
#4

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
Reply
#5

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.
Reply
#6

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?
Reply
#7

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...
}
Reply
#8

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;
}
Reply
#9

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!
Reply
#10

Remove ; on that line.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)