Advertisement
EHDSeven

DayZ Sahrani Vehicle Parser

Jun 1st, 2013
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. <?php
  2. /*******************************/
  3. /*  Vehicle Parser PHP Parser  */
  4. /*      Created by Seven       */
  5. /*******************************/
  6. function getClasses($file){
  7.     $classes = array("position[]"=>null, "vehicle"=>null, "azimut"=>null, "description"=>null);
  8.     $class = array();
  9.     $objects = array();
  10.     $contents = array();
  11.     $total = 0;
  12.     $skippedJunk = false;
  13.     $skipGroups = false;
  14.     $file = $file.".Sara/mission.sqm";
  15.     //Check if file exists.
  16.     if(File_Exists($file)) {
  17.         //Split into lines
  18.         $contents = explode("\n",file_get_contents($file));
  19.     }
  20.     foreach ($contents as $line) {
  21.         //Cleanup any spaces in each line
  22.         $Cleanline = trim($line);
  23.         $parts = array();
  24.         //Remove blank lines
  25.         if(empty($Cleanline) || $Cleanline == "" || $Cleanline == "{"){
  26.             continue;
  27.         }
  28.         //Find Start of Vehicles
  29.         if(strpos($line,"\tclass Vehicles") !== false && strpos($line,"\t\tclass Vehicles") === false) {
  30.             $skipGroups = true;
  31.             continue;
  32.         }
  33.         //Find start of object
  34.         if(strpos($Cleanline, "class Item") !== false) {
  35.             $class[$total] = array("position"=>"0,0,0", "vehicle"=>"blank", "azimut"=>"0", "description"=>"");
  36.             $skippedJunk = true;
  37.             continue;
  38.         }
  39.         //Don't Parse until we find the start string
  40.         if(!$skipGroups)
  41.             continue;
  42.         if(!$skippedJunk)
  43.             continue;
  44.         //Find end of Object and reset everything
  45.         if($Cleanline == "};") {
  46.             $objects[count($objects)] = $class[$total];
  47.             $total++;
  48.             $skippedJunk = false;
  49.             continue;
  50.         }
  51.         //Split the var from the value
  52.         if(strpos($Cleanline,"="))
  53.             $parts = explode("=", $Cleanline);
  54.         //Cleanup and add them to the class array
  55.         if( count($parts) > 0 && array_key_exists(trim($parts[0]), $classes)) {
  56.             //Fix var and trim values
  57.             if($parts[0] == "position[]") {
  58.                 $parts[0] = substr($parts[0],0,-2);
  59.                 $parts[1] = substr($parts[1],2,-3);
  60.             }
  61.             if($parts[0] == "vehicle")
  62.                 $parts[1] = substr($parts[1],1,-2);
  63.             if($parts[0] == "azimut")
  64.                 $parts[1] = substr($parts[1],0,-1);
  65.             if($parts[0] == "description")
  66.                 $parts[1] = substr($parts[1],1,-2);
  67.             $class[$total][ trim($parts[0]) ] = trim( $parts[1] );
  68.         }
  69.     }
  70.     return $objects;
  71. }
  72.  
  73. function GenerateSQL($zone) {
  74.     //Start SQL Statement
  75.     echo "INSERT INTO object_spawns VALUES <br>";
  76.     //Loop through all the zone
  77.     for($i=0;$i<count($zone);$i++) {
  78.     //Check if there is a file for the zone
  79.         if(File_Exists($zone[$i].".Sara/mission.sqm")) {
  80.             //Generate class for building
  81.             $classes = getClasses($zone[$i]);
  82.             for($j=0;$j<count($classes);$j++) {
  83.                 echo "  ('".$j."', ";
  84.                 echo "'".$classes[$j]["vehicle"]."',";
  85.                 echo "'[".$classes[$j]["azimut"].",[".$classes[$j]["position"]."]]',";
  86.                 echo "'".$classes[$j]["description"]."'";
  87.                 if($j < count($classes)-1)
  88.                     echo "),<br>";
  89.                 else
  90.                     echo ");";
  91.             }
  92.         }
  93.     }
  94. }
  95. $zones[0] = "ALL";
  96. /*Run The Generator*/
  97. echo "<pre>";
  98.     GenerateSQL($zones);
  99.     //print_r(getClasses('EML_ALL'));
  100. echo "</pre>";
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement