Quote:
Originally posted by Aruchinjiru
o.O oh cool I'll have to look at that. So basically you could edit the text file..to edit the level?
|
Yeah... and make programs to edit levels for you.
This would add an NPC randomly into all the levels in the directory it's in (we used it for the kingdom trees on 2k2)
PHP Code:
<?php
if ($action=="generate" && $randmax>=1 && sizeof($randtrees)>0) {
$dir = opendir("./");
$filelist = array();
$filecount = 0;
while (false!==($file = readdir($dir))) {
if (is_file($file) && $file!=="index.php") {
$filelist[$filecount] = $file;
$filecount++;
}
}
closedir($dir);
printf($filecount . " files recorded...<hr>");
$treetotal = 0;
$treefile = 0;
for ($cfile = 0;$cfile<$filecount;$cfile++) {
$treetotal += $treefile;
printf("Working on file: " . $filelist[$cfile] . "<br>");
$treefile = 0;
for ($cy = 0;$cy<64/8;$cy++) {
for ($cx = 0;$cx<64/8;$cx++) {
if (1>rand(0,$randmax)) {
$file = fopen($filelist[$cfile],"a");
$treetype = $randtrees[rand(0,sizeof($randtrees)-1)];
$writetofile =
"NPC - " . $cx*8 . " " . $cy*8 . "
//Tree added by tree generator
if (created) {
showcharacter;
this.type = $treetype;
setcharani realtree#v(this.type),;
}
join realtrees;
NPCEND
";
fwrite($file,$writetofile);
fclose($file);
$treefile++;
printf("Tree " . $treetype . " added to " . $cx*8 . "," . $cy*8 . " of " . $filelist[$cfile] . "<br>");
}
}
}
printf($treefile . " trees were added to " . $filelist[$cfile] . "<hr>");
}
printf($treetotal . " trees were added to " . $filecount . " levels.");
} else {
?>
<form method="get">
<input type="hidden" name="action" value="generate">
<br>
Odds for a tree (every 8x8 tiles): 1 in <input type="text" name="randmax" value="25">
<br>
Select trees to choose from:
<br>
<?
for ($i = 1;$i<=20;$i++) {
echo "Tree $i <input type=\"checkbox\" name=\"randtrees[]\" value=\"$i\"><br>";
}
?>
<br>
<input type="submit" value="Generate">
</form>
<?
}
?>