Advertisement
Guest User

repairvehicles.php

a guest
May 16th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?php
  2. $host = "localhost"; //The host IP. If the MySQL Server is on the same server as the DayZ Server, leave this as "localhost".
  3. $user = "username"; //User with SELECT and UPDATE privileges to the DayZ Database.
  4. $pass = "password"; //Password for user.
  5. $db = "databasename"; //The databasename of your DayZ Database.
  6. $port = 3306; // MySQL Server Port. Default is 3306. Only change if you're sure this isn't the port your MySQL Server uses.
  7. function repairVehicles($array, $host, $user, $pass, $db, $port) {
  8.     $link = mysql_connect($host, $user, $pass, $port);
  9.     if (!$link){
  10.         die('Could not connect: ' . mysql_error());
  11.     }
  12.     mysql_select_db($db);
  13.     foreach($array as &$string) {
  14.         if($string != "[]") {
  15.             $rawstring = $string;
  16.             $string = explode(",", $string);
  17.             foreach($string as $key => $v1) {
  18.                 if($key % 2) {
  19.                     $rest = explode("]",$v1);
  20.                     foreach($rest as $key2 => $v2) {
  21.                         if(is_numeric($v2)){
  22.                             $v2 = 1;
  23.                         }
  24.                     }
  25.                     $v1 = implode("]",$rest);
  26.                 }
  27.                 $string[$key] = $v1;
  28.             }
  29.             $string = implode(",",$string);
  30.             $query = "UPDATE instance_vehicle SET parts='$string' WHERE parts='$rawstring'";
  31.             mysql_query($query);
  32.         }
  33.     }
  34.     mysql_close($link);
  35. }
  36.  
  37. $link = mysql_connect($host, $user, $pass, $port);
  38. if (!$link){
  39.     die('Could not connect: ' . mysql_error());
  40. }
  41. mysql_select_db($db);
  42. $query = mysql_query("SELECT parts FROM instance_vehicle");
  43. $input = array();
  44. $index = 0;
  45. while($row = mysql_fetch_array($query, MYSQL_ASSOC)){
  46.     $input[$index] = $row['parts'];
  47.     $index++;
  48. }
  49. mysql_query("UPDATE instace_vehicle SET damage='0'");
  50. mysql_close($link);
  51. repairVehicles($input, $host, $user, $pass, $db, $port);
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement