[HELP] Load object from .txt
#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


Messages In This Thread
[HELP] Load object from .txt - by ThomasEvil - 25.07.2017, 18:02
Re: [HELP] Load object from .txt - by Kane - 25.07.2017, 22:11
Re: [HELP] Load object from .txt - by ThomasEvil - 26.07.2017, 23:30
Re: [HELP] Load object from .txt - by ThomasEvil - 27.07.2017, 19:48
Re: [HELP] Load object from .txt - by HoussamMaroc - 28.07.2017, 10:17
Re: [HELP] Load object from .txt - by Xeon™ - 28.07.2017, 11:31
Re: [HELP] Load object from .txt - by HoussamMaroc - 28.07.2017, 12:01
Re: [HELP] Load object from .txt - by Xeon™ - 28.07.2017, 12:04
Re: [HELP] Load object from .txt - by HoussamMaroc - 28.07.2017, 12:09
Re: [HELP] Load object from .txt - by HoussamMaroc - 28.07.2017, 12:11

Forum Jump:


Users browsing this thread: 1 Guest(s)