• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] First spell..

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
Hey,.. i couldnt find a tutorial that could really help me..
so i started messing around with the custom text place..
(Jass new gen, auto complete)

i did this:
made a gui trigger, added event + condition, changed to custom text
changed the condition to what ever i needed,
then added this:


JASS:
function Trig_Jass_Ability_Test_Conditions takes nothing returns boolean
        local string AbilityRawCode = "A000"
    if ( not ( GetSpellAbilityId() == S2I(AbilityRawCode) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Jass_Ability_Test_Actions takes nothing returns nothing
    local string AbilityRawCode = "A000"
    local string DummyRawCode = "Hpea"
    local location UnitSpawnLocation
    set UnitSpawnLocation = (GetRectCenter(gg_rct_Jass_Test))
    call CreateUnitAtLoc( Player(0), S2I(DummyRawCode), UnitSpawnLocation, 180 )
    call UnitAddAbility(GetLastCreatedUnit(), S2I(AbilityRawCode))
endfunction

//===========================================================================
function InitTrig_Jass_Ability_Test takes nothing returns nothing
    set gg_trg_Jass_Ability_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Jass_Ability_Test, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Jass_Ability_Test, Condition( function Trig_Jass_Ability_Test_Conditions ) )
    call TriggerAddAction( gg_trg_Jass_Ability_Test, function Trig_Jass_Ability_Test_Actions )
endfunction

i just want it to crete the unit.. thats all..
thanks for who ever can help..
 
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

Why so complicated. Ok I understand you converted GUI to Jass but this isn't all then. I fast recreate your trigger ( hope everything is correct now ^^ )

JASS:
function Trig_MyTrigger_Actions takes nothing returns nothing
    local real x = GetRectCenterX(gg_rct_Jass_Test)
    local real y = GetRectCenterY(gg_rct_Jass_Test)
    local unit u
    
        if GetSpellAbilityId() == 'A000' then
            set u = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'Hpea', Location(x, y), 180.00)
            call  UnitAddAbility(u, 'A000')
        endif
    
    set u = null
endfunction
//===========================================================================
function InitTrig_MyTrigger takes nothing returns nothing
    set gg_trg_MyTrigger = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MyTrigger, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_MyTrigger, function Trig_MyTrigger_Actions )
endfunction

Greetings
~ The Bomb King > Dr. Boom


'A000' Is the ability which have to be casted to run this trigger ( omg correct english? )
'Hpea' Is the unit you create.
 
Level 11
Joined
Apr 6, 2008
Messages
760
it look alot like converted GUI, prolly most of it is. well that dont mather we all gotta start some where

First of the Condition is more effective this way
also "A000" is wrong, its 'A000'. So the trigger won't run when you cast the spell. local string AbilityRawCode = "A000" is a really bad idea just input the rawcode right in to the function.

JASS:
function Trig_Jass_Ability_Test_Conditions takes nothing returns 
    return GetSpellAbilityId() == 'A000'
endfunction

again " " instead of ' '. Locations are bad just cords instead for a more effective code. I can also see some "BJ" functions, which are also bad cause it call an other function (Stupid too run 2 function instead of 1).

JASS:
function Trig_Jass_Ability_Test_Actions takes nothing returns nothing
    local location UnitSpawnLocation
    set UnitSpawnLocation = (GetRectCenter(gg_rct_Jass_Test))
    call CreateUnitAtLoc( Player(0), S2I(DummyRawCode), UnitSpawnLocation, 180 )
    call UnitAddAbility(GetLastCreatedUnit(), S2I(AbilityRawCode))
endfunction

this is how it should look

JASS:
function Trig_Jass_Ability_Test_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Trig_Jass_Ability_Test_Actions takes nothing returns nothing
    local location UnitSpawnLocation = (GetRectCenter(gg_rct_Jass_Test))
    call CreateUnitAtLoc( Player(0),'Hpea', UnitSpawnLocation, 180 )
    call UnitAddAbility(GetLastCreatedUnit(), 'A000')
    call RemoveLocation(UnitSpawnLocation)
endfunction


//===========================================================================
function InitTrig_Jass_Ability_Test takes nothing returns nothing
    set gg_trg_Jass_Ability_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Jass_Ability_Test, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Jass_Ability_Test, Condition( function Trig_Jass_Ability_Test_Conditions ) )
    call TriggerAddAction( gg_trg_Jass_Ability_Test, function Trig_Jass_Ability_Test_Actions )
endfunction

EDIT:

JASS:
function Trig_MyTrigger_Actions takes nothing returns boolean
    local unit u
    
        if GetSpellAbilityId() == 'A000' then
            set u = GetTriggerUnit()
            set u = CreateUnit(GetOwningPlayer(u), 'Hpea',GetRectCenterX(gg_rct_Jass_Test), GetRectCenterY(gg_rct_Jass_Test)), 180.00)
            call  UnitAddAbility(u, 'A000')
            set u = null
        endif

    return false
endfunction
//===========================================================================
function InitTrig_MyTrigger takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondtion( trig, Contion(function Trig_MyTrigger_Actions) )
endfunction
 
Level 11
Joined
Apr 6, 2008
Messages
760
GetTriggerUnit() will leak

JASS:
GetUnitTypeId(GetTriggerUnit())

JASS:
function Action takes nothing returns nothing
    local unit u = GetTriggerUnit()

    //STUFF

    set u = null
    //Null u when you are done with it
endfunction
 
Level 11
Joined
Sep 12, 2008
Messages
657
well.. i dont really care about leaks atm, but thanks, ill try using it from now =]
btw..how do i make a cheak how much life did my unit lost by
call UnitDamageTargetBJ(u, u, 10, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)?
i tried to make it chaos, then basicly heal 10, but still.. (healed 2-3 extra..)
it kept increasing my life.. any help would be necesery, thanks =]

Edit: Fixed it.. (set life of unit before damage, then set it back after damage.)
 
Last edited:
GetTriggerUnit() will leak
GetTriggerUnit() doesn't leak at all. It doesn't even create any object.

how do i make a cheak how much life did my unit lost by
call UnitDamageTargetBJ(u, u, 10, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)?
You have to use DAMAGE_TYPE_UNKNOWN (+Attack chaos) to have no damage reducing. Or you can use the difference between the unit's life before and after damaging to get the damages that are actually dealt.
EDIT : You got it.

Also, you can't use every fonctions in a trigger condition (like TriggerSleepAction). And you can't use GetLastCreatedUnit() after creating a unit without a BJ (such as CreateUnit and CreateUnitAtLoc).
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
GetTriggerUnit() will leak

It's actually the reference variable that will cause the "leak" in this case. The unit's handle ID will not be recycled if you don't set the variable that references GetTriggerUnit( ) (in your script) to null (but you do). The actual native GetTriggerUnit( ) won't cause a memory leak when used by itself, like: BJDebugMsg(GetUnitName(GetTriggerUnit( ))) will not like.
 
Level 11
Joined
Apr 6, 2008
Messages
760
Also, you can't use every fonctions in a trigger condition (like TriggerSleepAction). And you can't use GetLastCreatedUnit() after creating a unit without a BJ (such as CreateUnit and CreateUnitAtLoc).

GetLastCreatedUnit() just returns a unit from a function. bj_lastCreatedUnit is a globals variable hardcoded in wc3. So using GetLastCreatedUnit() would just be slower then just applying too bj_lastCreatedUnit, but my self i just rather make a global/local variable and use that instead.

JASS:
function GetLastCreatedUnit takes nothing returns unit
    return bj_lastCreatedUnit
endfunction

this is how the BJ version work.

JASS:
function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction

So in order "to get" the create unit you have to save it in a variable like this

JASS:
local unit u = CreateUnit(//Blah)

As you see CreateUnit() returns unit, the unit you created as you can see here. notice also it a "native" function. You should try to use only natives if you can (Cause most non natives call an other function like i metioned before)

JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit

All function is jass will Take and return parameters (even if the takes/returns nothing). Takes mean the function need those take parameters to work properly. And Return is the parameter the native will return

In this case the native will return unit (Spawned unit)

player id Takes a player like Player(0)
integer unitid is the rawcode of the unit to be create eg. 'A000'
real x, real y is the cordination to create the unit surely you have worked with cordinates in school
real face is the degree the unit should face when he spawns
return unit refeers that the native will return the unit spawned

Here is an other eg.

JASS:
function Add takes integer a, integer b returns integer
    return a + b
endfunction

So if i wanna call this function i do call Add(1,2)

But since its a call the return wont really mather but if i do

JASS:
local integer Sum = Add(1,2)

It will set Sum too 3
 
Status
Not open for further replies.
Top