mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-14 12:12:34 +03:00
Added Loottable convert script
This commit is contained in:
66
Tools/Loot Position/ConvertLoottables.pl
Normal file
66
Tools/Loot Position/ConvertLoottables.pl
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
# Customize
|
||||||
|
my $configFile = '../../SQF/dayz_code/Configs/CfgBuildingLoot/CfgBuildingLoot.hpp';
|
||||||
|
|
||||||
|
# do not touch
|
||||||
|
my $cfg = '';
|
||||||
|
my $collect = 0;
|
||||||
|
my $small = 0;
|
||||||
|
my @itemType;
|
||||||
|
my @itemChance;
|
||||||
|
open(CFG, '<', $configFile) or die $!;
|
||||||
|
while (my $line = <CFG>) {
|
||||||
|
|
||||||
|
if ($line =~ /itemType(Small)?\[\]\s*=\s*\{\s*$/) {
|
||||||
|
$collect = 1;
|
||||||
|
@itemType = ();
|
||||||
|
|
||||||
|
if (defined($1) && $1) {
|
||||||
|
$small = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$small = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
elsif ($collect == 1 && $line =~ /^\s*\{\s*"(\w*)",\s*"(\w*)"\s*\}/i) {
|
||||||
|
push(@itemType, {
|
||||||
|
Class => $1
|
||||||
|
,Type => $2
|
||||||
|
});
|
||||||
|
}
|
||||||
|
elsif ($collect == 1 && $line =~ /\};/) {
|
||||||
|
$collect = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($collect == 2 && $line =~ /itemChance(?:Small)?\[\]\s*=\s*\{/) {
|
||||||
|
$collect = 3;
|
||||||
|
@itemChance = ();
|
||||||
|
}
|
||||||
|
elsif ($collect == 3 && $line =~ /^\s*(\d+\.\d+),?/) {
|
||||||
|
push(@itemChance, $1);
|
||||||
|
}
|
||||||
|
elsif ($collect == 3 && $line =~ /\};/) {
|
||||||
|
$collect = 0;
|
||||||
|
|
||||||
|
$cfg .= "\t\titemChance[] = {\n" if $small == 0;
|
||||||
|
$cfg .= "\t\titemChanceSmall[] = {\n" if $small == 1;
|
||||||
|
for (my $i=0; $i<scalar(@itemType); $i++) {
|
||||||
|
$cfg .= sprintf("\t\t\t{\"%s\",\"%s\",%.3f}\n", $itemType[$i]->{Class}, $itemType[$i]->{Type}, $itemChance[$i]);
|
||||||
|
}
|
||||||
|
$cfg .= "\t\t};\n";
|
||||||
|
}
|
||||||
|
elsif ($line !~ /^\s*\/\// && $line !~ /^\s*$/) {
|
||||||
|
$cfg .= $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(CFG);
|
||||||
|
|
||||||
|
open(NEWCFG,'>', $configFile) or die $!;
|
||||||
|
print NEWCFG $cfg;
|
||||||
|
close(NEWCFG);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
Reference in New Issue
Block a user