[AJUDA] CreateDynamicObject
#1

Boas

E possivel carregar objetos "CreateDynamicObject" atraves do "OnGameModeInit" mas atraves de ficheiros .cfg ou outro tipo ficheiro no scriptfiles?

Exemplo, crio um ficheiro em scriptfiles/Objetos/Concessionaria/Concessionaria.cfg

Concessionaria.cfg contem objeto como exemplo
CreateDynamicObject(1495,253.18652344,110.53373718 ,1002.21875000,0.00000000,0.00000000,270.00000000) ;
CreateDynamicObject(1495,253.18652344,110.53373718 ,1002.21875000,0.00000000,0.00000000,270.00000000) ;
CreateDynamicObject(1495,253.18652344,110.53373718 ,1002.21875000,0.00000000,0.00000000,270.00000000) ;
....


Sera possivel? Alguem pode ajudar?
Reply
#2

Concessionaria.cfg:

1495,253.18652344,110.53373718 ,1002.21875000,0.00000000,0.00000000,270.00000000 ;
1495,253.18652344,110.53373718 ,1002.21875000,0.00000000,0.00000000,270.00000000 ;
1495,253.18652344,110.53373718 ,1002.21875000,0.00000000,0.00000000,270.00000000 ;

No Fim do seu Gamemode:

Quote:

stock LoadObjectsFromFile(const filename[])
{
new File:file_ptr,
index,
var_from_line[64],
line[256];

new objectModel;
Float:SpawnX;
Float:SpawnY;
Float:SpawnZ;
Float:SpawnRx;
Float:SpawnRy;
Float:SpawnRz;

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

vehicles_loaded = 0;

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

index = token_by_delim(line,var_from_line,',',index);
if(index == (-1)) continue;
objectModel = 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);

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

index = token_by_delim(line,var_from_line,';',index+1);
SpawnRz = strval(var_from_line);

CreateDynamicObject(vehicletype, SpawnX, SpawnY, SpawnZ, SpawnRx, SpawnRy, SpawnRz);
}

fclose(file_ptr);

return 1;
}

stock token_by_delim(const string[], return_str[], delim, start_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] == EOS) start_index = (-1);
return start_index;
}

Para finalizar:

Coloque no seu OnGameModeInit: LoadObjectsFromFile("ESeuDiretуrio");

OBS: Editei a funзгo agora entгo nгo й certeza que ele esteja funcionando, desculpe o cуdigo foi sem indentaзгo :/
Reply
#3

Seu ta dando erro:
Float:SpawnX;
Float:SpawnY;
Float:SpawnZ;
Float:SpawnRx;
Float:SpawnRy;
Float:SpawnRz;

pawn Код:
stock LoadObjectsFromFile(const filename[])
{
new File:file_ptr,
index,
var_from_line[64],
line[256];

new objectModel;
Float:SpawnX;
Float:SpawnY;
Float:SpawnZ;
Float:SpawnRx;
Float:SpawnRy;
Float:SpawnRz;

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

vehicles_loaded = 0;

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

index = token_by_delim(line,var_from_line,',',index);
if(index == (-1)) continue;
objectModel = 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);

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

index = token_by_delim(line,var_from_line,';',index+1);
SpawnRz = strval(var_from_line);

CreateDynamicObject(vehicletype, SpawnX, SpawnY, SpawnZ, SpawnRx, SpawnRy, SpawnRz);
}

fclose(file_ptr);

return 1;
}

stock token_by_delim(const string[], return_str[], delim, start_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] == EOS) start_index = (-1);
return start_index;
}
Reply
#4

Falta de atenзгo minha, tente agora:

Quote:

stock LoadObjectsFromFile(const filename[])
{
new File:file_ptr,
index,
var_from_line[64],
line[256];

new objectModel,
Float:SpawnX,
Float:SpawnY,
Float:SpawnZ,
Float:SpawnRx,
Float:SpawnRy,
Float:SpawnRz;

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

vehicles_loaded = 0;

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

index = token_by_delim(line,var_from_line,',',index);
if(index == (-1)) continue;
objectModel = 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);

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

index = token_by_delim(line,var_from_line,';',index+1);
SpawnRz = strval(var_from_line);

CreateDynamicObject(vehicletype, SpawnX, SpawnY, SpawnZ, SpawnRx, SpawnRy, SpawnRz);
}

fclose(file_ptr);

return 1;
}

stock token_by_delim(const string[], return_str[], delim, start_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] == EOS) start_index = (-1);
return start_index;
}

Reply
#5

error 017: undefined symbol "vehicles_loaded"
error 017: undefined symbol "vehicletype"
warning 204: symbol is assigned a value that is never used: "objectModel"


O que queria e so para carregar objetos e nao carros *-* consegue resolver um para mim? estou tentando encontrar no ****** mas nada aparece
Reply
#6

Fixed, try now:

Quote:

stock LoadObjectsFromFile(const filename[])
{
new File:file_ptr,
index,
var_from_line[64],
line[256];

new objectModel,
Float:SpawnX,
Float:SpawnY,
Float:SpawnZ,
Float:SpawnRx,
Float:SpawnRy,
Float:SpawnRz;

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

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

index = token_by_delim(line,var_from_line,',',index);
if(index == (-1)) continue;
objectModel = 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);

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

index = token_by_delim(line,var_from_line,';',index+1);
SpawnRz = strval(var_from_line);

CreateDynamicObject(objectModel, SpawnX, SpawnY, SpawnZ, SpawnRx, SpawnRy, SpawnRz);
}

fclose(file_ptr);

return 1;
}

stock token_by_delim(const string[], return_str[], delim, start_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] == EOS) start_index = (-1);
return start_index;
}

Reply
#7

Desculpe cara mas no eu e que meti mal o codigo e fez o servidor crashar!!

Vlw



realmente funciona!!
Reply
#8

Vlw
Reply
#9

uma duvida....

Poderei meter varios arquivos? exemplo
LoadObjectsFromFile("policiaexterior.cfg");
LoadObjectsFromFile("policiainterior.cfg");
LoadObjectsFromFile("concessionariainterior.cfg");
LoadObjectsFromFile("concessionariaexterior.cfg");
LoadObjectsFromFile("barinterior.cfg");
LoadObjectsFromFile("praia.cfg");

etc

Pk ao todo sao mais de 1000 "CreateDynamicObject"

Sera que nao buga?

Da certo?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)