SHARE
TWEET

Dynamic Objects System

Mongi Aug 12th, 2017 (edited) 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. --------------------------------------------------------------------------------
  3.     This FilterScript is created by Mongi.
  4.     Release Date: 12-08-2017
  5.     Version: 1 - Beta.
  6.  
  7.     If you spot any bug, Let me know!
  8.     And please don't remove the credits.
  9.    
  10.     Currently Bugs: None
  11. --------------------------------------------------------------------------------
  12. */
  13.  
  14. #include <a_samp>
  15. #include <zcmd>
  16. #include <sscanf2>
  17. #include <Dini>
  18.  
  19. /* Let's Define Some Colors */
  20. #define COLOR_YELLOW 0xFFFF00FF
  21. #define COLOR_RED 0xFF0000FF
  22.  
  23. // Defines
  24. #define MAX_OBJ 500
  25.  
  26. // Some Var.
  27. new ObjectEditing[MAX_PLAYERS] = -1;
  28.  
  29. public OnFilterScriptInit()
  30. {
  31.     print("\n--------------------------------------------");
  32.     print(" Dynamic Object System - Scripted By Mongi ");
  33.     print("--------------------------------------------\n");
  34.    
  35.     // Loading the objects and updating the currently ID -----------------------
  36.     new s[150];
  37.    
  38.     for(new obj=0 ; obj <= MAX_OBJ ; obj++)
  39.     {
  40.         format(s, sizeof(s), "ObjectsFile\\obj%d.ini", obj);
  41.         if(dini_Exists(s))
  42.         {
  43.             new id;
  44.             id = CreateObject(dini_Int(s, "Object"), floatstr(dini_Get(s, "X")), floatstr(dini_Get(s, "Y")), floatstr(dini_Get(s, "Z")), floatstr(dini_Get(s, "rX")), floatstr(dini_Get(s, "rY")), floatstr(dini_Get(s, "rZ")));
  45.             dini_IntSet(s, "ObjectID", id); // In Game Object ID
  46.         }
  47.         else{
  48.             break; // No more objects.
  49.         }
  50.     }
  51.     print("Objects Loaded!");
  52.     //--------------------------------------------------------------------------
  53.     return 1;
  54. }
  55.  
  56. public OnPlayerDisconnect(playerid, reason)
  57. {
  58.     ObjectEditing[playerid] = -1;
  59.     return 1;
  60. }
  61.  
  62. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  63. {
  64.     new Float:oldX, Float:oldY, Float:oldZ, Float:oldRotX, Float:oldRotY, Float:oldRotZ;
  65.     if(response == EDIT_RESPONSE_FINAL)
  66.     {
  67.         new pName[MAX_PLAYER_NAME], s[150];
  68.         GetPlayerName(playerid, pName, sizeof(pName));
  69.  
  70.         format(s, sizeof(s), "ObjectsFile\\obj%d.ini", ObjectEditing[playerid]);
  71.         dini_Set(s, "EditedBy", pName);
  72.         dini_FloatSet(s, "X", fX);
  73.         dini_FloatSet(s, "Y", fY);
  74.         dini_FloatSet(s, "Z", fZ);
  75.         dini_FloatSet(s, "rX", fRotX);
  76.         dini_FloatSet(s, "rY", fRotY);
  77.         dini_FloatSet(s, "rZ", fRotZ);
  78.  
  79.         SetObjectPos(objectid, fX, fY, fZ);
  80.         SetObjectRot(objectid, fRotX, fRotY, fRotZ);
  81.  
  82.         ObjectEditing[playerid] = -1;
  83.     }
  84.     if(response == EDIT_RESPONSE_CANCEL)
  85.     {
  86.         SetObjectPos(objectid, oldX, oldY, oldZ);
  87.         SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
  88.         ObjectEditing[playerid] = -1;
  89.     }
  90.     return 1;
  91. }
  92.  
  93. // Dynamic Objects
  94. CMD:createobject(playerid, params[])
  95. {
  96.     new s[150];
  97.     format(s, sizeof(s), "ObjectsFile\\obj%d.ini", MAX_OBJ);
  98.     if(dini_Exists(s)) return SendClientMessage(playerid, COLOR_RED, "Error: You've reached the max objects limit!");
  99.     new object;
  100.     if(sscanf(params, "d", object)) return SendClientMessage(playerid, -1, "Use: /createobject [Object ID]");
  101.     new Float:x, Float:y, Float:z;
  102.     GetPlayerPos(playerid, x, y, z);
  103.     new id, pName[MAX_PLAYER_NAME];
  104.     id = CreateObject(object, x+10, y+10, z, 0, 0, 0);
  105.     GetPlayerName(playerid, pName, sizeof(pName));
  106.     new day, month, year;
  107.     getdate(year, month, day);
  108.     for(new obj=0 ; obj <= MAX_OBJ ; obj++)
  109.     {
  110.         format(s, sizeof(s), "ObjectsFile\\obj%d.ini", obj);
  111.         if(!dini_Exists(s))
  112.         {
  113.             dini_Create(s);
  114.             dini_IntSet(s, "Object", object);
  115.             dini_IntSet(s, "ObjectID", id);
  116.             dini_Set(s, "CreatedBy", pName);
  117.             dini_IntSet(s, "Day", day);
  118.             dini_IntSet(s, "Month", month);
  119.             dini_IntSet(s, "Year", year);
  120.             dini_FloatSet(s, "X", x+10);
  121.             dini_FloatSet(s, "Y", y+10);
  122.             dini_FloatSet(s, "Z", z);
  123.             dini_FloatSet(s, "rX", 0);
  124.             dini_FloatSet(s, "rY", 0);
  125.             dini_FloatSet(s, "rZ", 0);
  126.  
  127.             SendClientMessage(playerid, COLOR_YELLOW, "Object Added!");
  128.             new string[256];
  129.             format(string, sizeof(string), "Object ID: %d / Object Pos: X - %f . Y - %f . Z - %f", obj, x+10, y+10, z);
  130.             SendClientMessage(playerid, COLOR_YELLOW, string);
  131.  
  132.             break;
  133.         }
  134.     }
  135.     return 1;
  136. }
  137. CMD:delobject(playerid, params[])
  138. {
  139.     new object;
  140.     if(sscanf(params, "d", object)) return SendClientMessage(playerid, -1, "Use: /delobject [Object ID]");
  141.     new s[150];
  142.     format(s, sizeof(s), "ObjectsFile\\obj%d.ini", object);
  143.     if(!dini_Exists(s)) return SendClientMessage(playerid, COLOR_RED, "Error: Invalid Object!");
  144.     DestroyObject(dini_Int(s, "ObjectID"));
  145.     dini_Remove(s);
  146.     new ss[150];
  147.     for(new obj=object ; obj <= MAX_OBJ ; obj++)
  148.     {
  149.         format(s, sizeof(s), "ObjectsFile\\obj%d.ini", obj);
  150.         format(ss, sizeof(ss), "ObjectsFile\\obj%d.ini", obj+1); //Next file
  151.         if(dini_Exists(ss))
  152.         {
  153.             dini_Create(s);
  154.             dini_IntSet(s, "Object", dini_Int(ss, "Object") );
  155.             dini_IntSet(s, "ObjectID", dini_Int(ss, "ObjectID"));
  156.             dini_Set(s, "CreatedBy", dini_Get(ss, "CreatedBy"));
  157.             dini_Set(s, "X", dini_Get(ss, "X"));
  158.             dini_Set(s, "Y", dini_Get(ss, "Y"));
  159.             dini_Set(s, "Z", dini_Get(ss, "Z"));
  160.             dini_Set(s, "rX", dini_Get(ss, "rX"));
  161.             dini_Set(s, "rY", dini_Get(ss, "rY"));
  162.             dini_Set(s, "rZ", dini_Get(ss, "rZ"));
  163.             dini_Remove(ss);
  164.         }
  165.     }
  166.  
  167.     new string[256];
  168.     format(string, sizeof(string), "Removed Object ID: %d.", object);
  169.     SendClientMessage(playerid, COLOR_YELLOW, string);
  170.     return 1;
  171. }
  172. CMD:editobject(playerid, params[])
  173. {
  174.     new object;
  175.     if(sscanf(params, "d", object)) return SendClientMessage(playerid, -1, "Use: /editobject [Object ID]");
  176.     new s[150];
  177.     format(s, sizeof(s), "ObjectsFile\\obj%d.ini", object);
  178.     if(!dini_Exists(s)) return SendClientMessage(playerid, COLOR_RED, "Error: Invalid Object!");
  179.     if(ObjectEditing[playerid] != -1) return SendClientMessage(playerid, COLOR_RED, "Error: You are already editing an Object!");
  180.     new string[250];
  181.     format(string, sizeof(string), "You are now editing object %d", object);
  182.     SendClientMessage(playerid, COLOR_YELLOW, string);
  183.     ObjectEditing[playerid] = object;
  184.     EditObject(playerid, dini_Int(s, "ObjectID"));
  185.     return 1;
  186. }
  187. CMD:gotoobject(playerid, params[])
  188. {
  189.     new object;
  190.     if(sscanf(params, "d", object)) return SendClientMessage(playerid, -1, "Use: /gotoobject [Object ID]");
  191.     new s[150];
  192.     format(s, sizeof(s), "ObjectsFile\\obj%d.ini", object);
  193.     if(!dini_Exists(s)) return SendClientMessage(playerid, COLOR_RED, "Error: Invalid Object!");
  194.     SetPlayerPos(playerid, floatstr(dini_Get(s, "X"))+10, floatstr(dini_Get(s, "Y"))+10, floatstr(dini_Get(s, "Z")));
  195.     return 1;
  196. }
  197. CMD:objectinfo(playerid, params[])
  198. {
  199.     new object;
  200.     if(sscanf(params, "d", object)) return SendClientMessage(playerid, -1, "Use: /gotoobject [Object ID]");
  201.     new s[150];
  202.     format(s, sizeof(s), "ObjectsFile\\obj%d.ini", object);
  203.     if(!dini_Exists(s)) return SendClientMessage(playerid, COLOR_RED, "Error: Invalid Object!");
  204.     SendClientMessage(playerid, COLOR_YELLOW, "Object Information:");
  205.     new string[256];
  206.     format(string, sizeof(string), "Object ID: %d", dini_Int(s, "Object"));
  207.     SendClientMessage(playerid, -1, string);
  208.     format(string, sizeof(string), "Created By: %s", dini_Get(s, "CreatedBy"));
  209.     SendClientMessage(playerid, -1, string);
  210.     format(string, sizeof(string), "Date Of Creation: %d/%d/%d", dini_Int(s, "Day"), dini_Int(s, "Month"), dini_Int(s, "Year"));
  211.     SendClientMessage(playerid, -1, string);
  212.     if(dini_Isset(s, "EditedBy"))
  213.     {
  214.         format(string, sizeof(string), "Edited By: %s", dini_Get(s, "EditedBy"));
  215.         SendClientMessage(playerid, -1, string);
  216.     }
  217.     SendClientMessage(playerid, COLOR_YELLOW, "Object Pos:");
  218.     format(string, sizeof(string), "X: %f - Y: %f - Z: %f", floatstr(dini_Get(s, "X")), floatstr(dini_Get(s, "Y")), floatstr(dini_Get(s, "Z")));
  219.     SendClientMessage(playerid, -1, string);
  220.  
  221.     SendClientMessage(playerid, COLOR_YELLOW, "Object Rot:");
  222.     format(string, sizeof(string), "rX: %f - rY: %f - rZ: %f", floatstr(dini_Get(s, "rX")), floatstr(dini_Get(s, "rY")), floatstr(dini_Get(s, "rZ")));
  223.     SendClientMessage(playerid, -1, string);
  224.     return 1;
  225. }
  226. CMD:oused(playerid, params[])
  227. {
  228.     new count = 0, s[150];
  229.     for(new obj=0 ; obj <= MAX_OBJ ; obj++)
  230.     {
  231.         format(s, sizeof(s), "ObjectsFile\\obj%d.ini", obj);
  232.         if(dini_Exists(s))
  233.         {
  234.             count++;
  235.         }
  236.     }
  237.     if(!count) return SendClientMessage(playerid, COLOR_RED, "You didn't create any object!");
  238.     new string[256];
  239.     format(string, sizeof(string), "You've created %d object(s).", count);
  240.     SendClientMessage(playerid, COLOR_YELLOW, string);
  241.     return 1;
  242. }
RAW Paste Data
Top