[HELP] Load object from .txt
#1

I need to load object from .txt file but iam stuck at this Anyone can help me solve this?

my .txt file looks like this:
Код:
19850,1196.842651,-1322.121337,15.398437,0.000000,0.000000,90.000000
1985,1196.842651,-1322.121337,23.938106,0.000000,0.000000,90.000000
1986,1196.842651,-1322.121337,23.938106,0.000000,0.000000,90.000000
1989,1197.681152,-1319.800903,18.398441,0.000000,0.000000,90.000000
It is CreateObject properties.

And there is my broken non working noobie code

Код:
forward LoadMap(inputtext[]);
public LoadMap(inputtext[])
{


	new load[192], path[64];
	format(load, sizeof(load), "%s\r\n",load);
	format(path, sizeof(path), "Objects/%s.txt", inputtext);
	
	new File:oFile;
	oFile = fopen(path, io_read);
	fread(oFile, load);
	new count;

	while (fread(oFile, load))
	{

	    CreateObject(load);
	    count++;

	}
    fclose(oFile);
	return count;
	
}
I was looking for solution about 2 hours but i still can't find how to do this right way ... Iam newbie "pawner".
Reply
#2

https://sampwiki.blast.hk/wiki/CreateObject
Код:
(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance = 0.0)
You're doing:
Код:
 CreateObject(load);
Reply
#3

It is just fail from the time when i tried many ways to get it done But i still have problem with that loading ... :/
Reply
#4

Can you give me some example how to load it right please?
Someone?
Reply
#5

ok done your fs bellow
PHP код:

#include <a_samp>
#include <core>
#include <float>
public OnFilterScriptInit()
{
    
LoadObjectsFromFile("/Objects/Objects.txt");
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
stock LoadObjectsFromFile(const filename[])
{
    new 
File:file_ptr;
    new 
line[256];
    new 
var_from_line[64];
    new 
Object;
    new 
Float:SpawnX;
    new 
Float:SpawnY;
    new 
Float:SpawnZ;
    new 
Float:SpawnRX;
    new 
index;
    new 
Objects_loaded;
    
file_ptr fopen(filename,filemode:io_read);
    if(!
file_ptr) return 0;
    
Objects_loaded 0;
    while(
fread(file_ptr,line,256) > 0)
    {
        
index 0;
        
          
index token_by_delim(line,var_from_line,',',index);
          if(
index == (-1)) continue;
          
Object strval(var_from_line);
          
          
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);
          
index token_by_delim(line,var_from_line,',',index+1);
          if(
index == (-1)) continue;
          
SpawnRX floatstr(var_from_line);
        
CreateObject(ObjectSpawnXSpawnYSpawnZSpawnRX0.00.0);
         
Objects_loaded++;
    }
    
fclose(file_ptr);
    
printf("Loaded %d Object From: %s",Objects_loaded,filename);
    return 
Objects_loaded;
}
stock token_by_delim(const string[], return_str[], delimstart_index)
{
    new 
x=0;
    while(
string[start_index] != EOS && string[start_index] != delim) {
        
return_str[x] = string[start_index];
        
x++;
        
start_index++;
    }
    
return_str[x] = EOS;
    if(
string[start_index] == EOSstart_index = (-1);
    return 
start_index;

Reply
#6

Quote:
Originally Posted by HoussamMaroc
Посмотреть сообщение
ok done your fs bellow
PHP код:

#include <a_samp>
#include <core>
#include <float>
public OnFilterScriptInit()
{
    
LoadObjectFromFile("/Objects/Objects.txt");
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
stock LoadObjectFromFile(const filename[])
{
    new 
File:file_ptr;
    new 
line[256];
    new 
var_from_line[64];
    new 
objecttype;
    new 
Float:SpawnX;
    new 
Float:SpawnY;
    new 
Float:SpawnZ;
    new 
Float:SpawnRot;
    new 
index;
    new 
objects_loaded;
    
file_ptr fopen(filename,filemode:io_read);
    if(!
file_ptr) return 0;
    
objects_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;
          
objecttype strval(var_from_line); continue
          
// Read X, Y, Z, Rotation
          
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);
          
index token_by_delim(line,var_from_line,',',index+1);
          if(
index == (-1)) continue;
          
SpawnRot floatstr(var_from_line);
          
CreateObject(objecttype,SpawnX,SpawnY,SpawnZ,SpawnRot,0.0,0.0); // respawn 30 minutes
        
printf("Loaded %d Objects from: %s",objects_loaded,filename);
        
objects_loaded++;
    }
    
fclose(file_ptr);
    return 
objects_loaded;
}
stock token_by_delim(const string[], return_str[], delimstart_index)
{
    new 
x=0;
    while(
string[start_index] != EOS && string[start_index] != delim) {
        
return_str[x] = string[start_index];
        
x++;
        
start_index++;
    }
    
return_str[x] = EOS;
    if(
string[start_index] == EOSstart_index = (-1);
    return 
start_index;

Credits please.
Reply
#7

you are admin?
Reply
#8

Quote:
Originally Posted by HoussamMaroc
Посмотреть сообщение
you are admin?
No
Reply
#9

HHHH
Reply
#10

wa sat rah mli saybt lcount dyali galo ndir credits 7ta ila knti drti thread
ou zidk ana saybto bo7di
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)