[HELP] File Path
#1

I posted this in Dracoblue's Dini post, but i'm not getting any replies, so I figured I would post here to, as I am in a rush to get this done.

So, I have a problem reading and writing to player files. I use XAdmin, so the path is scriptfiles/xadmin/users/PlayerNameHere.ini

Well, here is my code:

Code:

if(dini_Exists("scriptfiles/xadmin/Users/%s.ini"))
{
dini_IntSet("scriptfiles/xadmin/Users/%s.ini", "Job", 3);
}


It isn't reaching the player files, I don't think. I read something about %s not working with the file path?

How would I go about fixing that?

Thanks. Smiley
Reply
#2

You don't need to write \scriptfiles\ for the file's name. Everything is saving to scriptfiles by default.
Reply
#3

Yeah, true. But, is there anything else I am doing wrong? I've been looking around and searching but I can't find anything on the subject.
Reply
#4

You have to assign something to %s. Do you think Pawn is smart enough to guess that your %s should be a player name?

pawn Код:
new str[17 + MAX_PLAYER_NAME];
GetPlayerName(playerid, str, MAX_PLAYER_NAME);
format(str, sizeof str, "xadmin/Users/%s.ini", str);

if(dini_Exists(str))
But this will silently crash your server if a player have a name containing forbidden files characters.
Reply
#5

Quote:
Originally Posted by 0rb
You have to assign something to %s. Do you think Pawn is smart enough to guess that your %s should be a player name?

pawn Код:
new str[18 + MAX_PLAYER_NAME];
GetPlayerName(playerid, str, MAX_PLAYER_NAME);
format(str, sizeof str, "xadmin/Users/%s.ini", str);

if(dini_Exists(str))
But this will silently crash your server if a player have a name containing forbidden files characters.
Why do you do:

pawn Код:
new str[18 + MAX_PLAYER_NAME];
24 (MAX_PLAYER_NAME) + 18 = 42 but a player's name can only be max 24 characters..

Reply
#6

This is what I have right now, and I tried to pick up a job in my server and it didn't write it to the file. I'm absolutely clueless about the problem.

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

new string[64], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "xadmin/Users/%s.ini", name);
Then further down, once into the commands, I have:

Код:
if(dini_Exists(string))
{
dini_IntSet(string, "Job", 3);
}
Reply
#7

Quote:
Originally Posted by Sneaky.
Why do you do:

pawn Код:
new str[18 + MAX_PLAYER_NAME];
24 (MAX_PLAYER_NAME) + 18 = 42 but a player's name can only be max 24 characters..

The lenght of "xadmin/Users/" + ".ini".. (which is 17, my bad) so it doesn't waste the 47 unused cells in "new string[64], name[MAX_PLAYER_NAME];"
Reply
#8

Ah yeah, overlooked it.. my bad
Reply
#9

There is nothing wrong with your code. The only thing that could come to my mind is that is the file, you're trying to write in, actually created ?
Reply
#10

It is created. That's what's confusing me. I can't find a single problem with the code. Here is the full code of the area i'm having trouble with:

http://pastebin.com/m5f07d723

That's all of it.

Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)