Advertisement
Guest User

Untitled

a guest
Apr 24th, 2012
2,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.07 KB | None | 0 0
  1. //------------------------------------------------------------------------------
  2. //
  3. //                  In-Game Object Editor by Richie©
  4. //
  5. //------------------------------------------------------------------------------
  6.  
  7. #include <a_samp>
  8. #include <zcmd>
  9. #include <a_mysql> // BlueG's R7 plugin is required
  10. #include <sscanf2>
  11.  
  12. #define FILTERSCRIPT
  13.  
  14. #define THREAD_INITIATE_OBJECTS             (600)
  15. #define THREAD_SAVEOBJECT                   (601)
  16.  
  17. #define DELETEOBJECT 1234 // Dialog ID
  18. #define COLOR_RED 0xAA3333AA
  19. // ============================== MySQL ========================================
  20. #define SQL_HOST                "127.0.0.1"                         // IP
  21. #define SQL_USER                "user"                              // user
  22. #define SQL_PASS                "pass"                          // password
  23. #define SQL_DB                  "database"                          // database
  24. //------------------------------------------------------------------------------
  25. #define mysql_fetch_row(%1)     mysql_fetch_row_format(%1,"|")
  26. new gConnectionhandle;
  27. #define mysql_query(%1,%2) \
  28.     mysql_function_query(gConnectionhandle, %1, false, "OnQueryFinish", "siii", %1, %2, -1, 1)
  29. //==============================================================================
  30. #define MAX_IG_OBJECTS 999 // Maximum amount of objects.
  31.  
  32. enum _igObjects
  33. {
  34.     oID,
  35.     oObjectID,
  36.     Float:ofX,
  37.     Float:ofY,
  38.     Float:ofZ,
  39.     Float:orX,
  40.     Float:orY,
  41.     Float:orZ,
  42.     oObjectDesc[64]
  43. };
  44.  
  45. new InGameObjects[MAX_IG_OBJECTS][_igObjects];
  46. new ObjectToDelete[MAX_PLAYERS];
  47.  
  48. public OnFilterScriptInit()
  49. {
  50.     gConnectionhandle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
  51.     print("\nObject Editor by Richie© - Loaded\n");
  52.     initiateObjects();
  53.     mysql_debug(1);
  54.     return 1;
  55. }
  56.  
  57. public OnFilterScriptExit()
  58. {
  59.     mysql_close(gConnectionhandle);
  60.     return 1;
  61. }
  62.  
  63. stock initiateObjects()
  64. {
  65.     return mysql_query("SELECT * FROM `Objects`", THREAD_INITIATE_OBJECTS);
  66. }
  67.  
  68. CMD:object(playerid, params[])
  69. {
  70.     new object, description[64], string[128];
  71.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"You cant use this command!");
  72.     if(sscanf(params,"ds[64]",object, description)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /object [objectid] [description]");
  73.  
  74.     new Float:px, Float:py, Float:pz;
  75.     GetPlayerPos(playerid, px, py, pz);
  76.     new newobject = CreateObject(object, px+2, py+2, pz, 0.0, 0.0, 0.0);
  77.     EditObject(playerid, newobject);
  78.     InGameObjects[newobject][oObjectDesc] = description;
  79.     InGameObjects[newobject][oID] = 0;
  80.     InGameObjects[newobject][oObjectID] = object;
  81.     format(string, sizeof(string),"{0BDDC4}[Object Editor]{FFFFFF} Editing objectid %d, sqlid %d, description: %s", object, newobject, description);
  82.     SendClientMessage(playerid, -1, string);
  83.     return 1;
  84. }
  85.  
  86. CMD:selectobject(playerid, params[])
  87. {
  88.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"You cant use this command!");
  89.     SelectObject(playerid);
  90.     return 1;
  91. }
  92.  
  93. public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
  94. {
  95.     if(type == SELECT_OBJECT_GLOBAL_OBJECT)
  96.     {
  97.         EditObject(playerid, objectid);
  98.     }
  99.     else
  100.     {
  101.         EditPlayerObject(playerid, objectid);
  102.     }
  103.     return 1;
  104. }
  105.  
  106. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  107. {
  108.     if(!playerobject) // If this is a global object, move it for other players
  109.     {
  110.         if(!IsValidObject(objectid)) return SendClientMessage(playerid, -1, "Invalid object ID (Callback: OPEO)");
  111.         MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
  112.     }
  113.     new Query[360];
  114.     if(response == EDIT_RESPONSE_CANCEL)
  115.     {
  116.         ObjectToDelete[playerid] = objectid;
  117.         ShowPlayerDialog(playerid, DELETEOBJECT, DIALOG_STYLE_MSGBOX,"Delete Object", "Do you want to permanently delete this object?", "Yes", "No");
  118.     }
  119.     if(response == EDIT_RESPONSE_FINAL)
  120.     {
  121.         MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
  122.         InGameObjects[objectid][ofX] = fX;
  123.         InGameObjects[objectid][ofY] = fY;
  124.         InGameObjects[objectid][ofZ] = fZ;
  125.         InGameObjects[objectid][orX] = fRotX;
  126.         InGameObjects[objectid][orY] = fRotY;
  127.         InGameObjects[objectid][orZ] = fRotZ;
  128.  
  129.  
  130.         if(InGameObjects[objectid][oID] == 0)
  131.         {
  132.             format(Query, sizeof(Query), "INSERT INTO `Objects` (ObjectID, fX, fY, fZ, rX, rY, rZ, Description) VALUES (%d, %f, %f, %f, %f, %f, %f,'%s')",
  133.             InGameObjects[objectid][oObjectID], fX, fY, fZ, fRotX, fRotY, fRotZ, InGameObjects[objectid][oObjectDesc]);
  134.  
  135.             print(Query);
  136.  
  137.             mysql_query(Query, THREAD_SAVEOBJECT);
  138.  
  139.             InGameObjects[objectid][oID] = mysql_insert_id();
  140.         }
  141.         else
  142.         {
  143.             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",
  144.             InGameObjects[objectid][oObjectID], fX, fY, fZ, fRotX, fRotY, fRotZ, InGameObjects[objectid][oObjectDesc], InGameObjects[objectid][oID]);
  145.  
  146.             mysql_query(Query, THREAD_SAVEOBJECT);
  147.         }
  148.     }
  149.     return 1;
  150. }
  151.  
  152. forward OnQueryFinish(query[], resultid, extraid, connectionHandle);
  153. public OnQueryFinish(query[], resultid, extraid, connectionHandle)
  154. {
  155.     switch(resultid)
  156.     {
  157.         case THREAD_INITIATE_OBJECTS:
  158.         {
  159.             mysql_store_result();
  160.             new result[1024], objectid, sqlid, desc[64], Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, num = 0;
  161.             while(mysql_fetch_row(result))
  162.             {
  163.                 sscanf(result, "p<|>iiffffffs[64]",
  164.                 sqlid, objectid, x, y, z, rx, ry, rz, desc);
  165.  
  166.                 new newobject = CreateObject(objectid, x, y, z, rx, ry, rz);
  167.                 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);
  168.  
  169.                 InGameObjects[newobject][oID] = sqlid;
  170.                 InGameObjects[newobject][oObjectID] = objectid;
  171.                 InGameObjects[newobject][ofX] = x;
  172.                 InGameObjects[newobject][ofY] = y;
  173.                 InGameObjects[newobject][ofZ] = z;
  174.                 InGameObjects[newobject][orX] = rx;
  175.                 InGameObjects[newobject][orY] = ry;
  176.                 InGameObjects[newobject][orZ] = rz;
  177.                 InGameObjects[newobject][oObjectDesc] = desc;
  178.                 num++;
  179.             }
  180.             mysql_free_result();
  181.             printf("==================================");
  182.             printf("[ Objects - LOADED: %d objects ]", num);
  183.             printf("==================================");
  184.         }
  185.         case THREAD_SAVEOBJECT: return 1;
  186.     }
  187.     return 1;
  188. }
  189.  
  190. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) //New Dialog response
  191. {
  192.     switch(dialogid)
  193.     {
  194.         case DELETEOBJECT:
  195.         {
  196.             if(!response)
  197.             {
  198.                 SendClientMessage(playerid, COLOR_RED, "You selected no, object not deleted.");
  199.                 return 1;
  200.             }
  201.             new Query[128];
  202.             new objectid = ObjectToDelete[playerid];
  203.             format(Query, sizeof(Query), "DELETE FROM `Objects` WHERE `ID` = %i LIMIT 1", InGameObjects[objectid][oID]);
  204.             mysql_query(Query, THREAD_SAVEOBJECT);
  205.             DestroyObject(objectid);
  206.             SendClientMessage(playerid, COLOR_RED, "Object permanently deleted.");
  207.         }
  208.     }
  209.     return 0;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement