[UnSovled] /Coord Command Saving To File
#1

ok well im making a command that saves some info from the users pos and will i dont know how to make like new fileos = CreateFile or something so any ideas would be good

Cheers,

Nameless
Reply
#2

https://sampwiki.blast.hk/wiki/Fopen
Reply
#3

well i want the file to create a file not open on‌e =P
Reply
#4

Quote:
Originally Posted by FS}Nameless [LDR
]
well i want the file to create a file not open on‌e =P
Well then ...
https://sampwiki.blast.hk/wiki/Fcreate_code
It doesn't hurt to search. That took me less then 5 seconds.
Reply
#5

Quote:
Originally Posted by FS}Nameless [LDR
]
well i want the file to create a file not open on‌e =P
If you would bother clicking the link I gave you, then you would find your answer
Reply
#6

lol sorry dice you helped me alot so far i shouldn't of just read it and said to my self "oh i already looked there" but hey thanks for the fast reply's =)
Reply
#7

i am way confused maybe some one can make a code for me from this code
pawn Код:
if (strcmp("/coord", cmdtext, true, 10) == 0)
    {
    new t = playerid;
    new str[256];
    new Float:Pos[MAX_PLAYERS][4];
    GetPlayerPos(t,Pos[t][0],Pos[t][1],Pos[t][2]);
    GetPlayerFacingAngle(t,Pos[t][3]);
   
    format(str, 256,"x= %.4f y= %.4f z= %.4f a= %.4f",Pos[t][0],Pos[t][1],Pos[t][2],Pos[t][3]);
    SendClientMessage(playerid, 0xFF0000AA, "Thank You Your Coords And Vehicle ID Have Ben Saved");
    return 1;
    }
i want it to save a file name of the users name that type /command and to make it save they're Pos And there Vehicle ID to a .txt file
Reply
#8

pawn Код:
#include Dini.inc
OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/coord", cmdtext, true, 6) == 0)
{
if(!IsPlayerInAnyVehicle(playerid)){SendClientMessage(playerid,0xff0000aa,"You must be in a vehicle!"); return 1;}
new t = playerid;
new str[256], file[256], name[MAX_PLAYER_NAME];
new Float:Pos[MAX_PLAYERS][4];
GetPlayerPos(t,Pos[t][0],Pos[t][1],Pos[t][2]);
GetPlayerFacingAngle(t,Pos[t][3]);
GetPlayerName(playerid, name, MAX_PLAYER_NAME);

format(str, 256,"x= %.4f y= %.4f z= %.4f a= %.4f",Pos[t][0],Pos[t][1],Pos[t][2],Pos[t][3]); // you won't need that.
SendClientMessage(playerid, 0xFF0000AA, "Thank You Your Coords And Vehicle ID Have Ben Saved");
format(file,256,"userpos/%s.ini",name);
if(!dini_Exists(file)){ dini_Create(file);}
dini_FloatSet(file,"x",Pos[t][0]);
dini_FloatSet(file,"y",Pos[t][1]);
dini_FloatSet(file,"z",Pos[t][2]);
dini_FloatSet(file,"a",Pos[t][3]);
dini_IntSet(file,"vehid",GetPlayerVehicleID(playerid));
return 1;
}
return 1;
}
That should help you (Dini rocks! )
Reply
#9

http://forum.sa-mp.com/index.php?topic=126584.0

Just mess around with it.
Reply
#10

pawn Код:
if (strcmp("/coord", cmdtext, true, 10) == 0)
    {
        //new t = playerid; why this ?
        new str[70]; //does not need to be 256, look below
        new file[MAX_PLAYER_NAME+30]; //30 is if you're putting it in a subdirectory in /scriptfiles/
        //new Float:Pos[MAX_PLAYERS][4]; if you're making this an array for all players and all time use, then make iit global. If its created for one time use only (like in this cmd) and then never used again, then do like below
        new Float:Pos[4];
        GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
        GetPlayerFacingAngle(playerid,Pos[3]);
        format(str, 70,"x= %.4f y= %.4f z= %.4f a= %.4f",Pos[0],Pos[1],Pos[2],Pos[3]);
       
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
       
        format(str, 70,"x= %.4f y= %.4f z= %.4f a= %.4f\nVehicleID = %d",Pos[0],Pos[1],Pos[2],Pos[3], GetPlayerVehicleID(playerid));
        //29 non placeholder characters + 5*5character places for the floats + (MAX)4 character places for the vehid, if you really have 2k vehicles on the server = 58
        //thats almost 200 cells going to waste !

        format(file, MAX_PLAYER_NAME+30, "/Player Info/%s", pName); //creating the file path
        new File:Handler = fopen(file, io_write); //this will create a file and write into it. If the file already exists, it will write over it
        fwrite(Handler, str); //writing to the file
         fclose(Handler);
        SendClientMessage(playerid, 0xFF0000AA, "Thank You Your Coords And Vehicle ID Have Ben Saved");
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)