Save name to file -
HondaCBR - 22.11.2011
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
Re: Save name to file -
sim_sima - 22.11.2011
You made sure that the file exists?
Re: Save name to file -
JaTochNietDan - 22.11.2011
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
Re: Save name to file -
Hoborific - 22.11.2011
EDIT: ^ He covered it all.
Re: Save name to file -
HondaCBR - 22.11.2011
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);
Re: Save name to file -
JaTochNietDan - 22.11.2011
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);
Re: Save name to file -
HondaCBR - 22.11.2011
Thx man, would I use same function for car health? dini_Set?
Re: Save name to file -
JaTochNietDan - 22.11.2011
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
Re: Save name to file -
HondaCBR - 22.11.2011
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 }
Re: Save name to file -
JaTochNietDan - 22.11.2011
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)
}
Re: Save name to file -
HondaCBR - 22.11.2011
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;
}
Re: Save name to file -
JaTochNietDan - 22.11.2011
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
Re: Save name to file -
[MG]Dimi - 22.11.2011
Or JaTochNietDan made mistake or you didn't understand him
PHP Code:
if(!strcmp(VehicleInfo[playerid][Owner], name, true))
This will work
Re: Save name to file -
HondaCBR - 22.11.2011
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.
Re: Save name to file -
JaTochNietDan - 22.11.2011
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.
Re: Save name to file -
HondaCBR - 22.11.2011
but there is no player name in there, it has to compare playername and owner if thesame
Re: Save name to file -
JaTochNietDan - 23.11.2011
Quote:
Originally Posted by HondaCBR
but there is no player name in there, it has to compare playername and owner if thesame
|
There is no player name in where?
Re: Save name to file -
HondaCBR - 23.11.2011
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...