Advertisement
Guest User

SetObjectMaterialText Editor v0.1 by RIDE2DAY

a guest
Aug 10th, 2016
3,785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 33.81 KB | None | 0 0
  1. /* Scripted by RIDE2DAY */
  2. /* Official thread: http://forum.sa-mp.com/showthread.php?t=614667 */
  3.  
  4.  
  5. #include <a_samp>
  6.  
  7.  
  8. /* =============================== | [DEFINES] | ================================ */
  9. // - Settings - //
  10. #define MAX_SOMT_OBJECTS            (10)
  11.  
  12. // - Dialogs - //
  13. #define SOMT_MAIN_MENU              (100)
  14. #define SOMT_EDIT_MENU              (101)
  15. #define SOMT_EDIT_OBJECT_MODEL      (102)
  16. #define SOMT_EDIT_TEXT              (103)
  17. #define SOMT_EDIT_MATERIAL_INDEX    (104)
  18. #define SOMT_EDIT_MATERIAL_SIZE     (105)
  19. #define SOMT_EDIT_FONT_FACE         (106)
  20. #define SOMT_EDIT_FONT_SIZE         (107)
  21. #define SOMT_EDIT_BOLD              (108)
  22. #define SOMT_EDIT_COLOR             (109)
  23. #define SOMT_WRITE_COLOR            (110)
  24. #define SOMT_SELECT_COLOR           (111)
  25. #define SOMT_EDIT_TEXT_ALIGNMENT    (112)
  26. //#define SOMT_EDIT_OBJECTS           (113)
  27. #define SOMT_EXPORT_OBJECTS         (114)
  28.  
  29. // - Colors - //
  30. #define RED_E                       "{FF0000}"
  31. #define BLUE_E                      "{00A7EE}"
  32. #define WHITE_E                     "{FFFFFF}"
  33. #define YELLOW_E                    "{EEEA00}"
  34.  
  35. #define COLOR_BLUE                  (0x00A7EEFF)
  36.  
  37. // - Other - //
  38. #define strcpy(%0,%1,%2)            strcat((%0[0] = '\0', %0), %1, %2) /* By Y_Less */
  39.  
  40.  
  41. /* =============================== | [VARIABLES] | ================================ */
  42. // - SQLite - //
  43. new DB:sql_index;
  44.  
  45. // - Objects - //
  46. enum e_Objects
  47. {
  48.     ID,
  49.     ObjectModel,
  50.     Text[129],
  51.     MaterialIndex,
  52.     MaterialSize,
  53.     FontFace[51],
  54.     FontSize,
  55.     Bold,
  56.     FontColor,
  57.     BackgroundColor,
  58.     TextAlignment,
  59.     Float:ObjectCoords[6],
  60.     ObjectID,
  61.     bool:Exists,
  62.     bool:Edited
  63. }
  64. new obj_Info[MAX_SOMT_OBJECTS][e_Objects];
  65.  
  66. // - Player - //
  67. new p_ObjEditing[MAX_PLAYERS] = {-1, ...};
  68. new bool:p_FontOrBackg[MAX_PLAYERS];
  69.  
  70. /* =============================== | [CALLBACKS] | ================================ */
  71. public OnFilterScriptInit()
  72. {
  73.     // - Objects - //
  74.     for(new x = 0; x < MAX_SOMT_OBJECTS; x++)
  75.     {
  76.         obj_Info[x][ID] = -1;
  77.         obj_Info[x][Exists] = false;
  78.         obj_Info[x][Edited] = false;
  79.         obj_Info[x][ObjectID] = INVALID_OBJECT_ID;
  80.     }
  81.    
  82.     // - SQLite - //
  83.     sql_index = db_open("somt.db");
  84.    
  85.     if(sql_index)
  86.     {
  87.         db_free_result(
  88.             db_query(sql_index,
  89.                 "CREATE TABLE IF NOT EXISTS `object_info` (`id` INTEGER NOT NULL,\
  90.                 `objmodel` INTEGER NOT NULL,\
  91.                 `text` TEXT NOT NULL,\
  92.                 `matindex` INTEGER NOT NULL,\
  93.                 `matsize` INTEGER NOT NULL,\
  94.                 `fontface` TEXT NOT NULL,\
  95.                 `fontsize` INTEGER NOT NULL,\
  96.                 `bold` NUMERIC NOT NULL,\
  97.                 `fontcolor` INTEGER NOT NULL,\
  98.                 `backgcolor` INTEGER NOT NULL,\
  99.                 `textalign` INTEGER NOT NULL,\
  100.                 `ox` REAL NOT NULL,\
  101.                 `oy` REAL NOT NULL,\
  102.                 `oz` REAL NOT NULL,\
  103.                 `rx` REAL NOT NULL,\
  104.                 `ry` REAL NOT NULL,\
  105.                 `rz` REAL NOT NULL,\
  106.                 PRIMARY KEY(`id`))"
  107.             )
  108.         );
  109.        
  110.         LoadObjectsFromDatabase();
  111.     }
  112.     else
  113.     {
  114.         print("* [SQLite] An error occurred while trying to access the database.");
  115.     }
  116.    
  117.     // - Credits - //
  118.     print("\n ____________________");
  119.     print("|                    |");
  120.     print("| SOMT Editor Loaded |");
  121.     print("|--------------------|");
  122.     print("|      Scripted      |");
  123.     print("|         by         |");
  124.     print("|      RIDE2DAY      |");
  125.     print("|____________________|\n");
  126.     return 1;
  127. }
  128.  
  129. public OnFilterScriptExit()
  130. {
  131.     // - Objects - //
  132.     for(new x = 0; x < MAX_SOMT_OBJECTS; x++)
  133.     {
  134.         if(obj_Info[x][Exists] && IsValidObject(obj_Info[x][ObjectID]))
  135.         {
  136.             DestroyObject(obj_Info[x][ObjectID]);
  137.         }
  138.     }
  139.    
  140.     // - SQLite - //
  141.     db_close(sql_index);
  142.     return 1;
  143. }
  144.  
  145. public OnPlayerConnect(playerid)
  146. {
  147.     p_ObjEditing[playerid] = -1;
  148.     return 1;
  149. }
  150.  
  151. public OnPlayerDisconnect(playerid, reason)
  152. {
  153.     new idx = p_ObjEditing[playerid];
  154.    
  155.     if(idx != -1)
  156.     {
  157.         obj_Info[idx][Edited] = false;
  158.     }
  159.     return 1;
  160. }
  161.  
  162. public OnPlayerCommandText(playerid, cmdtext[])
  163. {
  164.     /*if(!strcmp(cmdtext, "/jetpack", true))
  165.     {
  166.         SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USEJETPACK);
  167.         return 1;
  168.     }*/
  169.     if(!strcmp(cmdtext, "/editor", true))
  170.     {
  171.         if(!IsPlayerAdmin(playerid))
  172.         {
  173.             SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"you must be an admin in order to use this command.");
  174.             return 1;
  175.         }
  176.        
  177.         ShowMainMenu(playerid);
  178.         return 1;
  179.     }
  180.     return 0;
  181. }
  182.  
  183. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  184. {
  185.     switch(dialogid)
  186.     {
  187.         case SOMT_MAIN_MENU:
  188.         {
  189.             if(response)
  190.             {
  191.                 switch(listitem)
  192.                 {
  193.                     case 0: /* New Object */
  194.                     {
  195.                         for(new x = 0; x < MAX_SOMT_OBJECTS; x++)
  196.                         {
  197.                             if(!obj_Info[x][Exists])
  198.                             {
  199.                                 p_ObjEditing[playerid] = x;
  200.                                 obj_Info[x][Exists] = true;
  201.                                 obj_Info[x][Edited] = true;
  202.                                 break;
  203.                             }
  204.                         }
  205.  
  206.                         if(p_ObjEditing[playerid] == -1)
  207.                         {
  208.                             SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"increase "BLUE_E"MAX_SOMT_OBJECTS "WHITE_E"or delete some objects, the limit has been reached.");
  209.                             ShowMainMenu(playerid);
  210.                             return 1;
  211.                         }
  212.  
  213.                         new idx = p_ObjEditing[playerid];
  214.  
  215.                         strcpy(obj_Info[idx][Text], "Scripted by\nRIDE2DAY\nor\nRIDE2MORROW.\nWe are not sure...", 129);
  216.                         obj_Info[idx][ObjectModel] = 19353;
  217.                         obj_Info[idx][MaterialIndex] = 0;
  218.                         obj_Info[idx][MaterialSize] = 140;
  219.                         strcpy(obj_Info[idx][FontFace], "Arial", 51);
  220.                         obj_Info[idx][FontSize] = 70;
  221.                         obj_Info[idx][Bold] = 0;
  222.                         obj_Info[idx][FontColor] = 0xFFFFFFFF;
  223.                         obj_Info[idx][BackgroundColor] = 0xFFB40404;
  224.                         obj_Info[idx][TextAlignment] = OBJECT_MATERIAL_TEXT_ALIGN_CENTER;
  225.  
  226.                         new Float:x, Float:y, Float:z, Float:ang;
  227.  
  228.                         GetPlayerPos(playerid, x, y, z);
  229.                         GetPlayerFacingAngle(playerid, ang);
  230.  
  231.                         obj_Info[idx][ObjectCoords][0] = x + (10.0 * floatsin(-ang, degrees));
  232.                         obj_Info[idx][ObjectCoords][1] = y + (10.0 * floatcos(-ang, degrees));
  233.                         obj_Info[idx][ObjectCoords][2] = z + 1.5;
  234.                         obj_Info[idx][ObjectCoords][3] = 0.0;
  235.                         obj_Info[idx][ObjectCoords][4] = 0.0;
  236.                         obj_Info[idx][ObjectCoords][5] = ang - 90.0;
  237.  
  238.                         obj_Info[idx][ObjectID] = CreateObject(obj_Info[idx][ObjectModel], obj_Info[idx][ObjectCoords][0], obj_Info[idx][ObjectCoords][1], obj_Info[idx][ObjectCoords][2], obj_Info[idx][ObjectCoords][3], obj_Info[idx][ObjectCoords][4], obj_Info[idx][ObjectCoords][5]);
  239.  
  240.                         SetObjectMaterialText(
  241.                             obj_Info[idx][ObjectID],
  242.                             obj_Info[idx][Text],
  243.                             obj_Info[idx][MaterialIndex],
  244.                             obj_Info[idx][MaterialSize],
  245.                             obj_Info[idx][FontFace],
  246.                             obj_Info[idx][FontSize],
  247.                             obj_Info[idx][Bold],
  248.                             obj_Info[idx][FontColor],
  249.                             obj_Info[idx][BackgroundColor],
  250.                             obj_Info[idx][TextAlignment]
  251.                         );
  252.  
  253.                         new info[65];
  254.                         format(info, sizeof(info), ""BLUE_E"INFO: "WHITE_E"new object created ("YELLOW_E"%d"WHITE_E").", idx);
  255.                         SendClientMessage(playerid, -1, info);
  256.                        
  257.                         SendClientMessage(playerid, COLOR_BLUE, "INFO: "WHITE_E"set object's position and click the "YELLOW_E"SAVE "WHITE_E"icon, or press "YELLOW_E"ESC "WHITE_E"to go directly to the edition menu.");
  258.  
  259.                         EditObject(playerid, obj_Info[idx][ObjectID]);
  260.                     }
  261.                     case 1: /* Edit Object */
  262.                     {
  263.                         SelectObject(playerid);
  264.                         SendClientMessage(playerid, -1, ""BLUE_E"INFO: "WHITE_E"click the object you want to edit.");
  265.                         //ShowPlayerDialog(playerid, SOMT_EDIT_OBJECTS, DIALOG_STYLE_LIST, ""BLUE_E"Edit Object", ""YELLOW_E"1. "WHITE_E"Show object list\n"YELLOW_E"2. "WHITE_E"Select with "YELLOW_E"SelectObject", ""WHITE_E"Select", ""WHITE_E"Back");
  266.                     }
  267.                     case 2: /* Export Objects */
  268.                     {
  269.                         ShowPlayerDialog(playerid, SOMT_EXPORT_OBJECTS, DIALOG_STYLE_LIST, ""BLUE_E"How do you want to export the objects?", ""YELLOW_E"1. "WHITE_E"Global objects\n"YELLOW_E"2. "WHITE_E"Player objects", ""WHITE_E"Export", ""WHITE_E"Back");
  270.                     }
  271.                 }
  272.             }
  273.         }
  274.         case SOMT_EDIT_MENU:
  275.         {
  276.             new idx = p_ObjEditing[playerid];
  277.            
  278.             if(response)
  279.             {
  280.                 switch(listitem)
  281.                 {
  282.                     case 0: /* Object Model */
  283.                     {
  284.                         ShowPlayerDialog(playerid, SOMT_EDIT_OBJECT_MODEL, DIALOG_STYLE_INPUT, ""BLUE_E"Object Model ID", ""WHITE_E"Type the model id you want to use for this object:", ""WHITE_E"Set", ""WHITE_E"Back");
  285.                     }
  286.                     case 1: /* Object Position */
  287.                     {
  288.                         EditObject(playerid, obj_Info[idx][ObjectID]);
  289.                         SendClientMessage(playerid, COLOR_BLUE, "INFO: "WHITE_E"set object's position and click the "YELLOW_E"SAVE "WHITE_E"icon, or press "YELLOW_E"ESC "WHITE_E"to go back to the edition menu.");
  290.                     }
  291.                     case 2: /* Object Text */
  292.                     {
  293.                         ShowPlayerDialog(playerid, SOMT_EDIT_TEXT, DIALOG_STYLE_INPUT, ""BLUE_E"Object Text", ""WHITE_E"Type what you want to write on the object in the next field:", ""WHITE_E"Set", ""WHITE_E"Back");
  294.                     }
  295.                     case 3: /* Material Index */
  296.                     {
  297.                         ShowPlayerDialog(playerid, SOMT_EDIT_MATERIAL_INDEX, DIALOG_STYLE_INPUT, ""BLUE_E"Material Index", ""WHITE_E"Type the material index you want to use for this object:", ""WHITE_E"Set", ""WHITE_E"Back");
  298.                     }
  299.                     case 4: /* Material Size */
  300.                     {
  301.                         new mat_sizes[447];
  302.                        
  303.                         strcat(mat_sizes,
  304.                             ""YELLOW_E"1. "WHITE_E"32x32 (10)\
  305.                             \n"YELLOW_E"2. "WHITE_E"64x32 (20)\
  306.                            \n"YELLOW_E"3. "WHITE_E"64x64 (30)\
  307.                            \n"YELLOW_E"4. "WHITE_E"128x32 (40)\
  308.                            \n"YELLOW_E"5. "WHITE_E"128x64 (50)\
  309.                            \n"YELLOW_E"6. "WHITE_E"128x128 (60)\
  310.                            \n"YELLOW_E"7. "WHITE_E"256x32 (70)"
  311.                         );
  312.                         strcat(mat_sizes,
  313.                             "\n"YELLOW_E"8. "WHITE_E"256x64 (80)\
  314.                            \n"YELLOW_E"9. "WHITE_E"256x128 (90)\
  315.                            \n"YELLOW_E"10. "WHITE_E"256x256 (100)\
  316.                            \n"YELLOW_E"11. "WHITE_E"512x64 (110)\
  317.                            \n"YELLOW_E"12. "WHITE_E"512x128 (120)\
  318.                            \n"YELLOW_E"13. "WHITE_E"512x256 (130)\
  319.                            \n"YELLOW_E"14. "WHITE_E"512x512 (140)"
  320.                         );
  321.                        
  322.                         ShowPlayerDialog(playerid, SOMT_EDIT_MATERIAL_SIZE, DIALOG_STYLE_LIST, ""BLUE_E"Select the material size you want to use:", mat_sizes, ""WHITE_E"Set", ""WHITE_E"Back");
  323.                     }
  324.                     case 5: /* Font Face */
  325.                     {
  326.                         ShowPlayerDialog(playerid, SOMT_EDIT_FONT_FACE, DIALOG_STYLE_INPUT, ""BLUE_E"Font Face", ""WHITE_E"Type below the name of the font you want to use:", ""WHITE_E"Set", ""WHITE_E"Back");
  327.                     }
  328.                     case 6: /* Font Size */
  329.                     {
  330.                         ShowPlayerDialog(playerid, SOMT_EDIT_FONT_SIZE, DIALOG_STYLE_INPUT, ""BLUE_E"Font Size", ""WHITE_E"Type the font size you want to use below (max. "YELLOW_E"255"WHITE_E"):", ""WHITE_E"Set", ""WHITE_E"Back");
  331.                     }
  332.                     case 7: /* Bold */
  333.                     {
  334.                         ShowPlayerDialog(playerid, SOMT_EDIT_BOLD, DIALOG_STYLE_MSGBOX, ""BLUE_E"Bold", ""WHITE_E"Would you like to set the text bold?", ""WHITE_E"Yes", ""WHITE_E"No");
  335.                     }
  336.                     case 8: /* Font Color */
  337.                     {
  338.                         p_FontOrBackg[playerid] = false;
  339.                         ShowPlayerDialog(playerid, SOMT_EDIT_COLOR, DIALOG_STYLE_LIST, ""BLUE_E"Font Color", ""YELLOW_E"1. "WHITE_E"Write color code\n"YELLOW_E"2. "WHITE_E"Select from the list", ""WHITE_E"Select", ""WHITE_E"Back");
  340.                     }
  341.                     case 9: /* Background Color */
  342.                     {
  343.                         p_FontOrBackg[playerid] = true;
  344.                         ShowPlayerDialog(playerid, SOMT_EDIT_COLOR, DIALOG_STYLE_LIST, ""BLUE_E"Background Color", ""YELLOW_E"1. "WHITE_E"Write color code\n"YELLOW_E"2. "WHITE_E"Select from the list", ""WHITE_E"Select", ""WHITE_E"Back");
  345.                     }
  346.                     case 10: /* Text Alignment */
  347.                     {
  348.                         ShowPlayerDialog(playerid, SOMT_EDIT_TEXT_ALIGNMENT, DIALOG_STYLE_LIST, ""BLUE_E"Text Alignment", ""YELLOW_E"1. "WHITE_E"Left\n"YELLOW_E"2. "WHITE_E"Center\n"YELLOW_E"3. "WHITE_E"Right", ""WHITE_E"Set", ""WHITE_E"Back");
  349.                     }
  350.                     case 11: /* Remove Object */
  351.                     {
  352.                         if(obj_Info[idx][ID] != -1)
  353.                         {
  354.                             RemoveObjectFromDatabase(idx);
  355.                         }
  356.                        
  357.                         obj_Info[idx][ID] = -1;
  358.                         obj_Info[idx][Exists] = false;
  359.                         obj_Info[idx][Edited] = false;
  360.                        
  361.                         if(IsValidObject(obj_Info[idx][ObjectID]))
  362.                         {
  363.                             DestroyObject(obj_Info[idx][ObjectID]);
  364.                         }
  365.                         obj_Info[idx][ObjectID] = INVALID_OBJECT_ID;
  366.                        
  367.                         new info[59];
  368.                         format(info, sizeof(info), ""BLUE_E"INFO: "WHITE_E"object "YELLOW_E"%d "WHITE_E"removed.", idx);
  369.                         SendClientMessage(playerid, -1, info);
  370.                        
  371.                         p_ObjEditing[playerid] = -1;
  372.                         ShowMainMenu(playerid);
  373.                     }
  374.                 }
  375.             }
  376.             else
  377.             {
  378.                 obj_Info[idx][Edited] = false;
  379.                
  380.                 if(obj_Info[idx][ID] == -1)
  381.                 {
  382.                     AddObjectToDatabase(idx);
  383.                 }
  384.                 else
  385.                 {
  386.                     UpdateObjectOnDatabase(idx);
  387.                 }
  388.                
  389.                 p_ObjEditing[playerid] = -1;
  390.                 ShowMainMenu(playerid);
  391.             }
  392.         }
  393.         case SOMT_EDIT_OBJECT_MODEL:
  394.         {
  395.             if(response)
  396.             {
  397.                 if(!isNumeric(inputtext))
  398.                 {
  399.                     SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"the model id must be a valid numeric value.");
  400.                     ShowPlayerDialog(playerid, SOMT_EDIT_OBJECT_MODEL, DIALOG_STYLE_INPUT, ""BLUE_E"Object Model ID", ""WHITE_E"Type the model id you want to use for this object:", ""WHITE_E"Set", ""WHITE_E"Back");
  401.                     return 1;
  402.                 }
  403.                
  404.                 obj_Info[p_ObjEditing[playerid]][ObjectModel] = strval(inputtext);
  405.                 UpdateObject(p_ObjEditing[playerid], true);
  406.                 ShowObjectEditMenu(playerid);
  407.             }
  408.             else
  409.             {
  410.                 ShowObjectEditMenu(playerid);
  411.             }
  412.         }
  413.         case SOMT_EDIT_TEXT:
  414.         {
  415.             if(response)
  416.             {
  417.                 if(!inputtext[0])
  418.                 {
  419.                     SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"the text must have at least "YELLOW_E"1 "WHITE_E"character.");
  420.                     ShowPlayerDialog(playerid, SOMT_EDIT_TEXT, DIALOG_STYLE_INPUT, ""BLUE_E"Object Text", ""WHITE_E"Type what you want to write on the object in the next field:", ""WHITE_E"Set", ""WHITE_E"Back");
  421.                     return 1;
  422.                 }
  423.  
  424.                 str_replace("\n", "\\n", inputtext, obj_Info[p_ObjEditing[playerid]][Text], false, 129);
  425.                 UpdateObject(p_ObjEditing[playerid], true);
  426.                 ShowObjectEditMenu(playerid);
  427.             }
  428.             else
  429.             {
  430.                 ShowObjectEditMenu(playerid);
  431.             }
  432.         }
  433.         case SOMT_EDIT_MATERIAL_INDEX:
  434.         {
  435.             if(response)
  436.             {
  437.                 if(!isNumeric(inputtext))
  438.                 {
  439.                     SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"the material index must be a valid numeric value.");
  440.                     ShowPlayerDialog(playerid, SOMT_EDIT_MATERIAL_INDEX, DIALOG_STYLE_INPUT, ""BLUE_E"Material Index", ""WHITE_E"Type the material index you want to use for this object:", ""WHITE_E"Set", ""WHITE_E"Back");
  441.                     return 1;
  442.                 }
  443.                
  444.                 obj_Info[p_ObjEditing[playerid]][MaterialIndex] = strval(inputtext);
  445.                 UpdateObject(p_ObjEditing[playerid], true);
  446.                 ShowObjectEditMenu(playerid);
  447.             }
  448.             else
  449.             {
  450.                 ShowObjectEditMenu(playerid);
  451.             }
  452.         }
  453.         case SOMT_EDIT_MATERIAL_SIZE:
  454.         {
  455.             if(response)
  456.             {
  457.                 obj_Info[p_ObjEditing[playerid]][MaterialSize] = (listitem + 1) * 10;
  458.                 UpdateObject(p_ObjEditing[playerid]);
  459.             }
  460.            
  461.             ShowObjectEditMenu(playerid);
  462.         }
  463.         case SOMT_EDIT_FONT_FACE:
  464.         {
  465.             if(response)
  466.             {
  467.                 if(!inputtext[0] || strlen(inputtext) > 50)
  468.                 {
  469.                     SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"the font face must have at least "YELLOW_E"1 "WHITE_E"character and "YELLOW_E"50 "WHITE_E"characters as maximum.");
  470.                     ShowPlayerDialog(playerid, SOMT_EDIT_FONT_FACE, DIALOG_STYLE_INPUT, ""BLUE_E"Font Face", ""WHITE_E"Type below the name of the font you want to use:", ""WHITE_E"Set", ""WHITE_E"Back");
  471.                     return 1;
  472.                 }
  473.                
  474.                 strcpy(obj_Info[p_ObjEditing[playerid]][FontFace], inputtext, 51);
  475.                 UpdateObject(p_ObjEditing[playerid]);
  476.                 ShowObjectEditMenu(playerid);
  477.             }
  478.             else
  479.             {
  480.                 ShowObjectEditMenu(playerid);
  481.             }
  482.         }
  483.         case SOMT_EDIT_FONT_SIZE:
  484.         {
  485.             if(response)
  486.             {
  487.                 if(isNumeric(inputtext) && 1 <= strval(inputtext) <= 255)
  488.                 {
  489.                     obj_Info[p_ObjEditing[playerid]][FontSize] = strval(inputtext);
  490.                     UpdateObject(p_ObjEditing[playerid]);
  491.                     ShowObjectEditMenu(playerid);
  492.                 }
  493.                 else
  494.                 {
  495.                     SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"the font size must be a valid number (min. "YELLOW_E"1 "WHITE_E"- max. "YELLOW_E"255"WHITE_E").");
  496.                     ShowPlayerDialog(playerid, SOMT_EDIT_FONT_SIZE, DIALOG_STYLE_INPUT, ""BLUE_E"Font Size", ""WHITE_E"Type the font size you want to use below (max. "YELLOW_E"255"WHITE_E"):", ""WHITE_E"Set", ""WHITE_E"Back");
  497.                 }
  498.             }
  499.             else
  500.             {
  501.                 ShowObjectEditMenu(playerid);
  502.             }
  503.         }
  504.         case SOMT_EDIT_BOLD:
  505.         {
  506.             if(response)
  507.             {
  508.                 obj_Info[p_ObjEditing[playerid]][Bold] = 1;
  509.             }
  510.             else
  511.             {
  512.                 obj_Info[p_ObjEditing[playerid]][Bold] =0;
  513.             }
  514.            
  515.             UpdateObject(p_ObjEditing[playerid]);
  516.             ShowObjectEditMenu(playerid);
  517.         }
  518.         case SOMT_EDIT_COLOR:
  519.         {
  520.             if(response)
  521.             {
  522.                 switch(listitem)
  523.                 {
  524.                     case 0: /* Write hexadecimal color. */
  525.                     {
  526.                         ShowPlayerDialog(playerid, SOMT_WRITE_COLOR, DIALOG_STYLE_INPUT, (p_FontOrBackg[playerid] == true ? (""BLUE_E"Background Color") : (""BLUE_E"Font Color")), ""WHITE_E"Write the color you want to use in the next field (format "YELLOW_E"0xAARRGGBB"WHITE_E"):", ""WHITE_E"Set", ""WHITE_E"Back");
  527.                     }
  528.                     case 1: /* Select from the list. */
  529.                     {
  530.                         ShowPlayerDialog(playerid, SOMT_SELECT_COLOR, DIALOG_STYLE_LIST, (p_FontOrBackg[playerid] == true ? (""BLUE_E"Background Color") : (""BLUE_E"Font Color")), "{FF0000}Red\n{04B404}Green\n{0000FF}Blue\n{FFFF00}Yellow\n{FF8000}Orange\n{000000}Black\n{FFFFFF}White\n{A4A4A4}Grey", ""WHITE_E"Set", ""WHITE_E"Back");
  531.                     }
  532.                 }
  533.             }
  534.             else
  535.             {
  536.                 ShowObjectEditMenu(playerid);
  537.             }
  538.         }
  539.         case SOMT_WRITE_COLOR:
  540.         {
  541.             if(response)
  542.             {
  543.                 if(!p_FontOrBackg[playerid])
  544.                 {
  545.                     obj_Info[p_ObjEditing[playerid]][FontColor] = HexToInt(inputtext);
  546.                 }
  547.                 else
  548.                 {
  549.                     obj_Info[p_ObjEditing[playerid]][BackgroundColor] = HexToInt(inputtext);
  550.                 }
  551.                
  552.                 UpdateObject(p_ObjEditing[playerid]);
  553.                 ShowObjectEditMenu(playerid);
  554.             }
  555.             else
  556.             {
  557.                 ShowPlayerDialog(playerid, SOMT_EDIT_COLOR, DIALOG_STYLE_LIST, (p_FontOrBackg[playerid] == true ? (""BLUE_E"Background Color") : (""BLUE_E"Font Color")), ""YELLOW_E"1. "WHITE_E"Write color code\n"YELLOW_E"2. "WHITE_E"Select from the list", ""WHITE_E"Select", ""WHITE_E"Back");
  558.             }
  559.         }
  560.         case SOMT_SELECT_COLOR:
  561.         {
  562.             if(response)
  563.             {
  564.                 new color;
  565.                 switch(listitem)
  566.                 {
  567.                     case 0: color = 0xFFFF0000; /* Red */
  568.                     case 1: color = 0xFF04B404; /* Green */
  569.                     case 2: color = 0xFF0000FF; /* Blue */
  570.                     case 3: color = 0xFFFFFF00; /* Yellow */
  571.                     case 4: color = 0xFFFF8000; /* Orange */
  572.                     case 5: color = 0xFF000000; /* Black */
  573.                     case 6: color = 0xFFFFFFFF; /* White */
  574.                     case 7: color = 0xFFA4A4A4; /* Grey */
  575.                 }
  576.                
  577.                 if(!p_FontOrBackg[playerid])
  578.                 {
  579.                     obj_Info[p_ObjEditing[playerid]][FontColor] = color;
  580.                 }
  581.                 else
  582.                 {
  583.                     obj_Info[p_ObjEditing[playerid]][BackgroundColor] = color;
  584.                 }
  585.                
  586.                 UpdateObject(p_ObjEditing[playerid]);
  587.                 ShowObjectEditMenu(playerid);
  588.             }
  589.             else
  590.             {
  591.                 ShowPlayerDialog(playerid, SOMT_EDIT_COLOR, DIALOG_STYLE_LIST, (p_FontOrBackg[playerid] == true ? (""BLUE_E"Background Color") : (""BLUE_E"Font Color")), ""YELLOW_E"1. "WHITE_E"Write color code\n"YELLOW_E"2. "WHITE_E"Select from the list", ""WHITE_E"Select", ""WHITE_E"Back");
  592.             }
  593.         }
  594.         case SOMT_EDIT_TEXT_ALIGNMENT:
  595.         {
  596.             if(response)
  597.             {
  598.                 obj_Info[p_ObjEditing[playerid]][TextAlignment] = listitem;
  599.                 UpdateObject(p_ObjEditing[playerid]);
  600.             }
  601.            
  602.             ShowObjectEditMenu(playerid);
  603.         }
  604.         /*case SOMT_EDIT_OBJECTS:
  605.         {
  606.             if(response)
  607.             {
  608.                 switch(listitem)
  609.                 {
  610.                     case 0:
  611.                     {
  612.                     }
  613.                     case 1:
  614.                     {
  615.                         SelectObject(playerid);
  616.                         SendClientMessage(playerid, -1, ""BLUE_E"INFO: "WHITE_E"click the object you want to edit.");
  617.                     }
  618.                 }
  619.             }
  620.             else
  621.             {
  622.                 ShowMainMenu(playerid);
  623.             }
  624.         }*/
  625.         case SOMT_EXPORT_OBJECTS:
  626.         {
  627.             if(response)
  628.             {
  629.                 new data[405];
  630.                
  631.                 new File:somt_file = fopen("SOMT_Objects.txt", io_write);
  632.  
  633.                 if(somt_file)
  634.                 {
  635.                     for(new x = 0; x < MAX_SOMT_OBJECTS; x++)
  636.                     {
  637.                         if(obj_Info[x][Exists])
  638.                         {
  639.                             new text[129];
  640.                             str_replace("\\n", "\n", obj_Info[x][Text], text, false, 129);
  641.  
  642.                             format(data, sizeof(data),
  643.                                 "new obj%d = %s%d, %0.4f, %0.4f, %0.4f, %0.4f, %0.4f, %0.4f);\r\n\
  644.                                 %sobj%d, \"%s\", %d, %d, \"%s\", %d, %d, 0x%x, 0x%x, %d);\r\n\r\n",
  645.                                 x,
  646.                                 (listitem == 0 ? ("CreateObject(") : ("CreatePlayerObject(playerid, ")),
  647.                                 obj_Info[x][ObjectModel],
  648.                                 obj_Info[x][ObjectCoords][0],
  649.                                 obj_Info[x][ObjectCoords][1],
  650.                                 obj_Info[x][ObjectCoords][2],
  651.                                 obj_Info[x][ObjectCoords][3],
  652.                                 obj_Info[x][ObjectCoords][4],
  653.                                 obj_Info[x][ObjectCoords][5],
  654.                                 (listitem == 0 ? ("SetObjectMaterialText(") : ("SetPlayerObjectMaterialText(playerid, ")),
  655.                                 x,
  656.                                 text,
  657.                                 obj_Info[x][MaterialIndex],
  658.                                 obj_Info[x][MaterialSize],
  659.                                 obj_Info[x][FontFace],
  660.                                 obj_Info[x][FontSize],
  661.                                 obj_Info[x][Bold],
  662.                                 obj_Info[x][FontColor],
  663.                                 obj_Info[x][BackgroundColor],
  664.                                 obj_Info[x][TextAlignment]
  665.                             );
  666.  
  667.                             fwrite(somt_file, data);
  668.                         }
  669.                     }
  670.  
  671.                     fclose(somt_file);
  672.  
  673.                     SendClientMessage(playerid, -1, ""BLUE_E"INFO: "WHITE_E"objects exported to "YELLOW_E"SOMT_Objects.txt "WHITE_E"(check scriptfiles).");
  674.                 }
  675.                 else
  676.                 {
  677.                     SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"the export file couldn't be created.");
  678.                 }
  679.             }
  680.             else
  681.             {
  682.                 ShowMainMenu(playerid);
  683.             }
  684.         }
  685.     }
  686.     return 0;
  687. }
  688.  
  689. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  690. {
  691.     new idx = p_ObjEditing[playerid];
  692.    
  693.     if(idx != -1 && objectid == obj_Info[idx][ObjectID])
  694.     {
  695.         switch(response)
  696.         {
  697.             case EDIT_RESPONSE_CANCEL:
  698.             {
  699.                 /* Set object to its original position if player cancels. */
  700.                 SetObjectPos(objectid, obj_Info[idx][ObjectCoords][0], obj_Info[idx][ObjectCoords][1], obj_Info[idx][ObjectCoords][2]);
  701.                 SetObjectRot(objectid, obj_Info[idx][ObjectCoords][3], obj_Info[idx][ObjectCoords][4], obj_Info[idx][ObjectCoords][5]);
  702.                
  703.                 ShowObjectEditMenu(playerid);
  704.             }
  705.             case EDIT_RESPONSE_FINAL:
  706.             {
  707.                 /* Update object's coordinates. */
  708.                 obj_Info[idx][ObjectCoords][0] = fX;
  709.                 obj_Info[idx][ObjectCoords][1] = fY;
  710.                 obj_Info[idx][ObjectCoords][2] = fZ;
  711.                 obj_Info[idx][ObjectCoords][3] = fRotX;
  712.                 obj_Info[idx][ObjectCoords][4] = fRotY;
  713.                 obj_Info[idx][ObjectCoords][5] = fRotZ;
  714.                
  715.                 ShowObjectEditMenu(playerid);
  716.             }
  717.             case EDIT_RESPONSE_UPDATE:
  718.             {
  719.                 /* Sync object for other players. */
  720.                 SetObjectPos(objectid, fX, fY, fZ);
  721.                 SetObjectRot(objectid, fRotX, fRotY, fRotZ);
  722.             }
  723.         }
  724.     }
  725.     return 1;
  726. }
  727.  
  728. public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
  729. {
  730.     if(type == SELECT_OBJECT_GLOBAL_OBJECT && p_ObjEditing[playerid] == -1)
  731.     {
  732.         for(new x = 0; x < MAX_SOMT_OBJECTS; x++)
  733.         {
  734.             if(obj_Info[x][ObjectID] == objectid)
  735.             {
  736.                 if(obj_Info[x][Edited] == false)
  737.                 {
  738.                     CancelEdit(playerid);
  739.                    
  740.                     p_ObjEditing[playerid] = x;
  741.                     obj_Info[x][Edited] = true;
  742.                     ShowObjectEditMenu(playerid);
  743.                    
  744.                     new info[59];
  745.                     format(info, sizeof(info), ""BLUE_E"INFO: "WHITE_E"editing object "YELLOW_E"%d"WHITE_E".", x);
  746.                     SendClientMessage(playerid, -1, info);
  747.                 }
  748.                 else
  749.                 {
  750.                     SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"someone else is editing that object.");
  751.                 }
  752.                 return 1;
  753.             }
  754.         }
  755.        
  756.         SendClientMessage(playerid, -1, ""RED_E"ERROR: "WHITE_E"that object hasn't been created with the SetObjectMaterialText editor.");
  757.     }
  758.     return 1;
  759. }
  760.  
  761.  
  762. /* =============================== | [FUNCTIONS] | ================================ */
  763. ShowMainMenu(playerid)
  764. {
  765.     ShowPlayerDialog(playerid, SOMT_MAIN_MENU, DIALOG_STYLE_LIST, ""BLUE_E"SetObjectMaterialText Editor by RIDE2DAY", ""YELLOW_E"1. "WHITE_E"New Object\n"YELLOW_E"2. "WHITE_E"Edit Object\n"YELLOW_E"3. "WHITE_E"Export Objects", ""WHITE_E"Select", ""WHITE_E"Exit");
  766.     return 1;
  767. }
  768.  
  769. ShowObjectEditMenu(playerid)
  770. {
  771.     new idx = p_ObjEditing[playerid];
  772.  
  773.     new info[36];
  774.     format(info, sizeof(info), ""BLUE_E"Editing Object: "YELLOW_E"%d", p_ObjEditing[playerid]);
  775.    
  776.     new f_color[9];
  777.     format(f_color, sizeof(f_color), "%x", obj_Info[idx][FontColor]);
  778.     strdel(f_color, 0, 2);
  779.    
  780.     new bg_color[9];
  781.     format(bg_color, sizeof(bg_color), "%x", obj_Info[idx][BackgroundColor]);
  782.     strdel(bg_color, 0, 2);
  783.    
  784.     new alignment[7];
  785.     switch(obj_Info[idx][TextAlignment])
  786.     {
  787.         case 0: alignment = "Left";
  788.         case 1: alignment = "Center";
  789.         case 2: alignment = "Right";
  790.     }
  791.    
  792.     new options[355];
  793.     format(options, sizeof(options),
  794.         "Option\tValue\n\
  795.         Model ID\t"YELLOW_E"%d\n\
  796.         Position\t"YELLOW_E"X Y Z\n\
  797.         Text\t"YELLOW_E"...\n\
  798.         Material Index\t"YELLOW_E"%d\n\
  799.         Material Size\t"YELLOW_E"%d\n\
  800.         Font Face\t"YELLOW_E"%s\n\
  801.         Font Size\t"YELLOW_E"%d\n\
  802.         Bold\t"YELLOW_E"%s\n\
  803.         Font Color\t{%s}0x%x\n\
  804.         Background Color\t{%s}0x%x\n\
  805.         Text Alignment\t"YELLOW_E"%s\n\
  806.         "RED_E"Remove Object",
  807.         obj_Info[idx][ObjectModel],
  808.         obj_Info[idx][MaterialIndex],
  809.         obj_Info[idx][MaterialSize],
  810.         obj_Info[idx][FontFace],
  811.         obj_Info[idx][FontSize],
  812.         (obj_Info[idx][Bold] == 1 ? ("Yes") : ("No")),
  813.         f_color, obj_Info[idx][FontColor],
  814.         bg_color, obj_Info[idx][BackgroundColor],
  815.         alignment
  816.     );
  817.    
  818.     ShowPlayerDialog(playerid, SOMT_EDIT_MENU, DIALOG_STYLE_TABLIST_HEADERS, info, options, ""WHITE_E"Edit", ""WHITE_E"Back");
  819.     return 1;
  820. }
  821.  
  822. UpdateObject(idx, bool:destroy=false)
  823. {
  824.     if(destroy)
  825.     {
  826.         if(IsValidObject(obj_Info[idx][ObjectID]))
  827.         {
  828.             DestroyObject(obj_Info[idx][ObjectID]);
  829.         }
  830.        
  831.         obj_Info[idx][ObjectID] = CreateObject(obj_Info[idx][ObjectModel], obj_Info[idx][ObjectCoords][0], obj_Info[idx][ObjectCoords][1], obj_Info[idx][ObjectCoords][2], obj_Info[idx][ObjectCoords][3], obj_Info[idx][ObjectCoords][4], obj_Info[idx][ObjectCoords][5]);
  832.     }
  833.  
  834.     SetObjectMaterialText(
  835.         obj_Info[idx][ObjectID],
  836.         obj_Info[idx][Text],
  837.         obj_Info[idx][MaterialIndex],
  838.         obj_Info[idx][MaterialSize],
  839.         obj_Info[idx][FontFace],
  840.         obj_Info[idx][FontSize],
  841.         obj_Info[idx][Bold],
  842.         obj_Info[idx][FontColor],
  843.         obj_Info[idx][BackgroundColor],
  844.         obj_Info[idx][TextAlignment]
  845.     );
  846.     return 1;
  847. }
  848.  
  849. LoadObjectsFromDatabase()
  850. {
  851.     new DBResult:res = db_query(sql_index, "SELECT * FROM `object_info`");
  852.    
  853.     new rows = db_num_rows(res);
  854.    
  855.     new text[129];
  856.    
  857.     for(new x = 0; x < rows; x++)
  858.     {
  859.         obj_Info[x][ID] = db_get_field_int(res, 0);
  860.         obj_Info[x][ObjectModel] = db_get_field_int(res, 1);
  861.        
  862.         db_get_field(res, 2, text, 129);
  863.         str_replace("\n", "\\n", text, obj_Info[x][Text], false, 129);
  864.        
  865.         obj_Info[x][MaterialIndex] = db_get_field_int(res, 3);
  866.         obj_Info[x][MaterialSize] = db_get_field_int(res, 4);
  867.         db_get_field(res, 5, obj_Info[x][FontFace], 51);
  868.         obj_Info[x][FontSize] = db_get_field_int(res, 6);
  869.         obj_Info[x][Bold] = db_get_field_int(res, 7);
  870.         obj_Info[x][FontColor] = db_get_field_int(res, 8);
  871.         obj_Info[x][BackgroundColor] = db_get_field_int(res, 9);
  872.         obj_Info[x][TextAlignment] = db_get_field_int(res, 10);
  873.         obj_Info[x][ObjectCoords][0] = db_get_field_float(res, 11);
  874.         obj_Info[x][ObjectCoords][1] = db_get_field_float(res, 12);
  875.         obj_Info[x][ObjectCoords][2] = db_get_field_float(res, 13);
  876.         obj_Info[x][ObjectCoords][3] = db_get_field_float(res, 14);
  877.         obj_Info[x][ObjectCoords][4] = db_get_field_float(res, 15);
  878.         obj_Info[x][ObjectCoords][5] = db_get_field_float(res, 16);
  879.        
  880.         obj_Info[x][Exists] = true;
  881.        
  882.         UpdateObject(x, true);
  883.        
  884.         db_next_row(res);
  885.     }
  886.    
  887.     db_free_result(res);
  888.     return 1;
  889. }
  890.  
  891. AddObjectToDatabase(idx)
  892. {
  893.     new DBResult:res = db_query(sql_index, "SELECT MAX(`id`) FROM `object_info`");
  894.    
  895.     if(db_num_rows(res))
  896.     {
  897.         new val[5];
  898.         db_get_field(res, 0, val, sizeof(val));
  899.        
  900.         db_free_result(res);
  901.        
  902.         obj_Info[idx][ID] = strval(val) + 1;
  903.  
  904.         new text[129];
  905.         new query[405];
  906.  
  907.         str_replace("\\n", "\n", obj_Info[idx][Text], text, false, 129);
  908.        
  909.         format(query, sizeof(query),
  910.             "INSERT INTO `object_info` VALUES ('%d', '%d', '%q', '%d', '%d', '%q', '%d', '%d', '%d', '%d', '%d', '%f', '%f', '%f', '%f', '%f', '%f')",
  911.             obj_Info[idx][ID],
  912.             obj_Info[idx][ObjectModel],
  913.             text,
  914.             obj_Info[idx][MaterialIndex],
  915.             obj_Info[idx][MaterialSize],
  916.             obj_Info[idx][FontFace],
  917.             obj_Info[idx][FontSize],
  918.             obj_Info[idx][Bold],
  919.             obj_Info[idx][FontColor],
  920.             obj_Info[idx][BackgroundColor],
  921.             obj_Info[idx][TextAlignment],
  922.             obj_Info[idx][ObjectCoords][0],
  923.             obj_Info[idx][ObjectCoords][1],
  924.             obj_Info[idx][ObjectCoords][2],
  925.             obj_Info[idx][ObjectCoords][3],
  926.             obj_Info[idx][ObjectCoords][4],
  927.             obj_Info[idx][ObjectCoords][5]
  928.         );
  929.        
  930.         db_free_result(db_query(sql_index, query));
  931.     }
  932.     else
  933.     {
  934.         print("* [SQLite] An error occurred while trying to add an object to the database.");
  935.     }
  936.     return 1;
  937. }
  938.  
  939. UpdateObjectOnDatabase(idx)
  940. {
  941.     new text[129];
  942.     new query[405];
  943.    
  944.     str_replace("\\n", "\n", obj_Info[idx][Text], text, false, 129);
  945.    
  946.     format(query, sizeof(query),
  947.         "UPDATE `object_info` SET `objmodel`='%d', `text`='%q', `matindex`='%d', `matsize`='%d', `fontface`='%q', `fontsize`='%d', `bold`='%d', `fontcolor`='%d', `backgcolor`='%d', `textalign`='%d', `ox`='%f', `oy`='%f', `oz`='%f', `rx`='%f', `ry`='%f', `rz`='%f' WHERE `id`='%d'",
  948.         obj_Info[idx][ObjectModel],
  949.         text,
  950.         obj_Info[idx][MaterialIndex],
  951.         obj_Info[idx][MaterialSize],
  952.         obj_Info[idx][FontFace],
  953.         obj_Info[idx][FontSize],
  954.         obj_Info[idx][Bold],
  955.         obj_Info[idx][FontColor],
  956.         obj_Info[idx][BackgroundColor],
  957.         obj_Info[idx][TextAlignment],
  958.         obj_Info[idx][ObjectCoords][0],
  959.         obj_Info[idx][ObjectCoords][1],
  960.         obj_Info[idx][ObjectCoords][2],
  961.         obj_Info[idx][ObjectCoords][3],
  962.         obj_Info[idx][ObjectCoords][4],
  963.         obj_Info[idx][ObjectCoords][5],
  964.         obj_Info[idx][ID]
  965.     );
  966.    
  967.     db_free_result(db_query(sql_index, query));
  968.     return 1;
  969. }
  970.  
  971. RemoveObjectFromDatabase(idx)
  972. {
  973.     new query[45];
  974.     format(query, sizeof(query), "DELETE FROM `object_info` WHERE `id`='%d'", obj_Info[idx][ID]);
  975.     db_free_result(db_query(sql_index, query));
  976.     return 1;
  977. }
  978.  
  979. isNumeric(const string[])
  980. {
  981.     new length = strlen(string);
  982.  
  983.     if(!string[0])
  984.     {
  985.         return 0;
  986.     }
  987.  
  988.     for (new i = 0; i < length; i++)
  989.     {
  990.         if((string[i] > '9' || string[i] < '0' && string[i] != '-' && string[i] != '+') || (string[i] == '-' && i != 0) || (string[i] == '+' && i != 0))
  991.         {
  992.             return 0;
  993.         }
  994.     }
  995.  
  996.     if(length == 1 && (string[0] == '-' || string[0] == '+'))
  997.     {
  998.         return 0;
  999.     }
  1000.     return 1;
  1001. }
  1002.  
  1003. stock HexToInt(string[])
  1004. {
  1005.     if(!string[0])
  1006.     {
  1007.         return 0;
  1008.     }
  1009.    
  1010.     new cur = 1;
  1011.     new res = 0;
  1012.    
  1013.     for(new i = strlen(string); i > 0; i--)
  1014.     {
  1015.         if(string[i - 1] < 58)
  1016.         {
  1017.             res= res + cur * (string[i - 1] - 48);
  1018.         }
  1019.         else
  1020.         {
  1021.             res = res + cur * (string[i - 1] - 65 + 10);
  1022.         }
  1023.         cur = cur * 16;
  1024.     }
  1025.     return res;
  1026. }
  1027.  
  1028. stock str_replace(newstr[], oldstr[], srcstr[], deststr[], bool: ignorecase = false, size = sizeof(deststr)) /* By Double-O-Seven */
  1029. {
  1030.     new idx;
  1031.     new rep;
  1032.     new newlen = strlen(newstr);
  1033.     new oldlen = strlen(oldstr);
  1034.     new srclen = strlen(srcstr);
  1035.  
  1036.     for(new i = 0; i < srclen; ++i)
  1037.     {
  1038.         if((i + oldlen) <= srclen)
  1039.         {
  1040.             if(!strcmp(srcstr [i], oldstr, ignorecase, oldlen))
  1041.             {
  1042.                 deststr[idx] = '\0';
  1043.                 strcat(deststr, newstr, size);
  1044.                
  1045.                 ++rep;
  1046.                
  1047.                 idx += newlen;
  1048.                 i += oldlen - 1;
  1049.             }
  1050.             else
  1051.             {
  1052.                 if(idx < (size - 1))
  1053.                 {
  1054.                     deststr[idx++] = srcstr[i];
  1055.                 }
  1056.                 else
  1057.                 {
  1058.                     return rep;
  1059.                 }
  1060.             }
  1061.         }
  1062.         else
  1063.         {
  1064.             if(idx < (size - 1))
  1065.             {
  1066.                 deststr[idx++] = srcstr[i];
  1067.             }
  1068.             else
  1069.             {
  1070.                 return rep;
  1071.             }
  1072.         }
  1073.     }
  1074.     deststr[idx] = '\0';
  1075.     return rep;
  1076. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement