Integer Attribute Question (Postponed/Solved)

I was just curious if it's possible to set a basic integer attribute to have a chance based use. Would that be a changescript or can it be manipulated in code-view? For example...

2 < chance >= 7
8 < chance >= 16

and so on :)


What exactly do you mean by "chance based value"? As in you want your attribute to be a random value within a range?

If you want the attribute itself to be set at random you'll have to use a script of some sort as far as I'm aware


What you are looking for (I believe) is:
GetRandomInt(1,6)
a random number between 1 and 6
IE: chance=GetRandomInt(2,7)
and chance=GetRandomInt(8,16)
Or, for 2 dice: chance=GetRandomInt(1,7) + chance=GetRandomInt(1,6)


I too am not sure what anonynn was/is asking for, sighs


the ' RandomChance' Function returns a boolean value, so it has nothing to do with any type of number usage mechanic/formula you might want.

for a range of integer values, there's two built-in Functions:

  1. GetRandomInt (MIN_VALUE, MAX_VALUE)

  2. DiceRoll ("NUMBER_OF_DICEdNUMBER_OF_SIDES_PER_DICE")

a normal 6-sided single dice ("1d6") has this range: 1-6
a single 100-sided dice ("1d100") has this range: 1-100
two 6-sided dice ("2d6") has this range: 2-12
three 6-sided dice ("3d6") has this range: 3-18

the minumum value is always 1xNUMBER_OF_DICE
the maximum value is is always NUMBER_OF_SIDESxNUMBER_OF_DICE

for both of these two built-in Functions, we don't know the actual formula/equation/mechanic involved for selecting the possible values (unless it's made public for us, somewhere)


and there's for Doubles (decimal numbers/floats/floating points):

GetRandomDouble ()

no parameter as it "randomly" selects a value in this range: 0.0-1.0 (excluding 0.0 and 1.0)

we also don't know the actual formula/equation/mechanic involved for selecting the possible values (unless it's made public for us, somewhere)


did you maybe want something like this?

if (RandomChance (90)) {
  integer_variable = GetRandomInt (2,7)
} else if (RandomChance (80)) {
  integer_variable = GetRandomInt (8,16)
}

As others have said, GetRandomInt is probably what you want, but there is also DiceRoll, which you can use use like this:

damage = DiceRoll("3d8")

So, would that be a "string type" then?

In my original question, I meant this, for example...

Weapon: Lasso Of The Dead
Attribute
damage INT 3

And I was thinking a "dice roll" or "random int" might be a better then a plain INT. So my question (which I didn't state very well, sorry about that!) was how would I make it a dice roll/random int chance?

Anonynn.


Then DiceRoll might be what you are looking for, as the damage could be a string. say "3d6", then you use DiceRoll to convert that to the actual random damage on a hit. That is how I should have done it in Deeper.


DiceRoll and GetRandomInt, both return an integer value, but if you want it to be a string, you can then convert that integer value into a string value

integer_variable = DiceRoll ("1d6")
string_variable = ToString (integer_value)

or as single line:

string_variable = ToString (DiceRoll ("1d6"))

the same with using GetRandomInt


combat scripting:

player.damage = DiceRoll ("3d6")
orc.life = orc.life - player.damage

or

player.damage = GetRandomInt (33, 67)
orc.life = orc.life - player.damage

or (using DiceRoll, but can use GetRandomInt too):

player.weapon.damage = 3
player.damage = player.weapon.damage + DiceRoll ("3d6") // or multiplication: player.weapon.damage * DiceRoll // or whatever other operation (division, subtraction, modulus, etc)
orc.life = orc.life - player.damage


or did you want something like this? just an example to show what is going on with it, you'd use it differently of course:

integer_variable = DiceRoll ("3d6")
boolean_variable = RandomChance (integer_variable)

or

integer_variable = GetRandomInt (33, 67)
boolean_variable = RandomChance (integer_variable)


That's the part I'm confused about. I don't know how to get the Integer to = DiceRoll ("3d6") since it only displays a number.


the Integer Attribute's value can't be directly set to an action/Function (GetRandomInt/DiceRoll):

'whatever' Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

(Object Name: whatever)
Attribute Name: whatever
Attribute Type: whatever
Attribute Value: (it's impossible for this to use an action/function, GetRandomInt/DiceRoll, to get a random value here directly)

so, you've got to use an action/scripting (function/verb/command/turnscript/etc) to do so, for example:

<game name="xxx">
  <attr name="start" type="script">
    player.damage_modifier = DiceRoll ("3d16")
  </attr>
</game>

<object name"room">
</object>

<object name="player">
  <attr name="parent" type="object">room</attr>
  <attr name="damage_modifier" type="int">0</attr>
</object>

as for how to do it via the GUI/Editor's 'add new script' script options/scripting, for examples:

set variable player.damage_modifier = [EXPRESSION] DiceRoll ("3d6")
or
set variable player.damage_modifier = [EXPRESSION] GetRandomInt (33, 67)


or if you want to do something like this:

<game name="xxx">
  <attr name="start" type="script">
    player.damage_modifier = DiceRoll ("3d16")
  </attr>
</game>

<object name"room">
</object>

<object name="player">
  <attr name="parent" type="object">room</attr>
  <attr name="damage_modifier" type="int">0</attr>
  <attr name="damage" type="int">1</attr>
  <attr name="weapon" type="object">unarmed</attr>
  <attr name="changedweapon" type="script">
    player.damage = player.weapon.damage + player.damage_modifier
  </attr>
</object>

<object name="unarmed">
  <attr name="damage" type="int">1</attr>
</object>

<object name="sword">
  <attr name="damage" type="int">10</attr>
</object>

Yeah, that's one of the problems. I have a "Weapon Type" where all the damage is handled with the player being unarmed, which I don't want to change. The individual weapon objects have a damage attribute on them that add to the base value. I wanted to randomize the damage added on the weapon itself. So I'm confused ^_^


so, on your individual weapon Objects (or their Object Types) and/or in your combat scripting area, you need to change some of your damage scripting around, so you're including the value from the GetRandomInt/DiceRoll (or GetRandomDouble, if you want to use doubles/decimal numbers: this is actually a good Function as it gives a percentage value, for example: 300 damage + 300 damage x 0.3 from GetRandomDouble = 300 + 90 = 390 damage, and/or next time it might be: 300 damage + 300 damage x 0.9 from GetRandomDouble = 300 + 270 = 570 damage)

could you post your relevant code and tell us what you want for the mechanic/formula/equation involving the randomness to your weapon/damage setup and whether you want the randomness generated only once for the entire game (static: it doesn't change) or if you want it to be generated each time such as per attack or weapon switch or whatever (dynamic: it changes), then we can help you add in the randomness to it


Actually, all of that sounds a little too complicated. I figured it would be a simple tweak here and there. I don't have a lot of time for this update to go this in-depth with the weapon stuff. So maybe another time ^_^

I appreciate all the help guys! Thank you! And sorry about the issues.

Anonynn.


it won't be that complicated, we just need to see what you got set up, to be able to know where/how to add it in, along with you letting us know how/what you want from/with it, too.


Ah well for weapon damage specifically you don't necessarily need it to store it as an integer if you want to use the DiceRoll function. You can just store the string of its dice roll value, use that in the weapon description or wherever the player sees it's damage value, and just plug that in when you need it to deal the damage.

ie

//in the weapon object
damage = "2d6"

//in combat
playerdamage = DiceRoll(weapon.damage)

Since DiceRoll uses a string you can take a valid string attribute and just use it directly, which also has the upside of making the damage value of the weapon easier to display since it's already a string.

Alternatively for the GetRandomInt method you'd need two attributes on the weapon for its minimum and maximum damage.
ie

//in the weapon object
damagemin = 2
damagemax = 12

//in combat
playerdamage  = GetRandomInt (weapon.damagemin, weapon.damagemax)

Also if I'm understanding what you were saying above about base damage with weapon damage you can just use base damage as the minimum value and the weapon damage + base damage as the maximum value.


Hello TinFoil just made a simple command that does what I believe you are looking for.

IN Your weapon object make sure damage is a string and then add 2d6 without quates.

And actually should fix problem lol Because you're calling everything else correctly.

Hope it works !


Oh! I'll try it out and let you know asap. Thank you!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums