18.07.2015, 08:14
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(playerid, COLOR_RED,"Sorry but you are not authorised to use this command");
if(sscanf(params, "i" ,modelid)) return SendClientMessage(playerid, COLOR_YELLOW,"Usage: /createobject <Model ID>");
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
for(new i=0; i<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(playerid, COLOR_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(playerid, COLOR_RED,"Sorry but you are not authorised to use this command");
if(sscanf(params,"i",id)) return SendClientMessage(playerid, COLOR_YELLOW,"Usage: /editobject <ID>");
if(!IsValidDynamicObject(objectz[id])) return SendClientMessage(playerid, COLOR_RED,"Failed: That Object ID does not exist");
EditDynamicObject(playerid, objectz[id]);
new str[128];
format(str,sizeof(str),"Success: You are editing object ID: %d",id);
SendClientMessage(playerid, COLOR_YELLOW,str);
return 1;
}
CMD:destroyobject(playerid,params[]){
new id;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED,"Sorry but you are not authorised to use this command");
if(sscanf(params,"i",id)) return SendClientMessage(playerid, COLOR_YELLOW,"Usage: /destroyobject <ID>");
if(!IsValidDynamicObject(objectz[id])) return SendClientMessage(playerid, COLOR_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(playerid, COLOR_RED,str);
ObjCreated[id]=false;
return 1;
}
forward LoadObjects(i, name[], value[]);
public LoadObjects(i, name[], 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(str, sizeof(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;
}