• 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] Help with this code - Game crashes!!

Status
Not open for further replies.
I am just starting - this is my first code after reading Daelin's perfect tutorial. This trigger is supposed to cause a certain damage to the attacked unit, when a unit of type H000 attacks and the target takes the damage. Unfortunately the game is closed right after being attacked.

JASS:
function ManaLeakCond1 takes nothing returns boolean
    return GetUnitTypeId(GetAttacker()) == 'H000'
endfunction

function ManaLeakCond2 takes nothing returns boolean
   return udg_AE_ManaLeakActive
endfunction

function ManaLeakAndCond takes nothing returns boolean
    return GetBooleanAnd(ManaLeakCond1(), ManaLeakCond2())
endfunction

function ManaLeakDamage takes nothing returns nothing
    local integer Level
    local integer Int
    set udg_AE_ManaLeakDamage = 1.00
    set Int = 0
    set Level = GetUnitAbilityLevelSwapped('A003', udg_AECaster)
    loop
        exitwhen Int >= Level
        set udg_AE_ManaLeakDamage = udg_AE_ManaLeakDamage * 2
        set Int = Int + 1
    endloop
    call UnitDamageTargetBJ( udg_AECaster, udg_AE_ManaLeakTarget, udg_AE_ManaLeakDamage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    call SetUnitManaBJ (udg_AE_ManaLeakTarget, GetUnitStateSwap( UNIT_STATE_MANA, udg_AE_ManaLeakTarget) - udg_AE_ManaLeakDamage )
    call SetUnitManaBJ (udg_AECaster, GetUnitStateSwap( UNIT_STATE_MANA, udg_AECaster) - 1 )
    call DestroyTrigger(udg_AE_ManaLeakTrigger)
    set udg_AE_ManaLeakTrigger = null
    set udg_AE_ManaLeakTarget = null
    set udg_AECaster = null
endfunction

function ManaLeakAct takes nothing returns nothing
    set udg_AE_ManaLeakTarget = GetAttackedUnitBJ()
    set udg_AECaster = GetAttacker()
    set udg_AE_ManaLeakTrigger = CreateTrigger()
    call TriggerRegisterUnitEvent (udg_AE_ManaLeakTrigger, udg_AE_ManaLeakTarget, EVENT_UNIT_DAMAGED)
    call TriggerAddAction (udg_AE_ManaLeakTrigger, function ManaLeakDamage )
endfunction

//===========================================================================
function InitTrig_AE_Mana_Leak takes nothing returns nothing
    set gg_trg_AE_Mana_Leak = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_AE_Mana_Leak, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition (gg_trg_AE_Mana_Leak, Condition(function ManaLeakAndCond))
    call TriggerAddAction( gg_trg_AE_Mana_Leak, function ManaLeakAct )
endfunction

The spell name is Mana Leak. It's based on Defend, so I can activate and deactivate it. There's a trigger that changes AE_ManaLeakActive (I'm sure that the problem is not with that one). Hope I'm not wasting your time, maybe it's an idiot spelling mistake...

Already THANKS
Hossomi

[edit: Jass codes in this site looks beautiful :p]
 
Level 5
Joined
May 22, 2006
Messages
150
Try this. I got no specific idea, where your fault could be, but maybe it is already fixed now...

JASS:
function ManaLeakDamage takes nothing returns nothing
  local integer int
  set udg_AE_ManaLeakDamage = 1.00
  set int = GetUnitAbilityLevel(udg_AECaster,'A003')
  set udg_AE_ManaLeakDamage = udg_AE_ManaLeakDamage * Pow(2,int)
  call UnitDamageTarget(udg_AECaster,udg_AE_ManaLeakTarget,udg_AE_ManaLeakDamage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
  call SetUnitState(udg_AE_ManaLeakTarget,UNIT_STATE_MANA,RMaxBJ(0,GetUnitState(udg_AE_ManaLeakTarget,UNIT_STATE_MANA) - udg_AE_ManaLeakDamage))
  call SetUnitState(udg_AECaster,UNIT_STATE_MANA,RMaxBJ(0,GetUnitState(udg_AECaster,UNIT_STATE_MANA) - 1))
  set udg_AE_ManaLeakTarget = null
  set udg_AECaster = null
  call DestroyTrigger(udg_AE_ManaLeakTrigger)
endfunction
 
function ManaLeakAct takes nothing returns nothing
  if GetUnitTypeId(GetAttacker()) == 'H000' and udg_AE_ManaLeakActive then
    set udg_AE_ManaLeakTarget = GetTriggerUnit()
    set udg_AECaster = GetAttacker()
    set udg_AE_ManaLeakTrigger = CreateTrigger()
    call TriggerRegisterUnitEvent(udg_AE_ManaLeakTrigger,udg_AE_ManaLeakTarget,EVENT_UNIT_DAMAGED)
    call TriggerAddAction(udg_AE_ManaLeakTrigger,function ManaLeakDamage)
  endif
endfunction

function InitTrig_AE_Mana_Leak takes nothing returns nothing
  set gg_trg_AE_Mana_Leak = CreateTrigger()
  call TriggerRegisterAnyUnitEventBJ(gg_trg_AE_Mana_Leak,EVENT_PLAYER_UNIT_ATTACKED)
  call TriggerAddAction(gg_trg_AE_Mana_Leak,function ManaLeakAct)
endfunction

If it still does not work, write this into some places of the code:
JASS:
call BJDebugMsg("Part: <something, that identifies the part of code, we are inside now> ")
Then try and tell me, which of these messages appeared last before your game crashes.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
JASS:
local integer int
      [...]
      set int = GetUnitAbilityLevel(udg_AECaster,'A003')

thank god that you fixed 99% of the BJ calls, etc, etc in that code... i was dreading doing it :D

anyways, that can easily be

JASS:
local integer int = GetUnitAbilityLevel(udg_AECaster,'A003')

why didnt you do that in the first place? :p

also, GetBooleanAnd = WTF

instead of using those 3 functions, with the

JASS:
function a takes nothing returns boolean
return ThisIsACondition
endfunction

function b takes nothing returns boolean
return ThisIsAnotherCondition
endfunction

function And takes nothing returns boolean
return GetBooleanAnd( a,b )
endfunction

just write

JASS:
function And takes nothing returns boolean
return ThisIsACondition and ThisIsAnotherCondition
endfunction
 
hehahaha sorry PurplePoot, and thanks both for help :D
because, as I said, this is my first code, so I based on Converted GUI-JASS heheh

Sorry LordZsar1 for your work, rewriting almost all the code!

Well.. I've tried this many times to find where the problem is, and it is exactly in the UnitDamageTarget call.

Some questions LordZsar, why do you use RMaxBJ to change mana? And what are those 'true' and 'false' in DamageTarget?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
UnitDamageTarget is weird, and sometimes gets a litlle buggy

Anyways, idk what hes doing with the RMaxBJ, but for the UnitDamageTarget, try replacing WEAPON_TYPE_WHOKNOWS with null, and making sure the variables are all correctly assigned.

(and that Thank God You Cleaned Up The Script was direced to you, Zsar :p)
 
It doesn't work yet, but I've discovered more about this problem: it crashes just because the event of the local trigger is EVENT_UNIT_DAMAGED. I had another spell almost the same, and then I put everything in just one, with EVENT_PLAYER_UNIT_ATTACKED event, and it worked. The same happened with Mana Leak.

So I'll make Mana Leak with 'A unit is attacked' event, to finish with this :D
 
Level 11
Joined
Jul 12, 2005
Messages
764
The crash is caused by a deadly circle. The trigger fires when the unit is damaged, but the trigger damages that unit, tre trigger fires again, damages the unit, and so on.... This way, the trigger would run infinite times.
Solution:
Destroy the trigger first, and THEN damage the unit. If you destroy the trigger right after you declare the locals, the trigger will still run, it will not break the action.

And forget EVENT_UNIT_ATTACKED. That is what causes strange things and not UnitDamageTarget...
 
Level 5
Joined
May 22, 2006
Messages
150
Rewriting code (or writing code from description) is my way to have fun. ^^

That is the only cause, that makes me visiting this forum: One may ask for code, I may write.
I lack the stamina to create a whole map and metascript by myself. ^^
(started 12 maps, 3 AIs, 2 metascripts... finished none)

Hell, I should have seen this! ~~
As I wrote somewhere else: Sometimes I feel very stupid. ^^
 
Should this work?
It's supposed to create a kind of Wisp (a counter) at the position of the KillingUnit and store the group of Wisps as a handle attached to Kinara (the hero's name), but not if the number of Counters in the group is greater or equal to the level of the ability x2.

It seems to only create the unit...
(cut a lot of the code, but I think it's not important)

JASS:
function CounterUp takes nothing returns nothing
    local unit Kinara = GetKillingUnit()
    local unit Kill = GetDyingUnit()
    local group G = GetHandleGroup(Kinara, "Counters")
    local integer Level = GetUnitAbilityLevelSwapped( 'A019', Kinara )
    local integer Counters = CountUnitsInGroup(G)

    if (Counters < Level * 2) and (IsUnitEnemy(Kill, GetOwningPlayer(Kinara)) == true) and (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(Kill, UNIT_TYPE_ANCIENT) == false) and GetUnitTypeId(Kinara) == 'N002' then
        set Counters = Counters + 1
        set Ang = I2R(360 / Counters)
        call CreateUnit(GetOwningPlayer(Kinara), 'u00C', GetLocationX(GetUnitLoc(Kinara)), GetLocationY(GetUnitLoc(Kinara)), Ang)
        call GroupAddUnitSimple(GetLastCreatedUnit(), G)
        call SetHandleHandle( Kinara, "Counters", G )
    endif
    set G = null
    set Kinara = null
    set Kill = null
endfunction

Am I deluded or Handle Vars are like Attached Variables?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Excuse me while I maim you *jk*

Anyways, you have to have stored the group at some point, so the first time it will return null, which is not good

About attachable vars, they were BASED off the handle vars.

and, here we go, a few code review thingees

GetDyingUnit = bleh. Use GetTriggerUnit

and that abominably long condition can be shortened to this

JASS:
 if Counters < Level * 2 and IsUnitEnemy(Kill, GetOwningPlayer(Kinara)) and GetUnitTypeId(Kinara) == 'N002' and not (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) or IsUnitType(Kill, UNIT_TYPE_ANCIENT))
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
lol...

no.

A) atleast as far as i can see, you never created the group.

B) CreateUnit does not return GetLastCreatedUnit(). You'll have to set [variable] = CreateUnit( blah )

C) fix that GroupAddUnitSimple call :p. It should just be GroupAddUnit

D) Lookit what I said in the post after that code

E) Replace GetUnitAbilityLevelSwapped with GetUnitAbilityLevel

F) the variable Ang that you're using was never defined.
 
:shock: Yang bless me...

A. Create the group, you mean, CreateGroup()? (ohh ignorance)
B. Fixed
C. Fixed
D. Read and fixed
E. Fixed
F. In fact, it was, but I cut it by accident xD

Now I wrote an If that Set G = CreateGroup() if G == null, as there was in KaTTaNa's example...

It still doesn't work, but I'll try more tomorrow morning 'cause now I need to sleep... That's what night serves for...

Again and again, thanks PurplePoot
Hossomi
 
Oh sorry, there's some time I don't enter here due to a lack of time ^^'
JASS:
function CounterUp takes nothing returns nothing  local unit Kinara = GetKillingUnit()
local unit Kill = GetTriggerUnit()
local unit u
local group G = GetHandleGroup(Kinara, "Counters")
local integer Level = GetUnitAbilityLevel( Kinara, 'A019' )
local integer Counters = CountUnitsInGroup(G)
local real Ang = 0
if (Counters < Level * 2) and (IsUnitEnemy(Kill, GetOwningPlayer(Kinara)) == true) and GetUnitTypeId(Kinara) == 'N002' and not (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) == false) or (IsUnitType(Kill, UNIT_TYPE_ANCIENT) == false) then 
if G == null then
set G = CreateGroup()
endif
set Counters = Counters + 1
set Ang = I2R(360 / Counters)
set u = CreateUnit(GetOwningPlayer(Kinara), 'u00C', GetLocationX(GetUnitLoc(Kinara)), GetLocationY(GetUnitLoc(Kinara)), Ang)
call GroupAddUnit(G, u)
call SetHandleHandle( Kinara, "Counters", G )
endif
set G = null
set Kinara = null
set Kill = null
endfunction

I think I fixed everything here.
May I change CreateUnit to CreateNUnitsAtLoc? I saw somewhere that this was buggy..
 
Level 11
Joined
Jul 12, 2005
Messages
764
JASS:
GetUnitTypeId(Kinara) == 'N002' and not (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) == false) or (IsUnitType(Kill, UNIT_TYPE_ANCIENT) == false)
should be
JASS:
GetUnitTypeId(Kinara) == 'N002' and not (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) or IsUnitType(Kill, UNIT_TYPE_ANCIENT))
Shouldn't these go into the conditions of the trigger???

And:
JASS:
GetLocationX(GetUnitLoc(Kinara)), GetLocationY(GetUnitLoc(Kinara))
shold be
JASS:
GetUnitX(Kinara), GetUnitY(Kinara)
[/code]
 
Status
Not open for further replies.
Top