mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-11 00:44:27 +00:00
Merge pull request #34 from daffyyyy/enhancement/website-knife-choosing
Choosing knife on website
This commit is contained in:
@@ -298,6 +298,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||||
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
Task.Run(async () => await GetKnifeFromDatabase(playerIndex));
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) {
|
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) {
|
||||||
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ class UtilsClass
|
|||||||
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
|
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
|
||||||
|
|
||||||
foreach ($json as $skin) {
|
foreach ($json as $skin) {
|
||||||
$skins[(int)$skin['weapon_defindex']][(int)$skin['paint']] = [
|
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
|
||||||
|
'weapon_name' => $skin['weapon_name'],
|
||||||
'paint_name' => $skin['paint_name'],
|
'paint_name' => $skin['paint_name'],
|
||||||
'image_url' => $skin['image'],
|
'image_url' => $skin['image'],
|
||||||
];
|
];
|
||||||
@@ -21,11 +22,12 @@ class UtilsClass
|
|||||||
$weapons = [];
|
$weapons = [];
|
||||||
$temp = self::skinsFromJson();
|
$temp = self::skinsFromJson();
|
||||||
|
|
||||||
foreach ($temp as $key => $value)
|
foreach ($temp as $key => $value) {
|
||||||
{
|
if (key_exists($key, $weapons))
|
||||||
if (key_exists($key, $weapons)) continue;
|
continue;
|
||||||
|
|
||||||
$weapons[$key] = [
|
$weapons[$key] = [
|
||||||
|
'weapon_name' => $value[0]['weapon_name'],
|
||||||
'paint_name' => $value[0]['paint_name'],
|
'paint_name' => $value[0]['paint_name'],
|
||||||
'image_url' => $value[0]['image_url'],
|
'image_url' => $value[0]['image_url'],
|
||||||
];
|
];
|
||||||
@@ -34,12 +36,58 @@ class UtilsClass
|
|||||||
return $weapons;
|
return $weapons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getKnifeTypes()
|
||||||
|
{
|
||||||
|
$knifes = [];
|
||||||
|
$temp = self::getWeaponsFromArray();
|
||||||
|
|
||||||
|
foreach ($temp as $key => $weapon) {
|
||||||
|
if (
|
||||||
|
!in_array($key, [
|
||||||
|
500,
|
||||||
|
503,
|
||||||
|
505,
|
||||||
|
506,
|
||||||
|
507,
|
||||||
|
508,
|
||||||
|
509,
|
||||||
|
512,
|
||||||
|
514,
|
||||||
|
515,
|
||||||
|
516,
|
||||||
|
517,
|
||||||
|
518,
|
||||||
|
519,
|
||||||
|
520,
|
||||||
|
521,
|
||||||
|
522,
|
||||||
|
523,
|
||||||
|
525
|
||||||
|
])
|
||||||
|
)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$knifes[$key] = [
|
||||||
|
'weapon_name' => $weapon['weapon_name'],
|
||||||
|
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
||||||
|
'image_url' => $weapon['image_url'],
|
||||||
|
];
|
||||||
|
$knifes[0] = [
|
||||||
|
'weapon_name' => "weapon_knife",
|
||||||
|
'paint_name' => "Default knife",
|
||||||
|
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($knifes);
|
||||||
|
return $knifes;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getSelectedSkins(array $temp)
|
public static function getSelectedSkins(array $temp)
|
||||||
{
|
{
|
||||||
$selected = [];
|
$selected = [];
|
||||||
|
|
||||||
foreach ($temp as $weapon)
|
foreach ($temp as $weapon) {
|
||||||
{
|
|
||||||
$selected[$weapon['weapon_defindex']] = $weapon['weapon_paint_id'];
|
$selected[$weapon['weapon_defindex']] = $weapon['weapon_paint_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
website/img/skins/weapon_knife.png
Normal file
BIN
website/img/skins/weapon_knife.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -15,18 +15,24 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
$skins = UtilsClass::skinsFromJson();
|
$skins = UtilsClass::skinsFromJson();
|
||||||
$querySelected = $query3 = $db->select("SELECT `weapon_defindex`, `weapon_paint_id` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
$querySelected = $query3 = $db->select("SELECT `weapon_defindex`, `weapon_paint_id` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||||
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
||||||
|
$selectedKnife = $db->select("SELECT * FROM `wp_player_knife` WHERE `wp_player_knife`.`steamid` = :steamid", ["steamid" => $steamid])[0];
|
||||||
|
$knifes = UtilsClass::getKnifeTypes();
|
||||||
|
|
||||||
if (isset($_POST['forma'])) {
|
if (isset($_POST['forma'])) {
|
||||||
$ex = explode("-", $_POST['forma']);
|
$ex = explode("-", $_POST['forma']);
|
||||||
|
|
||||||
if (array_key_exists($ex[1], $skins[$ex[0]])) {
|
if ($ex[0] == "knife") {
|
||||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
$db->query("INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(:steamid, :knife) ON DUPLICATE KEY UPDATE `knife` = :knife", ["steamid" => $steamid, "knife" => $knifes[$ex[1]]['weapon_name']]);
|
||||||
$db->query("UPDATE wp_player_skins SET weapon_paint_id = :weapon_paint_id WHERE steamid = :steamid AND weapon_defindex = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
} else {
|
||||||
} else {
|
if (array_key_exists($ex[1], $skins[$ex[0]])) {
|
||||||
$db->query("INSERT INTO wp_player_skins (`steamid`, `weapon_defindex`, `weapon_paint_id`) VALUES (:steamid, :weapon_defindex, :weapon_paint_id)", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
if (array_key_exists($ex[0], $selectedSkins)) {
|
||||||
|
$db->query("UPDATE wp_player_skins SET weapon_paint_id = :weapon_paint_id WHERE steamid = :steamid AND weapon_defindex = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
||||||
|
} else {
|
||||||
|
$db->query("INSERT INTO wp_player_skins (`steamid`, `weapon_defindex`, `weapon_paint_id`) VALUES (:steamid, :weapon_defindex, :weapon_paint_id)", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
header("Location: index.php");
|
|
||||||
}
|
}
|
||||||
|
header("Location: index.php");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -54,7 +60,47 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
echo "</h2></div>";
|
echo "</h2></div>";
|
||||||
} else {
|
} else {
|
||||||
echo "<div class='bg-primary'>Your current weapon skin loadout<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form></div>";
|
echo "<div class='bg-primary'>Your current weapon skin loadout<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form></div>";
|
||||||
echo "<div class='card-group'>";
|
echo "<div class='card-group mt-2'>";
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<div class="card text-center mb-3 border border-primary">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php
|
||||||
|
$actualKnife = $knifes[0];
|
||||||
|
foreach ($knifes as $knife) {
|
||||||
|
if ($selectedKnife['knife'] == $knife['weapon_name']) {
|
||||||
|
$actualKnife = $knife;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<div class='card-header'>";
|
||||||
|
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||||
|
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
||||||
|
echo "</div>";
|
||||||
|
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<form action="" method="POST">
|
||||||
|
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||||
|
<option>Select knife</option>
|
||||||
|
<?php
|
||||||
|
foreach ($knifes as $knifeKey => $knife) {
|
||||||
|
if ($selectedKnife['knife'] == $knife['weapon_name'])
|
||||||
|
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||||
|
else
|
||||||
|
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
foreach ($weapons as $defindex => $default) { ?>
|
foreach ($weapons as $defindex => $default) { ?>
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
<div class="card text-center mb-3">
|
<div class="card text-center mb-3">
|
||||||
@@ -64,7 +110,7 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
echo "<div class='card-header'>";
|
echo "<div class='card-header'>";
|
||||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]]["paint_name"]}</h5>";
|
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]]["paint_name"]}</h5>";
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]]['image_url']}' class='skin-image' >";
|
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]]['image_url']}' class='skin-image'>";
|
||||||
} else {
|
} else {
|
||||||
echo "<div class='card-header'>";
|
echo "<div class='card-header'>";
|
||||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||||
|
|||||||
Reference in New Issue
Block a user