Advertisement
EHDSeven

DayZ Sahrani CFGTownGenertator

May 29th, 2013
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.67 KB | None | 0 0
  1. <?php
  2. /*******************************/
  3. /* CFGTownGenerator PHP Parser */
  4. /*      Created by Seven       */
  5. /*******************************/
  6. function getClasses($file){
  7.     $classes = array("POSITION"=>null, "TYPE"=>null, "AZIMUT"=>null);
  8.     $class = array();
  9.     $objects = array();
  10.     $total = 0;
  11.     $skippedJunk = false;
  12.     $file = $file.".Sara/mission.biedi";
  13.     //Check if file exists.
  14.     if(File_Exists($file)) {
  15.         //Split into lines
  16.         $contents = explode("\n",file_get_contents($file));
  17.     }
  18.     foreach ($contents as $line) {
  19.         //Cleanup any spaces in each line
  20.         $line = trim($line);
  21.         $parts = array();
  22.         //Remove blank lines
  23.         if(empty($line) || $line == ""){
  24.             continue;
  25.         }
  26.         //Find start of object
  27.         if($line == 'objectType="vehicle";') {
  28.             $class[$total] = array("POSITION"=>"0,0,0", "TYPE"=>"blank", "AZIMUT"=>"0");
  29.             $skippedJunk = true;
  30.             continue;
  31.         }
  32.         //Don't Parse until we find the start string
  33.         if(!$skippedJunk)
  34.             continue;
  35.         //Find end of Object and reset everything
  36.         if($line == "};") {
  37.             $objects[count($objects)] = $class[$total];
  38.             $total++;
  39.             $skippedJunk = false;
  40.             continue;
  41.         }
  42.         //Split the var from the value
  43.         if(strpos($line,"="))
  44.             $parts = explode("=", $line);
  45.         //Cleanup and add them to the class array
  46.         if( count($parts) > 0 && array_key_exists(trim($parts[0]), $classes)) {
  47.             if($parts[0] == "POSITION")
  48.                 $parts[1] = substr($parts[1],2,-3);
  49.             if($parts[0] == "TYPE")
  50.                 $parts[1] = substr($parts[1],1,-2);
  51.             if($parts[0] == "AZIMUT")
  52.                 (float)$parts[1] = substr($parts[1],1,-2);
  53.             $class[$total][ trim($parts[0]) ] = trim( $parts[1] );
  54.         }
  55.     }
  56.     return $objects;
  57. }
  58.  
  59. function GenerateCFGTown($zone) {
  60.     //Loop through all the zone
  61.     for($i=0;$i<count($zone);$i++) {
  62.     //Check if there is a file for the zone
  63.         if(File_Exists($zone[$i][0].".Sara/mission.biedi")) {
  64.             //Start Generating class for zone
  65.             echo "  class ".$zone[$i][0]." {<br>";
  66.             echo "      position[] = ".$zone[$i][1].";<br>";
  67.             echo "      size = ".$zone[$i][2].";<br><br>";
  68.             //Generate class for building
  69.             $classes = getClasses($zone[$i][0]);
  70.             for($j=0;$j<count($classes);$j++) {
  71.                 echo "      class Object".$j." {<br>";
  72.                 echo "          Type=\"".$classes[$j]["TYPE"]."\";<br>";
  73.                 echo "          position[] = {".$classes[$j]["POSITION"]."};<br>";
  74.                 echo "          direction = ".$classes[$j]["AZIMUT"].";<br>";
  75.                 echo "          SetZUp = 1;<br>     };<br>";
  76.             }
  77.             echo "  };<br>";
  78.         }
  79.     }
  80. }
  81. $zones[0]       = array("NWI","{3549.5293, 16948.412}","2750");;
  82. $zones[count($zones)]   = array("EMLZ1","{9084.665, 15606.263}","4250");
  83. $zones[count($zones)]   = array("EMLZ2","{13508.527, 16287.334}","3000");
  84. $zones[count($zones)]   = array("EMLZ3","{17841.162, 13019.341}","2750");
  85. $zones[count($zones)]   = array("EMLZ4","{16090.729, 9587.1191}","2000");
  86. $zones[count($zones)]   = array("EMLZ5","{12505.881, 10952.824}","2000");
  87. $zones[count($zones)]   = array("EMLZ6","{9737.9395, 7844.0952}","1200");
  88. $zones[count($zones)]   = array("EMLZ7","{13373.855, 8715.9863}","1500");
  89. $zones[count($zones)]   = array("WMLZ1","{7483.5483, 8740.6846}","2750");
  90. $zones[count($zones)]   = array("WMLZ2","{10256.928, 10019.207}","1850");
  91. $zones[count($zones)]   = array("WMLZ3","{12007.973, 6930.9556}","1800");
  92. $zones[count($zones)]   = array("WMLZ4","{10791.405, 5391.6064}","1500");
  93. $zones[count($zones)]   = array("WMLZ5","{8694.2754, 5947.1602}","1600");
  94. $zones[count($zones)]   = array("WMLZ6","{9737.9395, 7844.0952}","1200");
  95. $zones[count($zones)]   = array("NEI","{17719.813, 18512.668}","1800");
  96. $zones[count($zones)]   = array("SWI","{2596.4631, 2593.689}","1900");
  97. $zones[count($zones)]   = array("SEI","{17488.941, 3990.011}","1800");
  98. /*Run The Generator*/
  99. echo "<pre>";
  100.     GenerateCFGTown($zones);
  101. echo "</pre>";
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement