how do you cars from a mission SQF file on a hosted server

Discussion in 'Mission Editing' started by brent65622, Jul 31, 2015.

  1. brent65622

    brent65622 Member

    Joined:
    Feb 9, 2014
    Messages:
    43
    Likes Received:
    0
    how do add you cars from a mission SQF file on a hosted server its near as easy as it is when i host a server at my house . I have vert hosting
     
  2. FallingSheep

    FallingSheep OpenDayZ Lord!

    Joined:
    Mar 17, 2013
    Messages:
    1,974
    Likes Received:
    576
    cars addes by SQF wont save on restart. best way is to add them via DB (SQL)
     
  3. brent65622

    brent65622 Member

    Joined:
    Feb 9, 2014
    Messages:
    43
    Likes Received:
    0
    How would i do that using MYSQL .
     
  4. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,421
    Likes Received:
    336
    You need a php/mysql script to parse the sqf vehicle script and insert them into your database. No idea how that works anymore but here is the code I used about 2 years ago . It parses the mission.sqf file for vehicles and adds the classnames and worldspace into the database. You would have to update this script to reflect the DB schema's
    And you need a webserver so you can execute this php code, xampp on your own local computer would work.
    Code:
    <?php
    
    // DATABASE CONNECTION INFO //
    $dbhost = 'localhost';
    $dbname = 'hivemind';
    $dbuser = 'dayz';
    $dbpass = 'dayz';
    
    $fileName = 'mission.sqf'; //path to your mission.sqm file
    $chance = 1; //Set a default chance for all vehicles spawns created
    $worldID = 10; // Check your world table for your specific world ID.
    ///////////////////
    
    // DO NOT EDIT ANYTHING BELOW THIS LINE //
    /*--------------------------------------*/
    
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname, $conn);
    $missionfile = file_get_contents($fileName);
    $rows = explode("\n",$missionfile);
    array_shift($rows);
    $vehiclecount =0;
    ?>
    
    <table border=1px>
    <tr><th>Class Name</th><th>Position</th><th>Vehicle ID</th></tr>
    <?php
    
            $IDQuery = "SELECT id
            FROM world_vehicle;";
            $resultIDQuery = mysql_query($IDQuery);
            while ($row = mysql_fetch_array($resultIDQuery, MYSQL_NUM)) 
                $userDataIDs[] = $row[0];
            $id = max($userDataIDs)+1;
           
           
    for($i=0;$i<count($rows);$i++)
    {
        $direction = 0;
        if (strpos($rows[$i],'_this = createVehicle [') !== false)
        {
            $strings = explode("\"",$rows[$i]);
            $firstOpenBracket = strpos($rows[$i], "[");
            $secondOpenBracket = strpos($rows[$i], "[", $firstOpenBracket + strlen("]"));
            $firstCloseBracket = strpos($rows[$i], "]");
           
            if (strpos($rows[$i+2],'_this setDir') !== false)
            {
                $firstSpace = strpos($rows[$i+2]," ");
                $secondSpace = strpos($rows[$i+2]," ",$firstSpace+strlen(" "));
                $thirdSpace = strpos($rows[$i+2]," ",$secondSpace+strlen(" "));
                $forthSpace = strpos($rows[$i+2]," ",$thirdSpace+strlen(" "));
                $period = strpos($rows[$i+2],".");
                $direction = substr($rows[$i+2],$forthSpace+1, $period-$forthSpace-1);
            }
           
            $pos = "[$direction," . substr($rows[$i],$secondOpenBracket, $firstCloseBracket-$secondOpenBracket+1) . "]";
            $pos = str_replace(array(' '), '',$pos);
            $newPos = explode(",",$pos);
            if (count($newPos) == 3)
            {
                $pos = "[$direction," . substr($rows[$i],$secondOpenBracket, $firstCloseBracket-$secondOpenBracket) . ",0]]";
                $pos = str_replace(array(' '), '',$pos);
            }
           
            //Class Check (Will insert a new classname if it doesnt exist)
            $checkClassNameQuery = "SELECT *
            FROM object_classes;";
            $resultClassNameQuery = mysql_query($checkClassNameQuery);
            $userDataClassNameQuery;
            $userDataVehicleIDs;
            while ($row = mysql_fetch_array($resultClassNameQuery, MYSQL_ASSOC)) 
                $userDataClassNameQuery[] = $row['classname'];
    
            $matchFound = 0;
            for($j=0;$j<count($userDataClassNameQuery)-1;$j++)
            {
                if ($strings[1] == $userDataClassNameQuery[$j]) 
                {
                    $matchFound = 1;
                }
            }
            $checkClassNameIDQuery = "SELECT id
            FROM object_classes;";
            $resultClassNameIDQuery = mysql_query($checkClassNameIDQuery);
            while ($row = mysql_fetch_array($resultClassNameIDQuery, MYSQL_NUM)) 
                $userDataVehicleIDs[] = $row[0];
            $classCount = max($userDataVehicleIDs) + 1;
            if($matchFound == 0)
            {
                echo "Inserting new Class Name at index, " . $classCount;?><br><?php
                $insertClassQuery = "INSERT INTO `object_classes` (`classname`, `damage`, `type`, `maxnum`,`chance`) 
                VALUES ('$strings[1]', '0.05', 'car', '20','.75');";
                $resultInsertClassQuery = mysql_query($insertClassQuery);
            }
            //Class Check End
           
           
            $getIDQuery = "SELECT *
            FROM object_classes
            WHERE classname = '$strings[1]';";
            $resultIDQuery = mysql_query($getIDQuery);
            $userDataIDQuery = mysql_fetch_array($resultIDQuery, MYSQL_ASSOC);
           
       
            $insertQuery = "INSERT INTO `object_spawns` (`objectUID`, `classname`, `mapID`, `worldspace`, `inventory`,`hitpoints`,`last_changed') 
            VALUES ('$id', '$vehicle_id', '$worldID', '$pos', '[[[],[]],[[],[]],[[],[]]]','[]',0);";
            $resultInsertQuery = mysql_query($insertQuery);
            $vehiclecount++;
            $id++;
            ?><tr><td><?php echo $strings[1]?></td><td><?php echo $pos?></td><td><?php echo $vehicle_id?></td></tr><?php
        }
    }
    ?>
    </table><br><br><b>
    <?php
    echo $vehiclecount;
    
    ?> </b>vehicles added to the database spawn tables.<br>
    <a href="http://127.0.0.1:78/dayz/">RETURN</a>
    
     
    FallingSheep likes this.

Share This Page