Objects Not Loading | y_ini Help
#1

Hey guys, can anyone help me with this code. the problem is that objects are not loading not getting created when Script Restarts. Please help. However, Objects are getting saved. There are no errors only 3 warning of loose indentation. and also if I've made 3 objects and when I restart script and then again make objects then instead of counting from 4 its creating objects from 0 again.

PHP код:

#include <a_samp>
#include <zcmd>
#include <streamer>
#include <sscanf2>
#include <YSI\y_ini>
#define COLOR_BLUE 0x009AE5B0
#define COLOR_YELLOW 0xFFFF00B4
#define COLOR_RED 0xB40000B5
#define MAX_OBJ 1000
#define Path "Objects/%i.ini"
new bool:ObjCreated[MAX_OBJ];
new 
objectz[MAX_OBJ];
enum obinfo{
   
model,
   
Float:posx,
   
Float:posy,
   
Float:posz,
   
Float:rotx,
   
Float:roty,
   
Float:rotz,
};
new 
gobject[MAX_OBJ][obinfo];
public 
OnFilterScriptInit()
{
    print(
" Object Editor By Rage Loaded!");
    for(new 
i=0;i<MAX_OBJ;i++){
      if(
fexist(SavePath(i))){  
      
INI_ParseFile(SavePath(i), "LoadObjects",.bExtra true, .extra i); 
      
objectz[i]=CreateDynamicObject(gobject[i][model],gobject[i][posx],gobject[i][posy],gobject[i][posz],gobject[i][rotx],gobject[i][roty],gobject[i][rotz]);
      
printf("Loaded %d",i);
      }
      else {
      break;
      
      }
    }
    
    return 
1;
}
public 
OnFilterScriptExit()
{
  print(
" Object Editor By Rage UNLoaded!");
  for(new 
i=0;i<MAX_OBJ;i++){
  
SaveFile(i);
  
  }
    return 
1;
}
CMD:createobject(playerid,params[]){
new 
modelid;
if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridCOLOR_RED,"Sorry but you are not authorised to use this command");
if(
sscanf(params"i" ,modelid)) return SendClientMessage(playeridCOLOR_YELLOW,"Usage: /createobject <Model ID>");
new 
Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
for(new 
i=0i<MAX_OBJ;i++){
if(!
ObjCreated[i]){
objectz[i]=CreateDynamicObject(modelid,x+2,y,z,0,0,0);
new 
str[128];
format(str,sizeof(str),"You have created a object(ID:%d) with Model ID:%d",i,modelid);
SendClientMessage(playeridCOLOR_BLUE,str);
new 
Float:x1,Float:y1,Float:z1;
GetObjectPos(objectz[i],x1,y1,z1);
new 
Float:x2,Float:y2,Float:z2;
GetObjectRot(objectz[i],x2,y2,z2);
ObjCreated[i]=true;
gobject[i][model]=modelid;
gobject[i][posx]=x1;
gobject[i][posy]=y1;
gobject[i][posz]=z1;
gobject[i][rotx]=x2;
gobject[i][roty]=y2;
gobject[i][rotz]=z2;
SaveFile(i);
    break;
}
}
return 
1;
}
CMD:editobject(playerid,params[]){
new 
id;
if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridCOLOR_RED,"Sorry but you are not authorised to use this command");
if(
sscanf(params,"i",id)) return SendClientMessage(playeridCOLOR_YELLOW,"Usage: /editobject <ID>");
if(!
IsValidDynamicObject(objectz[id])) return SendClientMessage(playeridCOLOR_RED,"Failed: That Object ID does not exist");
EditDynamicObject(playeridobjectz[id]);
new 
str[128];
format(str,sizeof(str),"Success: You are editing object ID: %d",id);
SendClientMessage(playeridCOLOR_YELLOW,str);
return 
1;
}
CMD:destroyobject(playerid,params[]){
new 
id;
if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridCOLOR_RED,"Sorry but you are not authorised to use this command");
if(
sscanf(params,"i",id)) return SendClientMessage(playeridCOLOR_YELLOW,"Usage: /destroyobject <ID>");
if(!
IsValidDynamicObject(objectz[id])) return SendClientMessage(playeridCOLOR_RED,"Failed: That Object ID does not exist");
DestroyDynamicObject(objectz[id]);
new 
str[128];
format(str,sizeof(str),"Success: You have deleted object ID:%d",id);
SendClientMessage(playeridCOLOR_RED,str);
ObjCreated[id]=false;
return 
1;
}
forward LoadObjects(iname[], value[]);
public 
LoadObjects(iname[], value[]){
 
INI_Int("model",gobject[i][model]);
INI_Float("posx",gobject[i][posx]);
INI_Float("posy",gobject[i][posy]);
INI_Float("posz",gobject[i][posz]);
INI_Float("rotx",gobject[i][rotx]);
INI_Float("roty",gobject[i][roty]);
INI_Float("rotz",gobject[i][rotz]);
return 
1;
}
stock SavePath(objectid){
 new 
str[10];
 
format(strsizeof(str),Path,objectid);
 
 return 
str;
}
forward SaveFile(objectid);
public 
SaveFile(objectid){
 new 
INI:file=INI_Open(SavePath(objectid));
 
INI_WriteInt(file,"model",gobject[objectid][model]);
INI_WriteFloat(file,"posx",gobject[objectid][posx]);
INI_WriteFloat(file,"posy",gobject[objectid][posy]);
INI_WriteFloat(file,"posz",gobject[objectid][posz]);
INI_WriteFloat(file,"rotx",gobject[objectid][rotx]);
INI_WriteFloat(file,"roty",gobject[objectid][roty]);
INI_WriteFloat(file,"rotz",gobject[objectid][rotz]);
INI_Close(file);
return 
1;

Reply
#2

Try remove this:

Код:
else { 
      break; 
       
      }
Because,what if you delete id 1 but id 2 exists
Reply
#3

Anyone else?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)