• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Looking for "Teacher"

Status
Not open for further replies.
Level 6
Joined
Jul 18, 2009
Messages
200
Im kinda new to vJASS. I wanted to learn how to use methods and/or structs.
So i wanted someone that could pm question to.
Anyone willing to?

PS: Im aware of that this post may be can be a little childish. But im serious. :hohum:
//Chaos_Knight
 
Level 13
Joined
May 11, 2008
Messages
1,198
you can pm me. i don't know much, but i might be able to answer some questions. i have been using structs and methods with success, even though i don't fully understand them.

i know that sounds funny, but what i mean is that i wouldn't know how to make up my own struct and method combination, but i've been copying the same sets and editing them as necessary. i can show you some examples if you want, but first i guess we gotta figure out what your questions are.
 
Level 6
Joined
Jul 18, 2009
Messages
200
I can help you with that but I've never used UAC; I'd prefer to make something like that from scratch.
Basically you're going to enumerate units around the owner of the aura, check the distance between their origins, and reduce strength for the enumerated unit per some math function.

Yeah, in the theory, it's very easy. But for me which does know a little, i dont even know how to enumrate in range. :sad:
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well when you enumerate units it uses a group to enumerate them to.

JASS:
function ForGroupFunc takes nothing returns nothing
    local unit picked=GetEnumUnit() //each enumerated unit will be passed through this function
    //say we wanted to add strength to enumerated units, only if they are heroes
    if(IsUnitType(picked, UNIT_TYPE_HERO)) then
        call SetHeroStr(picked, GetHeroStr(picked)+5)
    endif

    //remember that before the function ends the handle variable must be set to null
    set picked=null
endfunction

function EnumerateUnits takes nothing returns nothing
    local group g=CreateGroup()
    local real x=0 //this is the x-coordinate of the "in-range" point
    local real y=0 //this is the y-coordinate of the "in-range" point
    local real r=100 //this is the range that enumerates are enumerated from point x, y

    call GroupEnumUnitsInRange(g, x, y, r, null) //the null is a filter function that can filter out units
    //now that you have enumerated the units with the function, you can direct actions
    //towards those units by using ForGroup, such as:
    call ForGroup(g, function ForGroupFunc)
    //the ForGroupFunc is defined above, and each enumerated unit is referenced as GetEnumUnit()

    //because a group is a handle, it must be destroyed/nulled
    call DestroyGroup(g)
    set g=null
endfunction

JASS works in functions. Everything that "happens" in JASS is because of actions that are defined in functions.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
JASS:
globals
    constant integer  CLOSE_RANGE_BONUS    = 15
    constant integer  MEDIUM_RANGE_BONUS   = 10
    constant integer  LONG_RANGE_BONUS     = 5

    //it will also be useful to have the ranges that are associated with
    //the bonus values defined above
    constant real     CLOSE_RANGE          = 50
    constant real     MEDIUM_RANGE         = 75
    constant real     LONG_RANGE           = 100

    //we will also need the coordinates of the x/y that are used for the
    //group enumeration so that we can reference them in the enum func.
    real globX
    real globY
endglobals

function ForGroupFunc takes nothing returns nothing
    local unit picked=GetEnumUnit() //each enumerated unit will be passed through this function
    local real x=GetUnitX(picked)
    local real y=GetUnitY(picked)
    local real range
    //say we wanted to add strength to enumerated units, only if they are heroes
    if(IsUnitType(picked, UNIT_TYPE_HERO)) then

        //depending on the distance to the global coordinates the unit will
        //recieve a different bonus
        set range=SquareRoot((x-globX)*(x-globX) + (y-globY)*(y-globY))

        if(range<=CLOSE_RANGE) then
            call SetHeroStr(picked, GetHeroStr(picked)+CLOSE_RANGE_BONUS)
        elseif(range<=MEDIUM_RANGE) then
            call SetHeroStr(picked, GetHeroStr(picked)+MEDIUM_RANGE_BONUS)
        else 
            //the unit is automatically included in LONG_RANGE because that is the range parameter
            //of the group enumeration
            call SetHeroStr(picked, GetHeroStr(picked)+LONG_RANGE_BONUS)
        endif
    endif

    //remember that before the function ends the handle variable must be set to null
    set picked=null
endfunction

function EnumerateUnits takes nothing returns nothing
    local group g=CreateGroup()
    local real x=0 //this is the x-coordinate of the "in-range" point
    local real y=0 //this is the y-coordinate of the "in-range" point
    local real r=100 //this is the range that enumerates are enumerated from point x, y

    //instead of setting r to 100 we're going to use the constant values defined in globals
    set r=LONG_RANGE //units in CLOSE_RANGE and MEDIUM_RANGE will also be enumerated

    //setup the global x/y variables so they can be used in ForGroupFunc
    set globX=x
    set globY=y

    call GroupEnumUnitsInRange(g, x, y, r, null) //the null is a filter function that can filter out units
    //now that you have enumerated the units with the function, you can direct actions
    //towards those units by using ForGroup, such as:
    call ForGroup(g, function ForGroupFunc)
    //the ForGroupFunc is defined above, and each enumerated unit is referenced as GetEnumUnit()

    //because a group is a handle, it must be destroyed/nulled
    call DestroyGroup(g)
    set g=null
endfunction
 
Status
Not open for further replies.
Top