Save name to file
#1

Im trying to save player name to file using this

pawn Код:
new string[24], file[256], name[24];
    GetPlayerName(playerid, name, 24);
    format(file,sizeof(file),"Cars/%s.ini",name);
    if(dini_Exists(file))
    {
        dini_IntSet(file, "Owner", format(string, sizeof(string), "%s",name));
But it saves 1 isnted of name

any ideas? can someone fix it? thx
Reply
#2

You made sure that the file exists?
Reply
#3

First of all, you don't want to insert the return value of format, second of all, you don't need format at all, third of all, you're using the integer function of dini when you need to use the string version and finally that renders the string variable useless.

Here is a simple example when applying the above explanation!

pawn Код:
dini_Set(file, "Owner", name);
Hope that helps
Reply
#4

EDIT: ^ He covered it all.
Reply
#5

pawn Код:
new name;
GetPlayerName(playerid, name);
VehicleInfo[playerid][Owner] = name);
This is when you buy it, why is this wrong?

And this gives me: : error 035: argument type mismatch (argument 3)
pawn Код:
new file[256], name[24];
    GetPlayerName(playerid, name, 24);
    format(file,sizeof(file),"Cars/%s.ini",name);
    if(dini_Exists(file))
    {
        dini_IntSet(file, "Owner", name);
Reply
#6

You're not reading what I said, you're using the wrong dini function, you're using the one for integers, you need to use the one for strings, which is what I showed you:

pawn Код:
dini_Set(file, "Owner", name);
Reply
#7

Thx man, would I use same function for car health? dini_Set?
Reply
#8

Quote:
Originally Posted by HondaCBR
Посмотреть сообщение
Thx man, would I use same function for car health? dini_Set?
Car health is a float, therefore you would use dini_FloatSet.

You can read the full documentation on the dini library here:

https://sampwiki.blast.hk/wiki/Useful_Fu....28Dini.inc.29
Reply
#9

Thx man this helped a lot, just one more question how could I compare this:
if: VehicleInfo[playerid][Owner] is playername that enter the vehicle { action }
Reply
#10

Using strcmp, you can read about strcmp here:

https://sampwiki.blast.hk/wiki/strcmp

For example:

pawn Код:
if(!strcmp(VehicleInfo[playerid][Owner], "name", true))
{
    // The strings match ("name" is the owner)
}
Reply
#11

It doesnt work, it doesnt matter what your name is and the name in file, when you enter a vehicle it just comes up with that message, and also it comes up on all the cars even the ones you cant buy that are not in the file, any ideas?

This is what im using
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    new file[256], name[24];
    GetPlayerName(playerid, name, sizeof(name));
    format(file,sizeof(file),"Cars/%s.ini",name);
    if(!strcmp(VehicleInfo[playerid][Owner], "name", true))
    {
        SendClientMessage(playerid, COLOR_ORANGE, "YOUR CAR");
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_ORANGE, "NOT YOUR CAR");
    }
    return 1;
}
Reply
#12

That's because you're comparing it literally to "name" instead of the contents of the variable name.

For example:

pawn Code:
if(!strcmp(VehicleInfo[playerid][Owner], name, true))
I suggest you read the PAWN documentation over here:

http://www.compuphase.com/pawn/pawn.htm
Reply
#13

Or JaTochNietDan made mistake or you didn't understand him
PHP Code:
if(!strcmp(VehicleInfo[playerid][Owner], nametrue)) 
This will work
Reply
#14

I changed it and still it doesnt work, just to let you know what i want:
When you buy a vehicle a file is create NAME.ini and inside there there is something Owner=NAME
for example JOE_DAVIS.ini and inside Owner=JOE_DAVIS, and what i want is, when you enter a vehicle of yours it will let you stay in, otherwise it removes you out.

pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    new file[256], name[24];
    GetPlayerName(playerid, name, sizeof(name));
    format(file,sizeof(file),"Cars/%s.ini",name);
    if(!strcmp(VehicleInfo[playerid][Owner], name, true))
    {
        SendClientMessage(playerid, COLOR_ORANGE, "TEST TWOJE AUTO PAWEL.");
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_ORANGE, "TEST NIE TWOJE AUTO");
    }
    return 1;
}
This is the code, but its wrong, could anyone change it so it does what I want it to do. Thank you.
Reply
#15

Then you need to get the information from the file, you're not doing that there, you're not making any use of any file reading functions!

You need to use dini_Get to read the data from the file and return it to be compared with strcmp (string compare), for example:

pawn Code:
if(!strcmp(VehicleInfo[playerid][Owner], dini_Get(file, "Owner"), true))
I really suggest you read up on some basic PAWN tutorials.
Reply
#16

but there is no player name in there, it has to compare playername and owner if thesame
Reply
#17

Quote:
Originally Posted by HondaCBR
View Post
but there is no player name in there, it has to compare playername and owner if thesame
There is no player name in where?
Reply
#18

in that line you wrote it only checks for owner but it doesnt comapre it with playername who enters vehicle.

I want it to get name of player who enters a car, and check in that car file for Owner= and if names are the same return 1; otherwise removeplayerfromvehicle...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)