#1

Hey I'm still struggling with code I'm trying to do, what I'm trying to do is save player's crimes and load them..
What I tried is this:

pawn Код:
CMD:makewanted(playerid,params[])
{
    new id, reason[80], string[50];
    PlayerInfo[playerid][Crime] = reason[70];
    if(sscanf(params, "us[80]",id ,reason)) return SendClientMessage(playerid,-1,"USAGE: /report <PlayerID/Part of Name> <Reason>");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Player Not connected");
   
    new INI:File = INI_Open(UserPath(playerid));
    INI_WriteString(File,"Crimes",reason);
    INI_Close(File);
    format(string, sizeof(string), "Crime %s saved", reason);
    SendClientMessage(playerid, -1, string);
    return 1;
}

CMD:wanted(playerid,params[])
{
    new string[128];
    new INI:File = INI_Open(UserPath(playerid));
    format(string, sizeof(string), "Your current crimes: %s", PlayerInfo[playerid][Crime]);
    SendClientMessage(playerid, -1, string);
    INI_Close(File);
    return 1;
}
It saves the crime but can't load it :S
Reply
#2

Quote:
Originally Posted by Overhaul
Посмотреть сообщение
Load Y_INI string data with the INI_String function, I don't see you using that.

Syntax for INI_String:
INI_String(name[], dest[], size)
You moved it. Read my quote above from your first misplaced thread.

EDIT: Open the file, load the data and assign a variable to that piece of data, close the file. Use the variables to use the retrieved data.
Reply
#3

There is no loading in this code.
Read this topic it will help you learn the loading and saving of accounts https://sampforum.blast.hk/showthread.php?tid=273088
Reply
#4

So far I'm trying to do this
pawn Код:
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_String("Crime",PlayerInfo[playerid][Crime],24); // ERROR LINE
    return 1;
}
and it sends me those errors:

pawn Код:
(647) : error 001: expected token: ")", but found "["
(647) : warning 215: expression has no effect
(647) : error 001: expected token: ";", but found "]"
(647) : error 029: invalid expression, assumed zero
(647) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Reply
#5

Can we seen your PlayerInfo enum?
Reply
#6

Sure

pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    Crime
}

new PlayerInfo[MAX_PLAYERS][pInfo];
REST:

pawn Код:
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_String("Crime",PlayerInfo[playerid][Crime],24);
    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;
}
pawn Код:
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"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
    }
    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,"Crimes",PlayerInfo[playerid][Crime]);
    INI_Close(File);
    return 1;
}
Reply
#7

Hello,
"Crime" is a string, you need to declare that in the enum.
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    Crime[24]
}
Also, i advise you to load the information into variables when the player loads, change them according to the vars, and when they need to be saved, save them. Get the information from the vars and dont open the file each time you need to load something.


Here is a better function for a user path. Its more secure than yours and here is why;
Your function does not minimize the whole nickname when loaded, so for example when a player joins the server as User, another one can join the server again as USER since your function counts account names according to capitalizing; Here is a new, better one:

Код:
UserPath(playerid)
{
    new str[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));

    for(new d,len = strlen(name); d != len; d++)
        name[d] = tolower(name[d]);

    format(str,sizeof(str),USERPATH,name);
    return str;
}
"Crime" is now a string, you will have to deal with it as such and not as an int.

Quote:
Originally Posted by Lajko1
Посмотреть сообщение
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    INI_WriteInt(File,"Crimes",PlayerInfo[playerid][Crime]);
    return 1;
}
pawn Код:
INI_WriteString(File,"Crimes",PlayerInfo[playerid][Crime]);
Reply
#8

INI_WriteString(File,"Crimes",PlayerInfo[playerid][Crime],24);

817) : warning 202: number of arguments does not match definition
Reply
#9

Are you blind? Did i place a 4th argument?
Reply
#10

Well I still can't load it and show the reason in message

pawn Код:
CMD:wanted(playerid,params[])
{
    //https://sampforum.blast.hk/showthread.php?tid=436664
    new string[128];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,24);
    new INI:File = INI_Open(UserPath(playerid));
    //INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
    INI_WriteString(File,"Crimes",PlayerInfo[playerid][Crime]);
    format(string, sizeof(string), "Your current crimes: %s", PlayerInfo[playerid][Crime]);
    SendClientMessage(playerid, -1, string);
    INI_Close(File);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)