Jump to content
  • 0

pomoc Problém s načítanim dát


MrShoTys74

Dotaz

Zdravím vás prosim vás mam problém s uloženými datami.

Skúsil som na servery vytvorit nový účet na ktorý som dal nejake peniaze par krát som zomrel atd.. aby som mohol otestovať či funguje zaznamenavanie tých dát.

ale ked skúsim založiť nový účet hodí mi to všetky nahrane veci z toho prvého založeneho účtu.

Prosim vás vedel by mi s tym niekto pomoct? Dakujem velmi pekne.

 

Spoiler

#include <a_samp>
#include <YSI\y_ini>
#include <YSI\y_commands>
#include <YSI_Server\y_colours>

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
#define DIALOG_INFO 5
#define DIALOG_SPAWNINFO 6

#define PATH "/Users/%s.ini"

#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"


enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    pWanted,
    pSkin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new pickup_info;

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Wanted",PlayerInfo[playerid][pWanted]);
    INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

main()
{
    print("\n----------------------------------");
    print("RealnySvet 7.0");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    SetGameModeText("Reálny Svet 7.0");

    pickup_info = CreatePickup(1239, 1, 2144.60,1424.97,10.82, -1);
    Create3DTextLabel("Informacie", 0x008080FF, 2144.60, 1424.97, 10.82, 40.0, 0, 0);
    AddStaticVehicleEx(451,2100.8000000,1408.7000000,10.7000000,0.0000000,112,26,15); //Primo
    AddStaticVehicleEx(549,2126.3999000,1398.2000000,10.7000000,0.0000000,88,88,15); //Tampa
    AddStaticVehicleEx(410,2145.6001000,1409.1000000,10.6000000,180.0000000,93,27,15); //Manana
    AddStaticVehicleEx(521,2126.3000000,1408.6000000,10.5000000,180.0000000,63,62,15); //FCR-900
    AddStaticVehicleEx(478,2107.2000000,1398.7000000,10.9000000,0.0000000,109,122,15); //Walton
    AddStaticVehicleEx(510,2113.6001000,1408.2000000,10.5000000,0.0000000,109,122,15); //Mountain Bike
    AddStaticVehicleEx(471,2145.3000000,1399.0000000,10.4000000,0.0000000,52,26,15); //Quad

    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Prihlasenie",""COL_WHITE"Pre prihlásenie zadajte svoje heslo nižšie.","Prihlasit","Ukončit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registracia",""COL_WHITE"Zadajte svoje heslo nižšie a zaregistrujte si nový účet.","Registracia","Ukoncit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Wanted",PlayerInfo[playerid][pWanted]);
    INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    INI_Close(File);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerPos(playerid, 2091.00,1442.34,10.82);
    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
    return 1;
}

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

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}


public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if (pickupid == pickup_info)
    {
    ShowPlayerDialog(playerid, DIALOG_SPAWNINFO, DIALOG_STYLE_MSGBOX, "Notice", "You are connected to the server", "Close", "");
    }
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registrácia",""COL_RED"Zadali ste neplatné heslo.\n"COL_WHITE"Zadajte svoje heslo nižšie a zaregistrujte si nový účet.","Registracia","Ukončit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Wanted",0);
                INI_WriteInt(File,"Skin",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                SetPlayerWantedLevel(playerid, PlayerInfo[playerid][pWanted]);
                SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
                new str[256];
                format(str,256,"Peniaze: %d$\nSkin: %d\nDeaths: %i\nKills: %i\nWanted: %i ",GetPlayerMoney(playerid),GetPlayerSkin(playerid),PlayerInfo[playerid][pDeaths],PlayerInfo[playerid][pKills],GetPlayerWantedLevel(playerid));
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_2,DIALOG_STYLE_MSGBOX,"Info",str,"Pokračovať","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerWantedLevel(playerid, PlayerInfo[playerid][pWanted]);
                    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
                    SpawnPlayer(playerid);
                    new str[256];
                    format(str,256,"Peniaze: %d$\nSkin: %d\nDeaths: %i\nKills: %i\nWanted: %i ",GetPlayerMoney(playerid),GetPlayerSkin(playerid),PlayerInfo[playerid][pDeaths],PlayerInfo[playerid][pKills],GetPlayerWantedLevel(playerid));
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2,DIALOG_STYLE_MSGBOX,"Info",str,"Pokračovať","");
                    
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Prihlasenie",""COL_RED"Zadali ste nesprávne heslo.\n"COL_WHITE"Pre prihlásenie zadajte svoje heslo nižšie.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
 

 

stats.png

Link to comment
Share on other sites

4 odpovědí na tuto otázku

Recommended Posts

  • 2
před 10hodinami, MrShoTys74 said:

Ano to mna napadlo a aj som na samp fóre našiel nieco podobne s tým že tam ma byt podmienka na resetovanie tých dat ale nikde som nenašiel žiadnu funkciu 😅 , prosím ta vedel by si mi s tým pomoct ? Ja sem v pawnu celkem nový a skúšam len základne “skripty” a aj to poväčšine cez tutoriály

na to nie je vyslovene funkcia, len tej premennej stačí nastaviť východziu hodnotu - v tomto prípade "0"

PlayerInfo[playerid][pDeaths] = 0; // zresetuje počet smrtí

A to môžeš vykonať napr. pri odpojení hráča zo serveru - callback "OnPlayerDisconnect" (ideálne, až po uložení dát), alebo hneď pri pripojení hráča k serveru - callback "OnPlayerConnect".

public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pDeaths] = 0; // zresetuje počet smrtí

    if(fexist(UserPath(playerid)))
    {
...

 

Edited by milous22
  • Líbí se mi to! (+1) 1
Link to comment
Share on other sites

  • 0

Ano to mna napadlo a aj som na samp fóre našiel nieco podobne s tým že tam ma byt podmienka na resetovanie tých dat ale nikde som nenašiel žiadnu funkciu 😅 , prosím ta vedel by si mi s tým pomoct ? Ja sem v pawnu celkem nový a skúšam len základne “skripty” a aj to poväčšine cez tutoriály

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...