SA-MP Forums Archive
Kill, Death and server Visit counter doesn't work out for me! - 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: Kill, Death and server Visit counter doesn't work out for me! (/showthread.php?tid=295850)



Kill, Death and server Visit counter doesn't work out for me! - Kasis - 08.11.2011

pawn Код:
enum pInfo
{
    pKills,
    pDeaths,
    pVisits,
}

public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pVisits]++;
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}
I got working register system and everything there is set properly.

This just simply isnt working out.

If I edit my player notepad file with for example 5 server visits 10 deaths and 15 kills then in game I get that when i chech my stats. But as fact, its not working while I am playing, basically they are not counting anything.


Re: Kill, Death and server Visit counter doesn't work out for me! - Stigg - 08.11.2011

This:
pawn Код:
enum pInfo
{
    pKills,
    pDeaths,
    pVisits,
}
Should be:
pawn Код:
enum pInfo
{
    pKills,
    pDeaths,
    pVisits//leave the last one off.
}



Re: Kill, Death and server Visit counter doesn't work out for me! - GAMER_PS2 - 08.11.2011

To late but yeah delete , on pVisits


Re: Kill, Death and server Visit counter doesn't work out for me! - Kasis - 08.11.2011

That didn't work out.


Re: Kill, Death and server Visit counter doesn't work out for me! - Stigg - 08.11.2011

Try:
pawn Код:
//At the top
enum pInfo
{
    pKills,
    pDeaths,
    pVisits
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pVisits]++;
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/stats", cmdtext, true, 10) == 0)//test cmd
    {
       if(IsPlayerConnected(playerid))
       {
           new statstring[128];
           format(statstring, sizeof(statstring), "| Your Stats | Kills: %d | Deaths: %d | Visits: %d |",PlayerInfo[playerid][pKills],PlayerInfo[playerid][pDeaths],PlayerInfo[playerid][pVisits]);
           SendClientMessage(playerid,-1, statstring);
       }
       return 1;
    }
    return 0;
}



Re: Kill, Death and server Visit counter doesn't work out for me! - FarSe. - 08.11.2011

Do you load/save the data from/to 'user file'?


Re: Kill, Death and server Visit counter doesn't work out for me! - Kasis - 08.11.2011

Quote:
Originally Posted by FarSe.
Посмотреть сообщение
Do you load/save the data from/to 'user file'?
Yes and that works well.

Quote:
Originally Posted by Stigg
Посмотреть сообщение
Try:
pawn Код:
//At the top
enum pInfo
{
    pKills,
    pDeaths,
    pVisits
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pVisits]++;
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/stats", cmdtext, true, 10) == 0)//test cmd
    {
       if(IsPlayerConnected(playerid))
       {
           new statstring[128];
           format(statstring, sizeof(statstring), "| Your Stats | Kills: %d | Deaths: %d | Visits: %d |",PlayerInfo[playerid][pKills],PlayerInfo[playerid][pDeaths],PlayerInfo[playerid][pVisits]);
           SendClientMessage(playerid,-1, statstring);
       }
       return 1;
    }
    return 0;
}
This works well on clean script and that is exectly what I have. Gonna go trought my script step by step.
Thanks for help.





Okay... Everything seems to be alright with my script, but there is still problem. It doesn't count my logins.


Re: Kill, Death and server Visit counter doesn't work out for me! - Stigg - 08.11.2011

Can we see your code then ?


Re: Kill, Death and server Visit counter doesn't work out for me! - Kasis - 08.11.2011

pawn Код:
enum pInfo
{
    pKills,
    pDeaths,
    pVisits
}

new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
        gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if (!dini_Exists(file))
    {
        ShowPlayerDialog(playerid, 100, DIALOG_STYLE_INPUT, "Test", "Welcome, your not registered!", "Register", "Leave");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid, 200, DIALOG_STYLE_INPUT, "Test", "Welcome back to server!", "Login", "Leave");
    }

        PlayerInfo[playerid][pVisits]++;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
        new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]);
        dini_IntSet(file, "Visits", PlayerInfo[playerid][pVisits]);        
    }
    gPlayerLogged[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
        gPlayerLogged[playerid] = 1;
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
        SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    // |-------|        |---------|     REGISTER / LOGIN      |-----------|       |----------|
    if (dialogid == 100)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Test", "Welcome, your not registered!", "Register", "Leave");
        dini_Create(file);
        dini_IntSet(file, "Password", udb_hash(inputtext));
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
        dini_IntSet(file, "Visits", PlayerInfo[playerid][pVisits] = 0);
        format(string, 128, ""COL_ORANGE"You succesfully registered the nickname "COL_VIOLET"%s "COL_ORANGE"with password "COL_VIOLET"%s"COL_ORANGE", you have been auto logged in.", name, inputtext);
        SendClientMessage(playerid, -1, string);
        gPlayerLogged[playerid] = 1;
    }
    if (dialogid == 200)
    {
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Test", "Welcome back to server!", "Login", "Leave");
        new tmp;
        tmp = dini_Int(file, "Password");
        if(udb_hash(inputtext) != tmp) {
            SendClientMessage(playerid, -1, ""COL_RED"[Error] "COL_WHITE"Wrong password!");
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Test", "Welcome back to server!", "Login", "Leave");
        }
        else
        {
            gPlayerLogged[playerid] = 1;
            PlayerInfo[playerid][pKills] = dini_Int(file, "Kills");
        PlayerInfo[playerid][pDeaths] = dini_Int(file, "Deaths");
        PlayerInfo[playerid][pVisits] = dini_Int(file, "Visits");
            SendClientMessage(playerid, -1, ""COL_ORANGE"Successfully logged in!");
        }
    }
    return 1;
}
Here you go, I hope this will help you to solve my problem.


Re: Kill, Death and server Visit counter doesn't work out for me! - Stigg - 08.11.2011

Try:
pawn Код:
if (dialogid == 200)
    {
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Test", "Welcome back to server!", "Login", "Leave");
        new tmp;
        tmp = dini_Int(file, "Password");
        if(udb_hash(inputtext) != tmp) {
            SendClientMessage(playerid, -1, ""COL_RED"[Error] "COL_WHITE"Wrong password!");
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Test", "Welcome back to server!", "Login", "Leave");
        }
        else
        {
        gPlayerLogged[playerid] = 1;
        PlayerInfo[playerid][pKills] = dini_Int(file, "Kills");
        PlayerInfo[playerid][pDeaths] = dini_Int(file, "Deaths");
        PlayerInfo[playerid][pVisits] = dini_Int(file, "Visits");
        SendClientMessage(playerid, -1, ""COL_ORANGE"Successfully logged in!");
        PlayerInfo[playerid][pVisits]++;//move visits to player login
        }
    }
Delete the on player connect pVisits, put it under when player logs in.


Re: Kill, Death and server Visit counter doesn't work out for me! - Kasis - 08.11.2011

Awesome! That worked! Thanks man!


Re: Kill, Death and server Visit counter doesn't work out for me! - Stigg - 08.11.2011

Quote:
Originally Posted by kasis223
Посмотреть сообщение
Awesome! That worked! Thanks man!
No prob's, we got there in the end.