Hey, its me again.
Here's my script, that now doesn't give me any errors (atleast! 🙂 )
But it also doesn't give me data I am trying to get
<?php
include ('config.php');
$playerlvl = 100; //Rand (2, 100)-1;
$chance = Rand (0,10000)-1;
$itemstats = array( "strenght", "dexterity", "inteligence", "stamina", "health points", "energy points", "armor rating");
$data = 0;
$quality = 0;
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'] = round(10 + 3 * $playerlvl * $qmulti/2);
$data['maxwdmg'] = round(20 + 3 * $playerlvl * $qmulti/2);
$data['statt1'] = $itemstats[rand(0,6)];
$data['statt2'] = $itemstats[rand(0,6)];
$data['stat1'] = round($playerlvl * ($qmulti/2));
$data['stat2'] = round($playerlvl * ($qmulti/2));
}
else {
$data['statAR'] = round($playerlvl * 3/2 + rand(0, 10));
$data['statt1'] = $itemstats[rand(0,6)];
$data['statt2'] = $itemstats[rand(0,6)];
$data['stat1'] = round($playerlvl * ($qmulti/2));
$data['stat2'] = round($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> (test for qlvl - $itemqlvl) </br>";
switch($itemqlvl){
case "0":
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)];
$data = statgen($playerlvl, $qmulti, $itemstats, $itemtype);
}
else {
$itemtype = 0;
}
//Prints out results/tests.
function wprop($data, $quality, $itemtype) {
if ($itemtype == 0) {
$case = 0;
}
elseif ($itemtype == "weapon") {
$case = 1;
}
elseif ($itemtype != "weapon") {
$case = 2;
}
switch($case):
case 0:
$wprop['stats'] = "Monster didn/'t drop anything";
$wprop['type'] = "";
break;
case 2:
if ($data['statt1'] == $data['statt2']) {
if ($data['statt1'] == "armor rating") {
$data['stat'] = $data['statAR'] + $data['stat1'] + $data['stat2'];
$wprop['stats'] = "Armor rating: ".$data['stat']."";
}
else {
$data['stat'] = $data['stat1'] + $data['stat2'];
$wprop['stats'] ="Armor: ".$data['statAR']." </br> ".$data['statt1']." - ".$data['stat']."";
}
}
elseif ($data['statt1'] == "armor rating") {
$data['stat'] = $data['statAR'] + $data['stat1'];
$wprop['stats'] = "Armor: ".$data['stat']." </br> ".$data['statt2']." - ".$data['stat2']."";
}
elseif ($data['statt2'] == "armor rating") {
$data['stat'] = $data['statAR'] + $data['stat2'];
$wprop['stats'] = "Armor: ".$data['stat']." </br> ".$data['statt1']." - ".$data['stat1']."";
}
else {
$wprop['stats'] = "Armor: ".$data['statAR']." </br> ".$data['statt1']." - ".$data['stat1']." </br> ".$data['statt2']." - ".$data['stat2']."";
}
$wprop['type'] = "You searched monsters body and found $quality $itemtype!</br>";
return $ataoutput;
break;
case 1:
if ($data['statt1'] == $data['statt2']) {
$data['stat'] = $data['stat1'] + $data['stat2'];
$wprop['stats'] = "Dmg:" .$data['minwdmg']." - " .$data['maxwdmg']." </br>".$data['statt1']." - ".$data['stat']." ";
}
else {
$wprop['stats'] = "Dmg:" .$data['minwdmg']." - " .$data['maxwdmg']." </br>".$data['statt1']." - ".$data['stat1']." </br> ".$data['statt2']." - ".$data['stat2'].".";
}
$wprop['type'] = "You searched monsters body and found $quality $itemtype!</br>";
return $wprop;
break;
endswitch;
}
$wprop = wprop($data, $quality, $itemtype);
echo "".$wprop['type']." ".$wprop['stats']."";
?>
All I get is this
Chance: 8619
Hello LVL 100 adventurer!
(test for qlvl - 1)
But it also should print out the most important part - funcions wprop data!
Any ideas why anything isn't happening or any other tips for me?
Question 2:
wprop function is executed in both cases, even if item does not drop. But it needs some values from case if item does drop, is there a way that i could tell function to ignore these values if they arent generated in that case, or should i just define them as = 0 at begining of the script?