• 🏆 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!

[Solved] ChatGPT tried to make a passive ability but failed miserably (vJass)

Level 3
Joined
Sep 9, 2019
Messages
15
For intro --- I have 0 knowledge of vJass. I tried to "make" a trigger for a passive ability. It has 1% to proc an attribute from 3 attributes. It can give +1 strength or +1 agility or +1 intelligence. The ability has 5 level ups in total. Level 1 = 1% proc, Level 2 = 2% proc, Level 3 = 3% proc, Level 4 = 4% proc, Level 5 = 5% proc. The ability can proc on any unit.
Now the ChatGPT made this:

JASS:
globals
    // Define the attributes
    private constant integer ATTRIBUTE_STRENGTH = 0
    private constant integer ATTRIBUTE_AGILITY = 1
    private constant integer ATTRIBUTE_INTELLIGENCE = 2

    // Define the proc chances for each level
    private constant real[] PROC_CHANCES = [0.01, 0.02, 0.03, 0.04, 0.05]

endglobals

private struct AttributeProc
    // Define the proc chances for each attribute at different levels
    private real[3] procChances
    
    // The function to calculate the proc chance for a specific attribute at a given level
    private static method real getProcChance(integer attribute, integer level) returns real
        return PROC_CHANCES[level - 1] * I2R((attribute + 1) * 100)
    endmethod

    // The function to determine which attribute is proc'd
    private static method integer getProcAttribute(integer level) returns integer
        local real roll = GetRandomReal(0.0, 1.0)
        local integer attribute = -1

        if roll <= getProcChance(ATTRIBUTE_STRENGTH, level) then
            set attribute = ATTRIBUTE_STRENGTH
        elseif roll <= getProcChance(ATTRIBUTE_AGILITY, level) then
            set attribute = ATTRIBUTE_AGILITY
        elseif roll <= getProcChance(ATTRIBUTE_INTELLIGENCE, level) then
            set attribute = ATTRIBUTE_INTELLIGENCE
        endif

        return attribute
    endmethod
endstruct

private function Trigger_PassiveAbilityProc takes nothing returns nothing
    local integer level = 1 // Change this to get the actual level of your passive ability
    local integer attribute = AttributeProc.getProcAttribute(level)

    if attribute == ATTRIBUTE_STRENGTH then
        // Give +1 strength
        call SetHeroStr(GetTriggerUnit(), GetHeroStr(GetTriggerUnit(), false) + 1, true)
    elseif attribute == ATTRIBUTE_AGILITY then
        // Give +1 agility
        call SetHeroAgi(GetTriggerUnit(), GetHeroAgi(GetTriggerUnit(), false) + 1, true)
    elseif attribute == ATTRIBUTE_INTELLIGENCE then
        // Give +1 intelligence
        call SetHeroInt(GetTriggerUnit(), GetHeroInt(GetTriggerUnit(), false) + 1, true)
    endif
endfunction

private function InitTrig_PassiveAbilityProc takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddAction(t, function Trigger_PassiveAbilityProc)
endfunction

//===========================================================================
// Initialization
//===========================================================================
private function InitCustomTriggers takes nothing returns nothing
    call InitTrig_PassiveAbilityProc()
endfunction

I think it has multiple errors. I'm not sure what can I do... Any help is appreciated <3
If you can repair this or do a GUI version. I will be grateful.
 
The spell description is unclear.
When should it proc? On hit taken? On attack hit? Before attack is "launched"? On Spell Cast? On Level up? On what?
What should happen? Gain +1 random stat (agi, str or int)?
It's a passive on a hero-ability, right?
Is there any cap to max-gained stats or stack infinitely?
Can multiple unit with this ability exist on the map?
 
Level 3
Joined
Sep 9, 2019
Messages
15
The spell description is unclear.
When should it proc? On hit taken? On attack hit? Before attack is "launched"? On Spell Cast? On Level up? On what?
What should happen? Gain +1 random stat (agi, str or int)?
It's a passive on a hero-ability, right?
Is there any cap to max-gained stats or stack infinitely?
Can multiple unit with this ability exist on the map?
Nice questions!
Well, let's see.
When should it proc? -- On hitting someone, ally or enemy.
What should happen? Gain +1 random stat (agi, str or int)? -- Yes, random stat.
It's a passive on a hero-ability, right? -- Yep, passive ability.
Is there any cap to max-gained stats or stack infinitely? -- Infinitely.
Can multiple unit with this ability exist on the map? -- Nope. Only one hero with this ability.
 
Level 27
Joined
Nov 25, 2021
Messages
480
I'm guessing this is fine enough, if you want your Hero to have a chance to proc this ability whenever they DECLARE an attack. If you only want them to have a chance to proc this ability when they deal damage with an attack, you'll have to use a Damage Detection System. Although, I think there's already a built-in DDS in 1.35 Editor, but I'm not familiar with that version, so I can't confirm.

  • Events
    • Unit - A unit Is attacked
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Level of YOUR_ABILITY for (Attacking unit)) Greater than 0
        • (Random integer number between 1 and 100) Less than or equal to (Level of YOUR_ABILITY for (Attacking unit))
      • Then - Actions
        • Set TempInt = (Random integer number between 1 and 3)
        • If (TempInt Equal to 1) then do (Hero - Create Tome of Strength and give it to (Attacking unit)) else do (Do nothing)
        • If (TempInt Equal to 2) then do (Hero - Create Tome of Agility and give it to (Attacking unit)) else do (Do nothing)
        • If (TempInt Equal to 3) then do (Hero - Create Tome of Intelligence and give it to (Attacking unit)) else do (Do nothing)
      • Else - Actions
  • Events
    • Unit - A unit Is attacked
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Level of YOUR_ABILITY for (Attacking unit)) Greater than 0
        • (Random integer number between 1 and 100) Less than or equal to (Level of YOUR_ABILITY for (Attacking unit))
      • Then - Actions
        • Set TempInt = (Random integer number between 1 and 3)
        • If (TempInt Equal to 1) then do (Custom script: call SetHeroStr(GetAttacker(), GetHeroStr(GetAttacker(), false) + 1, true) else do (Do nothing)
        • If (TempInt Equal to 2) then do (Custom script: call SetHeroAgi(GetAttacker(), GetHeroAgi(GetAttacker(), false) + 1, true) else do (Do nothing)
        • If (TempInt Equal to 3) then do (Custom script: call SetHeroInt(GetAttacker(), GetHeroInt(GetAttacker(), false) + 1, true) else do (Do nothing)
      • Else - Actions
 
Level 3
Joined
Sep 9, 2019
Messages
15
I'm guessing this is fine enough, if you want your Hero to have a chance to proc this ability whenever they DECLARE an attack. If you only want them to have a chance to proc this ability when they deal damage with an attack, you'll have to use a Damage Detection System. Although, I think there's already a built-in DDS in 1.35 Editor, but I'm not familiar with that version, so I can't confirm.

  • Events
    • Unit - A unit Is attacked
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Level of YOUR_ABILITY for (Attacking unit)) Greater than 0
        • (Random integer number between 1 and 100) Less than or equal to (Level of YOUR_ABILITY for (Attacking unit))
      • Then - Actions
        • Set TempInt = (Random integer number between 1 and 3)
        • If (TempInt Equal to 1) then do (Hero - Create Tome of Strength and give it to (Attacking unit)) else do (Do nothing)
        • If (TempInt Equal to 2) then do (Hero - Create Tome of Agility and give it to (Attacking unit)) else do (Do nothing)
        • If (TempInt Equal to 3) then do (Hero - Create Tome of Intelligence and give it to (Attacking unit)) else do (Do nothing)
      • Else - Actions
Thank you so much <3
Worked great!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
Replace:
  • Events
    • Unit - A unit is attacked
With:
  • Events
    • Unit - A unit Takes damage
Replace:
  • (Attacking unit)
With:
  • (Damage source)
Profit.

Also, this is still vague my friend!
When should it proc? -- On hitting someone, ally or enemy.
Please, use specific terms from the game, Warcraft 3 has a million ways to "hit someone".

Sorry to be so nitpicky but as of late we've been getting tons of questions that are just so vague. I want to help but I have like 3 different ideas of what you actually want. It's a help us help you sort of situation. I know when you're new to all of this you aren't as aware of this but just try to put yourselves in the shoes of a stranger who literally has zero idea of what you want and can't read your mind.
 
Top