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

[JASS] deal missile dmg while walking

Level 1
Joined
Sep 21, 2023
Messages
2
Hello everyone :),

This is my very first post. Please be nice to me xD.

I am semi-experienced in programming with JASS. I learn most of it here from you :).

I'm currently working on a project. I want to build the mobile game Brotato in Warcraft with multiplayer functions.
But now I'm failing at my first spell xD xD. I would like to be able to shoot the searing arrow while running.

I've put a lot of days into it and haven't gotten any results yet. The best thing I've managed so far is definitely the damage while running and the occasional arrow hitting the opponent.

Maybe there is someone here who has the desire and time to check my code for errors or give me suggestions for improvements (tips).

JASS:
library HeroStats // initializer FillHeroArray
    globals
        unit array evryhro
    endglobals

function FillHeroArray takes nothing returns nothing
    local unit u
    local integer loopvar = 0

    loop

        exitwhen loopvar >= bj_MAX_PLAYERS
        set u = FirstOfGroup(GetUnitsOfPlayerAll(Player(loopvar)))
           
        loop
            exitwhen u == null

            if IsUnitType(u, UNIT_TYPE_HERO) then
                set evryhro[loopvar] = u
            endif

            set u = null
        endloop

        set loopvar = loopvar + 1
    endloop
endfunction

function IsA000Hero takes unit hero returns boolean
    local integer spellId = 'A000' // Hier den ID-Code deiner Fähigkeit 'A000' einfügen
    return GetUnitAbilityLevel(hero, spellId) > 0
endfunction

function getXCoordinates takes unit u returns real
        return GetUnitX(u)
endfunction

function getYCoordinates takes unit u returns real
        return GetUnitY(u)
endfunction

function GetHeroStat takes unit hero, integer statType returns real
    local real statValue = 0.0
    if statType == 1 then
        // Stärke
        set statValue = GetHeroStr(hero, true)
    elseif statType == 2 then
        // Agilität
        set statValue = GetHeroAgi(hero, true)
    elseif statType == 3 then
        // Intelligenz
        set statValue = GetHeroInt(hero, true)
    endif
       
    return statValue
endfunction

function CalculateCriticalHit takes real critChance returns boolean
    local real randomValue = GetRandomReal(0.0, 1.0)
    return randomValue <= critChance
endfunction

endlibrary

JASS:
library GCU
   
    globals
       
    endglobals

function GetNearestUnitInGroup takes unit hero, rect customRangeRect, real maxRange returns unit
    local real x
    local real y
    local unit nearestUnit = null
    local real closestDist = maxRange
    local unit u
    local real dist
    local group units = CreateGroup()

    set x = GetUnitX(hero)
    set y = GetUnitY(hero)

    call GroupEnumUnitsInRect(units, customRangeRect, null)

    loop
   
        set u = FirstOfGroup(units)
        exitwhen u == null
    if not GetPlayerAlliance(GetOwningPlayer(u), GetOwningPlayer(hero), ALLIANCE_PASSIVE) then
            if GetUnitState(u, UNIT_STATE_LIFE) > 0 then
                set dist = SquareRoot(Pow(x - GetUnitX(u), 2) + Pow(y - GetUnitY(u), 2))

                if dist < closestDist then
                    set nearestUnit = u
                    set closestDist = dist
                endif
            endif
    endif

        call GroupRemoveUnit(units, u)
    endloop

    return nearestUnit
endfunction
   
endlibrary

JASS:
library MissileArrow // initializer InitMissileArrow
    globals
        private timer MissileArrowTimer
        private real missileInterval = 0.5 // Anpassbare Intervalle
    endglobals

    private function MissileArrowAction takes unit hero returns nothing
        local unit nearestEnemy
        local real spellLevel = GetUnitAbilityLevel(hero, 'A000')
    local real heroagi = GetHeroStat(hero, 2)
        local real damage = 100.0 + heroagi + (spellLevel * spellLevel * 25.0)
    local unit dummy

        set nearestEnemy = GetNearestUnitInGroup(hero, gg_rct_Fight_Area, 2000.0) // Adjust the maximum range as needed
        if nearestEnemy != null and GetUnitState(nearestEnemy, UNIT_STATE_LIFE) > 0 and GetUnitState(hero, UNIT_STATE_LIFE) > 0 then
        //set udg_ArrowUnit = CreateUnitAtLoc(GetOwningPlayer(hero), 'duca', GetUnitLoc(hero), bj_UNIT_FACING)
        set dummy = CreateUnitAtLoc(GetOwningPlayer(hero), 'duca', GetUnitLoc(hero), bj_UNIT_FACING)
        call SetUnitMoveSpeed(dummy, 5000.0)
        call IssueTargetOrderBJ( dummy, "attack", nearestEnemy )
        //call TriggerSleepAction(.5)
        if CalculateCriticalHit(spellLevel * 0.1) then
        set damage = damage * 2
                call show_textdamage(damage, true, nearestEnemy, hero)
        else
                call show_textdamage(damage, false, nearestEnemy, hero)
        endif
       
            if GetUnitState(nearestEnemy, UNIT_STATE_LIFE) <= 0.405 then
                set nearestEnemy = null
            endif
        call RemoveUnit(dummy)
        endif
    endfunction

    private function MissileArrowPeriodic takes nothing returns nothing
        local unit hero
        local group heroGroup = CreateGroup() // Create a new unit group
        local integer i

        set i = 0 // Initialize i
        loop
            exitwhen i >= bj_MAX_PLAYERS

            set hero = evryhro[i]

            if hero != null and IsA000Hero(hero) then
                call MissileArrowAction(hero)
                call GroupRemoveUnit(heroGroup, hero)
                set hero = FirstOfGroup(heroGroup)
                exitwhen hero == null
            endif
            set i = i + 1
        endloop

        call DestroyGroup(heroGroup)
    endfunction

    private function MissileArrowStart takes nothing returns nothing
        set MissileArrowTimer = CreateTimer()
        call TimerStart(MissileArrowTimer, missileInterval, true, function MissileArrowPeriodic)
    endfunction

    function InitMissileArrow takes nothing returns nothing
        call MissileArrowStart()
    endfunction

endlibrary



Kind regards
TeKey

P.S.: as a reminder, I'm semi good at Jass :-D
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
Hello, here's a system you may (see my first post). It's based on the missile systems in Battleship/Tanks maps:
Forgive me for not looking over your code but I'm feeling lazy at the moment.

This may be closer to Brotato, see my first post:
I created the basic foundation for a Vampire Survivors type map.

I find it best not to reinvent the wheel and instead use some of the great libraries that others have created over the years. Chopinski's Relativistic Missile system is perfect for something like this.
 
Last edited:
Level 1
Joined
Sep 21, 2023
Messages
2
Hello, here's a system you may (see my first post). It's based on the missile systems in Battleship/Tanks maps:
Forgive me for not looking over your code but I'm feeling lazy at the moment.

This may be closer to Brotato, see my first post:
I created the basic foundation for a Vampire Survivors type map.

I find it best not to reinvent the wheel and instead use some of the great libraries that others have created over the years. Chopinski's Relavistic Missile system is perfect for something like this.
Ok...... this is a lot of code.....
Damn this takes time to understand xD xD
First of all thank you very much <3 <3 <3 :D :D

your basic foundation is the right way i need, now i have to combine the spells from phoenix fire replacement with your foundation.
 
Top