• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Question on how to do a simple formula

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
Alright I've been wracking my brain trying to figure out a proper formula to ease my coding problems. It's just general math, so I figured it could be put in this thread for analysis.

The game gets a random integer from 1 to 12.

When this spell is level 1, I want it to have a 50/50 chance of doing one effect or the other.

At level 2, it should split into 1/3 chance of doing 1 effect of two others. So a 100% chance of doing something, but only one of 3 things.

Finally at level 3, it should have a 1 in 4 chance, following the same principles as previous.

I figured 12 goes into 1 2 3 4 and 6, so it'd be the appropriate number to use.

The first part is set up great.

i < 12/1+lvl and i >= 0

At level one it's if the number is 6 or less, at level 2 if it's 4 or less, and level 2 if it's 3 or less.

6/6 = 12
4/4/4 = 12
3/3/3/3 = 12

Just like I want, but I can't figure out the equations for the rest. I can only calculate for the first part of it.
 
Level 9
Joined
May 28, 2007
Messages
365
integer chance = (GetAbilityLevel()+1)/2
integer effect = GetRandomInt(0, chance)

I'm still a little confused on what you want to be honest.

The unit has ability. The level of the ability + 1 is the number of effect that he can cast. You want an integer to return one of the effects?
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
I'll try your method, it seems like it should work.

Update: Your formula needed some adjustments. I didn't need to divide by 2 because at level 2 it would be a 2/3 chance, which is weird.

Instead I just made it a 0,GetUnitAbilityLevel() chance. if it lands on 0 it's lesser rune, 1 it's a mimic, 2 it's a regular rune and 3 it's a strong rune. I've modified the code to show the changes

Still incase, to clarify:

Well what I want is a formula so I don't have to make an if statement with sub-ifstatements for every level.

Instead I was hoping to acquire a formula that would allow me to do this.

If the player casts the spell at level 1, there's a 50% chance to create a rune or 50% chance to create a hostile mimic.

At level 2 there's a 1 in 3 chance to create a rune, 1 in 3 chance to create a stronger rune, or a 1 in 3 chance to create a mimic. So there's a 100% chance you're gonna create something.

At level 3 there's a 1 in 4 chance to create a rune, 1 in 4 chance to create a stronger rune, 1 in 4 chance to create the strongest rune, or a 1 in 4 chance to create a hostile mimic. So 100% chance to create something, and a 1 in 4 chance per item.

I'm stating this because I could do it like 40% chance to create X and 30% chance to create Y, but both items can be created in one instance of the spell.
Or I could do it like 40% for X, 30% for Y, and 30% to have nothing created, but you can't create X and Y in one instance of the spell.

I'm trying to achieve the latter, where only one thing can be created in a single instance of the spell.

Anyways, I've succeeded so here is my workaround :D

JASS:
function Transmute_Actions takes nothing returns nothing
 local unit c = GetTriggerUnit()
 
 local real X = GetSpellTargetX()
 local real Y = GetSpellTargetY()
 
 local integer lvl = (GetUnitAbilityLevel(c, 'tran')
 local integer i = GetRandomInt(0,lvl)
 
    if i = 0 then  //At level 1 i < 6, i < 4, i < 2
        call RemoveItem(GetSpellTargetItem())
        call CreateItem('A009', X, Y)
    elseif i = 1 then
        call RemoveItem(GetSpellTargetItem())
        call CreateUnit(Player(13), 'mimi', X, Y, 270)
        call UnitApplyTimedLife(c,'B000',20*lvl)
    elseif i = 2 then
        call RemoveItem(GetSpellTargetItem())
        call CreateItem('A009', X, Y)
    elseif i = 3 then
        call RemoveItem(GetSpellTargetItem())
        call CreateItem('A009', X, Y)
    endif
endfunction
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
EDIT: Oh, you figured it out?

  • Set Item_Array[1] = Claws of Attack +15
  • Set Item_Array[2] = Crown of Kings +5
  • Set Item_Array[3] = Kelen's Dagger of Escape
  • Set Item_Array[4] = Mask of Death
  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Holy Light
    • Actions
      • Set Temp_Integer_1 = (Level of (Ability being cast) for (Triggering unit))
      • Set Temp_Integer_2 = (Random integer number between 1 and (Temp_Integer_1 + 1))
      • Item - Create Item_Array[Temp_Integer_2] at (Random point in Region 000 <gen>)
At ability lvl 1 it randomizes between 1 and 2.
At ability lvl 2 it randomizes between 1, 2 and 3.
At ability lvl 3 it randomizes between 1, 2,3 and 4.
 
Status
Not open for further replies.
Top