Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------
- //
- // In-Game Object Editor by Richie©
- //
- // Note: For SA-MP CreateObject.
- // Its possible to change to streamer plugin by changing:
- // CreateObject to CreateDynamicObject
- // EditObject to EditDynamicObject
- //
- // And changing callback and fX to x, fY to y etc:
- // OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
- // OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
- //------------------------------------------------------------------------------
- #include <a_samp>
- #include <zcmd>
- #include <a_mysql> // Created this with BlueG's mysql plugin, R34.
- #include <sscanf2>
- #define FILTERSCRIPT
- #define DELETEOBJECT 1234 // Dialog ID
- #define COLOR_RED 0xAA3333AA
- // ============================== MySQL ========================================
- #define SQL_HOST "127.0.0.1" // IP
- #define SQL_USER "user" // user
- #define SQL_PASS "pass" // password
- #define SQL_DB "database" // database
- //------------------------------------------------------------------------------
- new gConnectionhandle;
- //==============================================================================
- #define MAX_IG_OBJECTS 999 // Maximum amount of objects.
- enum _igObjects
- {
- oID,
- oObjectID, // Model ID
- Float:ofX,
- Float:ofY,
- Float:ofZ,
- Float:orX,
- Float:orY,
- Float:orZ,
- oObjectDesc[64]
- };
- new InGameObjects[MAX_IG_OBJECTS][_igObjects];
- new ObjectToDelete[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- gConnectionhandle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
- print("\nObject Editor by Richie© - Loaded\n");
- initiateObjects();
- return 1;
- }
- public OnFilterScriptExit()
- {
- mysql_close(gConnectionhandle);
- return 1;
- }
- stock initiateObjects()
- {
- return mysql_function_query(gConnectionhandle, "SELECT * FROM `Objects`", true, "OnObjectsLoad", "");
- }
- CMD:object(playerid, params[])
- {
- new object, description[64], string[128];
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"You cant use this command!");
- if(sscanf(params,"ds[64]",object, description)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /object [objectid] [description]");
- new Float:px, Float:py, Float:pz;
- GetPlayerPos(playerid, px, py, pz);
- new newobject = CreateObject(object, px+2, py+2, pz, 0.0, 0.0, 0.0);
- EditObject(playerid, newobject);
- InGameObjects[newobject][oObjectDesc] = description;
- InGameObjects[newobject][oID] = 0;
- InGameObjects[newobject][oObjectID] = object;
- format(string, sizeof(string),"{0BDDC4}[Object Editor]{FFFFFF} Editing objectid %d, sqlid %d, description: %s", object, newobject, description);
- SendClientMessage(playerid, -1, string);
- return 1;
- }
- CMD:selectobject(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"You cant use this command!");
- SelectObject(playerid);
- return 1;
- }
- public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
- {
- if(type == SELECT_OBJECT_GLOBAL_OBJECT)
- {
- EditObject(playerid, objectid);
- }
- else
- {
- EditPlayerObject(playerid, objectid);
- }
- return 1;
- }
- public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
- {
- if(!playerobject) // If this is a global object, move it for other players
- {
- if(!IsValidObject(objectid)) return SendClientMessage(playerid, -1, "Invalid object ID (Callback: OPEO)");
- MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
- }
- new Query[360];
- if(response == EDIT_RESPONSE_CANCEL)
- {
- ObjectToDelete[playerid] = objectid;
- ShowPlayerDialog(playerid, DELETEOBJECT, DIALOG_STYLE_MSGBOX,"Delete Object", "Do you want to permanently delete this object?", "Yes", "No");
- }
- if(response == EDIT_RESPONSE_FINAL)
- {
- MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
- InGameObjects[objectid][ofX] = fX;
- InGameObjects[objectid][ofY] = fY;
- InGameObjects[objectid][ofZ] = fZ;
- InGameObjects[objectid][orX] = fRotX;
- InGameObjects[objectid][orY] = fRotY;
- InGameObjects[objectid][orZ] = fRotZ;
- if(InGameObjects[objectid][oID] == 0)
- {
- mysql_format(gConnectionhandle, Query, sizeof(Query), "INSERT INTO `Objects` (ObjectID, fX, fY, fZ, rX, rY, rZ, Description) VALUES (%d, %f, %f, %f, %f, %f, %f,'%e')",
- InGameObjects[objectid][oObjectID], fX, fY, fZ, fRotX, fRotY, fRotZ, InGameObjects[objectid][oObjectDesc]);
- mysql_function_query(gConnectionhandle, Query, true, "AddObject", "d", objectid);
- }
- else
- {
- mysql_format(gConnectionhandle, Query, sizeof(Query), "UPDATE `Objects` SET ObjectID = %d, fX = %f, fY = %f, fZ = %f, rX = %f, rY = %f, rZ = %f, Description = '%e' WHERE ID = %d",
- InGameObjects[objectid][oObjectID], fX, fY, fZ, fRotX, fRotY, fRotZ, InGameObjects[objectid][oObjectDesc], InGameObjects[objectid][oID]);
- mysql_function_query(gConnectionhandle, Query, true, "NoReturnThread", "");
- }
- }
- return 1;
- }
- forward AddObject(objectid);
- public AddObject(objectid)
- {
- InGameObjects[objectid][oID] = mysql_insert_id();
- return 1;
- }
- forward OnObjectsLoad();
- public OnObjectsLoad()
- {
- new rows, fields, num;
- new id, model, Float:Pos[6], Data[64];
- cache_get_data(rows, fields);
- for(new i = 0; i < rows; i++)
- {
- id = cache_get_field_content_int(i, "ID");
- model = cache_get_field_content_int(i, "ObjectID"); // Model ID
- Pos[0] = cache_get_field_content_float(i, "fX");
- Pos[1] = cache_get_field_content_float(i, "fY");
- Pos[2] = cache_get_field_content_float(i, "fZ");
- Pos[3] = cache_get_field_content_float(i, "rX");
- Pos[4] = cache_get_field_content_float(i, "rY");
- Pos[5] = cache_get_field_content_float(i, "rZ");
- cache_get_field_content(i, "Description", Data);
- new newobject = CreateObject(model, Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]);
- InGameObjects[newobject][oID] = id;
- InGameObjects[newobject][oObjectID] = model;
- InGameObjects[newobject][ofX] = Pos[0];
- InGameObjects[newobject][ofY] = Pos[1];
- InGameObjects[newobject][ofZ] = Pos[2];
- InGameObjects[newobject][orX] = Pos[3];
- InGameObjects[newobject][orY] = Pos[4];
- InGameObjects[newobject][orZ] = Pos[5];
- InGameObjects[newobject][oObjectDesc] = Data;
- num++;
- }
- printf("==================================");
- printf("[ Objects - LOADED: %d objects ]", num);
- printf("==================================");
- return 1;
- }
- forward NoReturnThread();
- public NoReturnThread()
- {
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) //New Dialog response
- {
- switch(dialogid)
- {
- case DELETEOBJECT:
- {
- if(!response)
- {
- SendClientMessage(playerid, COLOR_RED, "You selected no, object not deleted.");
- return 1;
- }
- new Query[128];
- new objectid = ObjectToDelete[playerid];
- format(Query, sizeof(Query), "DELETE FROM `Objects` WHERE `ID` = %i LIMIT 1", InGameObjects[objectid][oID]);
- mysql_function_query(gConnectionhandle, Query, true, "NoReturnThread", "");
- DestroyObject(objectid);
- SendClientMessage(playerid, COLOR_RED, "Object permanently deleted.");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement