[item]
id=287
name=Hunter shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=2
price=600
dmg=ranged,6,10
requires_stat=offense,7
requires_stat=physical,3
...
INCLUDE items/base/armor/chitin_light/chest.txt
No, it's not you just didn't understood how it works. It can be used to generate any item configuration you want.Danimal {l Wrote}:Hello BZT, even thought its a nice basic generator is too limited.
You should have a json for each of those. Values can be generated randomly, and they can be shifted by an offset using the "add" field if needed.Danimal {l Wrote}:You see, the idea i had is being able to input the item level, plus the stat gain per level (like Lv3 sword with gains of Min 1-Max 3 gives swords of damage ranging 3-9 points at random), since there are basically 3 damage types on Flare i would check the weapon circle button and then Melee/magic/ranged damage in the now empty combox under weapon (or any kind of similar control object). Armor is similar in which instead of having damage ranges (like dmg=melee,3,9; dmg=ment,3,9; dmg=ranged,3,9) has Absortion (abs=2,4). "Others" just means its not a weapon or amor so it doesnt need those values (more on this later); You got pretty well the starting and finish id.
This means you'll have to create a json for each of these combinations. Where you say you a press a 70%,50%,30% button, I say pick one of the jsons.Danimal {l Wrote}:The middle column with requeriment need to check any of the four stats and press 70%,50%,30% button. This outputs the item 70%,50%,30% level * 5 (char stat gain per lv) of the needed stat to wear, as a line into the extra input data textbox. Ex:
You should have a json withDanimal {l Wrote}:So if i press Dextery 75% and Strenght 30%, this should appear into the extra input data textbox.
requires_stat=offense,7
requires_stat=physical,3
"name": "requires_stat", "value": "offense,7"
"name": "requires_stat", "value": "physical,3"
Yeah, I've figured that. That's why I've told you that you haven't understood how my tool works. It has NOTHING hadwired, except for the id of course. If in the future you want to add new declarations, just add them to the json, and those fields will be dumped to the output as well.Danimal {l Wrote}:Why that mysterious extra input data textbox? That box would contain any object declaration or requeriments i add in the future and doesnt exist yet.
For those most used combinations you should have an INCLUDE. But you can just as well create one json for each, like ring.json, sword.json, etc.Danimal {l Wrote}:Ideally, there would be buttoms for the most used item definitions in the empty space over the textbox, so i can just press it and it gets added (like rings or swords definition).
"name": "INCLUDE", "value": "items/types/combination%d.txt", "min": 1, "max": "20"
<?php
/* get arguments from command line */
$lvl = $_SERVER['argv'][1]; // first is the level
$off = $_SERVER['argv'][2]; // second is the offense percentage
$phy = $_SERVER[argv][3]; // third is the physical percentage
?>
level=<?=$lvl?>
dmg=ranged,<?=($lvl * 3)?>,<?=($lvl * 3 + 4)?>
requires_stat=offense,<?=$off?>
requires_stat=physical,<?=$phy?>
price=<?=rand(100, 500)?>
<? if($off >= 3) { ?>
requires_stat=offense,<?=$off?>
<? } ?>
That's why I've recommended php. You see, unlike other programming languages, php works as a templater by default. This means everything that's not inside a <? ?> block gets copied to the output verbatim, so it is particularly usable for generating item files. No programming skills needed, the first block just gets the arguments and places them in named variables, otherwise all you need is <?=...?> which calculates an expression and outputs its value. For these only mathematical expressions needed, like addition, subtraction, multiplication, division and grouping with parenthesis. Just the basic things. About the programming stuff, all you need to know is that variables are prefixed by '$', and that you can get a random number with "rand(min,max)", that's all.Danimal {l Wrote}:Thanks, but the thing is i cant code for my life...
Ill try to chew this slowly
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
<?}?>
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
[item]
id=<?=$id?>
name=Hunter shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=<?=$level?>
price=<?=rand(100 * $level, 150 * $level)?>
dmg=ranged,6,10
requires_stat=offense,7
requires_stat=physical,3
<?}?>
php.exe template.php startid=287 endid=299 level=2
For example, you could also create 20 different combinations, and then generate 1000 items out of those randomly with
{l Code}: {l Select All Code}
"name": "INCLUDE", "value": "items/types/combination%d.txt", "min": 1, "max": "20"
Yes, you got that right!Danimal {l Wrote}:I think, I get php a bit better than JavaScript, maybe because of having more samples, can the same calculations be done in the one you sent me?
Like im guessing i should go like this to make random damage values and requires:
Not sure what you wanted, but all you need is simple algebra. The calculated number is automatically converted to a string and added to the output, you don't have to worry about that. For example <?=$level * 5 * 70 / 100?> returns the 70% of 5 times level. But <?=$level * 5 * 0.7?> would do too. About those, it reminded me that you might need to convert floating point numbers to integers, for that use "floor()" (rounds down) and "ceil()" (rounds up). So for example <?=floor(1.7)?> will print "1" to the output, while <?=ceil(1.7)?> will print "2".Danimal {l Wrote}:requires_stat=offense,<?=$level *= 5 *= 70 /= 100?> (i have no idea if thats how you nest operations on php, and top of it, it needs to return an integer
Sadly no. All it can do is add, but no complex expressions and no variables (except an implicit one). That's why I've said if you need calculated things, you should use a scripting language.Danimal {l Wrote}:Could i do the same with your teamplater? it would be much less hassle for me just creating/modifying .jsons; but it doesnt accept level variables?
Ah ok, with my templater you create several txt with "name=something" variations, name them "nameX.txt" and use a random INCLUDE. But I guess you want more complex expressions anyway, so here's how you can do it with php: <?=["a","b","c"][rand(0,2)]?> (might look ugly, I admit). So here in the first [] block, you list the strings. In the second, as the parameter to rand, you use 0 and the number of strings minus 1.Danimal {l Wrote}:And how would i go with name variations? like i said before base name + random abjective from a list: "Shortbow" "of poachers", same for random magical properties, i dont understand what you are telling me here:
name=<?=["Short","Long","Recursive","Asymmetric","Mongol"][rand(0,4)]?>bow
Yes. If you want calculated expressions and variables, then definitely a scripting language is the way to go. If you were on Linux, I'd say use shell script with HEREDOC or awk, but on Windows I'd recommend to download php, probably that's the simplest (for templating, simpler than python or batch files).Danimal {l Wrote}:Would it be better to try php?
That's good, that's exactly how it should look like (it enters an interactive mode without any error message). Now to use it, create template php files, starting with that one liner and ending in that "<?}?>". At first, just try to copy'n'paste mine from above. Let's say you save it by the name "abc.php", then you can run it like this:Danimal {l Wrote}:Running php.exe give me that screen. How do i go at creating the teamplater with the code you gave me? and calling it?.
php.exe abc.php startid=10 endid=11 level=2
php.exe abc.php startid=10 endid=11 level=2 >items.txt
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
[item]
id=<?=$id?>
name=Hunter shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=<?=$level?>
price=<?=rand(100 * $level, 150 * $level)?>
dmg=ranged,6,10
requires_stat=offense,7
requires_stat=physical,3
<?}?>
Have no worries, it's the same here. We have no air conditioner.Danimal {l Wrote}:Sorry for taking so long but where i live its too hot and im having constant brainmelts.
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
[item]
id=<?=$id?>
name=<?=["Goblin","Hunter","Poacher","Metal","Flexible"][rand(0,4)]?> shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=<?=$level?>
price=<?=rand(75 * $level, 150 * $level)?>
dmg=ranged,<?=rand(0, 1 * $level)?>,<?=rand(1 * $level, 3 * $level)?>
requires_stat=offense,<?=ceil($level * 5 * 0.7)?>
requires_stat=physical,<?=ceil($level * 5 * 0.3)?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][rand(0,5)]?>,<?=rand(1, 1 * $level)?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][rand(0,5)]?>,<?=rand(1, 1 * $level)?>
<?}?>
c:\php>php.exe abc.php startid=1 endid=3 level=5
[item]
id=1
name=Flexible shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=5
price=607
dmg=ranged,0,14
requires_stat=offense,18
requires_stat=physical,8
bonus=mental,1
bonus=defense,4
quality=magic
[item]
id=2
name=Flexible shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=5
price=647
dmg=ranged,1,5
requires_stat=offense,18
requires_stat=physical,8
bonus=hp,2
bonus=mental,1
quality=magic
[item]
id=3
name=Goblin shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=5
price=411
dmg=ranged,2,12
requires_stat=offense,18
requires_stat=physical,8
bonus=mp,5
bonus=absorb_min,5
quality=magic
Well done, good to hear!Danimal {l Wrote}:Bzt, i finally got to it, this is the fully working base
Great, haven't popped into my mind because my IDE automatically removes spaces at the end of lines. But if it works, great!Danimal {l Wrote}:I solved the line break problem by chance, neither \n or \r\n worked, but it just needed an empty space after the line of code.
You're welcome, and if you have more questions, just shout! I hope this solution is flexible enough to satisfy all your needs.Danimal {l Wrote}:Thanks for your help, but don´t go too far, Im sure I´ll need you again.
Not entirely sure what you want to achieve, but yeah, you can do conditional values. Without diving into conditional control blocks like "if" and "switch", the simplest is to use the trinary operator. It looks like this:Danimal {l Wrote}:Hello again Bzt, now that my holidays are over i´ll restart working on my mod; but i need something else for the item generator. Is there a way to make a condition that checks when a certain bonus is randomly selected if it´s one of a few (hp, mp or hp_regen, mp_regen) it´s multiplied by some value before output?;
(expression ? true value : false value)
I guess that could be something likeDanimal {l Wrote}:Lv 5 item -> bonus=mp,5 ; which is basically useless at that level, so it would need to be multiplied with a rand(3,7).
bonus=mp,<?=5 * ($level > 5 ? 1 : rand(3,7))?>
Yes, but you have to store those randomly generated values into variables first so that you can later reference them. Probably the best place for that is inside the first <??> block. For example:Danimal {l Wrote}:Equally, I would like a more inteligent name generator, is there a way to check the first two randomly generated bonus and give an according name?
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){ // note, ?> moved down
$bonus1 = rand(1,5); // save the random value into a variable
?>
bonus=mp,<?=$bonus1?>
name=<?=($bonus1 < 3 ? "Simple" : "Gigamega")?> Shortbow
...
$bonus1 = rand(1,5);
$names = [ "", "Simple", "Average", "Cool", "Super", "Gigamega" ]; // note, array index starts at 0, hence the first empty string
?>
bonus=mp,<?=$bonus1?>
name=<?=$names[$bonus1]?> Shortbow
...
$names = [ "", "", "", "", "Super ", "Gigamega " ]; // note space added at the end here and not below
?>
name=<?=$names[$bonus1]?>Shortbow
Could be, but I think your approach is also good. Knowing the numerical value first helps to write simpler expressions, and you can also use a numerical value as an array index.Danimal {l Wrote}:I think this is done the reverse way in games and the name determinates the bonus?
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
[item]
id=<?=$id?>
name=<?=["Goblin","Hunter","Poacher","Metal","Flexible"][rand(0,4)]?> shortbow
INCLUDE items/base/weapons/ranged/shortbow.txt
level=<?=$level?>
price=<?=rand(75 * $level, 150 * $level)?>
dmg=ranged,<?=rand(0, 1 * $level)?>,<?=rand(1 * $level, 3 * $level)?>
requires_stat=offense,<?=ceil($level * 5 * 0.7)?>
requires_stat=physical,<?=ceil($level * 5 * 0.3)?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][rand(0,5)]?>,<?=rand(1, 1 * $level)?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][rand(0,5)]?>,<?=rand(1, 1 * $level)?>
<?}?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][rand(0,5)]?>,<?=rand(1, 1 * $level)?>
bonus=hp,2
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
[item]
id=<?=$id?>
INCLUDE items/base/weapons/ranged/shortbow.txt
level=<?=$level?>
price=<?=rand(75 * $level, 150 * $level)?>
dmg=ranged,<?=rand(0, 1 * $level)?>,<?=rand(1 * $level, 3 * $level)?>
requires_stat=offense,<?=ceil($level * 5 * 0.7)?>
requires_stat=physical,<?=ceil($level * 5 * 0.3)?> [b]#Up to this point same as before[/b]
# Variables declaration, i guess this goes right after header and not here?
$traits #stores how many bonus traits the item will have, needs to take it from console input
$name #empty name variable
$adj1 #empty name variable
$adj2 #empty name variable
$bonus #empty variable for bonus type
$rand_value # empty variable to store a random numerical value to be used along bonus
$i #for the loop control
i= 1 #not starting from 0
while i =! $traits, do #controls how many times the loops runs based on numbers of desired item traits
{
$bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][rand(0,5)]?> #decides type of bonus randomly and stores it
$rand_value= <?=rand(1, 1 * $level)?> #generates the random numerical value bonus will use and stores it
switch (bonus) {
case offense:
bonus=<?="offense",<?=rand_value #prints the line for the game item, output ex. "bonus=offense,5"
if i=1 and i<3 #this one makes it so the object only has 2 adjectives + item name, it checks if it´s the first or second adjective and allows no more
if rand_value >= 100 #this one checks the numerical value and adds a word to the adjective
{
adj1= "Titan power"
} else if rand_value >=80
adj1= "Giant power"
} else if rand_value >=60
adj1= "Ogre power"
} else if rand_value >=40
adj1= "Bull power"
} else if rand_value >=20
adj1= "Boar power"
} else if rand_value >=10
adj1= "Wolf power"
elseif i=2 and i<3 #if first adjective is taken fills the second adjective variable which is shorter/different to the first
if rand_value >= 100
{
adj2= "Titan"
} else if rand_value >=80
adj2= "Giant"
} else if rand_value >=60
adj2= "Ogre"
} else if rand_value >=40
adj2= "Bull"
} else if rand_value >=20
adj2= "Boar"
} else if rand_value >=10
adj2= "Wolf"
break;
case hp:
bonus=<?="hp", rand_value * rand(3,7) #prints the line for the game item, output ex. "bonus=hp,21"; this and the previous case are what I need to expand by myself the switch loop
................ same adjective process as before
break;
case defense:
................ same as before until all cases are covered
break;
} #end of switch loop
} #end of i controled loop
name = ?>adj1 ?>"shortbow of the" ?>?>adj2 #prints the name using the adjectives variables, ex. "Bull power shortbow of the ranger"
if $traits >= 5 #based on the number of traits print rarity
quality=Unique
elseif $traits <= 3
quality=Rare
elseif $traits <= 2
quality=Magic
}
As I've said, if you want to reference a value later, then just put it in a variable. For example,Danimal {l Wrote}:a condition checks if the bonus type is "hp", "mp" (or any other I´ll add in the future);
...
$bonustype = rand(0, 5);
?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][$bonustype]?>,<?=rand(1, 1 * $level)?>
For example:Danimal {l Wrote}:2 extra hp or mp is useless on a lv5 item, so the condition would check first if any of those bonus types have been output (hp, mp...) leaving the other types untouched(mental, defense...) but if hp, mp... are detected the numerical value (bonus=hp,2) is multiplied with random value of 3 to 7, so "2 * rand(3,7)" it would then print something like "bonus=hp,8" (2*4).
...
$bonustype = rand(0, 5);
?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][$bonustype]?>,<?=rand(1, $level) * ($bonustype < 2 ? rand(3, 7) : 1)?>
...
$bonustype = rand(0, 5);
?>
bonus=<?=["hp","mp","mental","offense","defense","absorb_min"][$bonustype]?>,<?=rand(1, $level) * ($bonustype == 0 || $bonustype == 1 ? rand(3, 7) : 1)?>
That depends how many kind of output you want. If two different kind is enough, then trinary or "if" block is the best (here you can count an empty output as one option). Looks like this:Danimal {l Wrote}:From what little I remember about programming a switch would be best?
<? if(expression) { ?>
things to output if expression is true
<? } else { ?>
things to output if expression is false
<? } ?>
<? if(expression) { ?>
things to output if expression is true
<? } ?>
<? switch(expression) {
case (v1): ?>things to print if value is v1
<? case (v2): ?>things to print if value is v2
<? case (v3): ?>things to print if value is v3
<? case (v4): ?>things to print if value is v4
<?
...
} ?>
I don't know if this is more readable, or nicer looking, but definitely a solution and useful if you want different output per the expression's value. For example:Danimal {l Wrote}:Then no doubt more complex but nicer looking, the names could be generated by expanding the switch loop to house all possible bonus types.
<? switch($bonustype) {
case 0: ?>bonus=hp,<?=rand(1,2)?>
<? case 1: ?>bonus=mp,<?=rand(3,4)?>
<? case 2: ?>bonus=mental,<?=rand(5,6)?>
<? case 3: ?>bonus=defense,<?=rand(7,8)?>
<? } ?>
Yes. Go to the end of the first line, go back two characters and press an Enter. SoDanimal {l Wrote}:Variables declaration, i guess this goes right after header and not here?
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){
?>
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){
$bonustype = rand(3,7); // here comes a variable definition.
?>
For that, no need to define a variable, just add "traits=N" on the command line, and the $traits variable will be created for you.Danimal {l Wrote}:$traits #stores how many bonus traits the item will have, needs to take it from console input
for($i = 1; $i <= $traits; $i++) { // iterate traits time, $i will be 1 .. $traits
$bonus=["hp","mp","mental","offense","defense","absorb_min"][rand(0,5)]; // no need for <??> here, you're not in output mode
$rand_value= rand(1, 1 * $level);
switch ($bonus) {
case "offense": // $bonus is a string, so you need to use quotes here
?>bonus=offense,<?=rand_value?>
<? // use ?>things to print<?, and newline might be important here as you need that in the output too
if i=1 and i<3
if ($i == 1 && $i < 3) {
Don't worry, and I hope I could help. A few rules to keep in mind:Danimal {l Wrote}:Im sorry if it made your eyes bleed, but this the best i can express what want it to be.
if i=1 and i<3
if rand_value >= 100 #this one checks the numerical value and adds a word to the adjective
{
adj1= "Titan power"
} else if rand_value >=80
adj1= "Giant power"
} else if rand_value >=60
adj1= "Ogre power"
} else if rand_value >=40
adj1= "Bull power"
} else if rand_value >=20
adj1= "Boar power"
} else if rand_value >=10
adj1= "Wolf power"
<? if ($i == 1 && rand_value >= 100) { ?>
adj1= "Titan power"
<? } ?>
<? if ($i == 1 && rand_value >= 80) { ?>
adj1= "Giant power"
<?...
if ($i == 1) {
if ($rand_value >= 100) {
$adj1 = "Titan power";
} else if ($rand_value >= 80) {
$adj1 = "Giant power";
} else if ($rand_value >= 60) {
...
}
}
?>
$rand_index = intval($rand_value / 20);
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){
$name = "Shortbow";
$adj1 = "";
$adj2 = "";
$bonus = "";
$rand_value = "";
$i = 1;
?>
[item]
id=<?=$id?>
INCLUDE items/base/weapons/ranged/shortbow.txt
level=<?=$level?>
price=<?=rand($level * 100, $level * 100 * ($traits * 0.1 + 1))?>
for ($i = 1; $i <= $traits; $i++) {
i=<?=$i?>
}
name= <?=$name?> <?=$adj1?>
<?}?>
c:\php>php.exe 123.php startid=1 endid=1 level=2 traits=6
[item]
id=1
INCLUDE items/base/weapons/ranged/shortbow.txt
level=2
price=269
for ($i = 1; $i <= $traits; $i++) {
i=1}
name= Shortbow
Yes, you have to put it in that <??> because you want it to be executed and not printed.Danimal {l Wrote}:Edit: got it to work inside of <?php....?>; but its the only way?
Creating arrays is simple, you've done it before, just wrap the "," comma separated data in "[" and "]". For exampleDanimal {l Wrote}:this forces me to either create more variables to hold all information output of FOR or creating an array to do so, which is clearly a better choice since it can dinamically adjust its size opposed to having a fixed amount of variables which may come short. The problem is I have no fugging idea of how to do it; neither creation nor accesing later to it´s data to be printed.
$intarray = [ 1, 1, 2, 3, 5, 8, 13 ];
$strarray = [ "zero", "one", "two", "three" ];
<?=$intarray[0]?>
<?=$strarray[2]?>
foreach( $strarray as $element ) {
...
}
foreach( [ "zero", "one", "two", "three" ] as $numstr ) {
...
}
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){
$name = "Shortbow";
$adj1 = "";
$adj2 = "";
$bonus = "";
$rand_value;
$i;
$mult_value;
$bonus_array= [""];
for ($i = 1; $i <= $traits; $i++)
{
$bonus=["hp","offense"][rand(0,1)];
$rand_value= rand(1, 1 * $level);
$bonus_array[$i] = "bonus=$bonus,$rand_value";
switch ($bonus)
{
case "hp":
$mult_value = $rand_value * rand(3,7);
$bonus_array[$i] = "bonus=$bonus,$mult_value";
if ($i == 1)
{
if ($rand_value >= 100) {$adj1 = "Holy aegis";
} else if ($rand_value >= 80) {$adj1 = "Dragon scale";
} else if ($rand_value <= 60) {$adj1 = "Stone skin";}
}
if ($i == 2)
{
if ($rand_value >= 100) {$adj2 = "god";
} else if ($rand_value >= 80) {$adj2 = "dragon";
} else if ($rand_value <= 60) {$adj2 = "golem";}
}
break;
case "offense":
if ($i == 1)
{
if ($rand_value >= 100) {$adj1 = "Titan power";
} else if ($rand_value >= 80) {$adj1 = "Giant power";
} else if ($rand_value <= 60) {$adj1 = "Bull power";}
}
if ($i == 2)
{
if ($rand_value >= 100) {$adj1 = "Titan";
} else if ($rand_value >= 80) {$adj2 = "Giant";
} else if ($rand_value <= 60) {$adj2 = "Bull";}
}
break;
}
}
?>
[item]
id=<?=$id?>
<?if ($traits >= 5) {?>name=<?=["Legendary","Epic","Godly","Mythic","Ancient","Supreme"][rand(0,5)]?> <?=$adj1?> <?=$name?> of the <?=$adj2?> <?;
} else if ($traits >= 3) {?>name=<?=$adj1?> <?=$name?> of the <?=$adj2?><?;
} else if ($traits >= 1) {?>name=<?=$adj1?> <?=$name?> <?;
} else if ($traits == 0) {?>name=<?=$name?> <?;}
?>
INCLUDE items/base/weapons/ranged/shortbow.txt
level=<?=$level?>
price=<?=rand($level * 100, $level * 100 * ($traits * 0.1 + 1))?>
dmg=ranged,<?=rand(1, 1 * $level)?>,<?=rand(1 * $level, 3 * $level)?>
requires_stat=offense,<?=ceil($level * 5 * 0.7)?>
requires_stat=physical,<?=ceil($level * 5 * 0.3)?>
<? foreach( $bonus_array as $x ) {echo "$x" . PHP_EOL . "";}?>
<?if ($traits >= 5) {?>quality=unique <?;
} else if ($traits >= 3) {?>quality=rare <?;
} else if ($traits >= 1) {?>quality=magic <?;
} else if ($traits == 0) {?>quality=common <?;}?>
<?}?>
c:\php>php.exe 123.php startid=1 endid=3 level=10 traits=4
[item]
id=1
name=Bull power Shortbow of the golem
INCLUDE items/base/weapons/ranged/shortbow.txt
level=10
price=1398
dmg=ranged,10,23
requires_stat=offense,35
requires_stat=physical,15
bonus=offense,8
bonus=hp,16
bonus=offense,5
bonus=hp,24
quality=rare
Nope, I think this is good. You could make it better of course, but I see no point in optimisation. You'll only run this once, so performance isn't an issue and I believe reflecting your logic behind the values in a way that you understand is much more important. Also put a lot of comments, so that if you put your game down and you pick it up a year later, you'll know what's going on.Danimal {l Wrote}:I still need to create all bonus/cases inside switch loop and many more adjectives (just the two basics included atm), so that section will grow a lot. What do you thing, can it be improved before starting that?
// $i is used to select X here
You can surpress the error message, but it doesn't really matter as it's printed to the stderr, not to stdout, therefore not included in the output. If this bothers you, add "error_reporting(0);" (but then you won't get any error message at all, not even the ones you should care about).Danimal {l Wrote}:but not declaring the first value creates error at foreach loop
You can use a classic for loop with "count($bonus_array)", which returns the number of elements. Something likeDanimal {l Wrote}:Is there a way to ignore it without creating a classic "for" loop?.
for($i = 1; $i < count($bonus_array); $i++)
Glad to hear! Well done! About the first element, you should only print if it's not empty (this way newline won't be printed either):Danimal {l Wrote}:Right now the output is totally viable, but I would like to erase that empty line corresponding to $bonus_array[0].
if( !empty($x) ) echo "$x" . PHP_EOL;
array_shift($bonus_array);
foreach( $bobus_array as $x ) { ...
Users browsing this forum: No registered users and 1 guest