dayztools.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. class DayZTool: WorkbenchPlugin
  2. {
  3. void RunDayZBat(string filepath, bool wait = false)
  4. {
  5. if (filepath.Length() < 2) return;
  6. filepath.Replace("\\", "/");
  7. if (filepath[1] != ":")
  8. {
  9. string cwd;
  10. Workbench.GetCwd(cwd);
  11. filepath = cwd + "/" + filepath;
  12. }
  13. int index = filepath.IndexOf("/");
  14. int last_index = index;
  15. while(index != -1)
  16. {
  17. last_index = index;
  18. index = filepath.IndexOfFrom(last_index + 1, "/");
  19. }
  20. if (last_index == -1) return;
  21. string path = filepath.Substring(0, last_index);
  22. string bat = filepath.Substring(last_index + 1, filepath.Length() - last_index - 1);
  23. /*Print(filepath);
  24. Print(path);
  25. Print(bat);*/
  26. Workbench.RunCmd("cmd /c \"cd " + path + " & call " + bat + "\"", wait);
  27. }
  28. override void Configure()
  29. {
  30. Workbench.ScriptDialog("Mission directory","", this);
  31. }
  32. [ButtonAttribute("OK")]
  33. void DialogOk()
  34. {
  35. }
  36. };
  37. [WorkbenchPluginAttribute("DayZ Restart", "Just for testing", "ctrl+1", "", {"ScriptEditor"})]
  38. class RestartDayzTool: DayZTool
  39. {
  40. [Attribute("day_z_data_missions/killDayZ.bat", "fileeditbox", "Path to missions dir", "")]
  41. string KillBatPath;
  42. [Attribute("day_z_data_missions/_default_single/default_SampleMap3_Empty.bat", "fileeditbox", "Path to missions dir", "")]
  43. string MissionBatPath;
  44. override void Run()
  45. {
  46. RunDayZBat(KillBatPath, true);
  47. RunDayZBat(MissionBatPath);
  48. }
  49. }
  50. [WorkbenchPluginAttribute("DayZ Run", "Just for testing", "ctrl+2", "", {"ScriptEditor"})]
  51. class RunDayzTool: DayZTool
  52. {
  53. [Attribute("day_z_data_missions/_default_single/default_SampleMap3_Empty.bat", "fileeditbox", "Path to missions dir", "")]
  54. string MissionBatPath;
  55. override void Run()
  56. {
  57. RunDayZBat(MissionBatPath);
  58. }
  59. }
  60. [WorkbenchPluginAttribute("DayZ Kill", "Just for testing", "ctrl+3", "", {"ScriptEditor"})]
  61. class KillDayzTool: DayZTool
  62. {
  63. [Attribute("day_z_data_missions/killDayZ.bat", "fileeditbox", "Path to missions dir", "")]
  64. string KillBatPath;
  65. override void Run()
  66. {
  67. RunDayZBat(KillBatPath);
  68. }
  69. }