Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ObjectEdit By Psymetrix
- Information:
- This script allows more control over SA:MP's in-built object editor.
- Comments with the prefix 'NOTE:' require further changes or edits.
- Dialog structure:
- [+] Create
- [*] Insert model ID
- [*] Insert object ID (Clone object)
- [*] Select (Clone object)
- [+] Remove
- [*] Insert object ID
- [*] Select
- [+] Edit
- [*] Insert object ID
- [*] Select
- [+] Project
- [*] Save
- [*] Load
- [*] Export
- */
- #define FILTERSCRIPT
- #include <a_samp>
- #define EDITOR_VERSION "0.1"
- #define DIALOG_MENU 5666
- #define DIALOG_CREATE DIALOG_MENU+1
- #define DIALOG_REMOVE DIALOG_MENU+2
- #define DIALOG_EDIT DIALOG_MENU+3
- #define DIALOG_CREATE_MODEL DIALOG_MENU+4
- #define DIALOG_CREATE_ID DIALOG_MENU+5
- #define DIALOG_REMOVE_ID DIALOG_MENU+6
- #define DIALOG_EDIT_ID DIALOG_MENU+7
- #define DIALOG_PROJECT DIALOG_MENU+8
- #define DIALOG_SAVE DIALOG_MENU+9
- #define DIALOG_LOAD DIALOG_MENU+10
- #define DIALOG_EXPORT DIALOG_MENU+11
- #define DIALOG_NEW_PROJECT DIALOG_MENU+12
- #define EDIT_MODE_NONE 0
- #define EDIT_MODE_REMOVE 1
- #define EDIT_MODE_CLONE 2
- #define EDIT_MODE_EDIT 3
- new ObjectModel[MAX_OBJECTS] = {INVALID_OBJECT_ID, ...};
- new EditMode[MAX_PLAYERS] = {EDIT_MODE_NONE, ...};
- forward Delay_SelectObject(playerid);
- forward Delay_EditObject(playerid, objectid);
- Editor_CreateObject(model, Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz)
- {
- new objectid;
- objectid = CreateObject(model, x, y, z, rotx, roty, rotz);
- ObjectModel[objectid] = model;
- return objectid;
- }
- Editor_RemoveObject(objectid)
- {
- if (!IsValidObject(objectid) || ObjectModel[objectid] == INVALID_OBJECT_ID) return 0;
- DestroyObject(objectid);
- ObjectModel[objectid] = INVALID_OBJECT_ID;
- return 1;
- }
- Editor_DuplicateObject(objectid)
- {
- new Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz;
- GetObjectPos(objectid, x, y, z);
- GetObjectRot(objectid, rotx, roty, rotz);
- Editor_CreateObject(ObjectModel[objectid], x, y, z, rotx, roty, rotz);
- }
- Editor_RemoveEditorObjects()
- {
- for (new i; i < MAX_OBJECTS; i++)
- {
- Editor_RemoveObject(i);
- }
- }
- Editor_PlayerSelectObject(playerid)
- SetTimerEx("Delay_SelectObject", 200, false, "i", playerid);
- public Delay_SelectObject(playerid)
- SelectObject(playerid);
- Editor_PlayerEditObject(playerid, objectid)
- SetTimerEx("Delay_EditObject", 200, false, "ii", playerid, objectid);
- public Delay_EditObject(playerid, objectid)
- EditObject(playerid, objectid);
- ShowDialog(playerid, dialogid)
- {
- EditMode[playerid] = EDIT_MODE_NONE;
- switch(dialogid)
- {
- // Main editor dialog
- case DIALOG_MENU: ShowPlayerDialog(playerid, DIALOG_MENU, DIALOG_STYLE_LIST, "ObjectEdit "EDITOR_VERSION"", "[+] Create\n[+] Remove\n[+] Edit\n[+] Project", "Select", "Cancel");
- // DIALOG_MENU response
- case DIALOG_CREATE: ShowPlayerDialog(playerid, DIALOG_CREATE, DIALOG_STYLE_LIST, "ObjectEdit "EDITOR_VERSION" - Create", "[*] Insert model ID\n[*] Insert object ID (Clone object)\n[*] Select (Clone object)", "Select", "Back");
- case DIALOG_REMOVE: ShowPlayerDialog(playerid, DIALOG_REMOVE, DIALOG_STYLE_LIST, "ObjectEdit "EDITOR_VERSION" - Remove", "[*] Insert object ID\n[*] Select", "Select", "Back");
- case DIALOG_EDIT: ShowPlayerDialog(playerid, DIALOG_EDIT, DIALOG_STYLE_LIST, "ObjectEdit "EDITOR_VERSION" - Edit", "[*] Insert object ID\n[*] Select", "Select", "Back");
- // DIALOG_CREATE response
- case DIALOG_CREATE_MODEL: ShowPlayerDialog(playerid, DIALOG_CREATE_MODEL, DIALOG_STYLE_INPUT, "ObjectEdit "EDITOR_VERSION" - Create", "Please insert an object model ID.", "Create", "Back");
- case DIALOG_CREATE_ID: ShowPlayerDialog(playerid, DIALOG_CREATE_ID, DIALOG_STYLE_INPUT, "ObjectEdit "EDITOR_VERSION" - Create", "Please insert an object ID.", "Clone", "Back");
- // DIALOG_REMOVE response
- case DIALOG_REMOVE_ID: ShowPlayerDialog(playerid, DIALOG_REMOVE_ID, DIALOG_STYLE_INPUT, "ObjectEdit "EDITOR_VERSION" - Remove", "Please insert an object ID.", "Remove", "Back");
- // DIALOG_EDIT response
- case DIALOG_EDIT_ID: ShowPlayerDialog(playerid, DIALOG_EDIT_ID, DIALOG_STYLE_INPUT, "ObjectEdit "EDITOR_VERSION" - Edit", "Please insert an object ID.", "Edit", "Back");
- // Project dialog
- case DIALOG_PROJECT: ShowPlayerDialog(playerid, DIALOG_PROJECT, DIALOG_STYLE_LIST, "ObjectEdit "EDITOR_VERSION" - Project", "[*] Save\n[*] Load\n[*] Export\n[*] New", "Select", "Back");
- // DIALOG_PROJECT response
- case DIALOG_SAVE: ShowPlayerDialog(playerid, DIALOG_SAVE, DIALOG_STYLE_INPUT, "ObjectEdit "EDITOR_VERSION" - Save", "Please give a name for this project.\n\nDo not use file extensions.\n\nIf the project file already exists, it will be overwritten.", "Save", "Back");
- case DIALOG_LOAD: ShowPlayerDialog(playerid, DIALOG_LOAD, DIALOG_STYLE_INPUT, "ObjectEdit "EDITOR_VERSION" - Load", "Please give a project name to open.\n\nDo not use file extensions.\n\nPlease save your work.\nOpening a project will remove all existing objects\nadded by this editor.", "Load", "Back");
- case DIALOG_EXPORT: ShowPlayerDialog(playerid, DIALOG_EXPORT, DIALOG_STYLE_INPUT, "ObjectEdit "EDITOR_VERSION" - Export", "Please give a name for this export.\n\nDo not use file extensions.\n\nIf the export file already exists, it will be overwritten.", "Export", "Back");
- case DIALOG_NEW_PROJECT: ShowPlayerDialog(playerid, DIALOG_NEW_PROJECT, DIALOG_STYLE_MSGBOX, "ObjectEdit "EDITOR_VERSION" - New", "Do you really want to start a new project?\n\nThis will delete all objects added by the editor\nand cannot be undone!", "New", "Back");
- }
- }
- 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;
- }
- public OnFilterScriptInit()
- {
- return 1;
- }
- public OnFilterScriptExit()
- {
- Editor_RemoveEditorObjects();
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp(cmdtext, "/oedit", true) == 0)
- {
- ShowDialog(playerid, DIALOG_MENU);
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- // Main editor dialog
- if (dialogid == DIALOG_MENU)
- {
- if (response)
- {
- switch (listitem)
- {
- // Create
- case 0: ShowDialog(playerid, DIALOG_CREATE);
- // Remove
- case 1: ShowDialog(playerid, DIALOG_REMOVE);
- // Edit
- case 2: ShowDialog(playerid, DIALOG_EDIT);
- // Project
- case 3: ShowDialog(playerid, DIALOG_PROJECT);
- }
- }
- return 1;
- }
- // Create object dialog
- if (dialogid == DIALOG_CREATE)
- {
- if (!response) ShowDialog(playerid, DIALOG_MENU);
- else
- {
- switch (listitem)
- {
- case 0: ShowDialog(playerid, DIALOG_CREATE_MODEL);
- case 1: ShowDialog(playerid, DIALOG_CREATE_ID);
- case 2:
- {
- Editor_PlayerSelectObject(playerid);
- EditMode[playerid] = EDIT_MODE_CLONE;
- }
- }
- }
- return 1;
- }
- // Remove object dialog
- if (dialogid == DIALOG_REMOVE)
- {
- if (!response) ShowDialog(playerid, DIALOG_MENU);
- else
- {
- switch (listitem)
- {
- case 0: ShowDialog(playerid, DIALOG_REMOVE_ID);
- case 1:
- {
- Editor_PlayerSelectObject(playerid);
- EditMode[playerid] = EDIT_MODE_REMOVE;
- }
- }
- }
- return 1;
- }
- // Edit object dialog
- if (dialogid == DIALOG_EDIT)
- {
- if (!response) ShowDialog(playerid, DIALOG_MENU);
- else
- {
- switch (listitem)
- {
- case 0: ShowDialog(playerid, DIALOG_EDIT_ID);
- case 1:
- {
- Editor_PlayerSelectObject(playerid);
- EditMode[playerid] = EDIT_MODE_EDIT;
- }
- }
- }
- return 1;
- }
- // Project object dialog
- if (dialogid == DIALOG_PROJECT)
- {
- if (!response) ShowDialog(playerid, DIALOG_MENU);
- else
- {
- switch (listitem)
- {
- case 0: ShowDialog(playerid, DIALOG_SAVE);
- case 1: ShowDialog(playerid, DIALOG_LOAD);
- case 2: ShowDialog(playerid, DIALOG_EXPORT);
- case 3: ShowDialog(playerid, DIALOG_NEW_PROJECT);
- }
- }
- return 1;
- }
- // Create object by model
- if (dialogid == DIALOG_CREATE_MODEL)
- {
- if (!response || !inputtext[0]) ShowDialog(playerid, DIALOG_CREATE);
- else
- {
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- Editor_CreateObject(strval(inputtext), x, y, z, 0.0, 0.0, 0.0);
- ShowDialog(playerid, DIALOG_CREATE);
- }
- return 1;
- }
- // Create object by object ID (clone)
- if (dialogid == DIALOG_CREATE_ID)
- {
- if (!response || !inputtext[0]) ShowDialog(playerid, DIALOG_CREATE);
- else
- {
- Editor_DuplicateObject(strval(inputtext));
- ShowDialog(playerid, DIALOG_CREATE);
- }
- return 1;
- }
- // Remove object by object ID
- if (dialogid == DIALOG_REMOVE_ID)
- {
- if (!response || !inputtext[0]) ShowDialog(playerid, DIALOG_REMOVE);
- else
- {
- Editor_RemoveObject(strval(inputtext));
- ShowDialog(playerid, DIALOG_REMOVE);
- }
- return 1;
- }
- // Edit object by object ID
- if (dialogid == DIALOG_EDIT_ID)
- {
- if (!response || !inputtext[0]) ShowDialog(playerid, DIALOG_EDIT);
- else
- {
- Editor_PlayerEditObject(playerid, strval(inputtext));
- EditMode[playerid] = EDIT_MODE_EDIT;
- }
- return 1;
- }
- // Save project
- if (dialogid == DIALOG_SAVE)
- {
- if (!response || !inputtext[0]) ShowDialog(playerid, DIALOG_PROJECT);
- else
- {
- new File:pFile, string[128];
- format(string, sizeof(string), "%s.txt", inputtext);
- pFile = fopen(string, io_write);
- if (pFile)
- {
- new Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz;
- for (new i; i < MAX_OBJECTS; i++)
- {
- if (ObjectModel[i] && IsValidObject(i))
- {
- GetObjectPos(i, x, y, z);
- GetObjectRot(i, rotx, roty, rotz);
- format(string, sizeof(string), "%d, %f, %f, %f, %f, %f, %f\r\n", ObjectModel[i], x, y, z, rotx, roty, rotz);
- fwrite(pFile, string);
- }
- }
- fclose(pFile);
- ShowDialog(playerid, DIALOG_PROJECT);
- }
- }
- return 1;
- }
- // Load project
- if (dialogid == DIALOG_LOAD)
- {
- if (!response || !inputtext[0]) ShowDialog(playerid, DIALOG_PROJECT);
- else
- {
- new File:pFile, string[128];
- format(string, sizeof(string), "%s.txt", inputtext);
- if (fexist(string))
- {
- Editor_RemoveEditorObjects();
- new params[7][10];
- pFile = fopen(string, io_read);
- if (pFile)
- {
- while (fread(pFile, string))
- {
- split(string, params, ',');
- Editor_CreateObject(strval(params[0]), floatstr(params[1]), floatstr(params[2]), floatstr(params[3]), floatstr(params[4]), floatstr(params[5]), floatstr(params[6]));
- }
- fclose(pFile);
- ShowDialog(playerid, DIALOG_PROJECT);
- }
- }
- }
- return 1;
- }
- // Export project
- if (dialogid == DIALOG_EXPORT)
- {
- if (!response || !inputtext[0]) ShowDialog(playerid, DIALOG_PROJECT);
- else
- {
- // NOTE: eFile and string2 need changed back to oFile and string
- // and the warning removed.
- new File:eFile, string2[128];
- format(string2, sizeof(string2), "%s.pwn", inputtext);
- eFile = fopen(string2, io_write);
- if (eFile)
- {
- fwrite(eFile, "#define FILTERSCRIPT\r\n\n");
- fwrite(eFile, "#include <a_samp>\r\n\n");
- fwrite(eFile, "public OnGameFilterScriptInit()\r\n");
- fwrite(eFile, "{\r\n");
- new Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz;
- for (new i; i < MAX_OBJECTS; i++)
- {
- if (ObjectModel[i] != INVALID_OBJECT_ID && IsValidObject(i))
- {
- GetObjectPos(i, x, y, z);
- GetObjectRot(i, rotx, roty, rotz);
- format(string2, sizeof(string2), "\tCreateObject(%d,%f,%f,%f,%f,%f,%f);\r\n", ObjectModel[i], x, y, z, rotx, roty, rotz);
- fwrite(eFile, string2);
- }
- }
- fwrite(eFile, "\treturn 1;\r\n");
- fwrite(eFile, "}\r\n");
- fclose(eFile);
- ShowDialog(playerid, DIALOG_PROJECT);
- }
- }
- return 1;
- }
- // New project
- if (dialogid == DIALOG_NEW_PROJECT)
- {
- if (response) Editor_RemoveEditorObjects();
- else ShowDialog(playerid, DIALOG_PROJECT);
- }
- return 0;
- }
- public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
- {
- // We don't handle player objects in this script
- if (type != SELECT_OBJECT_GLOBAL_OBJECT) return 0;
- if (EditMode[playerid] == EDIT_MODE_REMOVE)
- {
- Editor_RemoveObject(objectid);
- CancelEdit(playerid);
- ShowDialog(playerid, DIALOG_REMOVE);
- }
- else if (EditMode[playerid] == EDIT_MODE_CLONE)
- {
- Editor_DuplicateObject(objectid);
- CancelEdit(playerid);
- ShowDialog(playerid, DIALOG_CREATE);
- }
- else if (EditMode[playerid] == EDIT_MODE_EDIT)
- {
- Editor_PlayerEditObject(playerid, objectid);
- }
- return 1;
- }
- public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
- {
- // We don't handle player objects in this script
- if (playerobject) return;
- if(response)
- {
- if (response == EDIT_RESPONSE_FINAL)
- {
- // Update the object
- SetObjectPos(objectid, fX, fY, fZ);
- SetObjectRot(objectid, fRotX, fRotY, fRotZ);
- if (EditMode[playerid] == EDIT_MODE_EDIT)
- {
- ShowDialog(playerid, DIALOG_EDIT);
- }
- }
- }
- else
- {
- // Undo last movements
- new Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz;
- GetObjectPos(objectid, x, y, z);
- GetObjectRot(objectid, rotx, roty, rotz);
- SetObjectPos(objectid, x, y, z);
- SetObjectRot(objectid, rotx, roty, rotz);
- if (EditMode[playerid] == EDIT_MODE_EDIT)
- {
- ShowDialog(playerid, DIALOG_EDIT);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment