SA-MP Forums Archive
[Include] The Guff - File related stuff [NEWBIE-FRIENDLY] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] The Guff - File related stuff [NEWBIE-FRIENDLY] (/showthread.php?tid=375391)



The Guff - File related stuff [NEWBIE-FRIENDLY] - Gangs_Rocks - 06.09.2012

The Guff
Newbie friendly file related functions

pawn Код:
stock LoadGObjectsFromFile(const filename[])
stock LoadGAddStaticVehiclesFromFile(const filename[])
stock LoadCreateVehiclesFromFile(const filename[])
What is it?
Well, I've seen a LOT of people asking how to read objects and vehicles from a file. This is exactly why I made this.
This requires SSCANF2 (The latest one) and the latest SAMP include. It's in BETA stage currently and it has only 3 functions. All credits to Jarnu and Lovro for the idea and helping me test it all, This is for you boys.

Code:


pawn Код:
#include <a_samp>
#include <sscanf2>

stock LoadGObjectsFromFile(const filename[])
{
    new File:file_ptr;
    new line[256];
    new Object;
    new Float:SpawnX;
    new Float:SpawnY;
    new Float:SpawnZ;
    new Float:SpawnRX;
    new Float:SpawnRY;
    new Float:SpawnRZ;
    new Float:draw;
    new Objects_loaded;

    file_ptr = fopen(filename,filemode:io_read);
    if(!file_ptr)
    {
        printf("[Guff] Couldn't load objects from %s [Reason : File doesn't exist]", filename);
    }
    else
    {
        Objects_loaded = 0;
        while(fread(file_ptr,line,256))
        {
            sscanf(line,"p<,>iffffffi",SpawnX, SpawnY, SpawnZ, SpawnRX, SpawnRY, SpawnRZ, draw);
            CreateObject(Object, SpawnX, SpawnY, SpawnZ, SpawnRX, SpawnRY, SpawnRZ, draw);
            Objects_loaded++;
        }
    }
    fclose(file_ptr);
    printf("[Guff] Loaded %d objects from: %s",Objects_loaded,filename);
    return Objects_loaded;
}


stock LoadGAddStaticVehiclesFromFile(const filename[])
{
    new File:file_ptr;
    new line[256];
    new modelid, Float:SpawnX, Float:SpawnY, Float:SpawnZ, Float:angle, color1, color2, Cars_Loaded;
    file_ptr = fopen(filename, filemode:io_read);
    if(!file_ptr)
    {
        printf("[Guff] Couldn't load permanent vehicles from %s [Reason : File doesn't exist]", filename);
    }
    else
    {
        Cars_Loaded = 0;
        while(fread(file_ptr, line, 256))
        {
            sscanf(line, "p<,>iiffffff", SpawnX, SpawnY, SpawnZ, angle, color1, color2);
            AddStaticVehicle(modelid, SpawnX, SpawnY, SpawnZ, angle, color1, color2);
            Cars_Loaded++;
        }
    }
    fclose(file_ptr);
    printf("[Guff] Loaded %d vehicles from: %s",Cars_Loaded,filename);
    return Cars_Loaded;
}

stock LoadCreateVehiclesFromFile(const filename[])
{
    new File:file_ptr;
    new line[256];
    new modelid, Float:SpawnX, Float:SpawnY, Float:SpawnZ, Float:angle, color1, color2, respawn, Cars_Loaded;
    file_ptr = fopen(filename, filemode:io_read);
    if(!file_ptr)
    {
        printf("[Guff] Couldn't load temporary vehicles from %s [Reason : File doesn't exist]", filename);
    }
    else
    {
        Cars_Loaded = 0;
        while(fread(file_ptr, line, 256))
        {
            sscanf(line, "p<,>iifffffff", SpawnX, SpawnY, SpawnZ, angle, color1, color2, respawn);
            CreateVehicle(modelid, SpawnX, SpawnY, SpawnZ, angle, color1, color2, respawn);
            Cars_Loaded++;
        }
    }
    fclose(file_ptr);
    printf("[Guff] Loaded %d vehicles from: %s",Cars_Loaded,filename);
    return Cars_Loaded;
}
Download : http://www.mediafire.com/download.php?5b99zaf8xbdbxm1

Test script :


pawn Код:
#include <a_samp>
#include <Guff>
#include <sscanf2>

main()
{
    print("\n----------------------------------");
    print(" Testing Log creator");
    print("----------------------------------\n");
}
public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    LoadGObjectsFromFile("Objects.txt");
    LoadGAddStaticVehiclesFromFile("Vehicles.txt");
    return 1;
}

Simple, But I hope it helps



Re: The Guff - File related stuff [NEWBIE-FRIENDLY] - seeeca - 07.09.2012

guf rip posoni


Re: The Guff - File related stuff [NEWBIE-FRIENDLY] - Gangs_Rocks - 07.09.2012

I don't understand, what do you want to say?


Re: The Guff - File related stuff [NEWBIE-FRIENDLY] - Jarnu - 07.09.2012

Great job,..


Re: The Guff - File related stuff [NEWBIE-FRIENDLY] - Mutha_X - 07.09.2012

Quote:
Originally Posted by Gangs_Rocks
Посмотреть сообщение
I don't understand, what do you want to say?
He said on russian using english chars "Rapper Guf is RIP, boys" it is old funny about this rapper there.


Re: The Guff - File related stuff [NEWBIE-FRIENDLY] - seeeca - 09.09.2012

Mutha_X, не пали контору


P.S. - Nice work.


Re: The Guff - File related stuff [NEWBIE-FRIENDLY] - Gangster-rocks - 15.09.2012

Cool bro i love it and hope you make better and better that that


Re: The Guff - File related stuff [NEWBIE-FRIENDLY] - Morozzzko - 16.09.2012

May Guf Rest in peace.
By the way - good job, but is your way faster than using MTA map loader or something like that?


AW: The Guff - File related stuff [NEWBIE-FRIENDLY] - BigETI - 16.09.2012

I would prefer to create a binary type of file system to load and save objects, vehicles etc. since binary files are quite faster to read and write and you don't have to convert plain text into its binary and vice versa so far.