Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------
- //
- // In-Game Object Editor by Richie©
- //
- //------------------------------------------------------------------------------
- #include <a_samp>
- #include <zcmd>
- #include <a_mysql> // BlueG's R7 plugin is required
- #include <sscanf2>
- #define FILTERSCRIPT
- #define THREAD_INITIATE_OBJECTS (600)
- #define THREAD_SAVEOBJECT (601)
- #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
- //------------------------------------------------------------------------------
- #define mysql_fetch_row(%1) mysql_fetch_row_format(%1,"|")
- new gConnectionhandle;
- #define mysql_query(%1,%2) \
- mysql_function_query(gConnectionhandle, %1, false, "OnQueryFinish", "siii", %1, %2, -1, 1)
- //==============================================================================
- #define MAX_IG_OBJECTS 999 // Maximum amount of objects.
- enum _igObjects
- {
- oID,
- oObjectID,
- 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();
- mysql_debug(1);
- return 1;
- }
- public OnFilterScriptExit()
- {
- mysql_close(gConnectionhandle);
- return 1;
- }
- stock initiateObjects()
- {
- return mysql_query("SELECT * FROM `Objects`", THREAD_INITIATE_OBJECTS);
- }
- 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)
- {
- format(Query, sizeof(Query), "INSERT INTO `Objects` (ObjectID, fX, fY, fZ, rX, rY, rZ, Description) VALUES (%d, %f, %f, %f, %f, %f, %f,'%s')",
- InGameObjects[objectid][oObjectID], fX, fY, fZ, fRotX, fRotY, fRotZ, InGameObjects[objectid][oObjectDesc]);
- print(Query);
- mysql_query(Query, THREAD_SAVEOBJECT);
- InGameObjects[objectid][oID] = mysql_insert_id();
- }
- else
- {
- format(Query, sizeof(Query), "UPDATE `Objects` SET ObjectID = %d, fX = %f, fY = %f, fZ = %f, rX = %f, rY = %f, rZ = %f, Description = '%s' WHERE ID = %d",
- InGameObjects[objectid][oObjectID], fX, fY, fZ, fRotX, fRotY, fRotZ, InGameObjects[objectid][oObjectDesc], InGameObjects[objectid][oID]);
- mysql_query(Query, THREAD_SAVEOBJECT);
- }
- }
- return 1;
- }
- forward OnQueryFinish(query[], resultid, extraid, connectionHandle);
- public OnQueryFinish(query[], resultid, extraid, connectionHandle)
- {
- switch(resultid)
- {
- case THREAD_INITIATE_OBJECTS:
- {
- mysql_store_result();
- new result[1024], objectid, sqlid, desc[64], Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, num = 0;
- while(mysql_fetch_row(result))
- {
- sscanf(result, "p<|>iiffffffs[64]",
- sqlid, objectid, x, y, z, rx, ry, rz, desc);
- new newobject = CreateObject(objectid, x, y, z, rx, ry, rz);
- printf("[rObject] Model: %d, X: %f, Y: %f, Z: %f, rX: %f, rY: %f, rZ: %f, Desc: %s", objectid, x, y, z, rx, ry, rz, desc);
- InGameObjects[newobject][oID] = sqlid;
- InGameObjects[newobject][oObjectID] = objectid;
- InGameObjects[newobject][ofX] = x;
- InGameObjects[newobject][ofY] = y;
- InGameObjects[newobject][ofZ] = z;
- InGameObjects[newobject][orX] = rx;
- InGameObjects[newobject][orY] = ry;
- InGameObjects[newobject][orZ] = rz;
- InGameObjects[newobject][oObjectDesc] = desc;
- num++;
- }
- mysql_free_result();
- printf("==================================");
- printf("[ Objects - LOADED: %d objects ]", num);
- printf("==================================");
- }
- case THREAD_SAVEOBJECT: return 1;
- }
- 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_query(Query, THREAD_SAVEOBJECT);
- DestroyObject(objectid);
- SendClientMessage(playerid, COLOR_RED, "Object permanently deleted.");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement