Need volunteer to create simple item generator for Flare

Need volunteer to create simple item generator for Flare

Postby Danimal » 25 Jun 2021, 18:03

Hello everyone, im developing a mod for Flare:
https://forum.freegamedev.net/viewtopic ... 22&t=14397

The biggest headache of it all is item creation. Every single item must be created by hand, numbered, named and given its properties. Its pure hell, and its pretty obvious ingame with items repeating a lot, sadly the engine doesnt have nor will have in the short future a random item generator. But it can be given a fake sense of randomness with lots of pre-created items; i tried making one but failed miserably, at the very least i got a mock-up of what i wanted.

If someone is interested in helping, it should be relatively easy for someone who knows programming, only requeriment is that it must run on Windows, ill fill on the details anyone interested.
Attachments
Captura de pantalla 2021-06-25 19.01.59.png
User avatar
Danimal
OD Moderator
 
Posts: 1389
Joined: 23 Nov 2010, 13:50

Re: Need volunteer to create simple item generator for Flare

Postby bzt » 25 Jun 2021, 20:34

Here you go. This is an extremely simple, GPL-licensed, Open Source templater to generate random items for flare. Precompiled binaries for Linux and Windows included in the zip.

This is a command line tool, so invoke it from "cmd.exe". Has three arguments: a json file, a starting id, and a last id. It will use the field definitions in the json to generate the items to stdout, which you can redirect to a file or append to items.txt. Basically you want to create as many json files as many item types you want. There's no restriction, you're absolutely free to create these as you like. Documentation included with an example json of course.

Cheers,
bzt
Attachments
flaregen.zip
(104.15 KiB) Downloaded 11 times
User avatar
bzt
 
Posts: 71
Joined: 23 May 2021, 21:46

Re: Need volunteer to create simple item generator for Flare

Postby Danimal » 26 Jun 2021, 18:19

Hello BZT, even thought its a nice basic generator is too limited.

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.

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:

{l Code}: {l Select All Code}
[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
...


5*2 = 10 -> 70% =7
5*2 = 10 -> 30% =3
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

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. And would get dumped into the body of every item created (say, i started creating chitin armor sets) i just put the declaration in there so every item gets it along with requeriments or any thing i add in there:

INCLUDE items/base/armor/chitin_light/chest.txt

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).

So after that, the quality button needs to be pressed with common being the default. What does it do? upon generation time it picks from a list of magical properties (cant repeat same property twice, Flare cant do that, common has no magical properties, its just the base item) as many times as quality allows (2,3,5), the property X variable gets replaced by the number generated depending on item level and gain ratio like the weapons. Also adds quality tag: quality=magic; quality=rare; quality=unique.

Ideally it would also contain a box for item basic name, if any of the magicals is selected, its get and abjective by ramdon from a list ("Short sword" "of carnage". Also a price box with min and max values, ideally ,it would get multiplied if quality is superior to common x1.20,x1.30,x1.50.
I would provide all needed lists with names, extra properties...

Sadly if its not this complex, its not useful.
User avatar
Danimal
OD Moderator
 
Posts: 1389
Joined: 23 Nov 2010, 13:50

Re: Need volunteer to create simple item generator for Flare

Postby bzt » 26 Jun 2021, 23:06

Danimal {l Wrote}:Hello BZT, even thought its a nice basic generator is too limited.
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}: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.
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}: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:
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}: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
You should have a json with
{l Code}: {l Select All Code}
"name": "requires_stat", "value": "offense,7"
"name": "requires_stat", "value": "physical,3"
Since you're using only 4 percentages, there are not so many combinations. But if I were you, I'd use an INCLUDE for each combination, that would simplify your items greatly.

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.
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}: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).
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.

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"
This works too.

As I've said, you have complete freedom how you create those jsons and what fields you define in them, flaregen makes no assumptions and does not tie your hands.



If you want more complex things like fields depending on each other and have calulcated values for example, then I'd recommend to pick a scripting language and use that script as a template. My pick would be php, because in CLI mode it runs out-of-the-box under Windows and Linux too, easy to install, simple to use (no need to install Apache for the CLI php) and has templater capabilities. For example:
{l Code}: {l Select All Code}
<?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?>
As you see, here "dmg" has calculated values which depend on the level for example. Random goes like this:
{l Code}: {l Select All Code}
price=<?=rand(100, 500)?>
You could also add conditional blocks.
{l Code}: {l Select All Code}
<? if($off >= 3) { ?>
requires_stat=offense,<?=$off?>
<? } ?>

But php would be just my choice, feel free to use any scripting language, I'm sure all of them can print strings and calculated values. For example python would work as well.

Cheers,
bzt
User avatar
bzt
 
Posts: 71
Joined: 23 May 2021, 21:46

Re: Need volunteer to create simple item generator for Flare

Postby Danimal » 27 Jun 2021, 18:35

Thanks, but the thing is i cant code for my life... :cry:
Ill try to chew this slowly
User avatar
Danimal
OD Moderator
 
Posts: 1389
Joined: 23 Nov 2010, 13:50

Re: Need volunteer to create simple item generator for Flare

Postby bzt » 27 Jun 2021, 23:53

Danimal {l Wrote}:Thanks, but the thing is i cant code for my life... :cry:
Ill try to chew this slowly
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.

But I've come up with an even better solution for you. Just copy'n'paste this one liner to the start of your template:
{l Code}: {l Select All Code}
<?php foreach($_SERVER['argv'] as $k=>$v)if($k>0){$a=explode("=",$v)[0];$$a=explode("=",$v)[1];}for($id=$startid;$id<=$endid;$id++){?>
and end it with
{l Code}: {l Select All Code}
<?}?>
Don't try to understand this, don't let it frighten you. Think of it as a one line magic. What this does is allowing you to specify variables directly from the command line.

For example (everything between the first and the last line are freely modifiable by you):
{l Code}: {l Select All Code}
<?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

<?}?>

Now you can generate items with it like this:
{l Code}: {l Select All Code}
php.exe template.php startid=287 endid=299 level=2
As you see, the first two arguments needed to execute the interpreter and name the template file. Everything else are variable=value pairs. You always must specify "startid" and "endid" and you can always refer to the actual id with "$id", but the rest depends on what variables you were using in the template. In this little example the one and only variable referenced was "$level", so you must give a value to it (otherwise you'll get a php warning) on the command line, in this example "level=2". Note: I've added an empty line at the end so that in the output the items will be separated, not needed, just for visibility.

This might seem a bit complex at first, but it is not. I'm doing it this way because I don't want to tell you what variables and fields to use for your items. I want to give you the freedom to create your templates as you like, and to modify them later as you need. You can create as many templates as you want with this method, just make sure that all starts with that one-liner and ends in "<?}?>".

Cheers,
bzt
User avatar
bzt
 
Posts: 71
Joined: 23 May 2021, 21:46

Re: Need volunteer to create simple item generator for Flare

Postby Danimal » 29 Jun 2021, 12:51

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:

<?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,<?=rand(0, 1 * $level)?>, <?=rand(1 * $level, 3 * $level)?> (for min-max damage random values )
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
requires_stat=physical,<?=$level *= 5 *= 30 /= 100?>

<?}?>

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? 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:

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"


Would it be better to try php?
User avatar
Danimal
OD Moderator
 
Posts: 1389
Joined: 23 Nov 2010, 13:50

Re: Need volunteer to create simple item generator for Flare

Postby bzt » 29 Jun 2021, 18:20

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:
Yes, you got that right!

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
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}: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?
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}: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:
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.
{l Code}: {l Select All Code}
name=<?=["Short","Long","Recursive","Asymmetric","Mongol"][rand(0,4)]?>bow


Danimal {l Wrote}:Would it be better to try php?
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).

Cheers,
bzt
User avatar
bzt
 
Posts: 71
Joined: 23 May 2021, 21:46

Re: Need volunteer to create simple item generator for Flare

Postby Danimal » 15 Jul 2021, 12:14

Bzt, i just downloaded a windows version pf php:
https://www.php.net/downloads.php

Running php.exe give me that screen. How do i go at creating the teamplater with the code you gave me? and calling it?.

Sorry for taking so long but where i live its too hot and im having constant brainmelts.
Attachments
php.png
User avatar
Danimal
OD Moderator
 
Posts: 1389
Joined: 23 Nov 2010, 13:50

Re: Need volunteer to create simple item generator for Flare

Postby bzt » 16 Jul 2021, 13:35

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?.
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:
{l Code}: {l Select All Code}
php.exe abc.php startid=10 endid=11 level=2
First is the name of the interpreter (php.exe in this case), then comes the name of the script (abc.php in this case), and all the other arguments are parsed by the script, and therefore depend on the script (in this case the start and end ids and the values for variables defined by the template).

Tips and tricks: you can simply redirect the output to a text file:
{l Code}: {l Select All Code}
php.exe abc.php startid=10 endid=11 level=2 >items.txt
and it might be possible that you might need double newlines, I'm not sure how the Win php version handles these as it's using "\r\n" for line endings, not "\n" like Linux.
So if the redirected txt doesn't have line breaks, then just double the newlines in the php file, like this:
{l Code}: {l Select All Code}
<?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


<?}?>
Once you got one php right, the door is open, you can alter that or copy and modify for a new template. You can modify the template as you like, use any fields, any expressions, any string lists etc. If you have any question, just shoot, I'll try to answer.

Danimal {l Wrote}:Sorry for taking so long but where i live its too hot and im having constant brainmelts.
Have no worries, it's the same here. We have no air conditioner.

Cheers,
bzt
User avatar
bzt
 
Posts: 71
Joined: 23 May 2021, 21:46

Re: Need volunteer to create simple item generator for Flare

Postby jdc » Today, 11:40

The code is not that hard, but you need to practice:

Need knowledge in the interface how is done. (don't have)
The code it self is easy.

let say is in C and in the console try getting codeblocks.

first you need to know what is for. To generate new items or from existing ones? I assume existing:

Get the list of items, lets also assume to variances (level and rarity) . in what level we are if we can get it in current level and second how rare.

need a loop

exit = 0;
while (not equal to 1) { ( (1 in computers is true)

check for level
check for rarity

if want the user to input values

scanf(option1)
scanf(option2)
scanf(option3)

if option 1(item_name){

}

if option 1(item_name){

}

- also try checking "the box" project in standard variables

}


if is just to add items usely this stuff should be in some kind of bidings for Lua, Python or even PHP as some mention. It should be in some kind of text file.

item name
item level
item min damage
item max damage
item rarity
...

It should allow to add information

item name new item
item level 4
item min damage 2
item max damage 10
item rarity 5
jdc
 
Posts: 118
Joined: 29 Jun 2017, 16:48

Re: Need volunteer to create simple item generator for Flare

Postby bzt » 42 minutes ago

@jdc: I literally have absolutely no clue what you are talking about.

First, about compiled languages: the OP doesn't want to learn programming. I wrote a little C tool to create object definitions from JSON files. It works, but the problem with that is that the OP wants variables and calculated values. For that, the only option would be a scripting language. I've suggested PHP because it runs under Windows and it works as a templater by default.

The difference to learning a programming language is this: with my last suggested solution, the OP should create object definition templates, with a special first and last line (that part contains the "magic", minimal addition to the object template). It supports variables (values provided from command line), and calculated values as well (expressions in the template). So all the "programming" is limited to the first and last line in the template, which is just copied verbatim as-is. With expressions only basic arithmetic needed, no complex programming skills required at all.

Second, codeblocks is an IDE, absolutely irrelevant and independent to the language used.

Cheers,
bzt
User avatar
bzt
 
Posts: 71
Joined: 23 May 2021, 21:46

Who is online

Users browsing this forum: No registered users and 1 guest

cron