#1  
Old 07-20-2017, 12:50 PM
sadbadmac's Avatar
sadbadmac sadbadmac is offline
Initiate
 
Join Date: Jul 2017
Location: Netherlands
Posts: 6
Default Generating a random number

FINAL EDIT: You need to change the value XXX in "goldAmountEquation,((generatorLevel*XXX)" to 100. That does the job.


How do you generate a random number between, lets say, 20-200? I know of math.random(20,200) but would that work inside of a .dbr file? Since the language is LUA it should work, right?

To give you a gist of what I'm trying to accomplish: I want the goldgenerator to drop at least XX amount of iron bits. I got that going (goldValueMin, XX,) but seeing the exact XX value everytime I break something, is immersion breaking. Too calculated, no RNGesus. So I want the object to drop at least XX amount of bits + a random XX amount on top of that.
e.g. 350 + math.random(20,200) = 435 Iron Bits
Obviously you would need to assign the "math.random" part a new name but would it work like this?

Code:
math.random(20,200) = ranInt
goldValueMin, 350 + ranInt,
I have basic coding knowledge but I'm still stupid... Do I need to create a new math.random function inside the goldgenerator.tpl first and then re-call that function inside the moneygenerator.dbr? If yes (I'm assuming you'd have to do that since a new function inside the .dbr without it being declared in the .tpl would just be ignored) what Type would it be? It should be Equation all things considered. And how would you call-up/use the function since if we look at the Equations for generating gold for multiple players - they calculate everything on the spot (I just noticed: what is generatorlevel? "goldAmountEquation, ((generatorLevel*.5)+15)*numberOfPlayers," the answer to all my questions?). What would be the correct syntax? A lot of questions but the ones about syntax and declaring/calling up the function are the most important ones.

I'd really appreciate it if someone could help or at least point to the documentation on those functions maybe x) tyvm

tl;dr: 1.) How do you create a new function in a .tpl
2.) How do you use that function in a .dbr
3.) How do you add/merge the generated number and the pre-set number together?

EDIT 1: Don't worry, I still didn't figure it out. But: merging the numbers is useless since IF math.random would work I could just set the values starting at 350 to a max Value of 750. Same result, less code. IF it would work...

Last edited by sadbadmac; 07-20-2017 at 04:33 PM.
Reply With Quote
  #2  
Old 07-20-2017, 02:24 PM
jiaco's Avatar
jiaco jiaco is offline
Super Moderator
 
Join Date: Jan 2010
Location: CET/CEST
Posts: 5,879
Default

Lua script needs to be in lua files in the sources.

To connect a dbr to lua, you need a dbr that has triggers, typically a ScriptEntity type. You do not want/need to be messing with templates at all as a modder.

You need to use a dbr that has a trigger (aka onAddToWorld or onPickup, etc...) and in that trigger space hook that dbr to a global lua function from your source/scripts.

This was not meant to get you all the way there. But just to get you to stop trying to put lua in the dbrs, it will not work. Lua is only used in lua scripts, which can be made accessible from dbrs with specific trigger fields that can link to the lua script.
__________________
Last edited by jiaco; Tomorrow at 11:34 PM.
Reply With Quote
  #3  
Old 07-20-2017, 02:35 PM
jiaco's Avatar
jiaco jiaco is offline
Super Moderator
 
Join Date: Jan 2010
Location: CET/CEST
Posts: 5,879
Default

Looking at what you actually want to do, methinks you should study the existing goldgenerator fields a bit more. Lua should not even be needed for this.
__________________
Last edited by jiaco; Tomorrow at 11:34 PM.
Reply With Quote
  #4  
Old 07-20-2017, 02:59 PM
Kathanious's Avatar
Kathanious Kathanious is offline
Herald
 
Join Date: Mar 2016
Location: Evansville, IN, USA
Posts: 1,220
Default

I'm curious, are you just trying to generate more gold, or are you putting your feet in the modding waters? Let us know if you want to swim...or drown
__________________
DAIL Curator - Self-proclaimed a$$, sloppy modder, village idiot.
Reply With Quote
  #5  
Old 07-20-2017, 03:00 PM
sadbadmac's Avatar
sadbadmac sadbadmac is offline
Initiate
 
Join Date: Jul 2017
Location: Netherlands
Posts: 6
Default

I understand. Thanks for stopping me from wasting even more time :v

I've found several script triggers by using the DBR Editor on the moneyobject.dbr. I'll try creating a lua script with the math.random method and hooking it up with the onDrop method. Theoretically speaking when something drops money it should trigger the math.random function and add whatever amount I defined in LUA to the dropped bits, right?

I'll be trying to figure that out for now

Cheers!
Reply With Quote
  #6  
Old 07-20-2017, 03:03 PM
sadbadmac's Avatar
sadbadmac sadbadmac is offline
Initiate
 
Join Date: Jul 2017
Location: Netherlands
Posts: 6
Default

Quote:
Originally Posted by Kathanious View Post
I'm curious, are you just trying to generate more gold, or are you putting your feet in the modding waters? Let us know if you want to swim...or drown
Both I guess? Can't really tell what counts as "modding" I'm just trying to increase the amount of iron bits. While I succeeded in increasing the dropped amounts of money I guess the real modding comes into play once I start using LUA and script my path to RNGesus... But yes I try to get into modding this game since it's a lot of fun since everything is so open source :3
Reply With Quote
  #7  
Old 07-20-2017, 03:16 PM
sadbadmac's Avatar
sadbadmac sadbadmac is offline
Initiate
 
Join Date: Jul 2017
Location: Netherlands
Posts: 6
Default

Quote:
Originally Posted by jiaco View Post
Looking at what you actually want to do, methinks you should study the existing goldgenerator fields a bit more. Lua should not even be needed for this.
I was thinking about that too... That's all I've been thinking about. There's just 7 lines that matter in the moneygenerator.dbr but I can't figure it out. Can I change the goldAmountEquation to do what I want?

Coming to think of it that actually sounds right... Knowing me: it isn't.

I'll give it a shot and write again once I had my mental breakdown and suffered from burn out
Reply With Quote
  #8  
Old 07-20-2017, 03:29 PM
jiaco's Avatar
jiaco jiaco is offline
Super Moderator
 
Join Date: Jan 2010
Location: CET/CEST
Posts: 5,879
Default

goldValueMin 350
goldValueMax 550

?
__________________
Last edited by jiaco; Tomorrow at 11:34 PM.
Reply With Quote
  #9  
Old 07-20-2017, 03:32 PM
mamba's Avatar
mamba mamba is offline
Praetorian
 
Join Date: Mar 2010
Posts: 9,636
Default

Quote:
Originally Posted by sadbadmac View Post
How do you generate a random number between, lets say, 20-200? I know of math.random(20,200) but would that work inside of a .dbr file? Since the language is LUA it should work, right?
as mentioned, no it would have to be in a lua script, not the dbr/tpl file

Quote:
To give you a gist of what I'm trying to accomplish: I want the goldgenerator to drop at least XX amount of iron bits. I got that going (goldValueMin, XX,) but seeing the exact XX value everytime I break something, is immersion breaking. Too calculated, no RNGesus.
RNG determined the exact amount, it just does not force you to keep track of your total to figure out how much you picked up
Reply With Quote
  #10  
Old 07-20-2017, 03:38 PM
sadbadmac's Avatar
sadbadmac sadbadmac is offline
Initiate
 
Join Date: Jul 2017
Location: Netherlands
Posts: 6
Default

Quote:
Originally Posted by jiaco View Post
goldValueMin 350
goldValueMax 550

?
I already have that in my code. This:

Code:
goldValueMin,450,
goldValueMax,3500,
goldSplitMin,1,
goldSplitMax,3,
goldSplitSizeMin,125,
I just don't see a lot of alteration. Its usually just 450 Iron Bits (or split up into stacks that add up to 450) lying around. What I want is 463, 564, 704 etc. Or is it already doing that by finding a value between goldValuMin/Max and I'm simply not noticing it?

EDIT: Does the gap need to be smaller?
EDIT2: Nope, smaller gap doesn't give me values between 450 and 500, just 450.
EDIT3: Okay, now I managed to only get 3500 and I think I know why: the values inside of goldAmountEquation, the numbers that get multiplied with generatorLevel, define the chances of one getting 450 or 3500. Needs further research though. I used values over 100 so that should explain why I was only getting 3.5k drops.
EDIT4: Yay! Success! I have different amounts dropping now. Ranging from 450 to 3500 and everything in between. Kudos jiaco, generatorLevel seemed to be the important part!

Last edited by sadbadmac; 07-20-2017 at 04:12 PM.
Reply With Quote
Reply

Tags
coding, generator, modding, question, solved

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Grim Dawn ©2017 Crate Entertainment, LLC.
vBulletin® 3.8.4 ©2000-2014, Jelsoft Enterprises Ltd.