Page MenuHomeContribution Center

Proof of Concept: Create Loadout Builder which adds loadouts to mySQL and creates ARMA3 formatted loadout
Closed, WontfixPublic

Description

Still to do: Requery names for objects and replace with classname

index.php

<body>
<h1>Loadout Creator</h1>
<form action="insert.php" method="post">

<label for="loadoutname">Loadout Name:</label>
        <input type="text" name="loadoutname" id="loadoutname">
<br>
<?php

$sql = "SELECT name FROM tarsenal WHERE type='bag' GROUP BY name;";

$result = mysqli_query($mysqli,$sql);
if (!is_null($result)) {
    echo '<label for="backpack">Backpack:';
    echo '<select name="bag">';
    echo '<option value="" name="bag" id="bag">none</option>';

    $num_results = mysqli_num_rows($result);
    for ($i=0;$i<$num_results;$i++) {
        $row = mysqli_fetch_array($result);
        $name = $row['name'];
        echo '<option name="bag" id="bag" value=" ' .$name. '">' .$name. '</option>';
    }

    echo '</select>';
    echo '</label>';
	echo "<br>";
}


$sql = "SELECT name FROM tarsenal WHERE type='headgear' GROUP BY name;";

$result = mysqli_query($mysqli,$sql);


if (!is_null($result)) {
    echo '<label>Headgear:';
    echo '<select name="headgear">';
    echo '<option value="" name="headgear" id="headgear">none</option>';

    $num_results = mysqli_num_rows($result);
    for ($i=0;$i<$num_results;$i++) {
        $row = mysqli_fetch_array($result);
        $name = $row['name'];
        echo '<option name="headgear" id="headgear" value="' .$name. '">' .$name. '</option>';
    }

    echo '</select>';
    echo '</label>';
	echo "<br>";
}

$sql = "SELECT name FROM tarsenal WHERE type='uniform' GROUP BY name;";

$result = mysqli_query($mysqli,$sql);
if (!is_null($result)) {
    echo '<label>Uniform:';
    echo '<select name="uniform">';
    echo '<option value="" name="uniform" id="uniform">none</option>';

    $num_results = mysqli_num_rows($result);
    for ($i=0;$i<$num_results;$i++) {
        $row = mysqli_fetch_array($result);
        $name = $row['name'];
        echo '<option name="uniform" id="uniform" value="' .$name. '">' .$name. '</option>';
    }

    echo '</select>';
    echo '</label>';
	echo "<br>";
}



mysqli_close($mysqli);

?>
 <input type="submit" value="Submit">
</form>
</body>

input.php

<?php
// Setup connection to mySQL db
	$link = new mysqli("localhost", "root", "1234", "arsenal");
	
	// Error handler if connection to db fails
	if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
	}
 
// Escape user inputs for security
$bag = mysqli_real_escape_string($link, $_REQUEST['bag']);
$headgear = mysqli_real_escape_string($link, $_REQUEST['headgear']);
$uniform = mysqli_real_escape_string($link, $_REQUEST['uniform']);
$loadoutname = mysqli_real_escape_string($link, $_REQUEST['loadoutname']);



$format = '"class %s {
	displayName = "%s";
	

	uniformClass = "%s";
	backpack = "%s";
	
	weapons[] = {
		"rhs_weap_m4a1"
	};

	linkedItems[] = {
		"%s",
		"rhsusf_iotv_ocp_Rifleman",
		"rhsusf_acc_M952V",
		"rhsusf_acc_compm4",
		"rhsusf_acc_grip2",
		"ItemCompass",
		"ItemWatch",
		"ItemMap"
	};
	
	items[] = {
		#include "Uniform.hpp"
	};
};';

$armaexport = sprintf($format, $loadoutname, $loadoutname, $uniform, $bag, $headgear); 

// Attempt insert query execution
$sql = "INSERT INTO loadouts (loadoutname, headgear, bag, uniform, armaexport) VALUES ('$loadoutname', '$headgear', '$bag', '$uniform', '$armaexport')";
if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
	echo $armaexport;
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 

 
// Close connection
mysqli_close($link);
?>

GUI

Output

MyPHPAdmin

Event Timeline

CplPidu triaged this task as Wishlist priority.May 14 2020, 7:19 PM
CplPidu created this task.

In order to improve this system and to allow easier joining of the databases in order to get additional information from the arsenal (complete equipment) DB the data structure in SQL should be compartimentalized:

One Table which holds the "meta data" of a loadout, i.e.
UID - 1
Name - Pidu's Rifleman
Armed Forces - USMC
Total Weight - 28.7 kg
Times used - 222

And one which holds the details of the loadouts.
UID - Same as above
Classname - rhs_weapon_....
name - M4 PIP
quantity - 1

This allows a direct inner join of both tables on UID and facilitates to get data from the arsenal. Additionally management of loadouts becomes easier through queries.

Changed to a shopping chart system to build the loadouts.
Based on sessions.
This makes it easier to beautify the whole process.
I also included only the currently allowed items in the loadouts.

Select items needed in loadout

Change quantity.

Redid the whole Code, in order to categorize the items in the builder. Also made "shopping cart" on the same site.


I am asking myself if this is the way to go. I put this project on hold for now.
Reasoning:
Priority would be an importer which allows the user to use an exported Arma 3 loadout to be parsed for the database and import it. As well as exporting from our db into an Arma 3 readable form.

CplPidu closed this task as Wontfix.May 21 2020, 6:38 PM