I have problem with function statgen() in this script
<?php
include ('config.php');
$playerlvl = Rand (2, 100)-1;
$chance = Rand (0,10000)-1;
$itemstats = array( "str", "dex", "int", "sta", "hp", "mp");
echo "Chance: $chance </br>";
echo "Hello LVL $playerlvl adventurer! </br>";
//Function that generates stats,$playerlvl, $qmulti, $itemstats, $itemtype are stated out of the function
function statgen($playerlvl, $qmulti, $itemstats, $itemtype) {
$data = array();
if ($itemtype == "weapon") {
$data['minwdmg'] = 10 + 3 * $playerlvl * ($qmulti/2);
$data['maxwdmg'] = 20 + 3 * $playerlvl * ($qmulti/2);
$data['statt1'] = $itemstats[rand(0,5)];
$data['statt2'] = $itemstats[rand(0,5)];
$data['stat1'] = $playerlvl * ($qmulti/2);
$data['stat2'] = $playerlvl * ($qmulti/2);
}
else {
$data['statAR'] = $playerlvl * 3/2 + rand(0, 10);
$data['statt1'] = $itemstats[rand(0,5)];
$data['statt2'] = $itemstats[rand(0,5)];
$data['stat1'] = $playerlvl * ($qmulti/2);
$data['stat2'] = $playerlvl * ($qmulti/2);
}
return $data;
}
// Gets itemqlvl, if its==0 than does nothing, else creates item
if ($chance <= 10){
$itemqlvl = 3;
}
elseif ($chance <= 100){
$itemqlvl = 2;
}
elseif ($chance <= 9000) {
$itemqlvl = 1;
}
else {
$itemqlvl = 0;
}
echo "</br> $itemqlvl";
switch($itemqlvl){
case "0":
echo "Monster didnt drop anything";
break;
case "1":
$quality = "common";
$qmulti = 2;
break;
case "2":
$quality = "enchanted";
$qmulti = 3;
break;
case "3":
$quality = "elite";
$qmulti = 4;
break;
}
if ($itemqlvl >= 1) {
$itemtypes = array( "weapon", "body", "legs", "feet", "hands", "head");
$itemtype = $itemtypes[rand(0, 5)];
statgen($playerlvl, $qmulti, $itemstats, $itemtype);
}
else {
$itemtype = 0;
}
//Prints out results/tests.
if ($itemqlvl >= 1&&$itemtype!=0) {
echo "You searched monsters body and found $quality $itemtype!</br>";
}
if ($itemtype == "weapon"&&$itemqlvl >= 1){
echo "Dmg:" .$data['minwdmg']." - " .$data['maxwdmg']." </br>".$data['statt1']." - ".$data['stat1']." </br> ".$data['statt2']." - ".$data['stat2'].".";
}
if ($itemtype != "weapon"&&$itemqlvl >= 1) {
echo "Armor: ".$data['statAR']." </br> ".$data['statt1']." - ".$data['stat1']." </br> ".$data['statt2']." - ".$data['stat2'].".";
}
?>
After runing it just throfs out error for echo part:
Chance: 3471
Hello LVL 98 adventurer!
itemqlvl - 1
Notice: Undefined variable: data in C:\wamp\www\Game\itemgen.php on line 80
Notice: Undefined variable: data in C:\wamp\www\Game\itemgen.php on line 80
Notice: Undefined variable: data in C:\wamp\www\Game\itemgen.php on line 80
Notice: Undefined variable: data in C:\wamp\www\Game\itemgen.php on line 80
Notice: Undefined variable: data in C:\wamp\www\Game\itemgen.php on line 80
Armor:
-
- .
Also this line doesnt seam to work for some reason unknown to me:
if ($itemqlvl >= 1&&$itemtype!=0) {
echo "You searched monsters body and found $quality $itemtype!</br>";
}
Any tips?