JASS Classroom, Lesson I

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Well, I got only 3 planned lessons, and each is one is almost as lengthy as a normal tutorial would be...
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
Is it impossible to use ctrl C and V in Jasscraft search function?
It gave an error.

edit: oO i didn't find anything for
Code:
SetUnitLife
ModifyHeroStat

in JAsscraft oO just the BJ functions... oO
 

mase

____ ___ ____ __
Reaction score
154
My 'mini-tests' are attached ><
 

Attachments

  • JASS I.txt
    1.7 KB · Views: 242

uberfoop

~=Admiral Stukov=~
Reaction score
177
edit: oO i didn't find anything for
Code:
SetUnitLife
ModifyHeroStat

in JAsscraft oO just the BJ functions... oO
Code:
native          SetUnitState        takes unit whichUnit, unitstate whichUnitState, real newVal returns nothing
Unit state can be like, UNIT_STATE_MANA or UNIT_STATE_LIFE
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
thanks!

oO this line doesn't work!!!!!!11111111111111

Code:
    native SetPlayerState   takes player TriggPlayer, gold whichPlayerState, ( TriggPlayer_Gold +  R2I(TriggUnit_MaxLife)) value returns nothing

code-order needed... please help...
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
I declare lesson I finished. Here are the 3 sent assignments.

My solution to the assignment.

JASS:
function ReplenishHero takes unit whichHero returns nothing
    local real    health = GetUnitState( whichHero, UNIT_STATE_MAX_LIFE )
    local real    mana   = GetUnitState( whichHero, UNIT_STATE_MAX_MANA )
    local player  p      = GetOwningPlayer(whichHero)
    local integer random = GetRandomInt( 0, 2 )
    
    if ( IsUnitType( whichHero, UNIT_TYPE_HERO ) == true ) then
        call SetUnitState( whichHero, UNIT_STATE_LIFE, health )
        call SetUnitState( whichHero, UNIT_STATE_MANA, mana )
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD ) + R2I(health) )
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER ) + R2I(mana) )
        if     ( random == 0 ) then
            call SetHeroAgi( whichHero, GetHeroAgi( whichHero, true ) + 1, true )
        elseif ( random == 1 ) then
            call SetHeroInt( whichHero, GetHeroInt( whichHero, true ) + 1, true )
        elseif ( random == 2 ) then
            call SetHeroStr( whichHero, GetHeroStr( whichHero, true ) + 1, true )
        endif
    endif
    
    set p = null
endfunction


Doom-Angels solution,

JASS:
function assignment takes unit u returns nothing
    local real    l = GetUnitState( u,UNIT_STATE_MAX_LIFE )
    local real    m = GetUnitState( u,UNIT_STATE_MAX_MANA )
    local integer r = GetRandomInt( 1, 3 )
    
    //if ( IsUnitType( u, UNIT_TYPE_HERO ) == true ) then
        call SetUnitState( u,UNIT_STATE_LIFE, l )
        call SetUnitState( u,UNIT_STATE_MANA, m )
        call SetPlayerState( GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, R2I(l) )
        call SetPlayerState( GetOwningPlayer(u), PLAYER_STATE_RESOURCE_LUMBER, R2I(m) )
        if     (r == 1) then
            call SetHeroStr(u,( GetHeroStr( u, false ) + 1 ), true )
        elseif (r == 2) then
            call SetHeroAgi(u,( GetHeroAgi( u, false ) + 1 ), true )
        elseif (r == 3) then
            call SetHeroInt(u,( GetHeroInt( u,false ) + 1 ), true )
        endif
    //endif
endfunction


Good Job. That is almost perfect. Only thing You forgot, was to check whether the unit is a hero.

Substances
solution,

JASS:
function IsUnitHero takes nothing returns boolean
    if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true then
        return true
    endif
    return false
    
    // return (IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true)
endfunction

function Assignment takes nothing returns nothing
    local player   p = GetTriggerPlayer()
    local boolexpr b = Condition(function IsUnitHero)
    
    // GetUnitsOfPlayerMatching =&gt;
    // local group    g = CreateGroup()
    // local boolexpr f = Condition( function IsUnithero )
    // call GroupEnumUnitsOfPlayer( g, p, f )
    local group    g = GetUnitsOfPlayerMatching(p,b)
    local integer  i = GetRandomInt(1,3)
    local unit     u
    
    //Unneeded, explained below.
    local integer array id
    set id[1]= bj_HEROSTAT_STR
    set id[2]= bj_HEROSTAT_AGI
    set id[3]= bj_HEROSTAT_INT
    
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call SetUnitState( u, UNIT_STATE_MANA, GetUnitState( u, UNIT_STATE_MAX_MANA ) )
        call SetUnitState( u, UNIT_STATE_LIFE, GetUnitState( u, UNIT_STATE_MAX_LIFE ) )
        call SetPlayerState( p,PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD ) + R2I(GetUnitState( u, UNIT_STATE_LIFE )) )
        call SetPlayerState( p,PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER ) + R2I(GetUnitState( u, UNIT_STATE_MANA )) )
        
        // ModifyHeroStat is a BJ. No arrays needed. To make it random. =&gt;
        // if     ( i == 0 ) then
        //     call SetHeroAgi( u, GetHeroAgi( u, true ) + 1, true )
        // elseif ( i == 1 ) then
        //     call SetHeroInt( u, GetHeroInt( u, true ) + 1, true )
        // elseif ( i == 2 ) then
        //     call SetHeroStr( u, GetHeroStr( u, true ) + 1, true )
        // endif
        call ModifyHeroStat( id<i>, u, id<i>, 1 )
        call GroupRemoveUnit(g,u)
        
        // &quot;Set u = null&quot; should be outside of the loop.
        set u = null
    endloop
endfunction</i></i>


The code should have been in one single function. In addition, I said the function takes a hero(an unit), so the looping procedure to find the unit is unnecessary.

IKilledKennys
solution,

JASS:
function act takes nothing returns nothing
    local group   grouped   = CreateGroup()
    local unit    picked
    local integer forloop   = 0
    local real    maxhealth
    local real    maxmana
    local integer gold
    local integer lumber
    local integer attribute
    local integer attbase
    local player  owner
    
    call GroupEnumUnitsInRect( grouped, GetWorldBounds(), null )
    loop
        set picked = FirstOfGroup(grouped) 
        //exitwhen ( IsUnitType( picked, UNIT_TYPE_HERO ) == true ) 
        exitwhen forloop == 1
        if IsUnitType(picked,UNIT_TYPE_HERO)==true then
            set forloop=1
        endif
        call GroupRemoveUnit(grouped,picked)
    endloop
    call DestroyGroup(grouped)
    
    set owner     = GetOwningPlayer(picked)
    set maxhealth = GetUnitState( picked,UNIT_STATE_MAX_LIFE )
    call SetUnitState( picked,UNIT_STATE_LIFE, maxhealth )
    set maxmana   = GetUnitState(picked,UNIT_STATE_MAX_MANA)
    call SetUnitState( picked, UNIT_STATE_MANA, maxmana )
    set gold      = GetPlayerState( owner, PLAYER_STATE_RESOURCE_GOLD )
    call SetPlayerState( owner, PLAYER_STATE_RESOURCE_GOLD, gold + R2I(maxhealth))
    set lumber    = GetPlayerState(owner,PLAYER_STATE_RESOURCE_LUMBER)
    
    //call SetPlayerState( owner, PLAYER_STATE_RESOURCE_LUMBER, lumber + R2I(maxmana))    
    call SetPlayerState( owner, PLAYER_STATE_RESOURCE_LUMBER, gold + R2I(maxmana))
    set attribute = GetRandomInt( 0, 2 )
    
    // GetHeroStatBJ... =&gt;
    // ModifyHeroStat is a BJ. To make it random =&gt;
    // if     ( attribute == 0 ) then
    //     call SetHeroAgi( picked, GetHeroAgi( picked, true ) + 1, true )
    // elseif ( attribute == 1 ) then
    //     call SetHeroInt( picked, GetHeroInt( picked, true ) + 1, true )
    // elseif ( attribute == 2 ) then
    //     call SetHeroStr( picked, GetHeroStr( picked, true ) + 1, true )
    // endif    
    set attbase   = GetHeroStatBJ( attribute, picked, false )
    call SetHeroStat( picked, attribute,( attbase + 1) )
    
    set grouped = null
    set picked  = null
    set owner   = null    
endfunction


You could have used less variables, that is a bit of an overkill. Anyway, no harm done with that. However, I said the function takes a hero(unit) so the procedure to find the unit is unnecessary.

Thanks for everyone, who participated. I hope this was a valueable lesson.:)
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
Almost perfect yay :p

so not much of the pupils made homework (or there weren't as many as i thought there were)

anyway when is the next lesson?
 

substance

New Member
Reaction score
34
The code should have been in one single function. In addition, I said the function takes a hero(an unit), so the looping procedure to find the unit is unnecessary.

Ahh, didnt know it had to be one function. Although, assuming the player had more than a few units it seems the boolean would be more efficient(depending on the event... mine was a player event)

And yes, the loop was incase the player had more than one hero unit =p

**edit, Oh and according to JASSCraft 'bj_HEROSTAT_STR' doesnt call another function... that's why i figured it was ok to use.
 
I

IKilledKEnny

Guest
Ah darn I didn't see you could do a function that takes unit. Oh well.

About the variables, I could have used about half of them, just to make is more readable though I used so many.

About the BJs, I know there are, however the function that they call is simple very long, and putting one or 2 BJs couldn't harm much. Also:

JASS:
if     ( random == 0 ) then
            call SetHeroAgi( whichHero, GetHeroAgi( whichHero, true ) + 1, true )
        elseif ( random == 1 ) then
            call SetHeroInt( whichHero, GetHeroInt( whichHero, true ) + 1, true )
        elseif ( random == 2 ) then
            call SetHeroStr( whichHero, GetHeroStr( whichHero, true ) + 1, true )


Could have been done like this:

JASS:
call SetHeroStat( picked, attribute,( attbase + 1) )


If you would look at the BJ, that what it does, simply shortened into one line.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
anyway when is the next lesson?

Soon enough. I maybe will make into a tutorial with assignments instead.

Although, assuming the player had more than a few units it seems the boolean would be more efficient(depending on the event... mine was a player event)

The assignment is following:

You have to make a function(not functions), which takes a hero typed unit, replenishes all its life- and mana points, gives the owner of the unit as many gold as many hitpoints the hero has plus as many lumber as many mana points the unit has. Also, the hero must receive +1 random attribute stat(str, agi or int).

**edit, Oh and according to JASSCraft 'bj_HEROSTAT_STR' doesnt call another function... that's why i figured it was ok to use.

Yes, but SetHeroStat is a BJ function.:)

Ah darn I didn't see you could do a function that takes unit. Oh well.

The assignment is following:

You have to make a function, which takes a hero typed unit...

:rolleyes:

About the variables, I could have used about half of them, just to make is more readable though I used so many.

Yeh, that is not such of a problem.;)

About the BJs, I know there are, however the function that they call is simple very long, and putting one or 2 BJs couldn't harm much.
If you would look at the BJ, that what it does, simply shortened into one line.

The length of the code itself does not matter. The amount of function calls does.


Anyway, thanks for all who participated.
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
oO shit, i couldn't finish my assignement :eek:
I think i will post it here today.

:(
:(
:(

Just had to many questions oO
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top