Not saving properly
#1

pawn Код:
#include <a_samp>

#define FILTERSCRIPT

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#endif

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/sethousepos", cmdtext, true, 10) == 0)
    {
      new file[256];
    new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        new File:properties = fopen("/properties.cfg", io_write);
    format(file, sizeof file, "HousePos: %d\n,%d\n,%d\n",x, y, z);
        {   fwrite(properties, file); }
    fclose(properties);
        return 1;
    }
    return 0;
}
Thats my code: This is properties.cfg

Код:
HousePos: 1122473179
,-1033036543
,1070202880
And well how do i get it to read from that file and set the players position?
Also if i was to example: [houseeterx],[houseentery][houseeterz][houseexitx][houseexity][houseexitz]
How would i get it to read which bits housexit, and which bit is house enter,

edit: sorry about the name it was originally for the coords not saving properly but i have fixed that
Reply
#2

a fast method would be to use sscanf and use spaces inbetween the parameters instead of commas.
Reply
#3

How would i get it to read the X, Y, Z positions and set the players pos to that?

And also how would i get it to recgonize whats HouseExit and HouseEnter
Reply
#4

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/sethousepos", cmdtext, true) == 0)
    {
        new file[256];
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        new File:properties = fopen("/properties.cfg", io_write);
        format(file, sizeof file, "%f,%f,%f",x, y, z);
        fwrite(properties, file);
        fclose(properties);
        return 1;
    }
    return 0;
}
Loading part. Haven't tested but should work.

pawn Код:
new Float:x, Float:y, Float:z;
new file[256];
new File:properties = fopen("/properties.cfg", io_read);
fread(properties, file);
sscanf(file, "p,fff", x, y, z);
fclose(properties);
SetPlayerPos(playerid, x, y, z);
Reply
#5

Ok,

One more question:

If a player buys a hotel room.

And it saves to hotelguests.cfg

It will save, Room number and players name,

But how would i get it to read the players name
Reply
#6

Use sscanf

https://sampwiki.blast.hk/wiki/Sscanf
https://sampwiki.blast.hk/wiki/Fast_Commands
http://forum.sa-mp.com/index.php?topic=145539.0

pawn Код:
sscanf(file, "p,is", room, playername);
Reply
#7

Ive not a clue how to use sscanf,
Even if i read about it,
I wouldnt be able to learn unless there was a tutorial for this specific bit, But there aint
Reply
#8

pawn Код:
sscanf(file, "p,is", room, playername);
file - the string you read from file
"i" - number, in this case hotel room
"s" - string, in this case player's name

https://sampwiki.blast.hk/wiki/Fast_Commands - this is a tutorial how to use sscanf with commands.
Reply
#9

Er ok so where would i put that code?
Reply
#10

Quote:
Originally Posted by Torran
Er ok so where would i put that code?
Where you want to load the info from file.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)