Advertisement
Guest User

SA-MP Object Editor

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