SA-MP Forums Archive
Whats wrong here? Trying to make an command to edit offline players cash. - 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: Whats wrong here? Trying to make an command to edit offline players cash. (/showthread.php?tid=447861)



Whats wrong here? Trying to make an command to edit offline players cash. - 101 - 01.07.2013

pawn Код:
CMD:addcashoffline(playerid, params[])
{
    new offlineplayer[24], filestring[79], cash;
    if(sscanf(params, "s[24]i", offlineplayer, cash)) return SendClientMessage(playerid, COLOR_RED, "/addcashoff NAME CASH");
    format(filestring, sizeof(filestring), AccountsPath, offlineplayer[24]);
    if(!fexist(filestring)) return SendClientMessage(playerid, COLOR_RED, "No palyer but that name");
    INI_ParseFile(filestring, "LoadAccountOffline_%s", .bExtra = true , .extra = offlineplayer[24]);
    new INI:File = INI_Open(filestring);
    INI_WriteInt(File, "Cash", PlayerData[offlineplayer[24]][pCash]+cash);
    INI_Close(File);
    format(gstring, sizeof(gstring), "%s now has $%d", offlineplayer[24], PlayerData[offlineplayer[24]][pCash]+cash);
    SendClientMessage(playerid, COLOR_RED, gstring);
    return 1;
}

forward LoadAccountOffline_user(offlineplayer[24], name[], value[]);
public LoadAccountOffline_user(offlineplayer[24], name[], value[])
{
    INI_Int("Cash", PlayerData[offlineplayer[24]][pCash]);
    return 1;
}
The error is error 032: array index out of bounds (variable "offlineplayer"), which all seems to relate to offlineplayer[24]

Thanks in advance


Re: Whats wrong here? Trying to make an command to edit offline players cash. - Nathan_Taylor - 02.07.2013

try
pawn Код:
CMD:addcashoffline(playerid, params[])
{
    new offlineplayer[MAX_PLAYER_NAME+1], filestring[79], cash;
    if(sscanf(params, "s[MAX_PLAYER_NAME+1]i", offlineplayer, cash)) return SendClientMessage(playerid, COLOR_RED, "/addcashoff NAME CASH");
    format(filestring, sizeof(filestring), AccountsPath, offlineplayer[MAX_PLAYER_NAME+1]);
    if(!fexist(filestring)) return SendClientMessage(playerid, COLOR_RED, "No palyer but that name");
    INI_ParseFile(filestring, "LoadAccountOffline_%s", .bExtra = true , .extra = offlineplayer[MAX_PLAYER_NAME+1]);
    new INI:File = INI_Open(filestring);
    INI_WriteInt(File, "Cash", PlayerData[offlineplayer[24]][pCash]+cash);
    INI_Close(File);
    format(gstring, sizeof(gstring), "%s now has $%d", offlineplayer[MAX_PLAYER_NAME+1], PlayerData[offlineplayer[MAX_PLAYER_NAME+1]][pCash]+cash);
    SendClientMessage(playerid, COLOR_RED, gstring);
    return 1;
}

forward LoadAccountOffline_user(offlineplayer[MAX_PLAYER_NAME+1], name[], value[]);
public LoadAccountOffline_user(offlineplayer[MAX_PLAYER_NAME+1], name[], value[])
{
    INI_Int("Cash", PlayerData[offlineplayer[MAX_PLAYER_NAME+1]][pCash]);
    return 1;
}
I may be wrong actually, but why do you keep defining the length of offlineplayer? Might that be causing the issues?


Re: Whats wrong here? Trying to make an command to edit offline players cash. - Praox - 02.07.2013

Try this:
pawn Код:
CMD:addcashoffline(playerid, params[])
{
    new offlineplayer[24], filestring[79], cash;
    if(sscanf(params, "s[24]i", offlineplayer, cash)) return SendClientMessage(playerid, COLOR_RED, "/addcashoff NAME CASH");
    format(filestring, sizeof(filestring), AccountsPath, offlineplayer);
    if(!fexist(filestring)) return SendClientMessage(playerid, COLOR_RED, "No palyer but that name");
    INI_ParseFile(filestring, "LoadAccountOffline_%s", .bExtra = true , .extra = offlineplayer);
    new INI:File = INI_Open(filestring);
    INI_WriteInt(File, "Cash", PlayerData[offlineplayer][pCash]+cash);
    INI_Close(File);
    format(gstring, sizeof(gstring), "%s now has $%d", offlineplayer, PlayerData[offlineplayer][pCash]+cash);
    SendClientMessage(playerid, COLOR_RED, gstring);
    return 1;
}

forward LoadAccountOffline_user(offlineplayer[24], name[], value[]);
public LoadAccountOffline_user(offlineplayer[24], name[], value[])
{
    INI_Int("Cash", PlayerData[offlineplayer][pCash]);
    return 1;
}



Re: Whats wrong here? Trying to make an command to edit offline players cash. - 101 - 02.07.2013

Nathan. I initially need to do it because it is a string, if I don't sscanf will throw errors

Neither worked btw, yours always throws error 032: array index out of bounds


And praox

error 033: array must be indexed (variable "offlineplayer") 4 times and once error 035: argument type mismatch (argument 5)


Re: Whats wrong here? Trying to make an command to edit offline players cash. - Income - 03.07.2013

Fix every line you have "offlineplayer[24]" since you've already defined that.
Alter that with "offlineplayer" instead;
For instance:

format(filestring, sizeof(filestring), AccountsPath, offlineplayer[24]);
-> format(filestring, sizeof(filestring), AccountsPath, offlineplayer);


Re: Whats wrong here? Trying to make an command to edit offline players cash. - 101 - 03.07.2013

That worked but sscanf gives me errors saying that strings without limit are deprecated