PDA

View Full Version : Y_ini error


1fret
17/04/2017, 11:29 PM
Ok so im trying to make an offline jailing system this is my code.

CMD:ojail(playerid, params[])
{
if(IsPlayerAdmin(playerid) || pInfo[playerid][Admin] >= 4)
{
new playerb[32], string[128], file[32], time[6];
if(sscanf(params, "s[32]i[6]s[128]", playerb, time, params)) return SendClientMessage(playerid, error, "Usage: /ojail [playername] [time] [reason]");
if(idCheck(playerb) != INVALID_PLAYER_ID) return SendClientMessage(playerid, error, "Player is connected to the server, use /ajail instead.");
if (!fexist(file)) return SendClientMessage(playerid,error,"Error: This player doesn't have an account.");
new INI:ACCOUNT = INI_Open(file);
INI_SetTag(ACCOUNT,"data");
INI_WriteInt(ACCOUNT, "Jailed", 2);
INI_WriteInt(ACCOUNT, "JailedTime", time);
INI_Close(ACCOUNT);
format(string, sizeof(string), "[AdmCmd]: {FF6347}An Administrator has been jailed %s. [Reason: %s]", playerb, params);
SendClientMessageToAll(red, string);
format(string, sizeof(string), "[OJAIL] %s has offline jailed %s . [Reason: %s]", GetName(playerid), playerb, params);
WriteToLog(string,"oJail");
}
else return ShowMessage(playerid, error, 1);
return 1;
}


//But i keep getting an argument type mismatch at this line
INI_WriteInt(ACCOUNT, "JailedTime", time);



Also could someone tell me how to read from a specific line in y_ini. Example say i want to show the players reason why he was banned on his next connection to the server , how do i read from the file..

Dont send me the link to the Y_ini topic cause i tried it already and failed... So could someone explain it and show me as well.

Nyitz
17/04/2017, 11:50 PM
time is an array, WriteInt writes integers.
How about this:


new unixtime, x, y, z;
unixtime=gettime(x,y,z);
new INI:ACCOUNT = INI_Open(file);
INI_SetTag(ACCOUNT,"data");
INI_WriteInt(ACCOUNT, "Jailed", 2);
INI_WriteInt(ACCOUNT, "JailedUntil", unixtime+JAIL_TIME_IN_SECONDS);
INI_Close(ACCOUNT);


Then you can operate on a UNIX timestamp, set jail time by simply passing time in seconds as a command parameter (/ojail <player> 30), and determine if player can leave jail already by comparing current time and his JailedUntil time in the database.

CaRaM3LL
17/04/2017, 11:51 PM
if(sscanf(params, "uds[128]", playerb, time, params)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /ojail [playername] [time] [reason]");

it should solve the problem.

1fret
18/04/2017, 01:02 AM
if(sscanf(params, "uds[128]", playerb, time, params)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /ojail [playername] [time] [reason]");

it should solve the problem.

that didn't work and also i would just like to know what i should use to save arrays in y_ini instead of you just making a coding and paste it..

StrikerZ
18/04/2017, 01:10 AM
Because you used time as a string and saving the time as Integer

CaRaM3LL
18/04/2017, 01:18 AM
Because you used time as a string and saving the time as Integer

That's right

transform this:

time[6];

to this:

time;

.. this guys explained very well.

1fret
18/04/2017, 01:21 AM
OMG im really sorry but i read true the comments and got what he was trying to say and the error was fixed but i forgot to update the thread..

I will still rep+ you guys

StrikerZ
18/04/2017, 01:25 AM
Also change if(sscanf(params, "s[32]i[6]s[128]"
To

if(sscanf(params, "s[32]ds[128]"