help me with dini -
emuk - 05.07.2011
I want to create private functions
an example:
A command usable only by people written in the file List.ini
how do I read the names from the file ?
thanks
Re: help me with dini -
willsuckformoney - 05.07.2011
pawn Код:
new Name[24], File[130], str[130];
GetPlayerName(playerid,Name,24);
format(str,130,"Folder/%s.ini",Name);
if(dini_Exists(File))
{
dini_Int(File,"Test"); //Reads integer (Number)
dini_IntSet(File,"Test",1); //Will Set 'Test' as the number 1
dini_Get(File,"Test"); //Will read a string from the line 'Test'
dini_Set(File,"Test","Hello"); //Will set the line of 'Test' as 'Hello' in the .ini file
}
Re: help me with dini -
emuk - 05.07.2011
this is for definited name but if i have the file List.ini
with:
Player1
Player2
how i do to check if the player who wrote is the Player1 or Player2 ?
With GetPlayerName(playerid,Name,24); i have the name but how to check if it is in the List.ini ?
Sorry for my bad english.
Re: help me with dini -
willsuckformoney - 05.07.2011
If i under stand you:
pawn Код:
new Name[24], File[130], str[130];
GetPlayerName(playerid,Name,24);
format(str,130,"Folder/%s.ini",Name);
if(dini_Exists(File))
{
if(dini_Get(File,"Player1") == Name)
{
//Your Code
}
}
AW: help me with dini -
Nero_3D - 05.07.2011
You could do it with that
pawn Код:
new
i = 1,
key[16] = "Player",
name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof name);
for( ; ; ++i) {
valstr(key[6], i, false);
if(strcmp(dini_Get("List.ini", key), Name, false) == 0) {
i = dini_Isset("List.ini", key);
break;
}
}
if the value is set (i == true) the playername is in the file
BUT dini isnt used for such things!, this will slow your script immensely down
Use normal file functions for that (or any
modern file system like y_ini)
pawn Код:
new
File: gFile,
tmp[MAX_STRING],
name[MAX_PLAYER_NAME];
gFile = fopen("List.ini", io_read);
GetPlayerName(playerid, name, sizeof name);
while(fread(gFile, tmp)) {
if(strcmp(tmp[strfind(tmp, "=", false) + 1], name, false) == 0) {
//found
break;
}
}
fclose(gFile);
Re: AW: help me with dini -
emuk - 05.07.2011
Quote:
Originally Posted by Nero_3D
You could do it with that
Use normal file functions for that (or any modern file system like y_ini)
pawn Код:
new File: gFile, tmp[MAX_STRING], name[MAX_PLAYER_NAME]; gFile = fopen("List.ini", io_read); GetPlayerName(playerid, name, sizeof name); while(fread(gFile, tmp)) { if(strcmp(tmp[strfind(tmp, "=", false) + 1], name, false) == 0) { //found break; } } fclose(gFile);
|
thanks !!
I'm sorry but i don't have understood where i must write if the player is found and where not?
first of the break is when is found ?
I tried to put an else but: invalid expression, assumed zero
AW: Re: AW: help me with dini -
Nero_3D - 05.07.2011
Quote:
Originally Posted by emuk
thanks !!
I'm sorry but i don't have understood where i must write if the player is found and where not?
first of the break is when is found ?
I tried to put an else but: invalid expression, assumed zero
|
Just put it in an function
pawn Код:
stock dini_SeekValue(const filename[], const value[], key[] = "", const ksize = sizeof key) {
new
File: gFile;
gFile = fopen(filename, io_read);
if(gFile) {
new
idx,
tmp[DINI_MAX_STRING];
while(fread(gFile, tmp)) {
DINI_StripNewLine(tmp);
idx = strfind(tmp, "=", false) + 1;
if(strcmp(tmp[idx], value, false) == 0) {
key[0] = tmp[idx - 1] = EOS;
strcat(key, tmp, ksize);
fclose(gFile);
return idx;
}
}
fclose(gFile);
}
return 0;
}
pawn Код:
new
name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof name);
if(dini_SeekValue("List.ini", name)) {
//found
} else {
//not found
}
if you want to know the key of the value
pawn Код:
new
key[DINI_MAX_STRING],
name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof name);
if(dini_SeekValue("List.ini", name, key)) {
printf("%s=%s", key, name);
//found
} else {
//not found
}
If you want to check if a key already exist just use dini_Isset
Re: help me with dini -
emuk - 05.07.2011
i tried :
if(strcmp(cmd, "/conferma", true) == 0) {
new
name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof name);
if(dini_SeekValue("List.ini", name)) {
SendClientMessage(playerid, COLOR_WHITE, " Found");
} else {
SendClientMessage(playerid, COLOR_WHITE, " Not Found");
}
return 1;
}
but with every nick it says not found !!
AW: help me with dini -
Nero_3D - 05.07.2011
Yes there was an mistake, it always return found, I fixed it in my last post
The only reason why it always returnd a fail is that it couldnt find the file
Check again if the directory / filename is correct
Re: help me with dini -
emuk - 05.07.2011
still problem, I know that I create problems useless xD