#define MAX_OBJ 1001
new oEdit[MAX_PLAYERS]; // checking if the player is editting an object.
new oEditID[MAX_PLAYERS]; // checking what id is getting editted.
new Float:oPos[MAX_PLAYERS][3]; // the old & new Positions from the object, ((edit mode))
new Float:oRot[MAX_PLAYERS][3]; // the old & new Rotations from the object, ((edit mode))
new oldoID; // Latest created or editted object id. for /duplicateobj!
new Float:oldodX, Float:oldodY, Float:oldodZ, Float:oldodRX, Float:oldodRY, Float:oldodRZ; // The rotations/positions from the last editted/created obj id.
enum objInfo
{
obj, // The object id.
Text3D:oText, // Text label.. attached to every object.
oModel, // the Model id.
Float:oX, // X postion from the object.
Float:oY, // Y postion from the object.
Float:oZ, // Z postion from the object.
Float:oRX, // X Rotation from the object.
Float:oRY, // Y Rotation from the object.
Float:oRZ, // Z Rotation from the object.
}
new ObjInfo[MAX_OBJ][objInfo];
stock SaveObjects2()
{
new idx = 1, File:file;
new string[256];
while(idx < MAX_OBJ)
{
format(string, sizeof(string), "%d|%f|%f|%f|%f|%f|%f\r\n",
ObjInfo[idx][oModel],
ObjInfo[idx][oX],
ObjInfo[idx][oY],
ObjInfo[idx][oZ],
ObjInfo[idx][oRX],
ObjInfo[idx][oRY],
ObjInfo[idx][oRZ]);
if(idx == 1)
{
file = fopen("objects22.cfg", io_write);
}
else
{
file = fopen("objects22.cfg", io_append);
}
fwrite(file, string);
fclose(file);
idx++;
}
print("Objects saved successfully.");
return 1;
}
stock LoadObjects()
{
new dinfo[15][128];
new string[256];
new File:file = fopen("objects22.cfg", io_read);
if(file)
{
new idx = 1;
while(idx < MAX_OBJ)
{
fread(file, string);
split(string, dinfo, '|');
ObjInfo[idx][oModel] = strval(dinfo[0]);
ObjInfo[idx][oX] = floatstr(dinfo[1]);
ObjInfo[idx][oY] = floatstr(dinfo[2]);
ObjInfo[idx][oZ] = floatstr(dinfo[3]);
ObjInfo[idx][oRX] = floatstr(dinfo[4]);
ObjInfo[idx][oRY] = floatstr(dinfo[5]);
ObjInfo[idx][oRZ] = floatstr(dinfo[6]);
if(ObjInfo[idx][oModel]) // If gate exists
{
ObjInfo[idx][obj] = CreateDynamicObject(ObjInfo[idx][oModel], ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], ObjInfo[idx][oRX], ObjInfo[idx][oRY], ObjInfo[idx][oRZ]);
format(string, sizeof(string), "Object ID: %d (Model ID: %d)", idx, ObjInfo[idx][oModel]);
ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], 10);
}
idx++;
}
}
print("Objects loaded successfully.");
return 1;
}
stock split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc))
{
if(strsrc[i] == delimiter || i == strlen(strsrc))
{
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
oEdit[playerid] = 0;
oEditID[playerid] = 0;
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COLOR_RED 0xAA3333AA
#define COLOR_BLUE 0x0000BBAA
#define COL_LIGHTBLUE "{00CED1}"
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_PURPLE 0x800080FF
SaveObjects2();
SaveObjects();
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
new string[128], idx;
idx = oEditID[playerid];
if(response == EDIT_RESPONSE_UPDATE)
{
SetDynamicObjectPos(objectid, x, y, z);
SetDynamicObjectRot(objectid, rx, ry, rz);
}
else if(response == EDIT_RESPONSE_CANCEL)
{
SetDynamicObjectPos(objectid, oPos[playerid][0], oPos[playerid][1], oPos[playerid][2]);
SetDynamicObjectRot(objectid, oRot[playerid][0], oRot[playerid][1], oRot[playerid][2]);
oPos[playerid][0] = 0; oPos[playerid][1] = 0; oPos[playerid][2] = 0;
oRot[playerid][0] = 0; oRot[playerid][1] = 0; oRot[playerid][2] = 0;
format(string, sizeof(string), " You have canceled editing object ID %d.", idx);
SendClientMessage(playerid, COLOR_GREY, string);
}
else if(response == EDIT_RESPONSE_FINAL)
{
SetDynamicObjectPos(objectid, x, y, z);
SetDynamicObjectRot(objectid, rx, ry, rz);
if(oEdit[playerid] == 1)
{
oldoID = ObjInfo[idx][oModel];
ObjInfo[idx][oX] = x;
ObjInfo[idx][oY] = y;
ObjInfo[idx][oZ] = z;
ObjInfo[idx][oRX] = rx;
ObjInfo[idx][oRY] = ry;
ObjInfo[idx][oRZ] = rz;
oldodX = ObjInfo[idx][oX];
oldodY = ObjInfo[idx][oY];
oldodZ = ObjInfo[idx][oZ];
oldodRX = ObjInfo[idx][oRX];
oldodRY = ObjInfo[idx][oRY];
oldodRZ = ObjInfo[idx][oRZ];
if(IsValidDynamic3DTextLabel(ObjInfo[idx][oText])) DestroyDynamic3DTextLabel(ObjInfo[idx][oText]);
format(string, sizeof(string), "Object ID: %d (Model ID: %d)", idx, ObjInfo[idx][oModel]);
ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], 10);
oEdit[playerid] = 0;
oEditID[playerid] = 0;
format(string, sizeof(string), " You have finished editing object ID %d's position.", idx);
SendClientMessage(playerid, COLOR_GREY, string);
}
}
return 1;
}
CMD:maptool(playerid, params[])
{
SendClientMessage(playerid, COLOR_PURPLE, "_____________________________________________________");
SendClientMessage(playerid, COLOR_RED, "*Mapper Commands: {FFFFFF}/createobj /editobj /deleteobj");
SendClientMessage(playerid, COLOR_RED, "*Mapper Commands: {FFFFFF}/nearobj /duplicateobj /gotoobj /saveobjects");
SendClientMessage(playerid, COLOR_PURPLE, "_____________________________________________________");
return 1;
}
CMD:createobj(playerid, params[])
{
new string[128], object;
if(sscanf(params, "i", object)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /createobj [objectid]");
for(new idx=1; idx<MAX_OBJ; idx++)
{
if(!ObjInfo[idx][oModel])
{
GetPlayerPos(playerid, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ]);
ObjInfo[idx][oModel] = object;
oldoID = ObjInfo[idx][oModel];
oldodX = ObjInfo[idx][oX];
oldodY = ObjInfo[idx][oY];
oldodZ = ObjInfo[idx][oZ];
oldodRX = ObjInfo[idx][oRX];
oldodRY = ObjInfo[idx][oRY];
oldodRZ = ObjInfo[idx][oRZ];
ObjInfo[idx][oX] = ObjInfo[idx][oX] + 2;
ObjInfo[idx][oY] = ObjInfo[idx][oY] + 2;
ObjInfo[idx][oRX] = 0;
ObjInfo[idx][oRY] = 0;
ObjInfo[idx][oRZ] = 0;
// Creating
format(string, sizeof(string), "Object ID: %d (Model ID: %d)", idx, ObjInfo[idx][oModel]);
ObjInfo[idx][obj] = CreateDynamicObject(ObjInfo[idx][oModel], ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], ObjInfo[idx][oRX], ObjInfo[idx][oRY], ObjInfo[idx][oRZ]);
ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], 10);
// Text
idx = MAX_OBJ;
}
}
return 1;
}
CMD:duplicateobj(playerid, params[])
{
new string[128] ,idx;
for(idx=1; idx<MAX_OBJ; idx++)
{
if(!ObjInfo[idx][oModel])
{
ObjInfo[idx][oModel] = oldoID;
ObjInfo[idx][oX] = oldodX;
ObjInfo[idx][oY] = oldodY;
ObjInfo[idx][oZ] = oldodZ;
ObjInfo[idx][oRX] = oldodRX;
ObjInfo[idx][oRY] = oldodRY;
ObjInfo[idx][oRZ] = oldodRZ;
// Creating
ObjInfo[idx][obj] = CreateDynamicObject(oldoID, oldodX, oldodY, oldodZ, oldodRX, oldodRY, oldodRZ);
ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, oldodX, oldodY, oldodZ, 10);
// Text
idx = MAX_OBJ;
}
}
return 1;
}
CMD:nearobj(playerid, params[])
{
new string[128];
for(new idx=1; idx<MAX_OBJ; idx++)
{
if(IsPlayerInRangeOfPoint(playerid, 5, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ]))
{
format(string, sizeof(string), "Nearest Object ID: %d", idx);
SendClientMessage(playerid, COLOR_PURPLE, string);
return 1;
}
}
SendClientMessage(playerid, COLOR_GREY, "You are not near a object!");
return 1;
}
CMD:editobj(playerid, params[])
{
new string[128], idx;
if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /editobj [objectid]");
if(!ObjInfo[idx][oModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid object id.");
oEdit[playerid] = 1;
oEditID[playerid] = idx;
GetDynamicObjectPos(ObjInfo[idx][obj], oPos[playerid][0], oPos[playerid][1], oPos[playerid][2]);
GetDynamicObjectRot(ObjInfo[idx][obj], oRot[playerid][0], oRot[playerid][1], oRot[playerid][2]);
EditDynamicObject(playerid, ObjInfo[idx][obj]);
format(string, sizeof(string), " You are now editing object ID %d's position.", idx);
SendClientMessage(playerid, COLOR_GREY, string);
return 1;
}
CMD:deleteobj(playerid, params[])
{
new idx, string[128];
if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /deleteobj [objid]");
if(!ObjInfo[idx][oModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid object id.");
ObjInfo[idx][oModel] = 0;
ObjInfo[idx][oX] = 0;
ObjInfo[idx][oY] = 0;
ObjInfo[idx][oZ] = 0;
ObjInfo[idx][oRX] = 0;
ObjInfo[idx][oRY] = 0;
ObjInfo[idx][oRZ] = 0;
DestroyDynamicObject(ObjInfo[idx][obj]);
DestroyDynamic3DTextLabel(ObjInfo[idx][oText]);
return 1;
}
CMD:gotoobj(playerid, params[])
{
new idx, string[128], string2[128];
if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /gotoobj [objectid]");
if(!ObjInfo[idx][oModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid object id.");
SetPlayerPos(playerid, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ]);
format(string, sizeof(string), " You have teleported to object ID %d.", idx);
SendClientMessage(playerid, COLOR_GREY, string);
return 1;
}
CMD:saveobjects(playerid, params[])
{
new string[128];
SendClientMessage(playerid, COLOR_RED, "Objects have been saved!");
SaveObjects();
SaveObjects2();
return 1;
}
stock RPN(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = 0; i < MAX_PLAYER_NAME; i++)
{
if(name[i] == '_') name[i] = ' ';
}
return name;
}
stock SaveObjects()
{
new idx = 1, File:file;
new string[256];
while(idx < MAX_OBJ)
{
format(string, sizeof(string), " CreateDynamicObject(%d,%f,%f,%f,%f,%f,%f);\r\n",
ObjInfo[idx][oModel],
ObjInfo[idx][oX],
ObjInfo[idx][oY],
ObjInfo[idx][oZ],
ObjInfo[idx][oRX],
ObjInfo[idx][oRY],
ObjInfo[idx][oRZ]);
if(idx == 1)
{
file = fopen("objects.cfg", io_write);
}
else
{
file = fopen("objects.cfg", io_append);
}
fwrite(file, string);
fclose(file);
idx++;
}
print("Objects saved successfully.");
return 1;
}
Just adding some steps and codes won't just make it like a tutorial. Explain it well, including the codes so that it will be regarded as a tutorial and everyone will be understanding. Better luck next time.
|