[Include] The Guff - File related stuff [NEWBIE-FRIENDLY]
#1

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
Reply
#2

guf rip posoni
Reply
#3

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

Great job,..
Reply
#5

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.
Reply
#6

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


P.S. - Nice work.
Reply
#7

Cool bro i love it and hope you make better and better that that
Reply
#8

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)