Thread: [Include] Inline file loading
View Single Post
Old 21/02/2019, 07:51 AM   #21
Huge Clucker
Join Date: Oct 2007
Posts: 415
Reputation: 15
Default Re: Inline file loading

Hi, I got a problem in my script, which the problem is as follows,

I have a notepad textfile called importpickups.txt and I'm trying to read these out every line is another record, but i'm having problems on loading the last variable which is text but not the comment.

1239,1111.9205,-1795.6251,16.5938,1,0,-1,Transport Malta;	// License Centre
1239,1553.5713,-1675.5229,16.1953,1,0,-1,Police Station;	// LSPD Entrance
1239,1835.9078,-1682.4229,13.3701,1,0,-1,Alahambra Disco;	// Alahambra
1239,1832.7723,-1842.3422,13.5781,1,0,-1,24/7;			// 24/7 Shop near Trainstation HQ
1239,1482.6650,-1771.7471,18.7958,1,0,-1,City Hall;		// City Hall
1239,1631.8289,-1172.0117,24.0781,1,0,-1,Maltco Lotteries;	// Betting Shop
1239,1458.7700,-1140.0200,24.0692,1,0,-1,Zip Clothes;		// Zip Clothes Shop
1239,1038.2988,-1339.9058,13.7350,1,0,-1,Doonys;		// Dounuts Shop
1239,1367.1497,-1279.7498,13.5469,1,0,-1,Ammu-Nation;		// Ammu-Nation LS
1239,1944.1481,-1771.3092,13.3906,1,0,-1,24/7;			// Fuel Station Idlewood (Fuel Pump)
1239,1929.7285,-1776.2769,13.5469,1,0,-1,24/7;			// 24/7 in FuelStation Idlewood
1239,1572.8419,-1337.4308,16.4844,1,0,-1,Star Tower;		// Star Tower Downstairs
1239,1566.1102,-1170.8138,24.0907,1,0,-1,98c 24/7;		// 98c 24/7 shop next to betting shop
1239,926.6556,-1352.7498,13.3766,1,0,-1,Cluckin Bell;		// Cluckin Bell Outside ( Market ) Behind Hospital
1239,999.7195,-919.9528,42.3281,1,0,-1,24/7;			// 24/7 shop Outside (Mulhalland) Abandoned Fuel Station
1239,2105.1025,-1806.4875,13.5547,1,0,-1,Pizza Hut;		// Well Stacked Pizza Outside ( Idlewood )
Can you help me on reading these please? I'm having trouble reading them, I already have sscanf in my gamemode but i dont know how to implement it to use this thing.

right now I have this code to read from the file.

pawn Code:
stock ImportPickupsFromFile(const filename[])
    new File:file_ptr;
    new line[256];
    new var_from_line[1024];
    new model;
    new Float:SpawnX;
    new Float:SpawnY;
    new Float:SpawnZ;
    new pid, ptype, pvw, ptitle[50];
    new index;
    new pickups_loaded;

    file_ptr = fopen(filename,filemode:io_read);
    if(!file_ptr) return 0;

    pickups_loaded = 0;

    while(fread(file_ptr,line,256) > 0)
        index = 0;

        // Read type
        index = token_by_delim(line,var_from_line,',',index);
        if(index == (-1)) continue;
        model = strval(var_from_line);

        // Read X, Y, Z, cords
        index = token_by_delim(line,var_from_line,',',index+1);
        if(index == (-1)) continue;
        SpawnX = floatstr(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        if(index == (-1)) continue;
        SpawnY = floatstr(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        if(index == (-1)) continue;
        SpawnZ = floatstr(var_from_line);

        // Read Color1, Color2
        index = token_by_delim(line,var_from_line,',',index+1);     // Property Type ( If its a Garage, Building Entry, House, etc )
        if(index == (-1)) continue;
        ptype = strval(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);     // Property ID
        if(index == (-1)) continue;
        pid = strval(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        if(index == (-1)) continue;
        pvw = strval(var_from_line);

        index = token_by_delim(line,var_from_line,';',index+1);
        ptitle = strval(var_from_line);
        new string[500];
        format(string,sizeof(string),"INSERT INTO 'pickups' (model, x, y, z, property_type, property_id, vw, title) VALUES (%d, %f, %f, %f, %d,%d,%d,%s);", model, SpawnX, SpawnY, SpawnZ, ptype, pid, pvw, ptitle);
        db_query(Database, string);
    printf("Loaded %d pickups from: %s",pickups_loaded,filename);
    return pickups_loaded;
Rep+ if my post helped, Thanks.
silvan is offline   Reply With Quote