25.03.2013, 20:41
Ingame Mapper system
Using Yini, sscanf, zcmd & streamer plugins!
as first, We'll define the max objects.
add this in the top of your gamemode.
Change ''1001'', with the maximum amounts of objects, that can be created ingame.
Then, We'll make some public defines, for the Editting & Duplicating of the mapper system.
Add this somewhere in the top of your gamemode.
Then, we'll add the obj info.
Then we will save & load the objects
The structure where we will save all objects.
And the structure, where we will load the objects.
We will define te ''split'' Also..
Then we will set the variables on 0, for every player if they connect to the server.
add this to ''OnPlayerConnect''.
Here we will define some colors.. add this in the top of your script..
Then ofcourse, we have to save all objects, when the server will disconnect.
Add this under ''OngamemodeExit''.
Then we will use the 0.3e dynamic obj system to edit objects.
Add this somewhere in your gamemode.
Also, We need commands, to use it.
add this to your commands.
We dont need to get the player name everytime.. So i used ''rpn''.
Add this in your gamemode.
Then ofcourse, those Textlabers are stupid.
Then we will make an extra save option.
That will save all objects in a file in the ''CreateDynamicObject'' Structure.
Add this..
You have to create a empty ''objects.cfg'' & ''objects22.cfg'' file in your scriptfiles folder.
To save all your objects in the the gamemode.
Paste all codes from objects.cfg and paste them under ''ongamemodeinit''.
then make your Two .cfg files empty.
& save them.
Thanks for reading this tutorial, sorry for my bad english.
rep+ is always welcome.
Using Yini, sscanf, zcmd & streamer plugins!
as first, We'll define the max objects.
add this in the top of your gamemode.
pawn Код:
#define MAX_OBJ 1001
Then, We'll make some public defines, for the Editting & Duplicating of the mapper system.
Add this somewhere in the top of your gamemode.
pawn Код:
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.
pawn Код:
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];
The structure where we will save all objects.
pawn Код:
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;
}
And the structure, where we will load the objects.
pawn Код:
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;
}
pawn Код:
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;
}
Then we will set the variables on 0, for every player if they connect to the server.
add this to ''OnPlayerConnect''.
pawn Код:
oEdit[playerid] = 0;
oEditID[playerid] = 0;
pawn Код:
#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
Add this under ''OngamemodeExit''.
pawn Код:
SaveObjects2();
SaveObjects();
Add this somewhere in your gamemode.
pawn Код:
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;
}
add this to your commands.
pawn Код:
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;
}
Add this in your gamemode.
pawn Код:
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;
}
Then we will make an extra save option.
That will save all objects in a file in the ''CreateDynamicObject'' Structure.
Add this..
pawn Код:
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;
}
To save all your objects in the the gamemode.
Paste all codes from objects.cfg and paste them under ''ongamemodeinit''.
then make your Two .cfg files empty.
& save them.
Thanks for reading this tutorial, sorry for my bad english.
rep+ is always welcome.