AttachObjectToVehicle save/load
#1

Im editing off of GarObject to make it so you can save/load attached objects to cars. I dont think ive ever been so confused in my life :S Well here is what im working with.. It wont save the file.

pawn Код:
stock SaveCObjectsToFile(pid, filename[], sendmsg = 1)
{
    new File:gFile, string[158], count;
    new vehicleid, objectid, Float:ofsX, Float:ofsY, Float:ofsZ, Float:rX, Float:rY, Float:rZ;
    if(strlen(filename) < 4) return SendClientMessage(pid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered is shorter than 4 characters. Minimum filename is 4 characters including the .txt extension.");
    if(strfind(filename, ".txt", true) == -1) return SendClientMessage(pid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered didn't have the .txt extension at the end. Please add it and continue.");
    if(CountTotalHoldingObjects(pid) == 0) return SendClientMessage(pid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}You do not have any objects to save.");
    else
    {
        if(fexist(filename))
        {
            fremove(filename);
        }
        gFile = fopen(filename, io_write);
        fclose(gFile);
        gFile = fopen(filename, io_append);
        Loop(o, 5)
        {
                format(string, sizeof(string), "AttachObjectToVehicle(playerid, %d, %d, %d, %f, %f, %f, %f, %f);\r\n", objectid, vehicleid, ofsX, ofsY, ofsZ, rX, rY, rZ);
                print(string);
                fwrite(gFile, string);
                count++;
            }
        }
        fclose(gFile);
        if(sendmsg == 1)
        {
            format(string, sizeof(string), "{009900}Save Successfull{FFFFFF}! Saved{009900} %d{FFFFFF} objects to {009900}%s{FFFFFF}.", count, filename);
            SendClientMessage(pid, COLOUR_INFO, string);
        }
    return 1;
}
stock LoadCObjectsFromFile(pid, filename[], sendmsg = 1)
{
    new File:gFile, string[158], count;
    new vehicleid, objectid, Float:ofsX, Float:ofsY, Float:ofsZ, Float:rX, Float:rY, Float:rZ;
    if(strfind(filename, ".txt", true) == -1) return SendClientMessage(pid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered didn't have the .txt extension at the end. Please add it and continue.");
    else
    {
        if(fexist(filename))
        {
            fremove(filename);
        }
        gFile = fopen(filename, io_write);
        fclose(gFile);
        gFile = fopen(filename, io_append);
        Loop(o, 5)
        {
                AttachObjectToVehicle(o, vehicleid, ofsX, ofsY, ofsZ, rX, rY, rZ);
                print(string);
                fwrite(gFile, string);
                count++;
            }
        }
        fclose(gFile);
        if(sendmsg == 1)
        {
            format(string, sizeof(string), "{009900}Save Successfull{FFFFFF}! Saved{009900} %d{FFFFFF} objects to {009900}%s{FFFFFF}.", count, filename);
            SendClientMessage(pid, COLOUR_INFO, string);
        }
    return 1;
}
This code is probably completly wrong, but if you have or can give me a vehicle object save FS that would be sweet.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)