Object Help
#1

Hey i am trying to make something that loads objects from file but for some reason it is not working here is the coding
Quote:

public LoadObjects()
{
new arrCoords[5][64];
new strFromFile2[256];
new File: file = fopen("LARP/object.txt", io_read);
if (file)
{
new idx = 10;
while (idx < sizeof(Object1))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
Object1[idx][oid] = strval(arrCoords[0]);
Object1[idx][obx] = strval(arrCoords[1]);
Object1[idx][oby] = strval(arrCoords[2]);
Object1[idx][obz] = strval(arrCoords[3]);
Object1[idx][orx] = strval(arrCoords[4]);
CreateDynamicObject(Object1[idx][oid],Object1[idx][obx],Object1[idx][oby],Object1[idx][obz],Object1[idx][orx],0,0);
idx++;
}
printf("[SCRIPT]: Loaded %d Objects", idx);
fclose(file);
}
return 1;
}

i saved 1 object in file in correct format and it will not load why
Reply
#2

post the error or warning that you are getting and try putting it in the [pawn] not quote
Reply
#3

Change:

new idx = 10;

To this:

new idx;
Reply
#4

Show the file and how you create Object1.
Reply
#5

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
NOTE: sscanf is needed
NOTE 2: I didn't make a version wich supports "," yet, will do later
pawn Код:
public OnGameModeInit()
{
// Example:
    LoadDynamicObjectsFromFile("MyObjectFile1.txt");
    LoadStaticObjectsFromFile("MyObjectFile2.txt");
// You may also load from folders
    LoadDynamicObjectsFromFile("/Objects/MyObjectFile3.txt"); // Will load objects from /scriptfiles/Objects/MyObjectFile3.txt
    LoadStaticObjectsFromFile("/Objects/MyObjectFile4.txt"); // Will load objects from /scriptfiles/Objects/MyObjectFile4.txt
    return 1;
}
LoadDynamicObjectsFromFile - By [03]Garsino
Код:
modelid float:SpawnX float:SpawnY float:SpawnZ float:SpawnRotX float:SpawnRotY SpawnRotZ worldid interiorid playerid float:distance
pawn Код:
stock LoadDynamicObjectsFromFile(filename[]) // For Incognito's streamer plugin
{
    new File:file_ptr, line[256], modelid, Float:SpawnX, Float:SpawnY, Float:SpawnZ, Float:SpawnRotX, Float:SpawnRotY, Float:SpawnRotZ, worldid, interiorid, playerid, Float:distance, objects_loaded;
    file_ptr = fopen(filename, io_read);
    if(!file_ptr) return printf("ERROR! Failed To Load Objects From The File %s (File Doesn't Exist In Scriptfiles Directory)!", filename);
    while(fread(file_ptr, line) > 0)
    {
        sscanf(line, "dffffffdddf", modelid, SpawnX, SpawnY, SpawnZ, SpawnRotX, SpawnRotY, SpawnRotZ, worldid, interiorid, playerid, distance);
        CreateDynamicObject(modelid, SpawnX, SpawnY, SpawnZ, SpawnRotX, SpawnRotY, SpawnRotZ, worldid, interiorid, playerid, distance);
        objects_loaded++;
    }
    fclose(file_ptr);
    printf("Loaded %d objects from: %s", objects_loaded, filename);
    return objects_loaded;
}
LoadStaticObjectsFromFile - By [03]Garsino
Код:
modelid float:SpawnX float:SpawnY float:SpawnZ float:SpawnRotX float:SpawnRotY SpawnRotZ
pawn Код:
stock LoadStaticObjectsFromFile(filename[])
{
    new File:file_ptr, line[256], modelid, Float:SpawnX, Float:SpawnY, Float:SpawnZ, Float:SpawnRotX, Float:SpawnRotY, Float:SpawnRotZ, objects_loaded;
    file_ptr = fopen(filename, io_read);
    if(!file_ptr) return printf("ERROR! Failed To Load Objects From The File %s (File Doesn't Exist In Scriptfiles Directory)!", filename);
    while(fread(file_ptr, line) > 0)
    {
        sscanf(line, "dffffff", modelid, SpawnX, SpawnY, SpawnZ, SpawnRotX, SpawnRotY, SpawnRotZ);
        CreateObject(modelid, SpawnX, SpawnY, SpawnZ, SpawnRotX, SpawnRotY, SpawnRotZ);
        objects_loaded++;
    }
    fclose(file_ptr);
    printf("Loaded %d objects from: %s", objects_loaded, filename);
    return objects_loaded;
}
Here is what i founded
Reply
#6

what would the save format be in then
Reply
#7

Quote:
Originally Posted by prez_jake
Посмотреть сообщение
what would the save format be in then
modelid, X, Y, Z, RotX, RotY, RotZ, world, interior, playerid, distance
Reply
#8

the file looked like this
969(fence),x,y,z,xr,yr,zr,0,0,0,0
Reply
#9

hey um i have one more thing
will the new objects i add the old way each have there own line if not how could i make it like that
how could i make it that each object had it's own line by changing my orignal code
Reply
#10

Um i have something new about it um
when i put more then one object in txt file it loads retartedly idk why or what happened but it does and loads a different object then the one i wanted do i need to put a box thing inbetween each object
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)