SetTimerEx
#1

Hi guys.

I have a problem with a part of my script.

There's a part in my spawn check, at the very start, that if the check works out then a timer gets set off. This works to an extent. When the server first starts, if a new player connects they must first disconnect then re-connect for the timer to work, in saying that, when a new player connects the timer activates but doesn't call the function after the time.

Here's the codes for the timer:
pawn Код:
new WelcomeTimerEx[MAX_PLAYERS];
The actual code to activate the timer:
pawn Код:
WelcomeTimerEx[playerid] = SetTimerEx("WelcomeTimer", 2500, false, "i", playerid);
And when a player connects:
pawn Код:
WelcomeTimerEx[playerid] = 0;
I also kill the timer at the end of "WelcomeTimer".

I'm not sure why this is happening, it's a strange bug. As said above, it works perfectly after a player disconnects then re-connects, and a player has to do that every time the server starts.
Reply
#2

You're not showing near enough code for anyone to be anywhere near to able to help you. (That was a long-winded sentence D: ).
Reply
#3

I'm not sure what to show, sorry.

Here's the check part I spoke about in the spawn check:
pawn Код:
if(gIsPlayerLoggedIn[playerid] == 0)
    {
        ClearScreen(playerid);
        TextDrawShowForPlayer(playerid, WelcomeScreen0);
        TextDrawShowForPlayer(playerid, WelcomeScreen1);
        TextDrawShowForPlayer(playerid, WelcomeScreen2);
        TextDrawShowForPlayer(playerid, WelcomeScreen3);
        print("before settimer");
        WelcomeTimerEx[playerid] = SetTimerEx("WelcomeTimer", 2500, false, "i", playerid);
        print("after settimer");
    }
As you can see I've done some debugging, everytime I connect, it prints both "before settimer" and "after settimer".

Here's the actual WelcomeTimer callback:
pawn Код:
public WelcomeTimer(playerid)
{
    print("1");
    new string[126];
    print("2");
    TextDrawHideForPlayer(playerid, WelcomeScreen0);
    print("3");
    TextDrawHideForPlayer(playerid, WelcomeScreen1);
    print("4");
    TextDrawHideForPlayer(playerid, WelcomeScreen2);
    print("5");
    TextDrawHideForPlayer(playerid, WelcomeScreen3);
    print("6");

    SetPlayerPos(playerid, -2089.1033, 2314.7834, 15.2437);
    SetPlayerCameraPos(playerid, -2085.851562, 2313.926513, 27.484699);
    SetPlayerCameraLookAt(playerid, -2090.496826, 2315.150634, 26.098077);

    TogglePlayerControllable(playerid, 0);

    format(string, sizeof(string), "{FFFFFF}You've connected to {33818E}Suburban Roleplay!");
    SendClientMessage(playerid, -1, string);

    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        if(PlayerData[playerid][Registered] == 0) /* Register Player */
        {
            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Register on Suburban Roleplay", "{FFFFFF}Welcome to Suburban Roleplay.\n\nYour account doesn't exist in our database. Please input a desired password below.", "Continue", "Quit");
        }
        else if(PlayerData[playerid][Registered] == 1) /* Login Player */
        {
            format(string, sizeof(string), "{FFFFFF}Welcome back, %s.\n\nPlease input your existing password below.", GetPlayersName(playerid));
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Log back into Suburban Roleplay", string, "Login", "Leave");
        }
    }
    else /* Register Player */
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Register on Suburban Roleplay", "{FFFFFF}Welcome to Suburban Roleplay.\n\nYour account doesn't exist in our database. Please input a desired password below.", "Continue", "Quit");
    }
    KillTimer(WelcomeTimerEx[playerid]);
    return 1;
}
Now when the player first connects, nothing from that prints, no 1, no 2, nothing. How ever when the player disconnects then re-connects, it all prints and all works 100%.

So yeah I have no idea what else to show because this is one of the weirdest bugs I've ever encountered, lol.
Reply
#4

Show ALL code related to it. ALL instances of the variables. ALL the SetTimer(Ex), KillTimer, variable declaration, timer function and all that shiz. Your timer may be being killed before it has a chance to call itself.
Reply
#5

pawn Код:
new WelcomeTimerEx[MP];

public WelcomeTimer(playerid)
{
    print("1");
    new string[126];
    print("2");
    TextDrawHideForPlayer(playerid, WelcomeScreen0);
    print("3");
    TextDrawHideForPlayer(playerid, WelcomeScreen1);
    print("4");
    TextDrawHideForPlayer(playerid, WelcomeScreen2);
    print("5");
    TextDrawHideForPlayer(playerid, WelcomeScreen3);
    print("6");

    SetPlayerPos(playerid, -2089.1033, 2314.7834, 15.2437);
    SetPlayerCameraPos(playerid, -2085.851562, 2313.926513, 27.484699);
    SetPlayerCameraLookAt(playerid, -2090.496826, 2315.150634, 26.098077);

    TogglePlayerControllable(playerid, 0);

    format(string, sizeof(string), "{FFFFFF}You've connected to {33818E}Suburban Roleplay!");
    SendClientMessage(playerid, -1, string);

    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        if(PlayerData[playerid][Registered] == 0) /* Register Player */
        {
            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Register on Suburban Roleplay", "{FFFFFF}Welcome to Suburban Roleplay.\n\nYour account doesn't exist in our database. Please input a desired password below.", "Continue", "Quit");
        }
        else if(PlayerData[playerid][Registered] == 1) /* Login Player */
        {
            format(string, sizeof(string), "{FFFFFF}Welcome back, %s.\n\nPlease input your existing password below.", GetPlayersName(playerid));
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Log back into Suburban Roleplay", string, "Login", "Leave");
        }
    }
    else /* Register Player */
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Register on Suburban Roleplay", "{FFFFFF}Welcome to Suburban Roleplay.\n\nYour account doesn't exist in our database. Please input a desired password below.", "Continue", "Quit");
    }
    KillTimer(WelcomeTimerEx[playerid]);
    return 1;
}

    if(gIsPlayerLoggedIn[playerid] == 0)
    {
        ClearScreen(playerid);
        TextDrawShowForPlayer(playerid, WelcomeScreen0);
        TextDrawShowForPlayer(playerid, WelcomeScreen1);
        TextDrawShowForPlayer(playerid, WelcomeScreen2);
        TextDrawShowForPlayer(playerid, WelcomeScreen3);
        print("before settimer");
        WelcomeTimerEx[playerid] = SetTimerEx("WelcomeTimer", 2500, false, "i", playerid);
        print("after settimer");
    }


public OnPlayerConnect(playerid)
{
    new string[126];
    gIsPlayerConnected[playerid] = 1;
    gIsPlayerLoggedIn[playerid] = 0;
    gIsPlayerSpawned[playerid] = 0;

    PlayerData[playerid][Registered] = 0;
    PlayerData[playerid][Age] = 0;
    PlayerData[playerid][Gender] = 0;
    PlayerData[playerid][Interior] = 0;
    PlayerData[playerid][VirtualWorld] = 0;
    PlayerData[playerid][Wallet] = 0;
    PlayerData[playerid][Bank] = 0;
    PlayerData[playerid][BankPin] = 0;
    PlayerData[playerid][Skin] = 0;
    PlayerData[playerid][AdminLevel] = 0;
    PlayerData[playerid][AdminKey] = 0;
    PlayerData[playerid][Dead] = 0;
    PlayerData[playerid][HospitalTime] = 0;
   
    format(string, sizeof(string), "None");
    strmid(PlayerData[playerid][LastKickedBy], string, 0, strlen(string), 255);
    strmid(PlayerData[playerid][LastKickReason], string, 0, strlen(string), 255);
    strmid(PlayerData[playerid][BannedBy], string, 0, strlen(string), 255);
    strmid(PlayerData[playerid][BanReason], string, 0, strlen(string), 255);
    strmid(PlayerData[playerid][Accent], string, 0, strlen(string), 255);
   
    HospitalTimerEx[playerid] = 0;
    WelcomeTimerEx[playerid] = 0;

    AdminCmdTimer[playerid] = 0;
    SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
    SpawnPlayer(playerid);
    return 1;
}
That's everything that involves the timer.
Reply
#6

Why do you kill the timer? It makes no sense to kill it AFTER it's been used. That's like throwing a banana that you've already eaten in the trash - it's impossible for starters unless you puke it up but yeah this analogy is going weird so let's stop here. Don't kill a timer that's already dead.

As for it not being called, try and replace all the code in the timer with just a print. Also why do you even have a variable for it? It never gets killed. You should kill it under OnPlayerDisconnect though in case they /q in the first 2 seconds after connecting. It may happen.

Summary: replace function contents with a print to see if it's being called.
Reply
#7

Quote:
Originally Posted by MP2
Посмотреть сообщение
Why do you kill the timer? It makes no sense to kill it AFTER it's been used. That's like throwing a banana that you've already eaten in the trash - it's impossible for starters unless you puke it up but yeah this analogy is going weird so let's stop here. Don't kill a timer that's already dead.

As for it not being called, try and replace all the code in the timer with just a print. Also why do you even have a variable for it? It never gets killed. You should kill it under OnPlayerDisconnect though in case they /q in the first 2 seconds after connecting. It may happen.

Summary: replace function contents with a print to see if it's being called.
I'm not sure why.. I just had a "just in case" thought I guess. How ever I moved it to OnPlayerDisconnect like you suggested.

As you can see in "WelcomeTimer" there's a "print("1");" at the very top, that does not get printed at all when the player connects for the first time.. but the timer does get activated as I can tell by the debugging.
Reply
#8

Bump.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)