diff --git a/Tools/Loot Position/ConvertLoottables.pl b/Tools/Loot Position/ConvertLoottables.pl new file mode 100644 index 000000000..612260ee1 --- /dev/null +++ b/Tools/Loot Position/ConvertLoottables.pl @@ -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 = ) { + + 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{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); \ No newline at end of file