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...
SetUnitLife
ModifyHeroStat
edit: oO i didn't find anything for
Code:SetUnitLife ModifyHeroStat
in JAsscraft oO just the BJ functions... oO
native SetUnitState takes unit whichUnit, unitstate whichUnitState, real newVal returns nothing
native SetPlayerState takes player TriggPlayer, gold whichPlayerState, ( TriggPlayer_Gold + R2I(TriggUnit_MaxLife)) value returns nothing
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
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
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 =>
// 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. =>
// 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)
// "Set u = null" should be outside of the loop.
set u = null
endloop
endfunction</i></i>
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... =>
// ModifyHeroStat is a BJ. To make it random =>
// 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
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.
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 )
call SetHeroStat( picked, attribute,( attbase + 1) )
anyway when is the next lesson?
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.
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...
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.
If you would look at the BJ, that what it does, simply shortened into one line.